using BLL; using Common; using Model; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web.Script.Serialization; using Json; using Lib; using System.Web.Mvc; namespace WMS.Areas.Business.Controllers { public class ErpInAjaxController : AjaxPage { // GET: Business/ErpInAjax public ActionResult GetErpInList() { try { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { DALErpIn provider = new DALErpIn(); PageInfo pageInfo = new PageInfo() { PageIndex = models.pageIndex, PageSize = models.pageSize }; models.DepartGuid = this.LoginDepartNum; List entity = provider.GetList(models, ref pageInfo).ToList(); Session["TEMPDATA_CACHE_INSTORDETAIL"] = entity; string json = JsonHelper.IListToJson(entity, "List"); string pjson = ConvertJson.Serializer(pageInfo); ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("PageInfo", new JsonObject(pjson)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); return Content(this.ReturnJson.ToString()); } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult SelMatNos() { try { var guid = Request["aaa"]; if (!string.IsNullOrEmpty(guid)) { List matList = new List(); // 判断缓存内是否包含此物料 if (Session["SEL_ERPIN_LIST"] != null) { matList = Session["SEL_ERPIN_LIST"] as List; foreach (ErpDetails details in matList) { if (details.MatGuid == guid) { return Content(null); } } } else { Session["SEL_ERPIN_LIST"] = new List(); } // 将物料编码添加到Session中 IDALMatNo provider = new DALMatNo(); Material matModel = provider.GetModel(guid); ErpDetails newDetail = new ErpDetails { MatGuid = matModel.Guid, MatNo = matModel.MatNo, MatName = matModel.MatName, MatType = matModel.MatType, MatTypeId = matModel.MatTypeId }; matList.Add(newDetail); Session["SEL_ERPIN_LIST"] = matList; } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult EmptySession() { Session["SEL_ERPIN_LIST"] = null; return Content(null); } public ActionResult GetMatNos() { try { if (Session["SEL_ERPIN_LIST"] == null) { return Content(null); } List matList = Session["SEL_ERPIN_LIST"] as List; string json = JsonHelper.IListToJson(matList, "List"); ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); return Content(this.ReturnJson.ToString()); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult IsCheckMatNo() { var Guid = Request["aaa"]; try { if (!string.IsNullOrEmpty(Guid)) { DALErpIn provider = new DALErpIn(); if (!provider.IsExist(Guid)) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "盘点出库指令已下发!"); } else { return Content(null); } } return Content(this.ReturnJson.ToString()); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult AddMat() { try { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { if (Session["SEL_ERPIN_LIST"] == null) { Session["SEL_ERPIN_LIST"] = new List(); } List list = Session["SEL_ERPIN_LIST"] as List; if (!list.IsEmpty()) { foreach (ErpDetails detail in list) { if (detail.MatGuid == models.MatGuid) { models.guid = detail.guid; list.Remove(detail); break; } } } list.Add(models); Session["SEL_ERPIN_LIST"] = list; string json1 = JsonHelper.IListToJson(list, "List"); ReturnJson.AddProperty("Result", new JsonObject(json1)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); return Content(this.ReturnJson.ToString()); } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult Add() { try { var dd = Request["entity"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { List list = Session["SEL_ERPIN_LIST"] as List; if (list == null) { return Content(null); } models.DepartGuid = this.LoginDepartNum; models.CreateUser = this.LoginUserCode; models.Statu = "01"; // 验证入库单明细物料信息 foreach (ErpDetails detail in list) { if (string.IsNullOrEmpty(detail.LingNo) || string.IsNullOrEmpty(detail.CurQuant) || string.IsNullOrEmpty(detail.MatNo)) { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "物料信息缺失!"); return Content(this.ReturnJson.ToString()); } } DALErpIn dalErp = new DALErpIn(); if (string.IsNullOrEmpty(models.OrdNo)) { if (dalErp.Add(models, list)) { Session["SEL_ERPIN_LIST"] = null; ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "添加订单成功"); } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "添加订单失败"); } } else { if (dalErp.Update(models, list)) { Session["SEL_ERPIN_LIST"] = null; ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "编辑订单成功"); } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "编辑订单失败"); } } return Content(this.ReturnJson.ToString()); } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult DelProduct() { try { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (!string.IsNullOrEmpty(models.MatGuid)) { List listMat = Session["SEL_ERPIN_LIST"] as List; for (int i = listMat.Count - 1; i >= 0; i--) { if (listMat[i].MatGuid == models.MatGuid) { if (!string.IsNullOrEmpty(listMat[i].guid)) { DALErpIn dALErpIn = new DALErpIn(); dALErpIn.DelOrdDetail(listMat[i].guid); } listMat.Remove(listMat[i]); } } Session["SEL_ERPIN_LIST"] = listMat; string json1 = JsonHelper.IListToJson(listMat, "List"); ReturnJson.AddProperty("Result", new JsonObject(json1)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "删除物料成功"); return Content(this.ReturnJson.ToString()); } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult CheckOrdStatus() { try { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { IDALErpIn provider = new DALErpIn(); Erp entity = provider.GetModel(models.OrdNo); if (entity.Statu == "等待执行") { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "入库单可编辑"); } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "入库单状态已改变,不可编辑,请刷新页面"); } return Content(this.ReturnJson.ToString()); } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult GetDetail() { try { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { if (string.IsNullOrEmpty(models.OrdNo)) { return Content(null); } models.DepartGuid = this.LoginDepartNum; PageInfo pageInfo = new PageInfo() { PageIndex = models.pageIndex, PageSize = models.pageSize }; DALErpInDetail detail = new DALErpInDetail(); List entity = detail.GetList(models).ToList(); Session["SEL_ERPIN_LIST"] = entity; string json = JsonHelper.IListToJson(entity, "List"); string pjson = ConvertJson.Serializer(pageInfo); ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("PageInfo", new JsonObject(pjson)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); return Content(this.ReturnJson.ToString()); } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult GetMatNo() { try { var matNo = Request["aaa"]; if (!string.IsNullOrEmpty(matNo)) { DALErpIn dALErpIn = new DALErpIn(); ErpDetails MatItem = dALErpIn.GetMatNo(matNo); string json = JsonHelper.ObjectToJson(MatItem, "Mat"); ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "查询成功!"); return Content(this.ReturnJson.ToString()); } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult GetDetails() { try { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { PageInfo pageInfo = new PageInfo() { PageIndex = models.pageIndex, PageSize = models.pageSize }; DALErpInDetail detail = new DALErpInDetail(); models.DepartGuid = this.LoginDepartNum; List entity = detail.GetList(models, ref pageInfo).ToList(); string json = JsonHelper.IListToJson(entity, "List"); string pjson = ConvertJson.Serializer(pageInfo); ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("PageInfo", new JsonObject(pjson)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); return Content(this.ReturnJson.ToString()); } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult Delete() { try { string dd = Request["list"]; ArrayList models = new JavaScriptSerializer().Deserialize(dd); string[] list = (string[])models.ToArray(typeof(string)); if (models != null) { IDALErpIn dalErp = new DALErpIn(); if (dalErp.DeleteOrdNo(list)) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "删除订单成功"); } else { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "删除订单失败"); } return Content(this.ReturnJson.ToString()); } return Content(null); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } public ActionResult Init() { try { Session["TEMPDATA_CACHE_INSTORDETAIL"] = null; List list = new List(); string json = JsonHelper.IListToJson(list, "List"); ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); return Content(this.ReturnJson.ToString()); } catch (Exception ex) { WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod()); return Content(null); } } // GET: Business/ErpInAjax public ActionResult LoadDetail() { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { List list = Session["TEMPDATA_CACHE_INSTORDETAIL"] as List; PageInfo pageInfo = new PageInfo() { PageIndex = models.pageIndex, PageSize = models.pageSize }; list = list.IsEmpty() ? new List() : list; pageInfo.RowCount = list.Count; list = list.IsEmpty() ? new List() : ((from u in list select u).Skip(pageInfo.PageSize * (pageInfo.PageIndex - 1)).Take(pageInfo.PageSize)).ToList(); string json = JsonHelper.IListToJson(list, "List"); string pjson = ConvertJson.Serializer(pageInfo); ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("PageInfo", new JsonObject(pjson)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); ReturnJson.AddProperty("SubCode", 0); ReturnJson.AddProperty("SubMessage", ""); return Content(this.ReturnJson.ToString()); } return Content(null); } /// /// 获取物料下托盘和货位存放位置 /// /// public ActionResult Getposition() { var OrdNo = Request["OrdNo"]; var MatNo = Request["MatNo"]; if (MatNo != null) { DALErpInDetail position = new DALErpInDetail(); List entity = position.Getposition(OrdNo, MatNo).ToList();//,ref pageInfo string json = JsonHelper.IListToJson(entity, "List"); ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); ReturnJson.AddProperty("SubCode", 0); ReturnJson.AddProperty("SubMessage", ""); return Content(this.ReturnJson.ToString()); } return Content(null); } // GET: Business/ErpInAjax public ActionResult AddProduct() { var dd = Request["Entity"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { List list = Session["TEMPDATA_CACHE_INSTORDETAIL"] as List; if (!list.IsEmpty()) { for (int i = 0; i < list.Count; i++) { ///< summary > /// 如果物料编码相同则删除保存最新列 /// if (list[i].Palno == null) { list[i].Palno = ""; } if (list[i].MatNo == models.MatNo/*&& list[i].Palno==models.Palno*/) { list.Remove(list[i]); i--; } } list.Add(models); Session["TEMPDATA_CACHE_INSTORDETAIL"] = list; ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); ReturnJson.AddProperty("SubCode", 0); ReturnJson.AddProperty("SubMessage", ""); } else { list = new List(); list.Add(models); Session["TEMPDATA_CACHE_INSTORDETAIL"] = list; ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); ReturnJson.AddProperty("SubCode", 0); ReturnJson.AddProperty("SubMessage", ""); } return Content(this.ReturnJson.ToString()); } return Content(null); } public ActionResult Audite() { string dd = Request["ajaxdata"]; if (dd != null) { var models = new JavaScriptSerializer().Deserialize(dd); ArrayList Matlist = new JavaScriptSerializer().Deserialize(models.list); string[] list = (string[])Matlist.ToArray(typeof(string)); IDALErpIn dalErp = new DALErpIn(); bool value = false; value = dalErp.UpdateAudit(list, models.Operation, LoginUserCode); if (value) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "删除订单成功"); } else { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "删除订单失败"); } ReturnJson.AddProperty("SubCode", 0); ReturnJson.AddProperty("SubMessage", ""); return Content(this.ReturnJson.ToString()); } return Content(null); } /// /// 入库单关单 /// /// public ActionResult Close() { string ordNo = Request["list"]; // 验证单据状态 DALErpIn provider = new DALErpIn(); Erp entity = provider.GetModel(ordNo); if (entity.Statu == "正在执行") { #region 处理组盘信息 // 判断是否存在正在执行的指令 if (!provider.IsIpallets(ordNo)) { ReturnJson.AddProperty("Code", 0); ReturnJson.AddProperty("Message", "存在执行中的任务指令,请先处理任务指令。"); return Content(this.ReturnJson.ToString()); } // 删除未执行的组盘信息 provider.DelIpallets(ordNo); #endregion // 修改入库单状态 bool bl = provider.UpdateClose(new string[] { ordNo }, "ER03"); if (bl) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "关闭入库单成功"); } else { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "关闭入库单失败"); } } else { ReturnJson.AddProperty("Code", 0); ReturnJson.AddProperty("Message", "入库单状态已改变,不可关单。"); } return Content(this.ReturnJson.ToString()); } public ActionResult GetErpInDetail() { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { PageInfo pageInfo = new PageInfo() { PageIndex = models.pageIndex, PageSize = models.pageSize }; IDALPurchaseDetail detail = new DALPurchaseDetail(); List entity = detail.GetList(models, ref pageInfo).ToList(); string json = JsonHelper.IListToJson(entity, "List"); string pjson = ConvertJson.Serializer(pageInfo); ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("PageInfo", new JsonObject(pjson)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "响应成功"); ReturnJson.AddProperty("SubCode", 0); ReturnJson.AddProperty("SubMessage", ""); return Content(this.ReturnJson.ToString()); } return Content(null); } /// ///托盘下拉框查询 /// public ActionResult BindOption() { string Addre = Request["ajaxdata"]; try { //DALErpIn addre = new DALErpIn(); //List entity = addre.GetList(Addre).ToList(); //string json = JsonHelper.IListToJson(entity,"list"); // ReturnJson.AddProperty("Palno", new JsonObject(json)); ReturnJson.AddProperty("Palno", LocalHelper.GetPalnoList(Addre, "")); return Json(this.ReturnJson.ToString()); } catch (System.Exception) { return Content(null); } } public ActionResult AddIPalletBind() { string dd = Request["ajaxdata"]; if (dd != null) { var models = new JavaScriptSerializer().Deserialize(dd); DALErpIn dalErp = new DALErpIn(); string messAgeStr = dalErp.AddIPalletBind(models.PalletNo, models.OrdNo, this.LoginUserCode, this.LoginDepartNum); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", messAgeStr); return Content(this.ReturnJson.ToString()); } return Content(null); } } }