using Estsh.Core.Controllers; using Estsh.Core.Model.ExcelModel; using Estsh.Core.Model.Result; using Estsh.Core.Models; using Estsh.Core.Services.IServices; using Estsh.Core.Util; using Microsoft.AspNetCore.Mvc; using System.Collections; /*************************************************************************************************** * * 更新人:sitong.dong * 描述:入库单管理 * 修改时间:2022.06.22 * 修改日志:系统迭代升级 * **************************************************************************************************/ namespace Estsh.Core.Web.Controllers { public class MovementInstockManageController : BaseController { private IMovementInstockManageService service; public MovementInstockManageController(IMovementInstockManageService _service) { service = _service; } // // GET: /Menu/ public ActionResult Index() { return View(); } /// /// 获取入库单管理列表数据 /// /// /// /// /// /// public ActionResult getMoveHeaderListByPage(string orderNo, string orderType, string orderStatus, string startTime, string endTime, Pager pager, String direction, String sort, string enabled = "Y") { int factoryId = CurrentEmp.FactoryId; Hashtable result = new Hashtable(); result.Add("pager.pageNo", pager.pageNo); Hashtable dataHt = this.service.getMoveHeaderListByPage(orderNo, orderType, orderStatus, startTime, endTime, enabled, factoryId, pager, direction, sort); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } /// /// 获取入库单管理明细列表数据 /// /// /// /// /// /// public ActionResult getMoveDetailListByPage(string orderNo, string enabled = "Y") { int factoryId = CurrentEmp.FactoryId; Hashtable result = new Hashtable(); Hashtable dataHt = this.service.getMoveDetailListByPage(orderNo, enabled, factoryId); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); return Json(result); } /// /// 获取入库单管理条码列表数据 /// /// /// /// /// /// public ActionResult getMoveSnListByPage(string orderNo, string partNo, string enabled = "Y") { int factoryId = CurrentEmp.FactoryId; Hashtable result = new Hashtable(); Hashtable dataHt = this.service.getMoveSnListByPage(orderNo, partNo, enabled, factoryId); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); return Json(result); } //打印查询 public ActionResult getInstockListByPrintCount(string orderNo, string enabled = "Y") { Hashtable result = new Hashtable(); int factoryId = CurrentEmp.FactoryId; List listData = this.service.getInstockListByPrintCount(orderNo, enabled, factoryId); result.Add("rows", listData); result.Add("pager.totalRows", listData.Count); return Json(result); } //打印查询 public ActionResult getInstockListByPrintRange(string orderNo,string rowRange, string enabled = "Y") { Hashtable result = new Hashtable(); string factoryId = CurrentEmp.FactoryId.ToString(); List listData = this.service.getInstockListByPrintRange(orderNo, rowRange,enabled, factoryId); return Json(listData); } //处理分组打印 public ActionResult EditBlockPrint(String orderNo,string orderType) { ViewData.Add("orderNo", orderNo); ViewData.Add("orderType", orderType); return View("EditBlockPrint"); } //打印查询 public ActionResult getMoveSnListByPrint(string orderNo, string groupCount, string enabled = "Y") { int factoryId = CurrentEmp.FactoryId; List listData = this.service.getMoveSnListByPrint(orderNo, enabled, factoryId); return Json(listData); } /// /// 生成条码 /// /// /// public ActionResult onBarcodeGenerator(String orderNos) { Hashtable result = new Hashtable(); try { string userId = CurrentEmp.EmpId.ToString(); string factoryId = CurrentEmp.FactoryId.ToString(); string factoryCode = CurrentEmp.FactoryCode; result = this.service.onBarcodeGenerator(orderNos, userId, factoryId, factoryCode); } catch (Exception e) { result.Add("message", "生成条码失败,请重查看!"); result.Add("flag", "error"); } return Json(result); } public ActionResult getSelectMoveOrderType() { Hashtable result = new Hashtable(); List menuList = this.service.GetMoveOrderType(); result.Add("list", menuList); return Json(result); } public ActionResult getSelectMoveOrderStatus() { Hashtable result = new Hashtable(); List menuList = this.service.GetMoveOrderStatus(); result.Add("list", menuList); return Json(result); } /// /// 获取父节点菜单下拉列表数据 /// /// public ActionResult getSelectFactory() { Hashtable result = new Hashtable(); List menuList = this.service.getSelectFactory(); result.Add("list", menuList); return Json(result); } public ActionResult getSelectWarehouse() { Hashtable result = new Hashtable(); List menuList = this.service.getSelectWarehouse(); result.Add("list", menuList); return Json(result); } public ActionResult getSelectZone() { Hashtable result = new Hashtable(); List menuList = this.service.getSelectZone(); result.Add("list", menuList); return Json(result); } public ActionResult getSelectZoneByZoneId(string zoneId) { Hashtable result = new Hashtable(); List Zones = service.getSelectZone(zoneId); return Json(Zones); } public ActionResult getSelectVendor() { Hashtable result = new Hashtable(); List menuList = this.service.getSelectVendor(); result.Add("list", menuList); return Json(result); } #region 过滤供应商 public ActionResult GetfileVendor(string q) { List list = fileVendor(q); return writeResult(list); } /// /// 过滤供应商 /// /// /// public List fileVendor(string key) { Hashtable autoComplateList = GetItemVendor(key); List result = new List(); foreach (System.Collections.DictionaryEntry item in autoComplateList) { //if (item.Value.ToString().ToUpper().StartsWith(key.ToUpper())) //{ result.Add(item.Value.ToString()); //} } return result; } /// /// 查询供应商 /// /// /// public Hashtable GetItemVendor(string key) { List autoComplateList = new List(); Hashtable result = new Hashtable(); try { List dt = service.GetfileVendor(key, CurrentEmp.FactoryId); for (int i = 0; i < dt.Count; i++) { result.Add(dt[i].VendorId.ToString(), dt[i].VendorName.ToString()); } } catch (Exception e) { result = new Hashtable(); } return result; } #endregion public ActionResult getSelectCustomer() { Hashtable result = new Hashtable(); List menuList = this.service.getSelectCustomer(); result.Add("list", menuList); return Json(result); } public ActionResult getSelectLocateDown(string zoneId) { Hashtable result = new Hashtable(); List menuList = this.service.getSelectLocateDown(zoneId); result.Add("list", menuList); return Json(result); } public ActionResult GetPart() { Hashtable result = new Hashtable(); List menuList = this.service.GetPart(); result.Add("list", menuList); return Json(result); } /// /// 保存数据 /// /// public ActionResult saveMovementInstockManage() { int orderType = int.Parse(Request.Form["orderType"]); int factoryId = CurrentEmp.FactoryId; String factoryCode = CurrentEmp.FactoryCode; String enabled = Request.Form["enabled"].ToString(); string vendorName = Request.Form["vendorName"]; string customerId = Request.Form["customerId"]; String planDate = Request.Form["planDate"].ToString(); String planTime = Request.Form["planTime"].ToString(); String destWarehouseId = Request.Form["destWarehouseId"].ToString(); String destZoneId = Request.Form["destZoneId"].ToString(); String destLocateId = Request.Form["destLocateId"].ToString(); String destErpWarehouse = Request.Form["destErpWarehouse"].ToString(); String reforderno = Request.Form["reforderno"].ToString(); String destWarehouseName = ""; List destWare = service.getSelectWarehouse(destWarehouseId); if (destWare.Count > 0) { destWarehouseName = destWare[0].WarehouseName; } String destZoneName = ""; List destZones = service.getSelectZone(destZoneId); if (destZones.Count > 0) { destZoneName = destZones[0].ZoneName; } else { destZoneName = ""; } String destLocateName = ""; List locates = service.getSelectLocate(destLocateId); if (locates.Count > 0) { destLocateName = locates[0].LocateName; } else { destLocateName = ""; } int VendorId = 0; SysVendor sysVendors = service.GetVendorInfoByName(vendorName, CurrentEmp.FactoryId); string vendorCode = ""; if (sysVendors != null) { VendorId = sysVendors.VendorId; vendorCode = sysVendors.VendorCode; } customerId = string.IsNullOrEmpty(customerId) ? "0" : customerId; List sysCustomers = service.getSelectCustomer(customerId.ToString()); string customerCode = ""; if (sysCustomers.Count > 0) { customerCode = sysCustomers[0].CustomerCode; } WmsInstock moveHeader = new WmsInstock(); moveHeader.OrderType = orderType; moveHeader.VendorId = VendorId; moveHeader.VendorCode = vendorCode; moveHeader.CustomerId = Convert.ToInt32(customerId); moveHeader.CustomerCode = customerCode; moveHeader.FactoryId = factoryId; moveHeader.FactoryCode = factoryCode; moveHeader.Enabled = enabled; moveHeader.RefOrderNo = reforderno; string detailRow = Request.Form["detailRow"].ToString(); IList moveDetailsList = Newtonsoft.Json.JsonConvert.DeserializeObject>(detailRow); for (int i = 0; i < moveDetailsList.Count; i++) { moveDetailsList[i].ItemNo = (i + 1).ToString(); //purchaseDetailList[i].PartId = Convert.ToInt32(PartId); string PartNo = string.IsNullOrEmpty(moveDetailsList[i].PartNo.ToString()) ? "0" : moveDetailsList[i].PartNo.ToString(); List parts = service.GetPart(PartNo); if (parts.Count > 0) { moveDetailsList[i].PartId = parts[0].PartId; moveDetailsList[i].PartSpec = parts[0].PartSpec; moveDetailsList[i].Unit = parts[0].Unit; } else { moveDetailsList[i].PartId = 0; moveDetailsList[i].PartSpec = ""; moveDetailsList[i].Unit = ""; } //moveDetailsList[i].Qty = string.IsNullOrEmpty(Qty) ? 0 : Convert.ToDecimal(Qty); moveDetailsList[i].RecQty = 0; moveDetailsList[i].PlanDate = planDate; moveDetailsList[i].PlanTime = planTime; moveDetailsList[i].DestWarehouseId = string.IsNullOrEmpty(destWarehouseId) ? 0 : Convert.ToInt32(destWarehouseId); moveDetailsList[i].DestWarehouseName = destWarehouseName; moveDetailsList[i].DestZoneId = string.IsNullOrEmpty(destZoneId) ? 0 : Convert.ToInt32(destZoneId); moveDetailsList[i].DestZoneName = destZoneName; moveDetailsList[i].DestLocateId = string.IsNullOrEmpty(destLocateId) ? 0 : Convert.ToInt32(destLocateId); moveDetailsList[i].DestLocateName = destLocateName; moveDetailsList[i].DestErpWarehouse = destErpWarehouse; moveDetailsList[i].Enabled = enabled; moveDetailsList[i].FactoryId = CurrentEmp.FactoryId; moveDetailsList[i].FactoryCode = CurrentEmp.FactoryCode; moveDetailsList[i].CreateUserId = CurrentEmp.EmpId; } String message = ""; try { moveHeader.CreateUserId = CurrentEmp.EmpId; bool flag = this.service.saveMovementManage(moveHeader, moveDetailsList); if (flag == true) { message = "添加成功"; } else { message = "添加失败!"; } } catch (Exception e) { message = "添加失败!"; } Hashtable result = new Hashtable(); result.Add("message", message); return Json(result); } #region 过滤零件号 public ActionResult GetPart_No(string q) { List list = filePart(q); return writeResult(list); } /// /// 过滤零件号 /// /// /// public List filePart(string key) { Hashtable autoComplateList = GetItemPart(key); List result = new List(); foreach (System.Collections.DictionaryEntry item in autoComplateList) { if (item.Value.ToString().ToUpper().StartsWith(key.ToUpper())) { result.Add(item.Value.ToString()); } } return result; } /// /// 查询零件号 /// /// /// public Hashtable GetItemPart(string key) { List autoComplateList = new List(); Hashtable result = new Hashtable(); try { List dt = service.GetPartNoInfo(key); for (int i = 0; i < dt.Count; i++) { result.Add(dt[i].PartId.ToString(), dt[i].PartNo.ToString()); } } catch (Exception e) { result = new Hashtable(); } return result; } #endregion #region 过滤零件号简码 public ActionResult GetPart_Spec(string q) { List list = filePartSpec(q); return writeResult(list); } /// /// 过滤零件号 /// /// /// public List filePartSpec(string key) { Hashtable autoComplateList = GetItemPartSpec(key); List result = new List(); foreach (System.Collections.DictionaryEntry item in autoComplateList) { if (item.Value.ToString().ToUpper().StartsWith(key.ToUpper())) { result.Add(item.Value.ToString()); } } return result; } /// /// 查询零件号 /// /// /// public Hashtable GetItemPartSpec(string key) { List autoComplateList = new List(); Hashtable result = new Hashtable(); try { List dt = service.GetPartSpecInfo(key); for (int i = 0; i < dt.Count; i++) { result.Add(dt[i].PartId.ToString(), dt[i].PartSpec.ToString()); } } catch (Exception e) { result = new Hashtable(); } return result; } #endregion public ActionResult getPartNoInfo(string partNo) { Hashtable resault = new Hashtable(); List list = service.GetPartNoInfo(partNo); return Json(list); } public ActionResult getPartNoInfoByPartNo(string partNo) { Hashtable resault = new Hashtable(); List list = service.GetPartNoInfoByPartNo(partNo); return Json(list); } public ActionResult getPartSpecInfo(string partSpec) { Hashtable resault = new Hashtable(); List list = service.GetPartSpecInfo(partSpec); return Json(list); } public ActionResult getPartSpecInfoByPartSpec(string partSpec) { Hashtable resault = new Hashtable(); List list = service.GetPartSpecInfoByPartSpec(partSpec); return Json(list); } private ActionResult writeResult(List list) { Hashtable result = new Hashtable(); result.Add("list", list); return Json(result); } public ActionResult GetErpwarehouse() { Hashtable resault = new Hashtable(); List pdlineList = service.GetErpwarehouse(); resault.Add("list", pdlineList); return Json(resault); } /// /// 编辑菜单 /// /// /// public ActionResult EditMoveInstockManage(String warehouseId) { ViewData.Add("editType", "new"); List menuList = this.service.getSelectWarehouse(); if (menuList.Count > 0) { //目标仓库绑定默认值 ViewData.Add("destWarehouseId", menuList[0].value); } return View("EditMoveInstockManage"); } /// /// 关闭 /// /// /// public ActionResult onClose(String orderNos) { bool flag = true; try { string empId = CurrentEmp.EmpId.ToString(); flag = this.service.onClose(orderNos, empId); } catch (Exception e) { flag = false; } Hashtable result = new Hashtable(); result.Add("status", flag); return Json(result); } /// /// 启用 /// /// /// public ActionResult onEnable(String orderNos) { bool flag = true; try { flag = this.service.EnableData(orderNos); } catch (Exception e) { flag = false; } Hashtable result = new Hashtable(); result.Add("status", flag); return Json(result); } /// /// 禁用 /// /// /// public ActionResult onDisable(String orderNos) { bool flag = true; try { flag = this.service.DisableData(orderNos); } catch (Exception e) { flag = false; } Hashtable result = new Hashtable(); result.Add("status", flag); return Json(result); } /// /// 导入 /// /// public ActionResult importFile() { int factoryId = CurrentEmp.FactoryId; string factoryCode = CurrentEmp.FactoryCode; Hashtable result = new Hashtable(); IFormFile file = Request.Form.Files[0]; List data = ExcelHelper.GetList(file, 0); result = service.ImportExcel(data, factoryId, factoryCode, CurrentEmp.EmpId); return Json(result); } public ActionResult uploadFile() { return View("uploadFile"); } /// /// 下载模板 /// /// public ActionResult downLoadExcel() { List listHt = new List();//导出空数据模板 var memoryStream = ExcelHelper.ToExcel(listHt); string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss"); return File(memoryStream.ToArray(), "application/ms-excel", "入库单管理" + dateTime + ".xls"); } } }