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 TrayDefineController : BaseController { private ITrayService service; private ICommonService commonService; public TrayDefineController(ITrayService _service, ICommonService _commonService) { service = _service; this.commonService = _commonService; } // // GET: /Role/ public ActionResult Index() { return View(); } #region 料架信息管理 /// /// 根据分页条件获取料架类型列表 /// /// /// /// /// /// public ActionResult getTrayByPage(String trayCode, String trayName, Pager pager, String direction, String sort) { Hashtable result = new Hashtable(); result.Add("pager.pageNo", pager.pageNo); Hashtable dataHt = this.service.getTrayByPage(trayCode, trayName, pager, direction, sort); result.Add("rows", dataHt["dt"]); result.Add("pager.totalRows", dataHt["totalCount"]); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } /// /// 获取料架类型列表 /// /// public ActionResult getTrayType() { Hashtable result = new Hashtable(); List typeList = this.service.getTrayType(); result.Add("list", typeList); return Json(result); } /// /// 获取料架排序方式数据 /// /// public ActionResult getTraySeq() { Hashtable result = new Hashtable(); List traySortList = commonService.GetSysEnum("g_tray_seq"); result.Add("list", traySortList); return Json(result); } /// /// 保存料架信息 /// /// public ActionResult saveTray() { String editType = Request.Form["editType"].ToString(); String trayId = Request.Form["trayId"].ToString(); String trayCode = Request.Form["trayCode"].ToString(); String trayName = Request.Form["trayName"].ToString(); int trayTypeId = Convert.ToInt32(Request.Form["typeId"].ToString()); int traySeq = Convert.ToInt32(Request.Form["enumDesc"]); GTray gTray = new GTray(); gTray.TrayCode = trayCode; gTray.TrayName = trayName; gTray.TrayTypeId = trayTypeId; gTray.TraySeq = traySeq; String message = ""; String flag = ""; if (editType != null && editType.Trim().Equals("edit")) { try { gTray.UpdateUserId = CurrentEmp.EmpId; gTray.TrayId = Convert.ToInt32(trayId); int i = this.service.updateTrayInfo(gTray); if (i == 1) { message = "修改成功!"; flag = "OK"; } else { message = "修改失败!"; flag = "fail"; } } catch (Exception e) { message = "修改失败!"; flag = "fail"; } } else { try { gTray.CreateUserId = CurrentEmp.EmpId; int i = this.service.saveTrayInfo(gTray); if (i == -1) { message = "料架类型代码:" + trayCode + "已存在!"; flag = "fail"; } else if (i == 1) { message = "添加成功!"; flag = "OK"; } else { message = "添加失败!"; flag = "fail"; } } catch (Exception e) { message = "添加失败!"; flag = "fail"; } } Hashtable result = new Hashtable(); result.Add("message", message); result.Add("flag", flag); return Json(result); } /// /// 编辑料架信息 /// /// /// public ActionResult editTray(String trayId) { if (!string.IsNullOrEmpty(trayId)) { List typeInfo = this.service.GetTrayById(trayId); //Hashtable htRoleInfo = (Hashtable)typeInfo[0]; ViewData.Add("editType", "edit"); ViewData.Add("trayId", trayId); ViewData.Add("trayCode", typeInfo[0].TrayCode); ViewData.Add("trayName", typeInfo[0].TrayName); ViewData.Add("traySeq", typeInfo[0].TraySeq); ViewData.Add("typeId", typeInfo[0].TrayTypeId); } else { ViewData.Add("editType", "new"); } return View("editTray"); } /// /// 删除料架数据 /// /// /// public ActionResult deleteTray(String ids) { int delCount = 0; try { delCount = this.service.deleteTray(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 导出数据 /// /// public ActionResult exportData(String trayTypeCode, String trayTypeName, Pager pager, String direction, String sort) { Hashtable dataHt = this.service.getTableListByPage(trayTypeCode, trayTypeName, pager, direction, sort); List listHt = (List)dataHt["dataList"]; var memoryStream = ExcelHelper.ToExcel(listHt); return File(memoryStream.ToArray(), "application/ms-excel", "料架信息.xls"); } /// /// 根据分页条件获取料架类型列表 /// /// /// /// /// /// public ActionResult getTrayDetailOfPager(String trayId, Pager pager, String direction, String sort) { Hashtable result = new Hashtable(); result.Add("pager.pageNo", pager.pageNo); Hashtable dataHt = this.service.getTrayDetailOfPager(trayId, pager, direction, sort); result.Add("rows", dataHt["dt"]); result.Add("pager.totalRows", dataHt["totalCount"]); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } /// /// 获取料架位置数据 /// /// public ActionResult getTrayLoc() { Hashtable result = new Hashtable(); List traySortList = commonService.GetSysEnum("sys_tray_loc"); result.Add("list", traySortList); return Json(result); } /// /// 放置总成的类型 /// /// public ActionResult getPlacePartLocation() { Hashtable result = new Hashtable(); List traySortList = commonService.GetSysEnum("sys_part_location"); result.Add("list", traySortList); return Json(result); } /// /// 编辑料架明细信息 /// /// /// public ActionResult editTrayDetail() { String trayId = Request.Form["trayId"].ToString(); String guid =string.IsNullOrEmpty(Request.Form["guid"]) ? "" : Request.Form["guid"].ToString(); if (guid.Equals("")) { ViewData.Add("editType", "new"); } else { List trayDetailInfo = this.service.GetTrayDetailByGuid(guid); ViewData.Add("editType", "edit"); ViewData.Add("trayLoc", trayDetailInfo[0].TrayLoc); ViewData.Add("placePartLocation", trayDetailInfo[0].PlacePartLocation); } List TrayInfo = this.service.GetTrayById(trayId); ViewData.Add("trayId", trayId); ViewData.Add("trayName", TrayInfo[0].TrayName); ViewData.Add("guid", guid); return View("editTrayDetail"); } /// /// 保存料架明细信息 /// /// public ActionResult saveTrayDetail() { String editType = Request.Form["editType"].ToString(); String guid = Request.Form["guid"].ToString(); int trayId = Convert.ToInt32(Request.Form["trayId"]); int trayLoc = Convert.ToInt32(Request.Form["trayLoc"].ToString()); String placePartLocation = Request.Form["placePartLocation"].ToString(); GTrayDetail gTrayDetail = new GTrayDetail(); gTrayDetail.TrayId = trayId; gTrayDetail.TrayLoc = trayLoc; gTrayDetail.PlacePartLocation = placePartLocation; String message = ""; String flag = ""; if (editType != null && editType.Trim().Equals("edit")) { try { gTrayDetail.UpdateUserId = CurrentEmp.EmpId; gTrayDetail.Guid = guid; int i = this.service.updateTrayDetailInfo(gTrayDetail); if (i == 1) { message = "修改成功!"; flag = "OK"; } else { message = "修改失败!"; flag = "fail"; } } catch (Exception e) { message = "修改失败!"; flag = "fail"; } } else { try { gTrayDetail.CreateUserId = CurrentEmp.EmpId; int i = this.service.saveTrayDetailInfo(gTrayDetail); if (i == 1) { message = "添加成功!"; flag = "OK"; } else { message = "添加失败!"; flag = "fail"; } } catch (Exception e) { message = "添加失败!"; flag = "fail"; } } Hashtable result = new Hashtable(); result.Add("message", message); result.Add("flag", flag); return Json(result); } /// /// 删除料架明细数据 /// /// /// public ActionResult deleteTrayDetail(String ids) { int delCount = 0; try { delCount = this.service.deleteTrayDetail(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.EnableData(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.DisableData(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 导出料架明细数据 /// /// public ActionResult exportDataDetail(String trayId, Pager pager, String direction, String sort) { Hashtable dataHt = this.service.getTrayDetailToList(trayId, pager, direction, sort); List listHt = (List)dataHt["dataList"]; var memoryStream = ExcelHelper.ToExcel(listHt); return File(memoryStream.ToArray(), "application/ms-excel", "料架明细信息.xls"); } #endregion } }