public ActionResult Query(WorkOrderViewModel model) { MethodReturnResult ReturnResult = new MethodReturnResult(); using (ERPClient client = new ERPClient()) { MethodReturnResult <DataSet> result = client.GetERPWorkOrder(model.OrderNumber); if (result.Code == 0) { if (result.Data.Tables[0].Rows.Count <= 0) { ReturnResult.Code = 1001; ReturnResult.Message = string.Format(StringResource.ERPWorkOrderQuery_Error_Query, model.OrderNumber); } } else { ReturnResult.Code = result.Code; ReturnResult.Message = result.Message; } } return(Json(ReturnResult)); }
public ActionResult GetOrderNumberByPackageNo(string lotNumber) { MethodReturnResult <DataSet> ds = new MethodReturnResult <DataSet>(); if (lotNumber.Contains(',')) { lotNumber = lotNumber.Split(',')[0].ToString(); } using (ERPClient client = new ERPClient()) { ds = client.GetReceiptOrderNumberByPackageNo(lotNumber); } //MethodReturnResult<Package> rst = new MethodReturnResult<Package>(); //List<Package> listPackage = new List<Package>(); //using (PackageQueryServiceClient client = new PackageQueryServiceClient()) //{ // rst = client.Get(lotNumber); // if (rst.Code <= 0 && rst.Data != null) // { // listPackage.Add(rst.Data); // } //} var data = from item in ds.Data.Tables[0].AsEnumerable() select new { OrderNumber = item["ORDER_NUMBER"] }; return(Json(data, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Query(MaterialReceiptQueryViewModel model) { using (ERPClient client = new ERPClient()) { MethodReturnResult ReturnResult = new MethodReturnResult(); MethodReturnResult <DataSet> result = client.GetERPMaterialReceipt(model.ReceiptNo); if (result.Code == 0) { if (result.Data.Tables[0].Rows.Count > 0) { WorkOrderServiceClient workClient = new WorkOrderServiceClient(); MethodReturnResult <WorkOrder> rst = await workClient.GetAsync(result.Data.Tables[0].Rows[0]["VPRODUCTBATCH"].ToString()); if (rst.Data == null) { ReturnResult.Code = 1001; ReturnResult.Message = string.Format(StringResource.ERPWorkOrder_Error_Query, model.ReceiptNo, result.Data.Tables[0].Rows[0]["VPRODUCTBATCH"].ToString()); } } else { ReturnResult.Code = 1001; ReturnResult.Message = string.Format(StringResource.ERPMaterialReceipt_Error_Query, model.ReceiptNo); } } else { ReturnResult.Code = result.Code; ReturnResult.Message = result.Message; } return(Json(ReturnResult)); } }
/// <summary> 取得ERP工单BOM信息 </summary> /// <param name="OrderNumber"></param> /// <returns></returns> public async Task <ActionResult> GetERPWorkOrderBOM(string OrderNumber) { using (ERPClient client = new ERPClient()) { List <WorkOrderBOMViewModel> list = new List <WorkOrderBOMViewModel>(); await Task.Run(() => { MethodReturnResult <DataSet> result = client.GetERPWorkOrderBOM(OrderNumber); if (result.Code == 0 && result.Data.Tables[0].Rows.Count > 0) { for (int i = 0; i < result.Data.Tables[0].Rows.Count; i++) { WorkOrderBOMViewModel workOrderBOMModel = new WorkOrderBOMViewModel(); workOrderBOMModel.RowNo = Int32.Parse(result.Data.Tables[0].Rows[i]["行号"].ToString()); //行号 workOrderBOMModel.ItemNo = Int32.Parse(result.Data.Tables[0].Rows[i]["序号"].ToString()); //序号 workOrderBOMModel.MaterialCode = result.Data.Tables[0].Rows[i]["MATERIALCODE"].ToString(); //物料代码 workOrderBOMModel.MaterialName = result.Data.Tables[0].Rows[i]["MATERIALNAME"].ToString(); //物料名称 workOrderBOMModel.Qty = Convert.ToDecimal(result.Data.Tables[0].Rows[i]["NUNITNUM"].ToString()); //消耗量 workOrderBOMModel.MaterialUnit = result.Data.Tables[0].Rows[i]["MEAS"].ToString(); //计量单位 workOrderBOMModel.MinUnit = Convert.ToDecimal(result.Data.Tables[0].Rows[i]["MINUNIT"].ToString()); //最小扣料单位 //workOrderBOMModel.ReplaceMaterial = result.Data.Tables[0].Rows[i]["MATERIALCODE"].ToString(); //可替换料 list.Add(workOrderBOMModel); } } ViewBag.BOMList = list; }); } return(PartialView("_BOMListPartial")); }
public ActionResult AddMaterialTypeFromERP() { MethodReturnResult returnResult = new MethodReturnResult(); using (ERPClient ErpClient = new ERPClient()) { BaseMethodParameter p = new BaseMethodParameter() { Creator = User.Identity.Name, OperateComputer = Request.UserHostAddress, Operator = User.Identity.Name, }; returnResult = ErpClient.AddMaterialTypeFromERP(p); }; return(Json(returnResult)); }
public ActionResult Detail(string ReceiptNo) { MaterialReceiptViewModel model = null; using (LineStoreServiceClient client = new LineStoreServiceClient()) { PagingConfig cfg = new PagingConfig() { OrderBy = "Key" }; MethodReturnResult <IList <LineStore> > result = client.Get(ref cfg); List <SelectListItem> LineStoreList = new List <SelectListItem>(); //LineStoreList.Add(new SelectListItem() { Text = "--Select--", Value = "select" }); foreach (LineStore item in result.Data) { LineStoreList.Add(new SelectListItem() { Text = item.Key, Value = item.Key }); } ViewBag.LineStore = LineStoreList; } using (ERPClient client = new ERPClient()) { //根据材料出库单单据号查询ERP中是否存在该出库单 MethodReturnResult <DataSet> result = client.GetERPMaterialReceiptStore(ReceiptNo); DataTable dtERP = new DataTable(); DataTable dtMES = new DataTable(); dtERP = result.Data.Tables["dtERP"]; dtMES = result.Data.Tables["dtMES"]; if (result.Data.Tables[0].Rows.Count > 0) { model = new MaterialReceiptViewModel() { ReceiptNo = dtERP.Rows[0]["VBILLCODE"].ToString(), OrderNumber = dtERP.Rows[0]["VPRODUCTBATCH"].ToString(), ReceiptDate = DateTime.Parse(dtERP.Rows[0]["DBILLDATE"].ToString()), LineStoreName = dtMES.Rows[0]["STORE_NAME"].ToString() }; } ViewBag.MaterialReceipt = model; return(View(model)); } }
public void InsertProjectInfoToMapics(OrderViewModelLight model) { var project = new ProjectInfo { BusinessId = model.BusinessId.GetValueOrDefault(), BusinessName = model.BusinessName, ERPAccountId = !string.IsNullOrEmpty(model.ERPAccountId) ? Convert.ToInt32(model.ERPAccountId) : 0, ProjectId = model.ProjectId, ProjectName = model.ProjectName, AccountId = model.AccountID, QuoteId = model.QuoteId }; var erpClient = new ERPClient(); erpClient.PostProjectsInfoToMapicsAsync(project); }
public string REback(string lotNumber) { MethodReturnResult result = new MethodReturnResult(); using (ERPClient client = new ERPClient()) { REbackdataParameter param = new REbackdataParameter(); param.PackageNo = lotNumber; param.ErrorMsg = ""; param.ReType = 2; param.IsDelete = 1; result = client.GetREbackdata(param); //if (result.Code == 1000) //{ // result.Message += string.Format(WIPResources.StringResource.REbackdata_Fail); //} } return(result.Message); }
public ActionResult Save(WorkOrderViewModel model) { MethodReturnResult result = new MethodReturnResult(); using (ERPClient client = new ERPClient()) { ERPWorkOrderParameter param = new ERPWorkOrderParameter(); param.Creator = User.Identity.Name; //操作员 param.OrderNumber = model.OrderNumber; //工单号 result = client.AddERPWorkOrder(param); if (result.Code == 0) { result.Message = string.Format(StringResource.ERPWorkOrder_Add_Success); } } return(Json(result)); }
public ActionResult Save(string ReceiptNo, string LineStore, string Description) { // MethodReturnResult res = new MethodReturnResult(); //string error_mes = string.Empty; MethodReturnResult result = new MethodReturnResult(); using (ERPClient client = new ERPClient()) { ERPMaterialReceiptParameter param = new ERPMaterialReceiptParameter(); param.ReceiptNo = ReceiptNo; param.LineStore = LineStore; param.Creator = User.Identity.Name; param.Description = Description; result = client.AddERPMaterialReceipt(param); if (result.Code == 0) { result.Message += string.Format(StringResource.ERPMaterialReceipt_Add_Success); //移除缓存 cache.Remove(ReceiptNo); } } return(Json(result)); }
/// <summary> /// 更新工单BOM /// </summary> /// <param name="OrderNumber">工单号</param> /// <param name="Priority"></param> /// <param name="Description"></param> /// <returns></returns> //public ActionResult SaveBOM(string OrderNumber, EnumWorkOrderPriority Priority, string Description) public ActionResult SaveBOM(WorkOrderViewModel model) { MethodReturnResult result = new MethodReturnResult(); using (ERPClient client = new ERPClient()) { ERPWorkOrderParameter param = new ERPWorkOrderParameter() { OrderNumber = model.OrderNumber, //工单号 Creator = User.Identity.Name //创建人 }; //调用BOM更新服务 result = client.UpdateBaseInfo(param); if (result.Code == 0) { result.Message = string.Format("ERP工单{0}BOM更新成功!", model.OrderNumber); } } return(Json(result)); }
public async Task <ActionResult> Save(SupplierToManufacturerViewModel model) { DateTime now = DateTime.Now; MethodReturnResult rst = new MethodReturnResult(); #region 界面录入信息合规性检查 using (MaterialServiceClient client = new MaterialServiceClient()) { MethodReturnResult <Material> result = client.Get(model.MaterialCode); if (result.Code != 0) { rst.Code = 1001; rst.Message = String.Format("MES中不存在物料编码:{0}", model.MaterialCode); return(Json(rst)); } else { if (model.OrderNumber != "*") { using (WorkOrderServiceClient clientOfWorkOrder = new WorkOrderServiceClient()) { MethodReturnResult <WorkOrder> resultOfOrder = clientOfWorkOrder.Get(model.OrderNumber); if (resultOfOrder.Code != 0) { rst.Code = 1001; rst.Message = String.Format("MES中不存在工单:{0}", model.OrderNumber); return(Json(rst)); } } } } } #endregion using (ERPClient erpClient = new ERPClient()) { MethodReturnResult <DataSet> ds_supplier = erpClient.GetERPSupplier(model.SupplierCode); MethodReturnResult <DataSet> ds_manufacturer = erpClient.GetByCodeERPManufacturer(model.ManufacturerCode); if (ds_supplier == null || ds_supplier.Data.Tables[0].Rows.Count == 0) { rst.Code = 1001; rst.Message = String.Format("ERP中不存在供应商:{0}", model.SupplierCode); return(Json(rst)); } if (ds_manufacturer == null || ds_manufacturer.Data.Tables[0].Rows.Count == 0) { rst.Code = 1001; rst.Message = String.Format("ERP中不存在生产厂商:{0}", model.ManufacturerCode); return(Json(rst)); } //新增转换供应商 using (SupplierServiceClient supplierClient = new SupplierServiceClient()) { MethodReturnResult <Supplier> result = await supplierClient.GetAsync(model.SupplierCode); if (result.Code != 0) { Supplier supplier = new Supplier() { Key = ds_supplier.Data.Tables[0].Rows[0]["CUSCODE"].ToString(), Name = ds_supplier.Data.Tables[0].Rows[0]["CUSNAME"].ToString(), NickName = " ", CreateTime = now, EditTime = now, Creator = User.Identity.Name, Editor = User.Identity.Name, Description = "" }; rst = await supplierClient.AddAsync(supplier); if (rst.Code != 0) { return(Json(rst)); } } } //新增转换生产厂商 using (ManufacturerServiceClient manufacturerClient = new ManufacturerServiceClient()) { MethodReturnResult <Manufacturer> result = await manufacturerClient.GetAsync(model.ManufacturerCode); if (result.Code != 0) { Manufacturer manufacturer = new Manufacturer() { Key = ds_manufacturer.Data.Tables[0].Rows[0]["CSCODE"].ToString(), Name = ds_manufacturer.Data.Tables[0].Rows[0]["CSNAME"].ToString(), NickName = " ", CreateTime = now, EditTime = now, Creator = User.Identity.Name, Editor = User.Identity.Name, Description = "" }; rst = await manufacturerClient.AddAsync(manufacturer); if (rst.Code != 0) { return(Json(rst)); } } } //新增转换规则 using (SupplierToManufacturerServiceClient client = new SupplierToManufacturerServiceClient()) { SupplierToManufacturer obj = new SupplierToManufacturer() { Key = new SupplierToManufacturerKey() { MaterialCode = model.MaterialCode.ToString().Trim().ToUpper(), OrderNumber = model.OrderNumber.ToString().Trim().ToUpper(), SupplierCode = model.SupplierCode.ToString().Trim().ToUpper() }, ManufacturerCode = model.ManufacturerCode.ToString().Trim().ToUpper(), CreateTime = now, EditTime = now, Creator = User.Identity.Name, Editor = User.Identity.Name }; rst = await client.AddAsync(obj); if (rst.Code == 0) { rst.Message = string.Format(ZPVMResources.StringResource.SupplierToManufacturer_Save_Success); } return(Json(rst)); } } }
public ActionResult PagingQueryReplace(string receiptNo, string orderBy, int?currentPageNo, int?currentPageSize) { using (ERPClient client = new ERPClient()) { int pageNo = currentPageNo ?? 0; int pageSize = currentPageSize ?? 20; if (Request["PageNo"] != null) { pageNo = Convert.ToInt32(Request["PageNo"]); } if (Request["PageSize"] != null) { pageSize = Convert.ToInt32(Request["PageSize"]); } MethodReturnResult <List <MaterialReceiptReplace> > MaterialReceiptReplaceDetailAll = new MethodReturnResult <List <MaterialReceiptReplace> >(); //获取全部领料明细 if (cache[receiptNo] != null) { MaterialReceiptReplaceDetailAll = (MethodReturnResult <List <MaterialReceiptReplace> >)cache[receiptNo]; } else { MethodReturnResult <DataSet> result = client.GetERPMaterialReceiptDetail(receiptNo); MaterialReceiptReplaceDetailAll = client.GetMaterialReceiptReplaceDetail(result, 0, 20); } List <MaterialReceiptReplaceViewModel> list = new List <MaterialReceiptReplaceViewModel>(); if (MaterialReceiptReplaceDetailAll.Code == 0 && MaterialReceiptReplaceDetailAll.Data != null) { //将数组添加到缓存中——使用Add方法 if (cache[receiptNo] == null) { cache.Add(receiptNo, MaterialReceiptReplaceDetailAll, null, DateTime.Now.AddSeconds(900), TimeSpan.Zero, CacheItemPriority.Normal, null); } int count = 0; if ((pageNo + 1) * pageSize < MaterialReceiptReplaceDetailAll.Data.Count) { count = (pageNo + 1) * pageSize; } else { count = MaterialReceiptReplaceDetailAll.Data.Count; } for (int i = Convert.ToInt32(pageNo * pageSize); i < count; i++) { MaterialReceiptReplaceViewModel model = new MaterialReceiptReplaceViewModel() { ItemNo = MaterialReceiptReplaceDetailAll.Data[i].Key, OrderNumber = MaterialReceiptReplaceDetailAll.Data[i].OrderNumber, OldMaterialCode = MaterialReceiptReplaceDetailAll.Data[i].OldMaterialCode, OldMaterialLot = MaterialReceiptReplaceDetailAll.Data[i].OldMaterialLot, MaterialCode = MaterialReceiptReplaceDetailAll.Data[i].MaterialCode, MaterialLot = MaterialReceiptReplaceDetailAll.Data[i].MaterialLot, Qty = MaterialReceiptReplaceDetailAll.Data[i].Qty, CellPower = MaterialReceiptReplaceDetailAll.Data[i].CellPower, CellGrade = MaterialReceiptReplaceDetailAll.Data[i].CellGrade, OldCellColor = MaterialReceiptReplaceDetailAll.Data[i].OldCellColor, CellColor = MaterialReceiptReplaceDetailAll.Data[i].CellColor, OldSupplierCode = MaterialReceiptReplaceDetailAll.Data[i].OldSupplierCode, OldSupplierName = MaterialReceiptReplaceDetailAll.Data[i].OldSupplierName, SupplierCode = MaterialReceiptReplaceDetailAll.Data[i].SupplierCode, SupplierName = MaterialReceiptReplaceDetailAll.Data[i].SupplierName, OldManufacturerCode = MaterialReceiptReplaceDetailAll.Data[i].OldManufacturerCode, OldManufacturerName = MaterialReceiptReplaceDetailAll.Data[i].OldManufacturerName, ManufacturerCode = MaterialReceiptReplaceDetailAll.Data[i].ManufacturerCode, ManufacturerName = MaterialReceiptReplaceDetailAll.Data[i].ManufacturerName, SupplierMaterialLot = MaterialReceiptReplaceDetailAll.Data[i].SupplierMaterialLot, Description = MaterialReceiptReplaceDetailAll.Data[i].Description }; list.Add(model); } PagingConfig cfg = new PagingConfig() { PageNo = pageNo, PageSize = pageSize, Records = MaterialReceiptReplaceDetailAll.Data.Count }; ViewBag.MaterialReceiptReplace = list; //ViewBag.MaterialReceiptReplaceDetailAll = MaterialReceiptReplaceDetailAll; ViewBag.ReceiptNo = receiptNo; ViewBag.PagingConfig = cfg; } return(PartialView("_ListPartial")); } }
//领料明细前20条 public ActionResult GetMaterialReceiptDetail(string ReceiptNo) { using (ERPClient client = new ERPClient()) { PagingConfig cfg = new PagingConfig(); List <MaterialReceiptReplaceViewModel> list = new List <MaterialReceiptReplaceViewModel>(); MethodReturnResult <DataSet> result = client.GetERPMaterialReceiptDetail(ReceiptNo); if (result.Code == 0 && result.Data.Tables[0].Rows.Count > 0) { MethodReturnResult <List <MaterialReceiptReplace> > lstMaterialReceiptReplace = new MethodReturnResult <List <MaterialReceiptReplace> >(); //获取全部领料明细 if (cache[ReceiptNo] != null) { lstMaterialReceiptReplace = (MethodReturnResult <List <MaterialReceiptReplace> >)cache[ReceiptNo]; } else { lstMaterialReceiptReplace = client.GetMaterialReceiptReplaceDetail(result, 0, 20); } if (lstMaterialReceiptReplace.Code == 0 && lstMaterialReceiptReplace.Data != null) { //将全部领料明细写入缓存 //将数组添加到缓存中——使用Add方法 if (cache[ReceiptNo] == null) { cache.Add(ReceiptNo, lstMaterialReceiptReplace, null, DateTime.Now.AddSeconds(900), TimeSpan.Zero, CacheItemPriority.Normal, null); } cfg.Records = result.Data.Tables[0].Rows.Count; int count = 0; if ((cfg.PageNo + 1) * cfg.PageSize < lstMaterialReceiptReplace.Data.Count) { count = (cfg.PageNo + 1) * cfg.PageSize; } else { count = lstMaterialReceiptReplace.Data.Count; } //生成领料明细前20条 for (int i = Convert.ToInt32(cfg.PageNo * cfg.PageSize); i < count; i++) { MaterialReceiptReplaceViewModel model = new MaterialReceiptReplaceViewModel() { ItemNo = lstMaterialReceiptReplace.Data[i].Key, OrderNumber = lstMaterialReceiptReplace.Data[i].OrderNumber, OldMaterialCode = lstMaterialReceiptReplace.Data[i].OldMaterialCode, OldMaterialLot = lstMaterialReceiptReplace.Data[i].OldMaterialLot, MaterialCode = lstMaterialReceiptReplace.Data[i].MaterialCode, MaterialLot = lstMaterialReceiptReplace.Data[i].MaterialLot, Qty = lstMaterialReceiptReplace.Data[i].Qty, CellPower = lstMaterialReceiptReplace.Data[i].CellPower, CellGrade = lstMaterialReceiptReplace.Data[i].CellGrade, OldCellColor = lstMaterialReceiptReplace.Data[i].OldCellColor, CellColor = lstMaterialReceiptReplace.Data[i].CellColor, OldSupplierCode = lstMaterialReceiptReplace.Data[i].OldSupplierCode, OldSupplierName = lstMaterialReceiptReplace.Data[i].OldSupplierName, SupplierCode = lstMaterialReceiptReplace.Data[i].SupplierCode, SupplierName = lstMaterialReceiptReplace.Data[i].SupplierName, OldManufacturerCode = lstMaterialReceiptReplace.Data[i].OldManufacturerCode, OldManufacturerName = lstMaterialReceiptReplace.Data[i].OldManufacturerName, ManufacturerCode = lstMaterialReceiptReplace.Data[i].ManufacturerCode, ManufacturerName = lstMaterialReceiptReplace.Data[i].ManufacturerName, SupplierMaterialLot = lstMaterialReceiptReplace.Data[i].SupplierMaterialLot, Description = lstMaterialReceiptReplace.Data[i].Description }; list.Add(model); } } ViewBag.MaterialReceiptReplace = list; //ViewBag.MaterialReceiptReplaceDetailAll = JsonConvert.SerializeObject(lstMaterialReceiptReplace); ViewBag.ReceiptNo = ReceiptNo; ViewBag.PagingConfig = cfg; } return(PartialView("_ListPartial")); } }
/// <summary> 取得ERP工单信息 </summary> /// <param name="OrderNumber"></param> /// <returns></returns> public async Task <ActionResult> Detail(string OrderNumber) { MethodReturnResult <ERPWorkOrderController> result = new MethodReturnResult <ERPWorkOrderController>(); WorkOrderViewModel model = new WorkOrderViewModel(); try { string strWOState = ""; string strERPOrderType = ""; string strOrderType = ""; string strERPDept = ""; string strLocationName = ""; MethodReturnResult <DataSet> resultWO = new MethodReturnResult <DataSet>(); using (ERPClient client = new ERPClient()) { //取得ERP工单信息 await Task.Run(() => { resultWO = client.GetERPWorkOrder(OrderNumber); }); if (resultWO.Code == 0 && resultWO.Data.Tables[0].Rows.Count > 0) { //根据ERP工单状态取得MES工单状态 strWOState = resultWO.Data.Tables[0].Rows[0]["FBILLSTATE"].ToString(); //ERP工单状态 //订单需要是投放状态(自由 - -1、审批 - 1、投放 - 2、完工 - 3、关闭 - 4) if (strWOState != "2") { result.Code = 1002; result.Message = "订单需要为投放状态!"; result.Detail = ""; } //根据ERP工单类型取得MES工单类型 strERPOrderType = resultWO.Data.Tables[0].Rows[0]["VTRANTYPECODE"].ToString(); //ERP工单类型 strOrderType = model.GetMESOrderType(strERPOrderType); //根据ERP部门代码取得MES对应的工厂代码 strERPDept = resultWO.Data.Tables[0].Rows[0]["CJCODE"].ToString(); strLocationName = model.GetLocationName(strERPDept); model.OrderNumber = resultWO.Data.Tables[0].Rows[0]["VBILLCODE"].ToString(); //工单号 model.OrderType = strOrderType; //工单类型 model.MaterialCode = resultWO.Data.Tables[0].Rows[0]["MATERIALCODE"].ToString(); //物料代码 model.ERPWorkOrderKey = resultWO.Data.Tables[0].Rows[0]["PK_DMO"].ToString(); //ERP工单号主键 model.OrderQuantity = Convert.ToDouble(resultWO.Data.Tables[0].Rows[0]["NNUM"].ToString()); //数量 model.LocationName = strLocationName; //生产车间 model.PlanStartTime = DateTime.Parse(resultWO.Data.Tables[0].Rows[0]["TPLANSTARTTIME"].ToString()); //计划开始日期 model.PlanFinishTime = DateTime.Parse(resultWO.Data.Tables[0].Rows[0]["TPLANENDTIME"].ToString()); //计划结束日期 model.Description = resultWO.Data.Tables[0].Rows[0]["VNOTE"].ToString(); //备注 } ViewBag.WorkOrder = model; } } catch (Exception e) { result.Code = 1002; result.Message = e.Message; result.Detail = e.ToString(); return(Json(result)); } return(View(model)); //MethodReturnResult<ERPWorkOrderController> result = new MethodReturnResult<ERPWorkOrderController>(); //WorkOrderViewModel model = new WorkOrderViewModel(); //try //{ // string strWOState = ""; // using (ERPClient client = new ERPClient()) // { // await Task.Run(() => // { // //取得ERP工单信息 // MethodReturnResult<DataSet> resultWO = client.GetERPWorkOrder(OrderNumber); // if (resultWO.Code == 0 && resultWO.Data.Tables[0].Rows.Count > 0) // { // model.OrderNumber = resultWO.Data.Tables[0].Rows[0]["VBILLCODE"].ToString(); //工单号 // model.MaterialCode = resultWO.Data.Tables[0].Rows[0]["MATERIALCODE"].ToString(); //物料代码 // //根据ERP工单状态取得MES工单状态 // strWOState = resultWO.Data.Tables[0].Rows[0]["FBILLSTATUS"].ToString(); //工单状态 // //订单需要是投放状态(自由 - -1、审批 - 1、投放 - 2、完工 - 3、关闭 - 4) // if (strWOState != "2") // { // result.Code = 1002; // result.Message = "订单需要为投放状态!"; // result.Detail = ""; // //return Json(result); // } // //model.OrderState = resultWO.Data.Tables[0].Rows[0]["FBILLSTATUS"].ToString(); //工单状态 // model.OrderType = resultWO.Data.Tables[0].Rows[0]["MATERIALTYPE"].ToString(); //工单类型 // model.OrderQuantity = Convert.ToDouble(resultWO.Data.Tables[0].Rows[0]["NNUM"].ToString()); //数量 // model.LocationName = resultWO.Data.Tables[0].Rows[0]["CJNAME"].ToString(); //生产车间 // model.PlanStartTime = DateTime.Parse(resultWO.Data.Tables[0].Rows[0]["TPLANSTARTTIME"].ToString()); //计划开始日期 // model.PlanFinishTime = DateTime.Parse(resultWO.Data.Tables[0].Rows[0]["TPLANENDTIME"].ToString()); //计划结束日期 // } // }); // ViewBag.WorkOrder = model; // } //} //catch (Exception e) //{ // result.Code = 1002; // result.Message = e.Message; // result.Detail = e.ToString(); // return Json(result); //} //return View(model); }
public async Task <ActionResult> Save(MaterialReplaceViewModel model) { DateTime now = DateTime.Now; MethodReturnResult rst = new MethodReturnResult(); #region 界面录入信息合规性检查 using (MaterialServiceClient client = new MaterialServiceClient()) { MethodReturnResult <Material> result = client.Get(model.ProductCode); if (result.Code != 0) { rst.Code = 1001; rst.Message = String.Format("MES中不存在产品编码:{0}", model.ProductCode); return(Json(rst)); } else { if (result.Data.IsProduct != true) { rst.Code = 1001; rst.Message = String.Format("物料编码[{0}]非产品!", model.ProductCode); return(Json(rst)); } if (model.OrderNumber != "*") { using (WorkOrderServiceClient clientOfWorkOrder = new WorkOrderServiceClient()) { MethodReturnResult <WorkOrder> resultOfOrder = clientOfWorkOrder.Get(model.OrderNumber); if (resultOfOrder.Code != 0) { rst.Code = 1001; rst.Message = String.Format("MES中不存在工单:{0}", model.OrderNumber); return(Json(rst)); } else { if (resultOfOrder.Data.MaterialCode != model.ProductCode) { rst.Code = 1001; rst.Message = String.Format("产品编码{0}与工单{1}不匹配!", model.ProductCode, model.OrderNumber); return(Json(rst)); } } } } } } #endregion using (ERPClient erpClient = new ERPClient()) { MethodReturnResult <DataSet> ds_supplier = erpClient.GetERPSupplier(model.OldMaterialSupplier); MethodReturnResult <DataSet> ds_supplier1 = erpClient.GetERPSupplier(model.NewMaterialSupplier); if (model.OldMaterialSupplier != "*") { if (ds_supplier.Data == null || ds_supplier.Data.Tables[0].Rows.Count == 0) { rst.Code = 1001; rst.Message = String.Format("ERP中不存在供应商:{0}", model.OldMaterialSupplier); return(Json(rst)); } if (ds_supplier.Data != null || ds_supplier.Data.Tables[0].Rows.Count > 0) { //新增替换前供应商 using (SupplierServiceClient supplierClient = new SupplierServiceClient()) { MethodReturnResult <Supplier> result = await supplierClient.GetAsync(model.OldMaterialSupplier); if (result.Code != 0) { Supplier supplier = new Supplier() { Key = ds_supplier.Data.Tables[0].Rows[0]["CUSCODE"].ToString(), Name = ds_supplier.Data.Tables[0].Rows[0]["CUSNAME"].ToString(), NickName = " ", CreateTime = now, EditTime = now, Creator = User.Identity.Name, Editor = User.Identity.Name, Description = "" }; rst = await supplierClient.AddAsync(supplier); if (rst.Code != 0) { return(Json(rst)); } } } } } if (model.NewMaterialSupplier != "000000") { if (ds_supplier1.Data == null || ds_supplier1.Data.Tables[0].Rows.Count == 0) { rst.Code = 1001; rst.Message = String.Format("ERP中不存在供应商:{0}", model.NewMaterialSupplier); return(Json(rst)); } //新增替换后供应商 using (SupplierServiceClient supplierClient1 = new SupplierServiceClient()) { MethodReturnResult <Supplier> result = await supplierClient1.GetAsync(model.NewMaterialSupplier); if (result.Code != 0) { Supplier supplier = new Supplier() { Key = ds_supplier1.Data.Tables[0].Rows[0]["CUSCODE"].ToString(), Name = ds_supplier1.Data.Tables[0].Rows[0]["CUSNAME"].ToString(), NickName = " ", CreateTime = now, EditTime = now, Creator = User.Identity.Name, Editor = User.Identity.Name, Description = "" }; rst = await supplierClient1.AddAsync(supplier); if (rst.Code != 0) { return(Json(rst)); } } } } //新增替换规则 using (MaterialReplaceServiceClient client = new MaterialReplaceServiceClient()) { MaterialReplace obj = new MaterialReplace() { Key = new MaterialReplaceKey() { ProductCode = model.ProductCode.ToString().Trim().ToUpper(), OrderNumber = model.OrderNumber.ToString().Trim().ToUpper(), OldMaterialCode = model.OldMaterialCode.ToString().Trim().ToUpper(), OldMaterialSupplier = model.OldMaterialSupplier.ToString().Trim().ToUpper() }, NewMaterialCode = model.NewMaterialCode.ToString().Trim().ToUpper(), NewMaterialSupplier = model.NewMaterialSupplier.ToString().Trim().ToUpper(), Creator = User.Identity.Name, Editor = User.Identity.Name, CreateTime = DateTime.Now, EditTime = DateTime.Now, Description = model.Description }; rst = await client.AddAsync(obj); if (rst.Code == 0) { rst.Message = string.Format(ZPVMResources.StringResource.MaterialReplace_Save_Success); } return(Json(rst)); } } }