using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Bowin.Common.Utility; using Bowin.Web.Controls.Mvc; using EMIS.CommonLogic.TeachingMaterial; using EMIS.ViewModel; using EMIS.ViewModel.TeachingMaterial; using EMIS.Web.Controls; using Bowin.Common.Data; using EMIS.CommonLogic.SystemServices; using EMIS.CommonLogic.CalendarManage; namespace EMIS.Web.Controllers.TeachingMaterial { [Authorization] public class StockOutController : Controller { public IStockOutServices StockOutServices { get; set; } public ISerialNumberServices SerialNumberServices { get; set; }//编号生成 public IStockInDetailServices StockInDetailServices { get; set; } public IStockInServices StockInServices { get; set; } public ISchoolYearServices SchoolYearServices { get; set; } /// /// 个人领书页面 /// /// [HttpGet] public ActionResult List() { var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true); ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年 return View(); } [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); //避开全选值 Guid? supplierID = null; Guid? schoolyearID = null; DateTime? startStockInTime = DateTime.Now; DateTime? endStockInTime = DateTime.Now; supplierID = pararms.getExtraGuid("SupplierDropdown");//书库ID schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");//学年 //startStockInTime = Convert.ToDateTime(Request.Form["EndStockInTime"]); endStockInTime = pararms.getExtraDateTime("EndStockInTime"); startStockInTime = pararms.getExtraDateTime("StartStockInTime"); return base.Json(StockOutServices.GetStockOutViewGrid(configuretView, schoolyearID, new List { (int)CF_StockOutType.StudentBook, (int)CF_StockOutType.TeacherBook }, supplierID, startStockInTime, endStockInTime, (int)pararms.page, (int)pararms.rows)); } public ActionResult RefundList() { var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true); ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年 return View(); } [HttpPost] public ActionResult RefundList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); //避开全选值 Guid? supplierID = null; Guid? schoolyearID = null; DateTime? startStockInTime = DateTime.Now; DateTime? endStockInTime = DateTime.Now; supplierID = pararms.getExtraGuid("SupplierDropdown");//书库ID schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");//学年 //startStockInTime = Convert.ToDateTime(Request.Form["EndStockInTime"]); endStockInTime = pararms.getExtraDateTime("EndStockInTime"); startStockInTime = pararms.getExtraDateTime("StartStockInTime"); return base.Json(StockOutServices.GetStockOutViewGrid(configuretView, schoolyearID, new List { (int)CF_StockOutType.Refund }, supplierID, startStockInTime, endStockInTime, (int)pararms.page, (int)pararms.rows)); } /// /// /// /// /// [HttpGet] public ActionResult Edit(Guid? stockOutID) { var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true); StockOutView stockOutView = new StockOutView(); if (stockOutID != null && stockOutID != Guid.Empty) { stockOutView = StockOutServices.GetSingleStockOut(stockOutID.Value); } else { var stockOutType = Convert.ToInt32(Request.Params["stockOutType"]);//获取出库类型 stockOutView = new StockOutView() { StockOutID = Guid.Empty, OutNumber = 1, StockOutTypeID = stockOutType, StockOutNo = StockOutServices.GetStockOutNo((CF_StockOutType)stockOutType), SchoolyearID = schoolYear.SchoolyearID, StockOutTime = DateTime.Now }; } return View(stockOutView); } /// /// /// /// /// [HttpPost] public ActionResult Edit(StockOutView stockOutView) { try { string type = Request.Params["hid_ActionsType"];//0 保存 1 提交 string time = DateTime.Now.ToString("yyyyMMdd"); var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal; var TMList = DataGrid.GetTableData("dgStockInTMSelectList");//获取底部列表项数据 string keyValue = SerialNumberServices.SetSN(time);//格式: 2016-3-25-001 if (TMList.Count <= 0) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:教材信息不能为空。" }); } else { StockOutServices.Save(stockOutView, TMList, user.UserID, type); } return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message }); } } /// /// Excel 导出 /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); Guid? libraryID = null; Guid? schoolyearID = null; libraryID = Request.Form["LibraryDropdown"].ParseStrTo(); schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo(); DateTime? startStockInTime = DateTime.Now; DateTime? endStockInTime = DateTime.Now; endStockInTime = DateTime.Parse(Request.Form["EndStockInTime"]); startStockInTime = DateTime.Parse(Request.Form["StartStockInTime"]); var dt = StockOutServices.GetStockOutViewList(configuretView, schoolyearID, new List { (int)CF_StockOutType.StudentBook, (int)CF_StockOutType.TeacherBook }, libraryID, startStockInTime, endStockInTime).Select(x => new { x.StockOutNo, x.SchoolyearName, // x.LibraryName, x.StockOutTypeName, x.StockOutSumMoney, x.RecipientUserName, x.StockOutUserName, x.StockOutTime, x.Desc }).ToTable(); string[] liststring = { "出库单据号", "学年学期", "出库类型", "单据总金额", "签收人", "经手人", "领书日期", "领书说明" }; neh.Export(dt, liststring, "出库管理信息"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/StockOut/List").AddMenuParameter() }); } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string stockOutIDs) { try { var stockOutIDList = stockOutIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList(); StockOutServices.Delete(stockOutIDList); return base.Json("删除成功。"); } catch (Exception ex) { string mge = ex.Message; return base.Json("删除失败,原因:" + mge); } } /// /// 个人领书明细 /// /// /// [HttpGet] public ActionResult StockOutDetailList(string stockOutID) { if (!string.IsNullOrEmpty(stockOutID)) ViewData["stockOutID"] = stockOutID; return View(); } /// /// 个人领书明细查询 /// /// /// [HttpPost] public ActionResult StockOutDetailList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); Guid? stockOutId = Request["stockOutId"].ParseStrTo(); return base.Json(StockOutServices.GetStockOutDetailViewGrid(stockOutId, (int)pararms.page, (int)pararms.rows)); } /// /// Excel 导出 /// /// [HttpPost] public ActionResult StockOutDetailExcel(Guid? stockOutId) { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var dt = StockOutServices.GetStockOutDetailViewList(stockOutId).Select(x => new { x.SchoolyearName, x.StockOutNo, x.GetBookNo, x.TeachingMaterialCode, x.TeachingMaterialName, x.PublishName, SupplierName = x.PublishName, x.PublishTime, x.Author, x.Quantity, x.Price, x.DiscountStr, x.DiscountPriceStr, x.TotalPriceStr, x.TotalDollarStr, x.RecipientUserName, x.StockOutUserName, StockOutTime = x.StockOutTime.Value.ToString("yyyy-MM-dd"), x.Desc }).ToTable(); string[] liststring = { "学年学期", "出库单据号","领书人", "教材编号", "教材名称", "供应商", "出版单位", "版本时间", "作者", "数量", "单价", "折扣率", "折合价", "码洋", "总价", "签收人","经手人", "出库日期", "出库说明" }; neh.Export(dt, liststring, "出库明细信息"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/StockOut/StockOutDetailList").AddMenuParameter() }); } /// /// 教材信息明细 /// /// /// [HttpPost] public ActionResult GetTMViewList(Guid? stockOutID) { if (stockOutID.HasValue) { var resultList = StockOutServices.GetStockOutByTMViewList(stockOutID.Value); return Json(new JsonDataGridResult { rows = resultList, total = resultList.Count }); } else { return Json(new JsonDataGridResult()); } } /// /// 提交 /// /// /// [HttpPost] public ActionResult Submit(string stockOutIDs) { try { var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal; var stockOutIDList = stockOutIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList(); StockOutServices.Submit(stockOutIDList, user.UserID); return base.Json("提交出库成功。"); } catch (Exception ex) { string mge = ex.Message; return base.Json("提交出库失败,原因:" + mge); } } /// /// 添加教材 /// /// public ActionResult TeachingMaterial() { return View(); } /// /// /// /// [HttpGet] public ActionResult GetStockOutByTMList() { return View(); } [HttpPost] public ActionResult GetStockOutByTMList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); bool? isLate = false; var teachingMaterialPoolID = pararms.getExtraGuid("TeachingMaterialDropdown"); var coursematerialID = pararms.getExtraGuid("CourseDropdown"); Guid? publishID = pararms.getExtraGuid("PublishDropdown"); var schoolyearID = pararms.getExtraGuid("SchoolyearID"); var isSelectMax = pararms.getExtraInt("hidIsSelectMax") == 1; // if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; return base.Json(StockOutServices.GetStockInByTeachingMaterialPoolViewGrid(configuretView, isLate, teachingMaterialPoolID, coursematerialID, isSelectMax, (int)pararms.page, (int)pararms.rows)); } [HttpGet] public ActionResult RefundListTeachingMaterial() { return View(); } [HttpPost] public ActionResult GetTeachingMaterialForRefund(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); bool? isLate = false; var teachingMaterialPoolID = pararms.getExtraGuid("TeachingMaterialDropdown"); var coursematerialID = pararms.getExtraGuid("CourseDropdown"); Guid? publishID = pararms.getExtraGuid("PublishDropdown"); var schoolyearID = pararms.getExtraGuid("SchoolyearID"); var isSelectMax = pararms.getExtraInt("hidIsSelectMax") == 1; // if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; return base.Json(StockOutServices.GetTeachingMaterialViewForRefundGrid(configuretView, isLate, teachingMaterialPoolID, coursematerialID, isSelectMax, (int)pararms.page, (int)pararms.rows)); } } }