123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- 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;
- using System.IO;
- using EMIS.Utility;
- namespace EMIS.Web.Controllers.TeachingMaterial
- {
- [Authorization]
- public class StockInController : Controller
- {
- public IStockInServices StockInServices { get; set; }
- //编号生成
- public ISerialNumberServices SerialNumberServices { get; set; }
- public IStockInDetailServices StockInDetailServices { get; set; }
- public ISchoolYearServices SchoolYearServices { get; set; }
- public ISupplierDiscountSetServices supplierDiscountSetServices { get; set; }
- /// <summary>
- /// 教材入库页面
- /// </summary>
- /// <returns></returns>
- [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);
- //避开全选值
- int? isLate = isLate = pararms.getExtraInt("LateDropdown");
- DateTime? startStockInTime = DateTime.Now;
- DateTime? endStockInTime = DateTime.Now;
- Guid? supplierID = pararms.getExtraGuid("PublishDropdown");
- Guid? schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");
- endStockInTime = pararms.getExtraDateTime("EndStockInTime");
- startStockInTime = pararms.getExtraDateTime("StartStockInTime");
- return base.Json(StockInServices.GetStockInViewGrid(configuretView, schoolyearID, supplierID, startStockInTime, endStockInTime, isLate,
- new List<int?> { (int)CF_StockInType.PurchasingStockIn }, (int)pararms.page, (int)pararms.rows));
- }
- [HttpGet]
- public ActionResult ReturnList()
- {
- var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
- ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年
- return View();
- }
- [HttpPost]
- public ActionResult ReturnList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- int? isLate = isLate = pararms.getExtraInt("LateDropdown");
- DateTime? startStockInTime = DateTime.Now;
- DateTime? endStockInTime = DateTime.Now;
- Guid? supplierID = pararms.getExtraGuid("PublishDropdown");
- Guid? schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");
- endStockInTime = pararms.getExtraDateTime("EndStockInTime");
- startStockInTime = pararms.getExtraDateTime("StartStockInTime");
- return base.Json(StockInServices.GetStockInViewGrid(configuretView, schoolyearID, supplierID, startStockInTime, endStockInTime, isLate,
- new List<int?> { (int)CF_StockInType.Return }, (int)pararms.page, (int)pararms.rows));
- }
- [HttpGet]
- public ActionResult Edit(Guid? stockInID)
- {
- var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
- StockInView stockInView;
- if (stockInID != null && stockInID != Guid.Empty)
- {
- stockInView = StockInServices.GetSingleStockIn(stockInID.Value);
- }
- else
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- var defaultsupplier = supplierDiscountSetServices.GetSupplierDiscountSetViewList(configuretView, true, null).FirstOrDefault();
- Guid? defaultID = null;
- if (defaultsupplier != null)
- {
- defaultID = supplierDiscountSetServices.GetSupplierDiscountSetViewList(configuretView, true, null).FirstOrDefault().PublishID;
- }
- //ViewBag.DefaultID = defaultID;
- string keyValue = SerialNumberServices.SetSN(DateTime.Now.ToString("yyyyMMdd"));
- var stockInType = Convert.ToInt32(Request.Params["stockInType"]);//获取入库默认类型
- stockInView = new StockInView()
- {
- StockInNumber = keyValue,
- StockInType = stockInType,
- StockInDocumentNo = StockInServices.GetStockInNo((CF_StockInType)stockInType),
- StockInID = Guid.Empty,
- SchoolyearID = schoolYear.SchoolyearID,
- StockInDJTime = DateTime.Now,
- SupplierID = defaultID
- };
- }
- return View(stockInView);
- }
- [HttpPost]
- public ActionResult Edit(StockInView stockInView)
- {
- try
- {
- string type = Request.Params["hid_ApprovalStatusName"];//0 保存 1 提交
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- var TMList = DataGrid.GetTableData<TeachingMaterialPoolView>("dgStockInTMSelectList");//获取底部列表项数据
- if (TMList == null || TMList.Count <= 0)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "操作失败,原因:教材信息不能为空。"
- });
- }
- else
- {
- StockInServices.Save(stockInView, TMList, user.UserID, type);
- }
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功。"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败,原因:" + ex.Message
- });
- }
- }
- /// <summary>
- /// Excel 导出
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Excel()
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- int? isLate = isLate = Request.Form["LateDropdown"].ParseStrTo<int>();
- Guid? supplierID = Request.Form["PublishDropdown"].ParseStrTo<Guid>();
- Guid? schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo<Guid>();
- DateTime? startStockInTime = DateTime.Now;
- DateTime? endStockInTime = DateTime.Now;
- endStockInTime = DateTime.Parse(Request.Form["EndStockInTime"]);
- startStockInTime = DateTime.Parse(Request.Form["StartStockInTime"]);
- var dt = StockInServices.GetStockInViewList(configuretView, schoolyearID, supplierID, startStockInTime, endStockInTime, isLate,
- new List<int?> { (int)CF_StockInType.PurchasingStockIn }).Select(x => new
- {
- x.SchoolyearName,
- x.StockInDocumentNo,
- x.SupplierName,
- x.HandlerUserName,
- x.StockInDJTime,
- x.StockInSumMoneyStr,
- x.Desc
- }).ToTable();
- string[] liststring = { "学年学期", "入库单据号", "供应商", "经手人", "入库单据日期", "入库总金额", "备注" };
- neh.Export(dt, liststring, "入库管理信息");
- return RedirectToAction("MsgShow", "Common", new
- {
- msg = "导出成功!",
- url = Url.Content("~/StockIn/List").AddMenuParameter()
- });
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string stockInIDs)
- {
- try
- {
- var stockInIDList = stockInIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
- StockInServices.Delete(stockInIDList);
- return base.Json("删除成功。");
- }
- catch (Exception ex)
- {
- string mge = ex.Message;
- // System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
- return base.Json("删除失败,原因:" + mge);
- }
- }
- /// <summary>
- /// 添加教材
- /// </summary>
- /// <returns></returns>
- public ActionResult TeachingMaterial()
- {
- var supplierID = Request["SupplierID"].ParseStrTo<Guid>();
- decimal? discount;
- if (supplierID.HasValue)
- {
- discount = supplierDiscountSetServices.GetDiscountByPublishID((Guid)supplierID);
- }
- else {
- discount = null;
- }
- ViewBag.Discount = discount;
- ViewBag.SupplierID = supplierID;
- return View();
- }
-
- /// <summary>
- /// 教材入库列表
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult GetStockInByTMList()
- {
- return View();
- }
- /// <summary>
- /// 查询教材入库列表
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult GetStockInByTMList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- var teachingMaterialPoolID = pararms.getExtraGuid("TeachingMaterialDropdown");
- var teachingMaterialCodeID = pararms.getExtraGuid("TeachingMaterialCodeDropdown");
- Guid? publishID = pararms.getExtraGuid("PublishDropdown");
- var schoolyearID = pararms.getExtraGuid("SchoolyearID");
- var supplierID = pararms.getExtraGuid("SupplierID");
- decimal? discount = 1;
- if (supplierID.HasValue)
- {
- discount = supplierDiscountSetServices.GetDiscountByPublishID((Guid)supplierID);
- }
- return base.Json(StockInServices.GetStockInByTeachingMaterialPoolViewGrid(configuretView, schoolyearID, teachingMaterialPoolID, teachingMaterialCodeID, discount, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="stockIn"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult GetTMViewList(Guid? stockIn)
- {
- if (stockIn.HasValue)
- {
- var resultList = StockInServices.GetStockInByTMViewList(stockIn.Value);
- return Json(new JsonDataGridResult<TeachingMaterialPoolView> { rows = resultList, total = resultList.Count });
- }
- else
- {
- return Json(new JsonDataGridResult<TeachingMaterialPoolView>());
- }
- }
-
- /// <summary>
- /// 教材入库明细
- /// </summary>
- /// <param name="stockInID"></param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult StockInDetailList(string stockInID)
- {
- if (!string.IsNullOrEmpty(stockInID))
- ViewData["stockInID"] = stockInID;
- return View();
- }
- /// <summary>
- /// 教材入库明细
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult StockInDetailList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- Guid? stockId = Request["stockId"].ParseStrTo<Guid>();
- return base.Json(StockInDetailServices.GetStockInDetailViewGrid(stockId, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// Excel 导出
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult StockInDetailExcel(Guid? stockId)
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- var dt = StockInDetailServices.GetStockInDetailViewList(configuretView, stockId).Select(x => new
- {
- x.SchoolyearName,
- x.StockInDocumentNo,
- x.StockInNumber,
- x.TeachingMaterialCode,
- x.TeachingMaterialName,
- x.PublishName,
- x.SupplierName,
- x.PublishTime,
- x.Author,
- x.Quantity,
- x.Price,
- x.DiscountStr,
- x.DiscountPriceStr,
- x.TotalPriceStr,
- x.TotalDollarStr,
- x.HandlerUserName,
- x.StockInUserName,
- x.StockInTime
- }).ToTable();
- string[] liststring = { "学年学期", "入库单据号", "入库编号", "教材编号", "教材名称", "供应商",
- "出版单位", "版本时间", "作者", "数量", "单价", "折扣率", "折合价", "码洋", "总价", "经手人", "入库人", "入库日期" };
- neh.Export(dt, liststring, "入库明细信息");
- return RedirectToAction("MsgShow", "Common", new
- {
- msg = "导出成功!",
- url = Url.Content("~/StockInDetail/List").AddMenuParameter()
- });
- }
- /// <summary>
- /// 提交
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Submit(string stockInIDs)
- {
- try
- {
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- var stockInIDList = stockInIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
- StockInServices.Submit(stockInIDList, user.UserID);
- return base.Json("提交入库成功。");
- }
- catch (Exception ex)
- {
- string mge = ex.Message;
- return base.Json("提交入库失败,原因:" + mge);
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="errorFile"></param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Import(string errorFile)
- {
- ViewBag.ErrorFile = errorFile;
- return View();
- }
- [HttpPost]
- public ActionResult Import(HttpPostedFileBase file)
- {
- try
- {
- //1.0 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls
- //2.0 XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx
- if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
- {
- throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
- }
- return null;
- }
- catch (Exception ex)
- {
- return RedirectToAction("MsgShow", "Common", new
- {
- WindowID = Request["WindowID"],
- msg = "导入失败,原因:" + ex.Message + "!",
- url = Url.Action("List").AddMenuParameter()
- });
- }
- }
- /// <summary>
- /// 自动入库(根据采购计划自动入库)
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult AutoNewStockIn()
- {
- var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true).SchoolyearID;
- ViewData["schoolYear"] = schoolYear;
- return View();
- }
- /// <summary>
- /// 自动入库确定(根据学生征订和教师征订)
- /// </summary>
- /// <param name="schoolyearID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult AutoNewStockIn(Guid? schoolyearID)
- {
- try
- {
- var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- StockInServices.AutoNewStockIn(schoolyearID, user.UserID);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "入库成功。"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "入库失败,原因:" + ex.Message
- });
- }
- }
- }
- }
|