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 PullGroupController : BaseController { private IPullGroupService service; public PullGroupController(IPullGroupService _service) { service = _service; } // // GET: /Menu/ public ActionResult Index() { return View(); } /// /// 获取采购单管理列表数据 /// /// /// /// /// /// public ActionResult getPullGroupListByPage(string groupCode, string groupName, 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.getPullGroupListByPage(groupCode, groupName, 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 getPullGroupDetailListByPage(string groupCode, string enabled = "Y") { int factoryId = CurrentEmp.FactoryId; Hashtable result = new Hashtable(); Hashtable dataHt = this.service.getPullGroupDetailListByPage(groupCode, enabled, factoryId); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); 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 getSelectVendor() { Hashtable result = new Hashtable(); List menuList = this.service.getSelectVendor(); 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 GetPdlineByPdlineCode(string pdlineCode) //{ // Hashtable result = new Hashtable(); // List menuList = this.service.getSelectZone(); // result.Add("list", menuList); // return Json(result); //} public ActionResult GetPdlineByKey() { Hashtable result = new Hashtable(); List menuList = this.service.GetPdlineByKey(); result.Add("list", menuList); return Json(result); } public ActionResult getPartNoInfo(string partNo) { Hashtable resault = new Hashtable(); List list = service.GetPartNoInfo(partNo); return Json(list); } public ActionResult getPartSpecInfo(string partSpec) { Hashtable resault = new Hashtable(); List list = service.GetPartSpecInfo(partSpec); return Json(list); } public ActionResult EditHandPullGroup(string groupCode) { ViewData.Add("editType", "edit"); ViewData.Add("groupCode", groupCode); return View("EditHandPullGroup"); } public ActionResult saveHandPullGroup() { String groupCode = Request.Form["groupCode"].ToString(); String handPullQty = Request.Form["handPullQty"].ToString(); String message = ""; String status = "0"; try { bool ret = this.service.saveHandPullGroup(groupCode, handPullQty); if (ret) { status = "1"; message = "手工拉动成功"; } else { status = "0"; message = "手工拉动失败!"; } } catch (Exception e) { status = "0"; message = "手工拉动失败!"; } Hashtable result = new Hashtable(); result.Add("status", status); result.Add("message", message); return Json(result); } /// /// 保存菜单数据 /// /// public ActionResult savePullGroup() { string ruid = Request.Form["ruid"].ToString(); String groupCode = Request.Form["groupCode"].ToString(); String groupName = Request.Form["groupName"].ToString(); String triggerValue = Request.Form["triggerValue"].ToString(); String pullValue = Request.Form["pullValue"].ToString(); int pullingType = Convert.ToInt32(String.IsNullOrEmpty(Request.Form["pullingType"]) ? 0 : Request.Form["pullingType"].ToString()); string pdlineCode = String.IsNullOrEmpty(Request.Form["pdlineCode"]) ? "" : Request.Form["pdlineCode"].ToString(); SysPdline sysPdlines = service.GetPdlineByPdlineCode(pdlineCode); string pdlineName = ""; if (sysPdlines != null) { pdlineName = sysPdlines.PdlineName; } decimal kittingQty = Convert.ToDecimal(Request.Form["kittingQty"].ToString()); int isAutoPrint = Convert.ToInt32(Request.Form["isAutoPrint"].ToString()); WmsPullingGroup wmsPulling = new WmsPullingGroup(); wmsPulling.GroupCode = groupCode; wmsPulling.GroupName = groupName; wmsPulling.TriggerValue = triggerValue; wmsPulling.PullValue = pullValue; wmsPulling.PullingType = pullingType; wmsPulling.PdlineName = pdlineName; wmsPulling.PdlineCode = pdlineCode; wmsPulling.KittingQty = kittingQty; wmsPulling.IsAutoPrint = isAutoPrint; wmsPulling.Enabled = "Y"; wmsPulling.FactoryId = CurrentEmp.FactoryId; wmsPulling.FactoryCode = CurrentEmp.FactoryCode; wmsPulling.CreateUserId = CurrentEmp.EmpId; string detailRow = Request.Form["detailRow"].ToString(); IList wmsPullingDetailList = Newtonsoft.Json.JsonConvert.DeserializeObject>(detailRow); for (int i = 0; i < wmsPullingDetailList.Count; i++) { //wmsPullingDetailList[i].PartId = Convert.ToInt32(PartId); string PartNo = string.IsNullOrEmpty(wmsPullingDetailList[i].PartNo.ToString()) ? "0" : wmsPullingDetailList[i].PartNo.ToString(); List parts = service.GetPart(PartNo); if (parts.Count > 0) { wmsPullingDetailList[i].PartId = parts[0].PartId; wmsPullingDetailList[i].PartSpec = parts[0].PartSpec; } else { wmsPullingDetailList[i].PartId = 0; wmsPullingDetailList[i].PartSpec = ""; } wmsPullingDetailList[i].Enabled = "Y"; wmsPullingDetailList[i].FactoryId = CurrentEmp.FactoryId; wmsPullingDetailList[i].FactoryCode = CurrentEmp.FactoryCode; wmsPullingDetailList[i].CreateUserId = CurrentEmp.EmpId; } String message = ""; String status = "0"; try { if (string.IsNullOrEmpty(ruid)) { List wmsPullings = service.getPullGroupDetailList(groupCode); if (wmsPullings.Count > 0) { status = "0"; message = "拉动组代码已存在,请检查"; } else { wmsPulling.CreateUserId = CurrentEmp.EmpId; int ret = this.service.savePullGroup(wmsPulling, wmsPullingDetailList); if (ret > 0) { status = "1"; message = "添加成功"; } else { status = "0"; message = "添加失败!"; } } } else { wmsPulling.UpdateUserId = CurrentEmp.EmpId; int ret = this.service.updatePullGroup(wmsPulling, wmsPullingDetailList); if (ret > 0) { status = "1"; message = "修改成功"; } else { status = "0"; message = "修改失败!"; } } } catch (Exception e) { status = "0"; message = "操作失败!"; } Hashtable result = new Hashtable(); result.Add("status", status); result.Add("message", message); return Json(result); } public ActionResult GetErpwarehouse() { Hashtable resault = new Hashtable(); List pdlineList = service.GetErpwarehouse(); resault.Add("list", pdlineList); return Json(resault); } /// /// 编辑菜单 /// /// /// public ActionResult EditPullGroup(String ruid) { if (!string.IsNullOrEmpty(ruid)) { Hashtable ht = this.service.getPullGroup(ruid); ViewData.Add("editType", "edit"); ViewData.Add("ruid", ht["ruid"]); ViewData.Add("groupCode", ht["groupCode"]); ViewData.Add("groupName", ht["groupName"]); ViewData.Add("pullingType", ht["pullingType"]); ViewData.Add("pdlineId", ht["pdlineId"]); ViewData.Add("pdlineCode", ht["pdlineCode"]); ViewData.Add("kittingQty", ht["kittingQty"]); ViewData.Add("isAutoPrint", ht["isAutoPrint"]); ViewData.Add("printCopies", ht["printCopies"]); ViewData.Add("triggerValue", ht["triggerValue"]); ViewData.Add("pullValue", ht["pullValue"]); } else { ViewData.Add("editType", "new"); } return View("EditPullGroup"); } #region 过滤零件号 private ActionResult writeResult(List list) { Hashtable result = new Hashtable(); result.Add("list", list); return Json(result); } 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 /// /// 启用 /// /// /// public ActionResult onEnable(String groupCode) { int delCount = 0; try { delCount = this.service.EnableData(groupCode); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 禁用 /// /// /// public ActionResult onDisable(String groupCode) { int delCount = 0; try { delCount = this.service.DisableData(groupCode); } 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 groupCode, string groupName, string enabled = "Y") { List listHt = this.service.getExportList(groupCode, groupName, 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"); } } }