using Estsh.Core.Controllers; using Estsh.Core.Model.EnumUtil; 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 LocateDefineController : BaseController { private ILocateDefineService service; public LocateDefineController(ILocateDefineService _service) { service = _service; } // // GET: /Menu/ public ActionResult Index() { return View(); } /// /// 获取库位管理列表数据 /// /// /// /// /// /// public ActionResult getLocateListByPage(String locateName, String locateDesc, string locateType,string zoneName, 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.getLocateListByPage(locateName, locateDesc, locateType, zoneName, 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 GetPart_no(string q) { List list = filePart(q); return writeResult(list); } private ActionResult writeResult(List list) { Hashtable result = new Hashtable(); result.Add("list", list); return Json(result); } /// /// 过滤零件号 /// /// /// 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.GetPartInfo(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; } ///// ///// 获取零件信息 ///// ///// //public ActionResult getPart() //{ // Hashtable result = new Hashtable(); // string partNo = Request.Form["partNo"].ToString(); // string message = ""; // List dt = service.GetPartInfo(0, partNo); // if (dt.Count > 0) // { // partId = dt[0].PartId.ToString(); // biaoNumber = dt[0].DefaultBoxQty.ToString(); // partSpec = dt[0].PartSpec.ToString(); // if (!service.IsPoPartNo(txtBuyNo, partNo)) // { // message = " [" + partNo + "]所选择零件与采购单数据不匹配! "; // result.Add("message", message); // result.Add("status", -1); // return Json(result); // } // if (!service.IsExistLineLocate(partId)) // { // message = " [" + partNo + "]:不存在此零件对应的线边库位配置信息! "; // result.Add("message", message); // result.Add("status", -1); // return Json(result); // } // result.Add("partId", partId); // result.Add("biaoNumber", biaoNumber); // result.Add("partSpec", partSpec); // result.Add("status", 1); // } // return Json(result); //} /// /// 获取父节点菜单下拉列表数据 /// /// public ActionResult getSelectWarehouse() { string factoryId = CurrentEmp.FactoryId.ToString(); Hashtable result = new Hashtable(); List menuList = this.service.getSelectWarehouse(factoryId); result.Add("list", menuList); return Json(result); } /// /// 获取父节点菜单下拉列表数据 /// /// public ActionResult getSelectZone(int WarehouseId) { Hashtable result = new Hashtable(); List menuList = this.service.getSelectZone(WarehouseId); result.Add("list", menuList); return Json(result); } /// /// 获取库位类型列表 /// /// public ActionResult GetLocateType() { Hashtable result = new Hashtable(); List menuList = this.service.GetLocateType(); result.Add("list", menuList); return Json(result); } public ActionResult GetpartInfo() { Hashtable result = new Hashtable(); List menuList = this.service.GetpartInfo(); result.Add("list", menuList); return Json(result); } /// /// 保存菜单数据 /// /// public ActionResult saveLocate() { String editType = Request.Form["editType"].ToString(); String locateName = Request.Form["locateName"].ToString(); String locateDesc = Request.Form["locateDesc"].ToString(); String locateCapacity = Request.Form["locateCapacity"].ToString(); String WarehouseId = Request.Form["WarehouseId"].ToString() == "" ? "0" : Request.Form["WarehouseId"].ToString(); List warehouses = service.getSelectWarehouseInfo(WarehouseId); string WarehouseNamee = warehouses.Count > 0 ? warehouses[0].WarehouseName : ""; String zoneId = Request.Form["zoneId"].ToString() == "" ? "0" : Request.Form["zoneId"].ToString(); List zones = service.getSelectZoneInfo(zoneId); string zoneName = zones.Count > 0 ? zones[0].ZoneName : ""; String enabled = Request.Form["enabled"].ToString(); int locateType = Convert.ToInt32(Request.Form["locateType"]); String partNo = Request.Form["partNo"].ToString(); int partId = 0; if (!string.IsNullOrEmpty(partNo)) { List dt = service.GetPartInfo(partNo); if (dt.Count > 0) { partId = dt[0].PartId; } } SysLocate sysLocate = new SysLocate(); sysLocate.LocateDesc = locateDesc; sysLocate.WarehouseId = Convert.ToInt32(WarehouseId); sysLocate.WarehouseName = WarehouseNamee; sysLocate.ZoneId = Convert.ToInt32(zoneId); sysLocate.ZoneName = zoneName; sysLocate.Enabled = enabled; sysLocate.LocateType = locateType; //sysLocate.PartId = partId; sysLocate.LocateName = locateName; sysLocate.LocateCapacity = string.IsNullOrEmpty(locateCapacity) ? 0 : decimal.Parse(locateCapacity); sysLocate.FactoryId = CurrentEmp.FactoryId; sysLocate.FactoryCode = CurrentEmp.FactoryCode; SysLocatePart sysLocatePart = new SysLocatePart(); sysLocatePart.LocateName = locateName; sysLocatePart.PartId = Convert.ToInt32(partId); sysLocatePart.PartNo = partNo; sysLocatePart.FactoryId = CurrentEmp.FactoryId; sysLocatePart.FactoryCode = CurrentEmp.FactoryCode; String message = ""; if (editType != null && editType.Trim().Equals("edit")) { try { String locateId = Request.Form["locateId"].ToString(); sysLocate.LocateId = Convert.ToInt32(locateId); sysLocatePart.LocateId = Convert.ToInt32(locateId); sysLocate.UpdateUserId = CurrentEmp.EmpId; sysLocatePart.UpdateUserId = CurrentEmp.EmpId; if (locateType == (int)WmsEnumUtil.LocateType.BASICS_LOCATE) { this.service.updateLocate(sysLocate, true, sysLocatePart); } else { this.service.updateLocate(sysLocate, false, sysLocatePart); } message = "修改成功"; } catch (Exception e) { message = "修改失败!"; } } else { try { if (this.service.getlocateByExistName(locateName) !=null) { message = "库位代码已存在,请检查!"; } else { sysLocate.CreateUserId = CurrentEmp.EmpId; sysLocatePart.CreateUserId = CurrentEmp.EmpId; if (locateType == (int)WmsEnumUtil.LocateType.BASICS_LOCATE) { this.service.saveLocate(sysLocate, true, sysLocatePart); } else { this.service.saveLocate(sysLocate, false, sysLocatePart); } message = "添加成功" + locateType; } } catch (Exception e) { message = "添加失败!" + e.Message; } } Hashtable result = new Hashtable(); result.Add("message", message); return Json(result); } /// /// 编辑菜单 /// /// /// public ActionResult editLocate(String locateId) { if (!string.IsNullOrEmpty(locateId)) { Hashtable ht = this.service.getLocateDetail(locateId); ViewData.Add("editType", "edit"); ViewData.Add("locateId", ht["locateId"]); ViewData.Add("locateName", ht["locateName"]); ViewData.Add("locateDesc", ht["locateDesc"]); ViewData.Add("warehouseId", ht["warehouseId"]); ViewData.Add("warehouseName", ht["warehouseName"]); ViewData.Add("warehouseDesc", ht["warehouseDesc"]); ViewData.Add("partNo", ht["partNo"]); ViewData.Add("zoneId", ht["zoneId"]); ViewData.Add("locateCapacity", ht["locateCapacity"]); ViewData.Add("locateType", ht["locateType"]); ViewData.Add("enabled", ht["enabled"]); } else { ViewData.Add("editType", "new"); } return View("EditLocateDefine"); } /// /// 删除菜单 /// /// /// public ActionResult deleteLocate(String ids) { int delCount = 0; try { delCount = this.service.deleteLocate(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 启用 /// /// /// public ActionResult onEnable(String ids) { int delCount = 0; try { delCount = this.service.EnableLocate(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 禁用 /// /// /// public ActionResult onDisable(String ids) { int delCount = 0; try { delCount = this.service.DisableLocate(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); 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"); } /// /// 导出数据到Excel /// BY NOAH /// carImport /// public ActionResult exportData(String locateName, String locateDesc, string locateType, string enabled = "Y") { List listHt = this.service.getExportList(locateName, locateDesc, locateType, enabled, CurrentEmp.FactoryId); var memoryStream = ExcelHelper.ToExcel(listHt); string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss"); return File(memoryStream.ToArray(), "application/ms-excel", "库位管理"+ dateTime + ".xls"); } /// /// 下载模板 /// /// public ActionResult downLoadExcel(string rackPart, string partPackage, string enabled = "Y") { List listHt = new List();//导出空数据模板 var memoryStream = ExcelHelper.ToExcel(listHt); string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss"); return File(memoryStream.ToArray(), "application/ms-excel", "库位管理"+ dateTime + ".xls"); } } }