三元财务API

archivesController.cs 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using CallCenterApi.Interface.Controllers.Base;
  6. using System.Web.Mvc;
  7. using System.Data;
  8. using CallCenterApi.DB;
  9. using System.IO;
  10. using System.Data.SqlClient;
  11. using CallCenterApi.Interface.Models.Dto;
  12. using CallCenterApi.Interface.Controllers.workorder;
  13. using CallCenterApi.Interface.Models.Enum;
  14. using CallCenter.Utility;
  15. using CallCenterApi.Interface.Models.Filter;
  16. using CallCenterApi.Interface.Models.Input;
  17. using CallCenterApi.Model;
  18. using CallCenterApi.Interface.Models.Common;
  19. using NPOI.SS.UserModel;
  20. using NPOI.XSSF.UserModel;
  21. using NPOI.HSSF.UserModel;
  22. using Newtonsoft.Json;
  23. using CallCenterApi.Common;
  24. namespace CallCenterApi.Interface.Controllers.archives
  25. {
  26. public class archivesController : BaseController
  27. {
  28. CallCenterApi.BLL.archives archivesbll = new BLL.archives();
  29. // GET: archives
  30. /// <summary>
  31. /// 查询档案物资表数据信息
  32. /// </summary>
  33. /// <returns></returns>
  34. public ActionResult GetList(int PageIndex, int PageSize,string A_archiveName)
  35. {
  36. #region 分页显示档案物资
  37. if (PageIndex == 0)
  38. {
  39. PageIndex = 1;
  40. }
  41. if (PageSize == 0)
  42. {
  43. PageSize = 10;
  44. }
  45. var sql = "";
  46. ///按名称模糊查询
  47. if (A_archiveName!=null)
  48. {
  49. if(A_archiveName!="")
  50. {
  51. sql += " and A_archiveName like '%" + A_archiveName + "%' ";
  52. }
  53. }
  54. Model.PageData<Model.archives> pageModel = new Model.PageData<Model.archives>();
  55. var recordCount = 0;
  56. var dt = BLL.PagerBLL.GetListPager(
  57. " (select * from ((SELECT ROW_NUMBER() OVER (PARTITION BY archives.id ORDER BY Operationlog.OperationDate DESC ) AS rid,archives.*,Operationlog.OperationContent,Operationlog.OperationDate,archivestate.stateName from archives left join Operationlog on Operationlog.archivesid=archives.id left join archivestate on archives.A_archiveState=archivestate.id )) t where rid=1 ) a",// archives as a left join archivestate as s on a.A_archiveState=s.id left join Operationlog as o on a.id=o.archivesid
  58. "a.id",
  59. "*",//a.*,s.stateName as stateName,o.OperationContent,o.OperationDate
  60. sql,
  61. "ORDER BY a.id desc ",
  62. PageSize,
  63. PageIndex,
  64. true,
  65. out recordCount);
  66. List<Model.archives> modelList = new BLL.archives().DataTableToList(dt);
  67. var list = new List<Model.archives>();
  68. foreach (var item in modelList)
  69. {
  70. list.Add(new Model.archives
  71. {
  72. id = item.id,
  73. A_archiveCode = item.A_archiveCode,
  74. A_archiveName = item.A_archiveName,
  75. A_archiveState = item.A_archiveState,
  76. A_archivePeople = item.A_archivePeople,
  77. stateName = item.stateName,
  78. OperationContent = item.OperationContent,
  79. OperationDate = item.OperationDate
  80. });
  81. }
  82. var obj = new
  83. {
  84. rows = list,
  85. total = recordCount
  86. };
  87. return Content(obj.ToJson());
  88. #endregion
  89. }
  90. /// <summary>
  91. /// 查询是否存在该数据
  92. /// </summary>
  93. /// <param name="id"></param>
  94. /// <returns></returns>
  95. public bool IfHave(int id)
  96. {
  97. var a = archivesbll.IfHave(id);
  98. return archivesbll.IfHave(id);
  99. }
  100. public ActionResult GetModelarchives(int id)
  101. {
  102. var model = archivesbll.GetModel(id);
  103. if (model == null)
  104. return Error("该信息不存在");
  105. var obj = new Model.archives
  106. {
  107. id = model.id,
  108. A_archiveCode=model.A_archiveCode,
  109. A_archiveName =model.A_archiveName,
  110. A_archiveState=model.A_archiveState,
  111. A_archivePeople =model.A_archivePeople,
  112. stateName = model.stateName,
  113. OperationContent = model.OperationContent,
  114. OperationDate = model.OperationDate
  115. };
  116. return Success("获取成功", obj);
  117. }
  118. /// <summary>
  119. /// 添加档案物资信息
  120. /// </summary>
  121. /// <param name="archive"></param>
  122. /// <returns></returns>
  123. public ActionResult AddorUpdateArchives(archivesInput archive)
  124. {
  125. var model = new CallCenterApi.Model.archives();
  126. if (archive.isadd <= 0)
  127. {
  128. model.A_archiveCode = archive.A_archiveCode;//关联客户表中的F_CustomerCode客户编号 关联显示客户名称
  129. model.A_archiveName = archive.A_archiveName;//物资名称
  130. if (archive.A_archiveState == 0)
  131. {
  132. model.A_archiveState = 1;//物资状态 关联物质状态表中的主键id 下拉选择
  133. }
  134. else {
  135. model.A_archiveState = archive.A_archiveState;//物资状态 关联物质状态表中的主键id 下拉选择
  136. }
  137. model.A_archivePeople =CurrentUser.UserData.F_UserCode; // //操作人 archive.A_archivePeople
  138. var archivesid = archivesbll.Add(model);
  139. if (archivesid > 0)
  140. {
  141. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  142. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;// CurrentUser.UserData.F_UserCode;//
  143. Operationlogmodel.OperationDate = DateTime.Now;
  144. Operationlogmodel.OperationContent = "添加了一条物资档案信息物资名称为:"+ archive.A_archiveName;
  145. Operationlogmodel.archivesid = archivesid;
  146. AddorUpdOperationlog(Operationlogmodel);
  147. return Success("添加档案成功" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  148. }
  149. else
  150. {
  151. return Error("添加档案失败" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  152. }
  153. }
  154. else {
  155. model = archivesbll.GetModel(archive.id);
  156. var archname = model.A_archiveName;
  157. if (model == null)
  158. return Error("该档案不存在");
  159. //model.F_SortModel = input.F_SortModel;
  160. model.A_archiveCode = archive.A_archiveCode;
  161. model.A_archiveName = archive.A_archiveName;
  162. model.A_archiveState = archive.A_archiveState;
  163. var uarchiveid = archive.id;
  164. //model.A_archiveRecord = archive.A_archiveRecord;
  165. model.A_archivePeople = CurrentUser.UserData.F_UserCode;// CurrentUser.UserData.F_UserCode;//操作人archive.A_archivePeople
  166. var people = archive.A_archivePeople;
  167. if (archivesbll.Update(model))
  168. {
  169. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  170. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;// CurrentUser.UserData.F_UserCode;
  171. Operationlogmodel.OperationDate = DateTime.Now;
  172. Operationlogmodel.OperationContent = "修改了一条物资档案信息";
  173. Operationlogmodel.archivesid = uarchiveid;
  174. AddorUpdOperationlog(Operationlogmodel);
  175. return Success("修改档案成功" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  176. }
  177. else {
  178. return Error("修改档案失败" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  179. }
  180. }
  181. }
  182. /// <summary>
  183. /// 删除档案物资信息
  184. /// </summary>
  185. /// <param name="id"></param>
  186. /// <returns></returns>
  187. public ActionResult DeleteQuestion(int id)
  188. {
  189. if (archivesbll.Delete(id))
  190. {
  191. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  192. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  193. Operationlogmodel.OperationDate = DateTime.Now;
  194. Operationlogmodel.OperationContent = "删除了一条物资档案信息";
  195. Operationlogmodel.archivesid = id;
  196. AddorUpdOperationlog(Operationlogmodel);
  197. return Success("删除档案成功" + ",操作人:" + CurrentUser.UserData.F_UserCode); ;
  198. }
  199. else
  200. {
  201. return Error("删除档案失败!" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  202. }
  203. }
  204. /// <summary>
  205. /// 获取档案状态数据信息
  206. /// </summary>
  207. /// <returns></returns>
  208. public ActionResult GetArchivestate()
  209. {
  210. DataTable dt = new DataTable();
  211. dt = archivesbll.GetArchivestate().Tables[0];
  212. return Success("加载成功", dt);
  213. }
  214. /// <summary>
  215. /// 添加档案状态信息
  216. /// </summary>
  217. /// <param name="archive"></param>
  218. /// <returns></returns>
  219. public ActionResult Addorarchivestate(archivestateInput archivestate)
  220. {
  221. var model = new CallCenterApi.Model.archivestate();
  222. model.stateName = archivestate.stateName;//状态名
  223. var archivesid = archivesbll.Addarchivestate(model);
  224. if (archivesid > 0)
  225. {
  226. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  227. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;//操作人
  228. Operationlogmodel.OperationDate = DateTime.Now;
  229. Operationlogmodel.OperationContent = "添加了一条物资状态信息";
  230. // Operationlogmodel.archivesid = archivesid;
  231. AddorUpdOperationlog(Operationlogmodel);
  232. return Success("添加成功" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  233. }
  234. else
  235. {
  236. return Error("添加失败" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  237. }
  238. }
  239. /// <summary>
  240. /// 删除物资状态信息
  241. /// </summary>
  242. /// <param name="id"></param>
  243. /// <returns></returns>
  244. public ActionResult delarchivestate(int id)
  245. {
  246. if (archivesbll.delarchivestate(id))
  247. {
  248. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  249. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  250. Operationlogmodel.OperationDate = DateTime.Now;
  251. Operationlogmodel.OperationContent = "删除了一条物资状态信息";
  252. //Operationlogmodel.archivesid = id;
  253. AddorUpdOperationlog(Operationlogmodel);
  254. return Success("删除成功" + ",操作人:" + CurrentUser.UserData.F_UserCode); ;
  255. }
  256. else
  257. {
  258. return Error("删除失败!" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  259. }
  260. }
  261. /// <summary>
  262. /// 获取外部客户操作表信息
  263. /// </summary>
  264. /// <returns></returns>
  265. public ActionResult GetCustomerBorrow(int PageIndex, int PageSize)
  266. {
  267. //DataTable dt = new DataTable();
  268. //dt = archivesbll.GetCustomerBorrow().Tables[0];
  269. //return Success("加载成功", dt);
  270. if (PageIndex == 0)
  271. {
  272. PageIndex = 1;
  273. }
  274. if (PageSize == 0)
  275. {
  276. PageSize = 10;
  277. }
  278. #region 分页显示客户操作人员的操作信息
  279. var sql = " ";
  280. Model.PageData<Model.customerBorrow> pageModel = new Model.PageData<Model.customerBorrow>();
  281. var recordCount = 0;
  282. var dt = BLL.PagerBLL.GetListPager(
  283. " customerBorrow as c left join archives as a on c.archivesid=a.id ",
  284. "c.id",
  285. "c.*,a.A_archiveName as A_archiveName",
  286. sql,
  287. "ORDER BY c.id desc ",
  288. PageSize,
  289. PageIndex,
  290. true,
  291. out recordCount);
  292. var list = archivesbll.DataTableToListcustomerBorrow(dt);
  293. var obj = new
  294. {
  295. rows = list.Select(x => new
  296. {
  297. id = x.id,
  298. archivesid = x.archivesid,
  299. BorrowOreturn= x.BorrowOreturn,
  300. BorrowDate = x.BorrowDate,
  301. BorrowPeople = x.BorrowPeople,
  302. A_archiveName=x.A_archiveName
  303. }),
  304. total = recordCount
  305. };
  306. return Content(obj.ToJson());
  307. #endregion
  308. }
  309. /// <summary>
  310. /// 添加与修改外部客户信息
  311. /// </summary>
  312. /// <param name="archive"></param>
  313. /// <returns></returns>
  314. public ActionResult AddorUpdateCustomerBorrow(customerBorrowInput customerBorrow)
  315. {
  316. var model = new CallCenterApi.Model.customerBorrow();
  317. if (customerBorrow.isadd <= 0)
  318. {
  319. ///修改物资状态为借阅中
  320. //根据状态名称获取状态id
  321. var isBorrow = customerBorrow.BorrowOreturn.ToString();
  322. var stateid = 1;
  323. if (isBorrow.Contains("借阅"))
  324. {
  325. stateid = archivesbll.GetStateid("借阅中");
  326. }
  327. else {
  328. stateid = archivesbll.GetStateid("在库");
  329. }
  330. //根据获取到的状态id修改物资状态
  331. var upstate = archivesbll.updateState(Convert.ToInt32(customerBorrow.archivesid), stateid);
  332. ///添加客户操作信息
  333. model.archivesid = customerBorrow.archivesid;//物品编号
  334. model.BorrowOreturn = customerBorrow.BorrowOreturn;//区分借阅还是归还
  335. model.BorrowDate = DateTime.Now;//客户操作时间
  336. model.BorrowPeople = CurrentUser.UserData.F_UserCode;// CurrentUser.UserData.F_UserCode ; //操作人customerBorrow.BorrowPeople
  337. var archivesid = customerBorrow.archivesid;
  338. if (archivesbll.AddCustomerBorrow(model) > 0)
  339. {
  340. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  341. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  342. Operationlogmodel.OperationDate = DateTime.Now;
  343. Operationlogmodel.OperationContent = "添加了一条借阅归还信息";
  344. Operationlogmodel.archivesid = archivesid;
  345. AddorUpdOperationlog(Operationlogmodel);
  346. return Success("添加成功" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  347. }
  348. else
  349. {
  350. return Error("添加失败" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  351. }
  352. }
  353. else
  354. {
  355. model = archivesbll.GetCustomerModel(customerBorrow.id);
  356. if (model == null)
  357. return Error("该信息不存在");
  358. //model.F_SortModel = input.F_SortModel;
  359. var uparchvieid = customerBorrow.archivesid;
  360. model.archivesid = customerBorrow.archivesid;
  361. model.BorrowOreturn = customerBorrow.BorrowOreturn;
  362. model.BorrowDate = customerBorrow.BorrowDate;
  363. model.BorrowPeople = CurrentUser.UserData.F_UserCode;// CurrentUser.UserData.F_UserCode;//操作人customerBorrow.BorrowPeople
  364. if (archivesbll.UpCustomerBorrow(model))
  365. {
  366. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  367. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  368. Operationlogmodel.OperationDate = DateTime.Now;
  369. Operationlogmodel.OperationContent = "修改了一条借阅归还信息";
  370. Operationlogmodel.archivesid = uparchvieid;
  371. AddorUpdOperationlog(Operationlogmodel);
  372. return Success("修改成功" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  373. }
  374. else
  375. {
  376. return Error("修改失败" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  377. }
  378. }
  379. }
  380. /// <summary>
  381. /// 删除一条客户操作的数据信息
  382. /// </summary>
  383. /// <param name="id"></param>
  384. /// <returns></returns>
  385. public ActionResult DelCustomerBorrow(int id)
  386. {
  387. var model = new CallCenterApi.Model.archives();
  388. model = archivesbll.GetModel(id);
  389. var archivesid = model.id;
  390. if (archivesbll.delCustomerBorrow(id))
  391. {
  392. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  393. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  394. Operationlogmodel.OperationDate = DateTime.Now;
  395. Operationlogmodel.OperationContent = "删除了一条借阅归还信息";
  396. Operationlogmodel.archivesid = archivesid;
  397. AddorUpdOperationlog(Operationlogmodel);
  398. return Success("删除成功" + ",操作人:" + CurrentUser.UserData.F_UserCode); ;
  399. }
  400. else
  401. {
  402. return Error("删除失败!" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  403. }
  404. }
  405. /// <summary>
  406. /// 获取内部员工操作表信息
  407. /// </summary>
  408. /// <returns></returns>
  409. public ActionResult GetinsideOperation(int PageIndex, int PageSize)
  410. {
  411. #region 基础查询 暂时不用
  412. //DataTable dt = new DataTable();
  413. //dt = archivesbll.GetinsideOperation().Tables[0];
  414. //return Success("加载成功", dt);
  415. #endregion
  416. #region 分页显示内部员工出入库的操作信息
  417. if (PageIndex == 0)
  418. {
  419. PageIndex = 1;
  420. }
  421. if (PageSize == 0)
  422. {
  423. PageSize = 10;
  424. }
  425. var sql = " ";
  426. Model.PageData<Model.insideOperation> pageModel = new Model.PageData<Model.insideOperation>();
  427. var recordCount = 0;
  428. var dt = BLL.PagerBLL.GetListPager(
  429. " insideOperation as c left join archives as a on c.archivesid=a.id ",
  430. "c.id",
  431. "c.*,a.A_archiveName as A_archiveName",
  432. sql,
  433. "ORDER BY c.id desc ",
  434. PageSize,
  435. PageIndex,
  436. true,
  437. out recordCount);
  438. var list = archivesbll.DataTableToListinsideOperation(dt);
  439. var obj = new
  440. {
  441. rows = list.Select(x => new
  442. {
  443. id = x.id,
  444. archivesid =x.archivesid,
  445. Warehousing =x.Warehousing,
  446. WarehousingDate =x.WarehousingDate,
  447. Operator =x.Operator,
  448. A_archiveName = x.A_archiveName
  449. }),
  450. total = recordCount
  451. };
  452. return Content(obj.ToJson());
  453. #endregion
  454. }
  455. /// <summary>
  456. /// 添加与修改内部员工信息
  457. /// </summary>
  458. /// <param name="archive"></param>
  459. /// <returns></returns>
  460. public ActionResult AddorUpdateinsideOperation(insideOperationInput insideOperation)
  461. {
  462. var model = new CallCenterApi.Model.insideOperation();
  463. if (insideOperation.isadd <= 0)
  464. {
  465. ///修改物资状态为借阅中
  466. //根据状态名称获取状态id
  467. var isBorrow = insideOperation.Warehousing.ToString();
  468. var stateid = 1;
  469. if (isBorrow.Contains("入库"))
  470. {
  471. stateid = archivesbll.GetStateid("在库");
  472. }
  473. else
  474. {
  475. stateid = archivesbll.GetStateid("已出库");
  476. }
  477. //根据获取到的状态id修改物资状态
  478. var upstate = archivesbll.updateState(Convert.ToInt32(insideOperation.archivesid), stateid);
  479. model.archivesid = insideOperation.archivesid;//物品编号
  480. model.Warehousing = insideOperation.Warehousing;//区分入库还是出库
  481. model.WarehousingDate = DateTime.Now;//操作时间
  482. model.Operator = CurrentUser.UserData.F_UserCode;// CurrentUser.UserData.F_UserCode; //操作人insideOperation.Operator
  483. var arvichid = insideOperation.archivesid;
  484. if (archivesbll.AddinsideOperation(model) > 0)
  485. {
  486. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  487. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  488. Operationlogmodel.OperationDate = DateTime.Now;
  489. Operationlogmodel.OperationContent = "添加了一条出入库信息";
  490. Operationlogmodel.archivesid = arvichid;
  491. AddorUpdOperationlog(Operationlogmodel);
  492. return Success("添加成功" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  493. }
  494. else
  495. {
  496. return Error("添加失败" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  497. }
  498. }
  499. model = archivesbll.GetinsideOperationModel(insideOperation.id);
  500. if (model == null)
  501. return Error("该信息不存在");
  502. //model.F_SortModel = input.F_SortModel;
  503. var archiveid = insideOperation.archivesid;
  504. model.archivesid = insideOperation.archivesid;
  505. model.Warehousing = insideOperation.Warehousing;
  506. model.WarehousingDate = DateTime.Now;
  507. model.Operator = CurrentUser.UserData.F_UserCode;// CurrentUser.UserData.F_UserCode;//操作人insideOperation.Operator
  508. if (archivesbll.UpinsideOperation(model))
  509. {
  510. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  511. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  512. Operationlogmodel.OperationDate = DateTime.Now;
  513. Operationlogmodel.OperationContent = "修改了一条出入库信息";
  514. Operationlogmodel.archivesid = archiveid;
  515. AddorUpdOperationlog(Operationlogmodel);
  516. return Success("修改成功" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  517. }
  518. else
  519. {
  520. return Error("修改失败" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  521. }
  522. }
  523. /// <summary>
  524. /// 删除一条内部员工出入库信息
  525. /// </summary>
  526. /// <param name="id"></param>
  527. /// <returns></returns>
  528. public ActionResult DelinsideOperation(int id)
  529. {
  530. var model = new CallCenterApi.Model.archives();
  531. model = archivesbll.GetModel(id);
  532. var archivesid = model.id;
  533. if (archivesbll.delinsideOperation(id))
  534. {
  535. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  536. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  537. Operationlogmodel.OperationDate = DateTime.Now;
  538. Operationlogmodel.OperationContent = "删除了一条出入库信息";
  539. Operationlogmodel.archivesid = archivesid;
  540. AddorUpdOperationlog(Operationlogmodel);
  541. return Success("删除成功" + ",操作人:" + CurrentUser.UserData.F_UserCode); ;
  542. }
  543. else
  544. {
  545. return Error("删除失败!" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  546. }
  547. }
  548. /// <summary>
  549. /// 获取操作记录表信息
  550. /// </summary>
  551. /// <returns></returns>
  552. public ActionResult GetOperationlog(int PageIndex, int PageSize)
  553. {
  554. #region 基础查询 暂时不用
  555. //DataTable dt = new DataTable();
  556. //dt = archivesbll.GetOperationlog().Tables[0];
  557. //return Success("加载成功", dt);
  558. #endregion
  559. #region 分页显示内部员工出入库的操作信息
  560. if (PageIndex == 0)
  561. {
  562. PageIndex = 1;
  563. }
  564. if (PageSize == 0)
  565. {
  566. PageSize = 10;
  567. }
  568. var sql = " ";
  569. Model.PageData<Model.Operationlog> pageModel = new Model.PageData<Model.Operationlog>();
  570. var recordCount = 0;
  571. var dt = BLL.PagerBLL.GetListPager(
  572. " Operationlog as c left join archives as a on c.archivesid=a.id ",
  573. "c.id",
  574. "c.*,a.A_archiveName as A_archiveName",
  575. sql,
  576. "ORDER BY c.id desc ",
  577. PageSize,
  578. PageIndex,
  579. true,
  580. out recordCount);
  581. var list = archivesbll.DataTableToListOperationlog(dt);
  582. var obj = new
  583. {
  584. rows = list.Select(x => new
  585. {
  586. id = x.id,
  587. archivesid = x.archivesid,
  588. Operator = x.Operator,
  589. OperationContent = x.OperationContent,
  590. OperationDate = x.OperationDate,
  591. A_archiveName = x.A_archiveName
  592. }),
  593. total = recordCount
  594. };
  595. return Content(obj.ToJson());
  596. #endregion
  597. }
  598. /// <summary>
  599. /// 添加与修改操作日志信息
  600. /// </summary>
  601. /// <param name="archive"></param>
  602. /// <returns></returns>
  603. public ActionResult AddorUpdOperationlog(OperationlogInput Operationlog)
  604. {
  605. var model = new CallCenterApi.Model.Operationlog();
  606. model.Operator = CurrentUser.UserData.F_UserCode;//操作人
  607. model.OperationContent = Operationlog.OperationContent;//操作内容
  608. model.OperationDate = DateTime.Now;//操作时间
  609. model.archivesid = Operationlog.archivesid;
  610. if (archivesbll.AddOperationlog(model) > 0)
  611. return Success("添加成功" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  612. return Error("添加失败" + ",操作人:" + CurrentUser.UserData.F_UserCode);
  613. }
  614. /// <summary>
  615. /// excel档案物资导入
  616. /// </summary>
  617. /// <returns></returns>
  618. public ActionResult ImportExcelarchives()
  619. {
  620. int userId = CurrentUser.UserData.F_UserId;
  621. HttpPostedFile _upFile = RequestString.GetFile("upFile");
  622. if (_upFile != null)
  623. {
  624. int headrow = 0;
  625. string filepath = "";
  626. string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
  627. string aLastName = _upFile.FileName.Substring(_upFile.FileName.LastIndexOf(".") + 1, (_upFile.FileName.Length - _upFile.FileName.LastIndexOf(".") - 1)); //扩展名
  628. if (aLastName != "xls" && aLastName != "xlsx")
  629. {
  630. return Error("文件类型错误,请选择Excel文件");
  631. }
  632. string newpath = datepath + "_" + _upFile.FileName;
  633. if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
  634. {
  635. Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
  636. }
  637. filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
  638. string PhysicalPath = Server.MapPath(filepath);
  639. _upFile.SaveAs(PhysicalPath);
  640. ///添加上传日志
  641. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  642. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  643. model_T_Sys_Accessories.F_FileName = _upFile.FileName;//附件名称
  644. model_T_Sys_Accessories.F_FileType = "exce";//附件类型
  645. model_T_Sys_Accessories.F_FileUrl = filepath;//附件地址
  646. model_T_Sys_Accessories.F_Size = _upFile.ContentLength;
  647. model_T_Sys_Accessories.F_UserCode = CurrentUser.UserData.F_UserCode;//上传人
  648. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  649. DataTable dt = new DataTable();
  650. IWorkbook workbook = null;
  651. using (FileStream file = new FileStream(PhysicalPath, FileMode.Open, FileAccess.Read))
  652. {
  653. if (aLastName == "xlsx") // 2007版本
  654. {
  655. workbook = new XSSFWorkbook(file);
  656. }
  657. else if (aLastName == "xls") // 2003版本
  658. {
  659. workbook = new HSSFWorkbook(file);
  660. }
  661. }
  662. ISheet sheet = workbook.GetSheetAt(0);
  663. System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  664. //获取sheet的第一行
  665. IRow headerRow = sheet.GetRow(headrow);
  666. int cellCount = headerRow.LastCellNum;
  667. if (cellCount < 1)
  668. return Error("文件标题没有数据");
  669. for (int j = 0; j < cellCount; j++)
  670. {
  671. ICell cell = headerRow.GetCell(j);
  672. dt.Columns.Add(cell.ToString());
  673. }
  674. BLL.archives bll = new BLL.archives();
  675. var pbll = new BLL.archives();
  676. var list = pbll.DataTableToList(pbll.GetList().Tables[0]);
  677. int count = 0;
  678. ////客户名称加入来电单位
  679. for (int i = (sheet.FirstRowNum + headrow + 1); i <= sheet.LastRowNum; i++)
  680. {
  681. IRow row = sheet.GetRow(i);
  682. DataRow dataRow = dt.NewRow();
  683. for (int j = row.FirstCellNum; j < cellCount; j++)
  684. {
  685. if (row.GetCell(j) != null)
  686. dataRow[j] = row.GetCell(j).ToString();
  687. }
  688. dt.Rows.Add(dataRow);
  689. if (dt.Rows.Count < 1)
  690. return Error("文件内容没有数据");
  691. //导入后要插入数据库
  692. var model = new Model.archives();
  693. //Model.T_RepositoryCategory pModel = new BLL.T_RepositoryCategory().GetModel(int.Parse(pid.Trim()));
  694. var pmodel = list.FirstOrDefault();
  695. model.A_archiveCode = dataRow[0].ToString();
  696. model.A_archiveName = dataRow[1].ToString();
  697. model.fileid = fid;
  698. if (dataRow[2] == null)
  699. {
  700. model.A_archiveState = 1;
  701. }
  702. else
  703. {
  704. model.A_archiveState = int.Parse(dataRow[2].ToString());
  705. }
  706. model.A_archivePeople = CurrentUser.UserData.F_UserCode;//操作人
  707. int n = bll.Add(model);
  708. if (n > 0)
  709. {
  710. var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  711. Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  712. Operationlogmodel.OperationDate = DateTime.Now;
  713. Operationlogmodel.OperationContent = "导入了一条物资档案信息";
  714. Operationlogmodel.archivesid = n;
  715. AddorUpdOperationlog(Operationlogmodel);
  716. count++;
  717. }
  718. }
  719. if (dt == null || dt.Rows.Count == 0)
  720. return Error("文件没有数据");
  721. else
  722. {
  723. var jstr = DataTableToJson(dt);
  724. return Success("导入成功 " + count + "条信息", jstr);
  725. }
  726. }
  727. return Error("文件不能为空");
  728. }
  729. /// <summary>
  730. /// 档案物资导出
  731. /// </summary>
  732. /// <param name="dt"></param>
  733. /// <returns></returns>
  734. /// <summary>
  735. /// 档案物资导出excel
  736. /// </summary>
  737. /// <returns></returns>
  738. public ActionResult ExportExcelarchives()
  739. {
  740. #region 获取数据
  741. DataTable dt = new DataTable();
  742. string str = "SELECT A_archiveCode AS '客户编号',A_archiveName AS'物资名称 ',A_archiveState AS '物资状态',A_archivePeople AS '操作人' FROM archives where 1=1 ORDER BY id desc";
  743. dt = DbHelperSQL.Query(str).Tables[0];
  744. foreach (DataRow dr in dt.Rows)
  745. {
  746. dr["客户编号"] = Utils.DropHTML(dr["客户编号"].ToString());
  747. }
  748. #endregion
  749. NPOIHelper npoi = new NPOIHelper();
  750. if (npoi.ExportToExcel("所有物资", dt) == "")
  751. {
  752. return Success("导出成功");
  753. }
  754. else
  755. {
  756. return Error("导出失败");
  757. }
  758. }
  759. #region 暂时不用
  760. ///// <summary>
  761. ///// 档案物资状态导入excel
  762. ///// </summary>
  763. ///// <returns></returns>
  764. //public ActionResult ImportExcelarchivesTate()
  765. //{
  766. // HttpPostedFile _upFile = RequestString.GetFile("upFile");
  767. // if (_upFile != null)
  768. // {
  769. // int headrow = 0;
  770. // string filepath = "";
  771. // string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
  772. // string aLastName = _upFile.FileName.Substring(_upFile.FileName.LastIndexOf(".") + 1, (_upFile.FileName.Length - _upFile.FileName.LastIndexOf(".") - 1)); //扩展名
  773. // if (aLastName != "xls" && aLastName != "xlsx")
  774. // {
  775. // return Error("文件类型错误,请选择Excel文件");
  776. // }
  777. // string newpath = datepath + "_" + _upFile.FileName;
  778. // if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
  779. // {
  780. // Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
  781. // }
  782. // filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
  783. // string PhysicalPath = Server.MapPath(filepath);
  784. // _upFile.SaveAs(PhysicalPath);
  785. // DataTable dt = new DataTable();
  786. // IWorkbook workbook = null;
  787. // using (FileStream file = new FileStream(PhysicalPath, FileMode.Open, FileAccess.Read))
  788. // {
  789. // if (aLastName == "xlsx") // 2007版本
  790. // {
  791. // workbook = new XSSFWorkbook(file);
  792. // }
  793. // else if (aLastName == "xls") // 2003版本
  794. // {
  795. // workbook = new HSSFWorkbook(file);
  796. // }
  797. // }
  798. // ISheet sheet = workbook.GetSheetAt(0);
  799. // System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  800. // //获取sheet的第一行
  801. // IRow headerRow = sheet.GetRow(headrow);
  802. // int cellCount = headerRow.LastCellNum;
  803. // if (cellCount < 1)
  804. // return Error("文件标题没有数据");
  805. // for (int j = 0; j < cellCount; j++)
  806. // {
  807. // ICell cell = headerRow.GetCell(j);
  808. // dt.Columns.Add(cell.ToString());
  809. // }
  810. // BLL.archives bll = new BLL.archives();
  811. // var pbll = new BLL.archives();
  812. // var list = pbll.DataTableToList1(pbll.GetArchivestate().Tables[0]);
  813. // int count = 0;
  814. // ////
  815. // for (int i = (sheet.FirstRowNum + headrow + 1); i <= sheet.LastRowNum; i++)
  816. // {
  817. // IRow row = sheet.GetRow(i);
  818. // DataRow dataRow = dt.NewRow();
  819. // for (int j = row.FirstCellNum; j < cellCount; j++)
  820. // {
  821. // if (row.GetCell(j) != null)
  822. // dataRow[j] = row.GetCell(j).ToString();
  823. // }
  824. // dt.Rows.Add(dataRow);
  825. // if (dt.Rows.Count < 1)
  826. // return Error("文件内容没有数据");
  827. // //导入后要插入数据库
  828. // var model = new Model.archivestate();
  829. // //Model.T_RepositoryCategory pModel = new BLL.T_RepositoryCategory().GetModel(int.Parse(pid.Trim()));
  830. // var pmodel = list.FirstOrDefault();
  831. // model.stateName = dataRow[0].ToString();
  832. // int n = bll.Addarchivestate(model);
  833. // if (n > 0)
  834. // {
  835. // var Operationlogmodel = new CallCenterApi.Interface.Models.Input.OperationlogInput();
  836. // Operationlogmodel.Operator = CurrentUser.UserData.F_UserCode;
  837. // Operationlogmodel.OperationDate = DateTime.Now;
  838. // Operationlogmodel.OperationContent = "导入了一条物资档案状态信息";
  839. // AddorUpdOperationlog(Operationlogmodel);
  840. // count++;
  841. // }
  842. // }
  843. // if (dt == null || dt.Rows.Count == 0)
  844. // return Error("文件没有数据");
  845. // else
  846. // {
  847. // var jstr = DataTableToJson(dt);
  848. // return Success("导入成功 " + count + "条信息", jstr);
  849. // }
  850. // }
  851. // return Error("文件不能为空");
  852. //}
  853. #endregion
  854. #region 暂时不用
  855. ///// <summary>
  856. ///// 档案物资状态导出
  857. ///// </summary>
  858. ///// <param name="dt"></param>
  859. ///// <returns></returns>
  860. ///// <summary>
  861. ///// 档案物资状态导出excel
  862. ///// </summary>
  863. ///// <returns></returns>
  864. //public ActionResult ExportExcel()
  865. //{
  866. // #region 获取数据
  867. // DataTable dt = new DataTable();
  868. // string str = "SELECT stateName AS '物资状态' FROM archivestate where 1=1 ORDER BY id desc";
  869. // dt = DbHelperSQL.Query(str).Tables[0];
  870. // foreach (DataRow dr in dt.Rows)
  871. // {
  872. // dr["物资状态"] = Utils.DropHTML(dr["物资状态"].ToString());
  873. // }
  874. // #endregion
  875. // NPOIHelper npoi = new NPOIHelper();
  876. // if (npoi.ExportToExcel("所有物资状态", dt) == "")
  877. // {
  878. // return Success("导出成功");
  879. // }
  880. // else
  881. // {
  882. // return Error("导出失败");
  883. // }
  884. //}
  885. #endregion
  886. public string DataTableToJson(DataTable dt)
  887. {
  888. string JsonString = string.Empty;
  889. JsonString = JsonConvert.SerializeObject(dt);
  890. return JsonString;
  891. }
  892. }
  893. }