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 LocatePartDefineController : BaseController { private ILocatePartDefineService service; public LocatePartDefineController(ILocatePartDefineService _service) { service = _service; } // // GET: /Menu/ public ActionResult Index() { return View(); } /// /// 获取库位零件管理列表数据 /// /// /// /// /// /// public ActionResult getLocateListByPage(string locateName, string locateDesc, string partNo, string partSpec,string partSpec2, Pager pager, String direction, String sort,string safetyPullOrder,string isSafetyPull, string enabled = "Y") { int factoryId = CurrentEmp.FactoryId; Hashtable result = new Hashtable(); result.Add("pager.pageNo", pager.pageNo); Hashtable dataHt = this.service.getLocateListByPage(locateName, locateDesc, partNo, partSpec, partSpec2, enabled, factoryId, pager, direction, safetyPullOrder, isSafetyPull, sort); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } #region 过滤库位 public ActionResult GetLocateName(string q) { List list = fileLocateName(q); return writeResult(list); } /// /// 过滤库位 /// /// /// public List fileLocateName(string key) { Hashtable autoComplateList = GetItemLocateName(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 GetItemLocateName(string key) { List autoComplateList = new List(); Hashtable result = new Hashtable(); try { List dt = service.GetLocateInfo(key); for (int i = 0; i < dt.Count; i++) { result.Add(dt[i].LocateId.ToString(), dt[i].LocateName.ToString()); } } catch (Exception e) { result = new Hashtable(); } return result; } #endregion #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.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; } #endregion private ActionResult writeResult(List list) { Hashtable result = new Hashtable(); result.Add("list", list); return Json(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(string 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 saveLocatePart() { String message = ""; String flag = ""; String editType = Request.Form["editType"].ToString(); String locateName = Request.Form["locateName"].ToString(); String partNo = Request.Form["partNo"].ToString(); String maxQty = Request.Form["maxQty"].ToString(); String minQty = Request.Form["minQty"].ToString(); String safetyQty = Request.Form["safetyQty"].ToString(); String wipMinQty = Request.Form["wipMinQty"].ToString(); String enabled = Request.Form["enabled"].ToString(); String guid = Request.Form["guid"].ToString(); List locateInfo = service.getSelectLocateInfo(locateName); if (locateInfo.Count == 0) { Hashtable resultMsg = new Hashtable(); resultMsg.Add("flag", "false"); resultMsg.Add("message", "库位代码不存在,请重新输入"); return Json(resultMsg); } int locateId = locateInfo[0].LocateId; string locateDesc = locateInfo[0].LocateDesc; List partInfo = service.GetPartInfo(partNo); if (partInfo.Count == 0) { Hashtable resultMsg = new Hashtable(); resultMsg.Add("flag", "false"); resultMsg.Add("message", "零件号不存在,请重新输入"); return Json(resultMsg); } int partId = partInfo[0].PartId; SysLocatePart sysLocatePart = new SysLocatePart(); sysLocatePart.LocateId = Convert.ToInt32(locateId); sysLocatePart.LocateName = locateName; sysLocatePart.LocateDesc = locateDesc; sysLocatePart.PartId = partId; sysLocatePart.PartNo = partNo; sysLocatePart.MaxQty = string.IsNullOrEmpty(maxQty) ? 0 : Convert.ToDecimal(maxQty); sysLocatePart.MinQty = string.IsNullOrEmpty(minQty) ? 0 : Convert.ToDecimal(minQty); sysLocatePart.SafetyQty = string.IsNullOrEmpty(safetyQty) ? 0 : Convert.ToDecimal(safetyQty); sysLocatePart.WipMinQty = string.IsNullOrEmpty(wipMinQty) ? 0 : Convert.ToDecimal(wipMinQty); sysLocatePart.Enabled = enabled; sysLocatePart.FactoryId = CurrentEmp.FactoryId; sysLocatePart.FactoryCode = CurrentEmp.FactoryCode; try { if (editType != null && editType.Trim().Equals("edit")) { sysLocatePart.Guid = guid; sysLocatePart.UpdateUserId = CurrentEmp.EmpId; int num = this.service.updateLocatePart(sysLocatePart); if (num > 0) { flag = "true"; message = "修改成功"; } else { flag = "false"; message = "修改失败!"; } } else { List locatePartInfo = service.getSelectLocatePartInfo(locateName, partNo); if (locatePartInfo.Count > 0) { Hashtable resultMsg = new Hashtable(); resultMsg.Add("flag", "false"); resultMsg.Add("message", "库位和零件号关系已维护"); return Json(resultMsg); } sysLocatePart.CreateUserId = CurrentEmp.EmpId; int num = this.service.saveLocatePart(sysLocatePart); if (num > 0) { flag = "true"; message = "添加成功"; } else { flag = "false"; message = "添加失败!"; } } } catch (Exception e) { flag = "false"; message = "添加失败!" + e.Message; } Hashtable result = new Hashtable(); result.Add("flag", flag); result.Add("message", message); return Json(result); } /// /// 编辑菜单 /// /// /// public ActionResult editLocatePart(String guid) { if (!string.IsNullOrEmpty(guid)) { Hashtable ht = this.service.getLocateDetail(guid); ViewData.Add("editType", "edit"); ViewData.Add("locateId", ht["locateId"]); ViewData.Add("locateName", ht["locateName"]); ViewData.Add("locateDesc", ht["locateDesc"]); ViewData.Add("partId", ht["partId"]); ViewData.Add("partNo", ht["partNo"]); ViewData.Add("partSpec", ht["partSpec"]); ViewData.Add("maxQty", ht["maxQty"]); ViewData.Add("minQty", ht["minQty"]); ViewData.Add("safetyQty", ht["safetyQty"]); ViewData.Add("wipMinQty", ht["wipMinQty"]); ViewData.Add("factoryId", ht["factoryId"]); ViewData.Add("factoryCode", ht["factoryCode"]); ViewData.Add("enabled", ht["enabled"]); ViewData.Add("guid", ht["guid"]); } else { ViewData.Add("editType", "new"); } return View("EditLocatePartDefine"); } /// /// 删除菜单 /// /// /// public ActionResult deleteLocatePart(String ids) { int delCount = 0; try { delCount = this.service.deleteLocatePart(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.EnableLocatePart(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.DisableLocatePart(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 partNo, string partSpec, string partSpec2, string enabled = "Y") { List listHt = this.service.getExportList(locateName, locateDesc, partNo, partSpec, partSpec2, 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"); } } }