StockInController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Common.Utility;
  7. using Bowin.Web.Controls.Mvc;
  8. using EMIS.CommonLogic.TeachingMaterial;
  9. using EMIS.ViewModel;
  10. using EMIS.ViewModel.TeachingMaterial;
  11. using EMIS.Web.Controls;
  12. using Bowin.Common.Data;
  13. using EMIS.CommonLogic.SystemServices;
  14. using EMIS.CommonLogic.CalendarManage;
  15. using System.IO;
  16. using EMIS.Utility;
  17. namespace EMIS.Web.Controllers.TeachingMaterial
  18. {
  19. [Authorization]
  20. public class StockInController : Controller
  21. {
  22. public IStockInServices StockInServices { get; set; }
  23. //编号生成
  24. public ISerialNumberServices SerialNumberServices { get; set; }
  25. public IStockInDetailServices StockInDetailServices { get; set; }
  26. public ISchoolYearServices SchoolYearServices { get; set; }
  27. public ISupplierDiscountSetServices supplierDiscountSetServices { get; set; }
  28. /// <summary>
  29. /// 教材入库页面
  30. /// </summary>
  31. /// <returns></returns>
  32. [HttpGet]
  33. public ActionResult List()
  34. {
  35. var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  36. ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年
  37. return View();
  38. }
  39. [HttpPost]
  40. public ActionResult List(QueryParamsModel pararms)
  41. {
  42. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  43. //避开全选值
  44. int? isLate = isLate = pararms.getExtraInt("LateDropdown");
  45. DateTime? startStockInTime = DateTime.Now;
  46. DateTime? endStockInTime = DateTime.Now;
  47. Guid? supplierID = pararms.getExtraGuid("PublishDropdown");
  48. Guid? schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");
  49. endStockInTime = pararms.getExtraDateTime("EndStockInTime");
  50. startStockInTime = pararms.getExtraDateTime("StartStockInTime");
  51. return base.Json(StockInServices.GetStockInViewGrid(configuretView, schoolyearID, supplierID, startStockInTime, endStockInTime, isLate,
  52. new List<int?> { (int)CF_StockInType.PurchasingStockIn }, (int)pararms.page, (int)pararms.rows));
  53. }
  54. [HttpGet]
  55. public ActionResult ReturnList()
  56. {
  57. var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  58. ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年
  59. return View();
  60. }
  61. [HttpPost]
  62. public ActionResult ReturnList(QueryParamsModel pararms)
  63. {
  64. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  65. //避开全选值
  66. int? isLate = isLate = pararms.getExtraInt("LateDropdown");
  67. DateTime? startStockInTime = DateTime.Now;
  68. DateTime? endStockInTime = DateTime.Now;
  69. Guid? supplierID = pararms.getExtraGuid("PublishDropdown");
  70. Guid? schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");
  71. endStockInTime = pararms.getExtraDateTime("EndStockInTime");
  72. startStockInTime = pararms.getExtraDateTime("StartStockInTime");
  73. return base.Json(StockInServices.GetStockInViewGrid(configuretView, schoolyearID, supplierID, startStockInTime, endStockInTime, isLate,
  74. new List<int?> { (int)CF_StockInType.Return }, (int)pararms.page, (int)pararms.rows));
  75. }
  76. [HttpGet]
  77. public ActionResult Edit(Guid? stockInID)
  78. {
  79. var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  80. StockInView stockInView;
  81. if (stockInID != null && stockInID != Guid.Empty)
  82. {
  83. stockInView = StockInServices.GetSingleStockIn(stockInID.Value);
  84. }
  85. else
  86. {
  87. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  88. var defaultsupplier = supplierDiscountSetServices.GetSupplierDiscountSetViewList(configuretView, true, null).FirstOrDefault();
  89. Guid? defaultID = null;
  90. if (defaultsupplier != null)
  91. {
  92. defaultID = supplierDiscountSetServices.GetSupplierDiscountSetViewList(configuretView, true, null).FirstOrDefault().PublishID;
  93. }
  94. //ViewBag.DefaultID = defaultID;
  95. string keyValue = SerialNumberServices.SetSN(DateTime.Now.ToString("yyyyMMdd"));
  96. var stockInType = Convert.ToInt32(Request.Params["stockInType"]);//获取入库默认类型
  97. stockInView = new StockInView()
  98. {
  99. StockInNumber = keyValue,
  100. StockInType = stockInType,
  101. StockInDocumentNo = StockInServices.GetStockInNo((CF_StockInType)stockInType),
  102. StockInID = Guid.Empty,
  103. SchoolyearID = schoolYear.SchoolyearID,
  104. StockInDJTime = DateTime.Now,
  105. SupplierID = defaultID
  106. };
  107. }
  108. return View(stockInView);
  109. }
  110. [HttpPost]
  111. public ActionResult Edit(StockInView stockInView)
  112. {
  113. try
  114. {
  115. string type = Request.Params["hid_ApprovalStatusName"];//0 保存 1 提交
  116. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  117. var TMList = DataGrid.GetTableData<TeachingMaterialPoolView>("dgStockInTMSelectList");//获取底部列表项数据
  118. if (TMList == null || TMList.Count <= 0)
  119. {
  120. return Json(new ReturnMessage()
  121. {
  122. IsSuccess = false,
  123. Message = "操作失败,原因:教材信息不能为空。"
  124. });
  125. }
  126. else
  127. {
  128. StockInServices.Save(stockInView, TMList, user.UserID, type);
  129. }
  130. return Json(new ReturnMessage()
  131. {
  132. IsSuccess = true,
  133. Message = "保存成功。"
  134. });
  135. }
  136. catch (Exception ex)
  137. {
  138. return Json(new ReturnMessage()
  139. {
  140. IsSuccess = false,
  141. Message = "保存失败,原因:" + ex.Message
  142. });
  143. }
  144. }
  145. /// <summary>
  146. /// Excel 导出
  147. /// </summary>
  148. /// <returns></returns>
  149. [HttpPost]
  150. public ActionResult Excel()
  151. {
  152. NpoiExcelHelper neh = new NpoiExcelHelper();
  153. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  154. int? isLate = isLate = Request.Form["LateDropdown"].ParseStrTo<int>();
  155. Guid? supplierID = Request.Form["PublishDropdown"].ParseStrTo<Guid>();
  156. Guid? schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo<Guid>();
  157. DateTime? startStockInTime = DateTime.Now;
  158. DateTime? endStockInTime = DateTime.Now;
  159. endStockInTime = DateTime.Parse(Request.Form["EndStockInTime"]);
  160. startStockInTime = DateTime.Parse(Request.Form["StartStockInTime"]);
  161. var dt = StockInServices.GetStockInViewList(configuretView, schoolyearID, supplierID, startStockInTime, endStockInTime, isLate,
  162. new List<int?> { (int)CF_StockInType.PurchasingStockIn }).Select(x => new
  163. {
  164. x.SchoolyearName,
  165. x.StockInDocumentNo,
  166. x.SupplierName,
  167. x.HandlerUserName,
  168. x.StockInDJTime,
  169. x.StockInSumMoneyStr,
  170. x.Desc
  171. }).ToTable();
  172. string[] liststring = { "学年学期", "入库单据号", "供应商", "经手人", "入库单据日期", "入库总金额", "备注" };
  173. neh.Export(dt, liststring, "入库管理信息");
  174. return RedirectToAction("MsgShow", "Common", new
  175. {
  176. msg = "导出成功!",
  177. url = Url.Content("~/StockIn/List").AddMenuParameter()
  178. });
  179. }
  180. /// <summary>
  181. /// 删除
  182. /// </summary>
  183. /// <param name="roleID"></param>
  184. /// <returns></returns>
  185. [HttpPost]
  186. public ActionResult Delete(string stockInIDs)
  187. {
  188. try
  189. {
  190. var stockInIDList = stockInIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
  191. StockInServices.Delete(stockInIDList);
  192. return base.Json("删除成功。");
  193. }
  194. catch (Exception ex)
  195. {
  196. string mge = ex.Message;
  197. // System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  198. return base.Json("删除失败,原因:" + mge);
  199. }
  200. }
  201. /// <summary>
  202. /// 添加教材
  203. /// </summary>
  204. /// <returns></returns>
  205. public ActionResult TeachingMaterial()
  206. {
  207. var supplierID = Request["SupplierID"].ParseStrTo<Guid>();
  208. decimal? discount;
  209. if (supplierID.HasValue)
  210. {
  211. discount = supplierDiscountSetServices.GetDiscountByPublishID((Guid)supplierID);
  212. }
  213. else {
  214. discount = null;
  215. }
  216. ViewBag.Discount = discount;
  217. ViewBag.SupplierID = supplierID;
  218. return View();
  219. }
  220. /// <summary>
  221. /// 教材入库列表
  222. /// </summary>
  223. /// <returns></returns>
  224. [HttpGet]
  225. public ActionResult GetStockInByTMList()
  226. {
  227. return View();
  228. }
  229. /// <summary>
  230. /// 查询教材入库列表
  231. /// </summary>
  232. /// <param name="pararms"></param>
  233. /// <returns></returns>
  234. [HttpPost]
  235. public ActionResult GetStockInByTMList(QueryParamsModel pararms)
  236. {
  237. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  238. var teachingMaterialPoolID = pararms.getExtraGuid("TeachingMaterialDropdown");
  239. var teachingMaterialCodeID = pararms.getExtraGuid("TeachingMaterialCodeDropdown");
  240. Guid? publishID = pararms.getExtraGuid("PublishDropdown");
  241. var schoolyearID = pararms.getExtraGuid("SchoolyearID");
  242. var supplierID = pararms.getExtraGuid("SupplierID");
  243. decimal? discount = 1;
  244. if (supplierID.HasValue)
  245. {
  246. discount = supplierDiscountSetServices.GetDiscountByPublishID((Guid)supplierID);
  247. }
  248. return base.Json(StockInServices.GetStockInByTeachingMaterialPoolViewGrid(configuretView, schoolyearID, teachingMaterialPoolID, teachingMaterialCodeID, discount, (int)pararms.page, (int)pararms.rows));
  249. }
  250. /// <summary>
  251. ///
  252. /// </summary>
  253. /// <param name="stockIn"></param>
  254. /// <returns></returns>
  255. [HttpPost]
  256. public ActionResult GetTMViewList(Guid? stockIn)
  257. {
  258. if (stockIn.HasValue)
  259. {
  260. var resultList = StockInServices.GetStockInByTMViewList(stockIn.Value);
  261. return Json(new JsonDataGridResult<TeachingMaterialPoolView> { rows = resultList, total = resultList.Count });
  262. }
  263. else
  264. {
  265. return Json(new JsonDataGridResult<TeachingMaterialPoolView>());
  266. }
  267. }
  268. /// <summary>
  269. /// 教材入库明细
  270. /// </summary>
  271. /// <param name="stockInID"></param>
  272. /// <returns></returns>
  273. [HttpGet]
  274. public ActionResult StockInDetailList(string stockInID)
  275. {
  276. if (!string.IsNullOrEmpty(stockInID))
  277. ViewData["stockInID"] = stockInID;
  278. return View();
  279. }
  280. /// <summary>
  281. /// 教材入库明细
  282. /// </summary>
  283. /// <param name="pararms"></param>
  284. /// <returns></returns>
  285. [HttpPost]
  286. public ActionResult StockInDetailList(QueryParamsModel pararms)
  287. {
  288. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  289. Guid? stockId = Request["stockId"].ParseStrTo<Guid>();
  290. return base.Json(StockInDetailServices.GetStockInDetailViewGrid(stockId, (int)pararms.page, (int)pararms.rows));
  291. }
  292. /// <summary>
  293. /// Excel 导出
  294. /// </summary>
  295. /// <returns></returns>
  296. [HttpPost]
  297. public ActionResult StockInDetailExcel(Guid? stockId)
  298. {
  299. NpoiExcelHelper neh = new NpoiExcelHelper();
  300. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  301. var dt = StockInDetailServices.GetStockInDetailViewList(configuretView, stockId).Select(x => new
  302. {
  303. x.SchoolyearName,
  304. x.StockInDocumentNo,
  305. x.StockInNumber,
  306. x.TeachingMaterialCode,
  307. x.TeachingMaterialName,
  308. x.PublishName,
  309. x.SupplierName,
  310. x.PublishTime,
  311. x.Author,
  312. x.Quantity,
  313. x.Price,
  314. x.DiscountStr,
  315. x.DiscountPriceStr,
  316. x.TotalPriceStr,
  317. x.TotalDollarStr,
  318. x.HandlerUserName,
  319. x.StockInUserName,
  320. x.StockInTime
  321. }).ToTable();
  322. string[] liststring = { "学年学期", "入库单据号", "入库编号", "教材编号", "教材名称", "供应商",
  323. "出版单位", "版本时间", "作者", "数量", "单价", "折扣率", "折合价", "码洋", "总价", "经手人", "入库人", "入库日期" };
  324. neh.Export(dt, liststring, "入库明细信息");
  325. return RedirectToAction("MsgShow", "Common", new
  326. {
  327. msg = "导出成功!",
  328. url = Url.Content("~/StockInDetail/List").AddMenuParameter()
  329. });
  330. }
  331. /// <summary>
  332. /// 提交
  333. /// </summary>
  334. /// <param name="roleID"></param>
  335. /// <returns></returns>
  336. [HttpPost]
  337. public ActionResult Submit(string stockInIDs)
  338. {
  339. try
  340. {
  341. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  342. var stockInIDList = stockInIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
  343. StockInServices.Submit(stockInIDList, user.UserID);
  344. return base.Json("提交入库成功。");
  345. }
  346. catch (Exception ex)
  347. {
  348. string mge = ex.Message;
  349. return base.Json("提交入库失败,原因:" + mge);
  350. }
  351. }
  352. /// <summary>
  353. ///
  354. /// </summary>
  355. /// <param name="errorFile"></param>
  356. /// <returns></returns>
  357. [HttpGet]
  358. public ActionResult Import(string errorFile)
  359. {
  360. ViewBag.ErrorFile = errorFile;
  361. return View();
  362. }
  363. [HttpPost]
  364. public ActionResult Import(HttpPostedFileBase file)
  365. {
  366. try
  367. {
  368. //1.0 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls
  369. //2.0 XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx
  370. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  371. {
  372. throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
  373. }
  374. return null;
  375. }
  376. catch (Exception ex)
  377. {
  378. return RedirectToAction("MsgShow", "Common", new
  379. {
  380. WindowID = Request["WindowID"],
  381. msg = "导入失败,原因:" + ex.Message + "!",
  382. url = Url.Action("List").AddMenuParameter()
  383. });
  384. }
  385. }
  386. /// <summary>
  387. /// 自动入库(根据采购计划自动入库)
  388. /// </summary>
  389. /// <returns></returns>
  390. [HttpGet]
  391. public ActionResult AutoNewStockIn()
  392. {
  393. var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true).SchoolyearID;
  394. ViewData["schoolYear"] = schoolYear;
  395. return View();
  396. }
  397. /// <summary>
  398. /// 自动入库确定(根据学生征订和教师征订)
  399. /// </summary>
  400. /// <param name="schoolyearID"></param>
  401. /// <returns></returns>
  402. [HttpPost]
  403. public ActionResult AutoNewStockIn(Guid? schoolyearID)
  404. {
  405. try
  406. {
  407. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  408. StockInServices.AutoNewStockIn(schoolyearID, user.UserID);
  409. return Json(new ReturnMessage()
  410. {
  411. IsSuccess = true,
  412. Message = "入库成功。"
  413. });
  414. }
  415. catch (Exception ex)
  416. {
  417. return Json(new ReturnMessage()
  418. {
  419. IsSuccess = false,
  420. Message = "入库失败,原因:" + ex.Message
  421. });
  422. }
  423. }
  424. }
  425. }