StockInStatisticsController.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 System.Data;
  14. using EMIS.CommonLogic.CalendarManage;
  15. namespace EMIS.Web.Controllers.TeachingMaterial
  16. {
  17. public class StockInStatisticsController : Controller
  18. {
  19. public IStockInDetailServices StockInDetailServices { get; set; }
  20. public ISchoolYearServices SchoolYearServices { get; set; }
  21. /// <summary>
  22. /// 入库统计页面
  23. /// </summary>
  24. /// <returns></returns>
  25. [HttpGet]
  26. public ActionResult List()
  27. {
  28. //默认当前学年
  29. var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  30. ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();
  31. return View();
  32. }
  33. [HttpPost]
  34. public ActionResult List(QueryParamsModel pararms)
  35. {
  36. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  37. //避开全选值
  38. Guid? supplierID = null;
  39. Guid? schoolyearID = null;
  40. Guid? teachingMaterialID = null;
  41. supplierID = pararms.getExtraGuid("PublishDropdown");
  42. schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");
  43. teachingMaterialID = pararms.getExtraGuid("TeachingMaterialDropdown");
  44. return base.Json(StockInDetailServices.GetStockInStatisticsViewGrid(configuretView, schoolyearID, supplierID, teachingMaterialID, (int)pararms.page, (int)pararms.rows));
  45. }
  46. #region 2.0 页面数据Excel导出
  47. /// <summary>
  48. /// Excel 导出
  49. /// </summary>
  50. /// <returns></returns>
  51. [HttpPost]
  52. public ActionResult Excel()
  53. {
  54. NpoiExcelHelper neh = new NpoiExcelHelper();
  55. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  56. Guid? supplierID = null;
  57. Guid? schoolyearID = null;
  58. Guid? teachingMaterialID = null;
  59. supplierID = Request.Form["PublishDropdown"].ParseStrTo<Guid>();
  60. schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo<Guid>();
  61. teachingMaterialID = Request.Form["TeachingMaterialDropdown"].ParseStrTo<Guid>();
  62. var dt = StockInDetailServices.GetStockInStatisticsVieList(configuretView, schoolyearID, supplierID, teachingMaterialID).Select(x => new
  63. {
  64. x.SchoolyearName,
  65. //x.StockInDocumentNo,
  66. //x.StockInType,
  67. x.TeachingMaterialCode,
  68. x.TeachingMaterialName,
  69. x.SupplierName,
  70. x.PublishName,
  71. x.PublishTime,
  72. x.Author,
  73. x.Quantity,
  74. x.Price,
  75. x.DiscountStr,
  76. x.DiscountPriceStr,
  77. x.TotalPriceStr,
  78. x.TotalDollarStr
  79. //x.HandlerUserName,
  80. //x.StockInUserName,
  81. //x.StockInTime
  82. }).ToTable();
  83. int sumQuantity = 0;
  84. decimal sumTotalPrice = 0;
  85. decimal sumTotalDollar = 0;
  86. foreach(DataRow dr in dt.Rows)
  87. {
  88. int quantity = (int)dr["Quantity"];
  89. decimal totalPrice = (decimal)dr["TotalPriceStr"];
  90. decimal totalDollar = (decimal)dr["TotalDollarStr"];
  91. sumQuantity += quantity;
  92. sumTotalPrice += totalPrice;
  93. sumTotalDollar += totalDollar;
  94. }
  95. //新增合计数量、码洋、实洋的行
  96. DataRow newrow = dt.NewRow();
  97. newrow["SchoolyearName"] = "";
  98. newrow["TeachingMaterialCode"] = "";
  99. newrow["TeachingMaterialName"] = "";
  100. newrow["SupplierName"] = "";
  101. newrow["PublishName"] = "";
  102. newrow["PublishTime"] = "";
  103. newrow["Author"] = "";
  104. newrow["Quantity"] = sumQuantity;
  105. newrow["Price"] = DBNull.Value;
  106. newrow["DiscountStr"] = DBNull.Value;
  107. newrow["DiscountPriceStr"] = DBNull.Value;
  108. newrow["TotalPriceStr"] = sumTotalPrice;
  109. newrow["TotalDollarStr"] = sumTotalDollar;
  110. dt.Rows.Add(newrow);
  111. string[] liststring = { "学年学期", "教材编号", "教材名称", "供应商",
  112. "出版单位", "版本时间", "作者", "数量", "单价", "折扣率", "折合价", "码洋", "实洋" };
  113. neh.Export(dt, liststring, "入库明细信息");
  114. return RedirectToAction("MsgShow", "Common", new
  115. {
  116. msg = "导出成功!",
  117. url = Url.Content("~/StockInDetail/List").AddMenuParameter()
  118. });
  119. }
  120. #endregion
  121. }
  122. }