// // POST: /WIP/LotCreate/Detail public ActionResult Detail(LotCreateMainViewModel model) { LotCreateDetailViewModel viewModel = new LotCreateDetailViewModel() { LineStoreName = model.LineStoreName, MaterialLot = model.MaterialLot, MaterialCode = model.MaterialCode, LotType = model.LotType, OrderNumber = model.OrderNumber, Count = model.Count, Description = string.Empty, MaterialQty = 0, ProductCode = string.Empty, Quantity = 0, RawQuantity = 0, RouteEnterpriseName = string.Empty, RouteName = string.Empty, RouteStepName = string.Empty, SupplierCode = string.Empty }; if (string.IsNullOrEmpty(model.MaterialLot)) { return(View(viewModel)); } //获取工单信息。 using (WorkOrderServiceClient client = new WorkOrderServiceClient()) { MethodReturnResult <WorkOrder> result = client.Get(model.OrderNumber); if (result.Code <= 0 && result.Data != null) { result.Code = 1000; result.Message = "工单号错误!"; return(Json(result)); //viewModel.ProductCode = result.Data.MaterialCode; } } //获取工单工艺信息。 using (WorkOrderRouteServiceClient client = new WorkOrderRouteServiceClient()) { PagingConfig cfg = new PagingConfig() { PageNo = 0, PageSize = 1, Where = string.Format("Key.OrderNumber='{0}'", model.OrderNumber), OrderBy = "Key.ItemNo" }; if (model.LotType == EnumLotType.Rework) { cfg.Where += " AND IsRework=1"; } else { cfg.Where += " AND IsRework=0"; } MethodReturnResult <IList <WorkOrderRoute> > result = client.Get(ref cfg); if (result.Code <= 0 && result.Data != null && result.Data.Count > 0) { viewModel.RouteEnterpriseName = result.Data[0].RouteEnterpriseName; viewModel.RouteName = result.Data[0].RouteName; viewModel.RouteStepName = result.Data[0].RouteStepName; } } //获取线边仓物料信息 using (LineStoreMaterialServiceClient client = new LineStoreMaterialServiceClient()) { LineStoreMaterialDetailKey key = new LineStoreMaterialDetailKey() { LineStoreName = model.LineStoreName, OrderNumber = model.OrderNumber, MaterialCode = model.MaterialCode, MaterialLot = model.MaterialLot }; MethodReturnResult <LineStoreMaterialDetail> result = client.GetDetail(key); if (result.Code <= 0 && result.Data != null) { viewModel.MaterialQty = result.Data.CurrentQty; viewModel.SupplierCode = result.Data.SupplierCode; } } //根据物料获取每批原材料建议数量和每批产品建议数量。 using (MaterialServiceClient client = new MaterialServiceClient()) { MethodReturnResult <Material> result = client.Get(viewModel.ProductCode); if (result.Code <= 0 && result.Data != null) { viewModel.RawQuantity = result.Data.MainRawQtyPerLot; viewModel.Quantity = result.Data.MainProductQtyPerLot; } } //根据工单号和批次个数生成批次号。 IList <string> lstLot = new List <string>(); using (LotCreateServiceClient client = new LotCreateServiceClient()) { MethodReturnResult <IList <string> > result = client.Generate(model.LotType, model.OrderNumber, model.Count, model.LineCode); if (result.Code <= 0 && result.Data != null && result.Data.Count > 0) { lstLot = result.Data; } } ViewBag.LotList = lstLot; //获取需要录入的批次号自定义特性 IList <BaseAttribute> lstAttribute = new List <BaseAttribute>(); using (BaseAttributeServiceClient client = new BaseAttributeServiceClient()) { PagingConfig cfg = new PagingConfig() { IsPaging = false, Where = string.Format("Key.CategoryName='{0}'", "LotCreateAttribute") }; MethodReturnResult <IList <BaseAttribute> > result = client.Get(ref cfg); if (result.Code <= 0 && result.Data != null && result.Data.Count > 0) { lstAttribute = result.Data; } } ViewBag.AttributeList = lstAttribute; return(View(viewModel)); }
public ActionResult Save(LotCreateDetailViewModel model) { MethodReturnResult result = new MethodReturnResult(); try { if (ModelState.IsValid) { CreateParameter p = new CreateParameter() { Creator = User.Identity.Name, LineStoreName = model.LineStoreName, LotType = model.LotType, OperateComputer = Request.UserHostAddress, Operator = User.Identity.Name, OrderNumber = model.OrderNumber, Quantity = model.Quantity, RawMaterialCode = model.MaterialCode, RawMaterialLot = model.MaterialLot, RawQuantity = model.RawQuantity, Remark = model.Description, RouteEnterpriseName = model.RouteEnterpriseName, RouteName = model.RouteName, RouteStepName = model.RouteStepName, LineCode = model.LineCode, LotNumbers = new List <string>() }; char splitChar = ','; //获取批次号值。 string[] lotNumbers = Request["LotNumber"].ToUpper().Split(splitChar); p.LotNumbers = lotNumbers.ToList(); //获取自定义属性值。 IList <BaseAttribute> lstAttribute = new List <BaseAttribute>(); using (BaseAttributeServiceClient client = new BaseAttributeServiceClient()) { PagingConfig cfg = new PagingConfig() { IsPaging = false, Where = string.Format("Key.CategoryName='{0}'", "LotCreateAttribute") }; MethodReturnResult <IList <BaseAttribute> > rst = client.Get(ref cfg); if (rst.Code <= 0 && rst.Data != null && rst.Data.Count > 0) { lstAttribute = rst.Data; } } p.Attributes = new Dictionary <string, IList <TransactionParameter> >(); foreach (BaseAttribute attr in lstAttribute) { string vals = Request["ATTR_" + attr.Key.AttributeName]; if (string.IsNullOrEmpty(vals)) { continue; } string[] attrValues = vals.Split(splitChar); for (int i = 0; i < p.LotNumbers.Count && i < attrValues.Length; i++) { string lotNumber = p.LotNumbers[i]; string tpVal = attrValues[i]; //如果没有设置值,则不进行数据存储。 if (string.IsNullOrEmpty(tpVal)) { continue; } if (!p.Attributes.ContainsKey(lotNumber)) { p.Attributes.Add(lotNumber, new List <TransactionParameter>()); } if (attr.DataType == EnumDataType.Boolean) { tpVal = tpVal == "on" ? "true" : "false"; } TransactionParameter tp = new TransactionParameter() { Index = attr.Order, Name = attr.Key.AttributeName, Value = tpVal }; p.Attributes[lotNumber].Add(tp); } } //创建批次。 using (LotCreateServiceClient client = new LotCreateServiceClient()) { result = client.Create(p); } //标签打印。 if (result.Code == 0) { result = PrintPrivate(model); } if (result.Code == 0) { result.Message = "保存成功。"; } } } catch (Exception ex) { result.Code = 1000; result.Message = ex.Message; result.Detail = ex.ToString(); } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return(Json(result)); }