/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { List<string> errpara = new List<string>(); IList<IProduct> prodList = CurrentSession.GetValue(Session.SessionKeys.ProdList) as IList<IProduct>; IList<DeliveryCarton> bindDNList = (IList<DeliveryCarton>)CurrentSession.GetValue(ExtendSession.SessionKeys.BindDNList); Pallet curPallet = (Pallet)CurrentSession.GetValue(Session.SessionKeys.Pallet); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IDeliveryRepository deliveryRep = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>(); IPalletRepository palletRep = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>(); ICartonRepository cartonRep = RepositoryFactory.GetInstance().GetRepository<ICartonRepository, Carton>(); Carton carton = (Carton)CurrentSession.GetValue(Session.SessionKeys.Carton); Delivery curDelivery =(Delivery) CurrentSession.GetValue(Session.SessionKeys.Delivery); // g.下文描述的是针对不同的情况,如何获取需要提示用户的信息 //a) 取Delivery 的PalletQty (IMES_PAK..DeliveryInfo.InfoValue,Condition: InfoType = 'PalletQty')属性值, //并取其整数部分保存到@paletqty 变量中;如果该属性不存在,则令@paletqty = 60 string paletqty = (string)curDelivery.GetExtendedProperty("PalletQty"); string regId = (string)curDelivery.GetExtendedProperty("RegId"); if (regId != null && regId.Length == 3) { regId = regId.Substring(1, 2); } else { regId = ""; } string shipWay = (string)curDelivery.GetExtendedProperty("ShipWay"); string carrier = (string)curDelivery.GetExtendedProperty("Carrier"); string flag = (string)curDelivery.GetExtendedProperty("Flag"); string model = prodList[0].Model; string pdline = prodList[0].ProId.Substring(0, 1); string ucc = curPallet.UCC; //if (string.IsNullOrEmpty(paletqty)) //{ // paletqty = "60"; //} string palletLayer = (string)curDelivery.GetExtendedProperty("PalletLayer"); string locWC = ""; #region CQ 棧板類型 string emeastr = string.Empty; string pclor = string.Empty; IList<PalletType> lstPalletType = IMES.Infrastructure.Utility.Common.CommonUti.GetPalletType(curPallet.PalletNo, curDelivery.DeliveryNo); if (lstPalletType.Count == 0) { pclor = ""; emeastr = "Other"; } else { pclor = lstPalletType[0].Code.Trim(); emeastr = lstPalletType[0].Type.Trim(); } int pqty = deliveryRep.GetSumDeliveryQtyOfACertainPallet(curPallet.PalletNo); #endregion #region for CQ 不使用 PalletyQty欄位來判斷棧板類型,所以disable Code ////b) 使用如下方法,取得变量@pqty ////SELECT @pqty = sum(DeliveryQty) FROM Delivery_Pallet NOLOCK WHERE PalletNo = @Plt //int pqty = deliveryRep.GetSumDeliveryQtyOfACertainPallet(curPallet.PalletNo); ////c) 使用如下方法,取得变量@pqty2 ////SELECT @pqty2=TierQty FROM PalletStandard WHERE FullQty=@paletqty //int pqty2 = palletRep.GetTierQtyFromPalletQtyInfo(paletqty); ////d) 如果@pqty>=@pqty2,则令@emeastr='海运,满一层请使用大的木头栈板' //string emeastr = string.Empty; //string pclor = string.Empty; //if (pqty > pqty2) //{ // emeastr = "海运,满一层请使用大的木头栈板"; //} ////e) 如果(@Region='SNE' or @Region='SCE' ) and @shipway<>'T002'时 ////i. 如果@pqty>=@pqty2 and @pqty2>0,则令@emeastr='满一层请使用chep栈板';@pclor=' H'; ////否则令@emeastr=' ';@pclor='' //if ((regId == "NE" || regId == "CE") && (shipWay != "T002")) //{ // if (pqty > pqty2 && pqty2 > 0) // { // emeastr = "满一层请使用chep栈板"; // pclor = " H"; // } // else // { // emeastr = ""; // pclor = ""; // } //} //else if ((regId == "NL") && (shipWay != "T002")) //{ //f) 不满足上一步的条件时,如果@Region='SNL' and @shipway<>'T002' 时 // //i. 如果@pqty>=@pqty2 and @pqty2>0,则令@emeastr='请使用绿色塑料栈板';@pclor=' P'; // //否则令@emeastr=' ';@pclor='' // if (pqty > pqty2 && pqty2 > 0) // { // emeastr = "请使用蓝色塑料栈板"; // pclor = " A"; // } // else // { // emeastr = ""; // pclor = ""; // } //} //else if ((regId == "NU" || regId == "CU") && (shipWay != "T002")) //{ //g) 不满足前面的条件时,如果(@Region='SNU' or @Region='SCU' ) and @shipway<>'T002' 时 // //i. 如果@pqty>=@pqty2 and @pqty2>0,则令@emeastr='请使用蓝色塑料栈板';@pclor=' A'; // //否则令@emeastr=' ';@pclor='' // if (pqty > pqty2 && pqty2 > 0) // { // emeastr = "请使用蓝色塑料栈板"; // pclor = " A"; // } // else // { // emeastr = ""; // pclor = ""; // } //} //else if ((regId == "NE" || regId == "CE") && (shipWay == "T002")) //{ // //h) 不满足前面的条件时,如果(@Region='SNE' or @Region='SCE' ) and @shipway='T002' 时, // // 则令@emeastr='EMEA海运,请使用E1栈板';@pclor=' K' // emeastr = "EMEA海运,请使用E1栈板"; // pclor = " K"; //} //else if ((regId == "AF") && (shipWay == "T001")) //{ // //i) 不满足前面的条件时,如果@shipway='T001' and @Region='SAF' 时, // //i. 如果@pqty>=@pqty2 and @pqty2>0,则令@emeastr='請使用綠色塑料棧板';@pclor=' P'; // //否则令@emeastr=' ';@pclor='' // if (pqty > pqty2 && pqty2 > 0) // { // emeastr = "请使用绿色塑料栈板"; // pclor = " P"; // } // else // { // emeastr = ""; // pclor = ""; // } //} ////else if (( regId == "CN") && (shipWay == "T001")) //else if ((ActivityCommonImpl.Instance.CheckDomesticDN(regId)) && (shipWay == "T001")) //{ // // j) 不满足前面的条件时,如果@shipway='T001' and @Region='SCN' 时, // //i. 如果@pqty>=@pqty2 and @pqty2>0,则令@emeastr='满一层请使用大的木头栈板';@pclor=' '; // //否则令@emeastr=' ';@pclor='' // if (pqty > pqty2 && pqty2 > 0) // { // emeastr = "满一层请使用大的木头栈板"; // pclor = " "; // } // else // { // emeastr = ""; // pclor = ""; // } //} //else //{ // emeastr = ""; // pclor = ""; //} #endregion //h.下文描述的是分配库位 //Model 的第10,11码是”29” 或者”39” 的产品是出货日本的产品;否则,是非出货日本的产品 //PAK_LocMas.WC = ‘JP’ 的为日本专用库位 //出货日本的Pallet优先分配出货日本专用库位,当出货日本专用库位用完时,出货日本的Pallet 方可使用普通库位 if (pqty <= 6) { locWC = "Virtual"; } string jpmodel = model.Substring(9, 2); //bool jpflag = false; if (jpmodel == "29" || jpmodel == "39") { locWC = "JP"; //jpflag = true; } //a) 当LEFT(@plt,2)<>'NA' and LEFT(@plt,2)<>'BA' 时,按照如下方法分配库位 string floor = (string)CurrentSession.GetValue(Session.SessionKeys.Floor); string loc = ""; //Boolean addflag = true; if (curPallet.PalletNo.Substring(0, 2) != "NA" && curPallet.PalletNo.Substring(0, 2) != "BA") { int palletQty = deliveryRep.GetSumDeliveryQtyOfACertainPallet(curPallet.PalletNo); //Vincent add Check NBO包裝方式 int palletLayerQty = 0; if (!string.IsNullOrEmpty(palletLayer) && int.TryParse(palletLayer, out palletLayerQty) && palletLayerQty > this.OverPalletLayer) { locWC = "NBO"; } //i. 取与@plt 结合的Product 数量,如果数量为1,则按照如下方法分配库位 IList<ProductModel> modelList = productRep.GetProductListByPalletNo(curPallet.PalletNo); IList<PakLocMasInfo> macList; // For Mantis 0000874: 6台及6台以下的栈板库位分配 // For Mantis 0000874: 6台及6台以下的栈板库位分配 //string pdline; //ProductModel newModel = new ProductModel(); //if (!string.IsNullOrEmpty(curPallet.PalletNo)) //{ // foreach (ProductModel pmodel in modelList) // { // if (pmodel.ProductID == curProduct.ProId) // { // addflag = false; // break; // } // } // if (addflag) // { // newModel.ProductID = curProduct.ProId; // newModel.Model = curProduct.Model; // newModel.CustSN = curProduct.CUSTSN; // modelList.Add(newModel); // } //} if (modelList.Count == 0) { // 1. 当使用Pno=@plt and Tp='PakLoc' and FL=@floor (@floor 来自页面用户的选择)查询PAK_LocMas表存在记录时, //则取该记录的SnoId 字段值保存到变量@loc 中,并更新PAK_LocMas表中满足Pno=@plt and Tp='PakLoc' 条件的 //记录的PdLine 字段值为Product Id 的第一位字符,Udt 为当前时间 //bool chkmas = palletRep.CheckExistPakLocMas(curPallet.PalletNo, "PakLoc", floor); PakLocMasInfo normalconf = new PakLocMasInfo(); normalconf.pno = curPallet.PalletNo; normalconf.tp = "PakLoc"; normalconf.fl = floor; normalconf.wc = locWC; macList = palletRep.GetPakLocMasList(normalconf); if (macList.Count == 0 && !string.IsNullOrEmpty(locWC)) { normalconf.wc = ""; macList = palletRep.GetPakLocMasList(normalconf); } if (macList.Count > 0) { loc = macList[0].snoId; palletRep.UpdatePakLocMasByIdDefered(CurrentSession.UnitOfWork, macList[0].id, curPallet.PalletNo, pdline, this.Editor); } else { normalconf.pno = ""; normalconf.tp = "PakLoc"; normalconf.fl = floor; normalconf.wc = locWC; macList = palletRep.GetPakLocMasList(normalconf); if (macList.Count == 0 && !string.IsNullOrEmpty(locWC)) { normalconf.wc = ""; macList = palletRep.GetPakLocMasList(normalconf); } if (macList.Count > 0)//(palletRep.CheckExistPakLocMas("", "PakLoc", floor)) { loc = macList[macList.Count - 1].snoId; palletRep.UpdatePakLocMasByIdDefered(CurrentSession.UnitOfWork, macList[macList.Count - 1].id, curPallet.PalletNo, pdline, this.Editor); //palletRep.UpdatePakLocMasForPdLineAndPnoDefered(CurrentSession.UnitOfWork,pdline,curPallet.PalletNo,"","PakLoc",loc); } else { //3.当不满足前面条件时,令@loc = 'Others' loc = "Others"; } } #region disable Code Vincent 不使用負面表列方式找庫位 //PakLocMasInfo neqconf = new PakLocMasInfo(); //neqconf.wc = "JP"; //if (jpflag) //{ // PakLocMasInfo conf = new PakLocMasInfo(); // conf.pno = curPallet.PalletNo; // conf.tp = "PakLoc"; // conf.fl = floor; // conf.wc = "JP"; // macList = palletRep.GetPakLocMasList(conf); // if (macList.Count == 0) // { // macList = palletRep.GetPakLocMasList(normalconf, neqconf);//(curPallet.PalletNo, "PakLoc", floor); // } //} //else //{ // macList = palletRep.GetPakLocMasList(normalconf, neqconf);//(curPallet.PalletNo, "PakLoc", floor); //} //if (macList.Count > 0) //{ // loc = macList[0].snoId; // //pdline = curProduct.ProId.Substring(0, 1); // palletRep.UpdatePakLocMasForPdLineDefered(CurrentSession.UnitOfWork, pdline, curPallet.PalletNo, "PakLoc"); //} //else //{ // //2.当使用Pno=@plt and Tp='PakLoc' and FL=@floor (@floor 来自页面用户的选择)查询PAK_LocMas表不存在记录时, // //如果使用Pno='' and Tp='PakLoc' and FL=@floor (@floor 来自页面用户的选择)查询PAK_LocMas表存在记录时, // //按照SnoId 字段转为整型排序,取第一条记录的SnoId 字段值保存到变量@loc 中, // //并更新PAK_LocMas 表中满足SnoId=@loc and Tp='PakLoc' and Pno='' 条件的记录的Pno 字段值为@plt, // //PdLine 字段值为Product Id 的第一位字符,Udt 为当前时间 // //分配库位时优先选择空的,再选择库位号小的 // normalconf.pno = ""; // if (jpflag) // { // PakLocMasInfo conf = new PakLocMasInfo(); // conf.pno = ""; // conf.tp = "PakLoc"; // conf.fl = floor; // conf.wc = "JP"; // macList = palletRep.GetPakLocMasList(conf); // if (macList.Count == 0) // { // macList = palletRep.GetPakLocMasList(normalconf, neqconf);//("", "PakLoc", floor); // } // } // else // { // macList = palletRep.GetPakLocMasList(normalconf, neqconf);//("", "PakLoc", floor); // } // if (macList.Count > 0)//(palletRep.CheckExistPakLocMas("", "PakLoc", floor)) // { // loc = macList[macList.Count - 1].snoId; // //pdline = curProduct.ProId.Substring(0, 1); // palletRep.UpdatePakLocMasForPdLineAndPnoDefered(CurrentSession.UnitOfWork, pdline, curPallet.PalletNo, "", "PakLoc", loc); // } // else // { // //3.当不满足前面条件时,令@loc = 'Others' // loc = "Others"; // } //} #endregion } else //ii. 如果数量不为1,则按照如下方法分配库位 { //1.查询PAK_LocMas 表,取满足条件Tp='PakLoc' and Pno=@plt 记录的SnoId 字段值保存到变量@loc 中, //如果ISNULL(@loc, '') = '',则令@loc = 'Others' PakLocMasInfo normalconf = new PakLocMasInfo(); normalconf.pno = curPallet.PalletNo; normalconf.tp = "PakLoc"; normalconf.wc = locWC; macList = palletRep.GetPakLocMasList(normalconf); if (macList.Count == 0 && !string.IsNullOrEmpty(locWC)) { normalconf.wc = ""; macList = palletRep.GetPakLocMasList(normalconf); } if (macList.Count == 0) { loc = ""; } else { loc = macList[0].snoId; } if (loc == "") { loc = "Others"; } #region disable Code Vincent 不使用負面表列方式找庫位 //PakLocMasInfo neqconf = new PakLocMasInfo(); //neqconf.wc = "JP"; //if (jpflag) //{ // PakLocMasInfo conf = new PakLocMasInfo(); // conf.pno = curPallet.PalletNo; // conf.tp = "PakLoc"; // conf.wc = "JP"; // macList = palletRep.GetPakLocMasList(conf); // if (macList.Count == 0) // { // macList = palletRep.GetPakLocMasList(normalconf, neqconf);//(curPallet.PalletNo, "PakLoc"); // } //} //else //{ // macList = palletRep.GetPakLocMasList(normalconf, neqconf);//(curPallet.PalletNo, "PakLoc"); //} //if (macList.Count == 0) //{ // loc = ""; //} //else //{ // loc = macList[0].snoId; //} //if (loc == "") //{ // loc = "Others"; //} #endregion } } else if (curPallet.PalletNo.Substring(0, 2) == "NA") { //b) 当LEFT(@plt,2)='NA'时,令@loc = 'OT' loc = "OT"; } else if (curPallet.PalletNo.Substring(0, 2) == "BA") { //c)当LEFT(@plt,2)='BA'时,令@loc=RTRIM(@carrier) loc = carrier.TrimEnd(); } //i.如果LEFT(@plt,2)<>'NA' and LEFT(@plt,2)<>'BA' /* if (curPallet.PalletNo.Substring(0, 2) != "NA" && curPallet.PalletNo.Substring(0, 2) != "BA") { //a)如果@pqty <= 6,则令@loc='',并更新PAK_LocMas 表中满足条件Pno=@plt and Tp='PakLoc' 记录的Pno 字段值为'' if (pqty <= 6) { loc = ""; palletRep.UpdatePakLocMasForPnoDefered(CurrentSession.UnitOfWork, "", curPallet.PalletNo, "PakLoc"); } }*/ //j. 如果@emeastr<>'',则令@loc=RTRIM(@loc)+RTRIM(@pclor) if (!string.IsNullOrEmpty(emeastr)) { loc = loc.TrimEnd() + pclor.TrimEnd(); } //k. 准备HP EDI 数据,调用存储过程op_PackingData 实现 //snoid char(9), --Product Id //@model char(12), --Product Model //@dn char(16), --Delivery //@plt char(12), --Pallet //@loc varchar(10),--Location //@pltqty int --Select Sum(DeliveryQty) from Delivery_Pallet where PalletNo = @plt //.CallOp_PackingData(string snoid, string model, string dn, string plt, string loc, int pltqty); //palletRep.CallOp_PackingData(curProduct.ProId, curProduct.Model, curDelivery.DeliveryNo, curPallet.PalletNo, loc, pqty); foreach (Product item in prodList) { palletRep.CallOp_PackingDataDefered(CurrentSession.UnitOfWork, item.ProId, item.Model, item.DeliveryNo, item.PalletNo, loc, pqty, carton.BoxId, ucc); } //如果Product 结合的Delivery 的Flag IMES_PAK..DeliveryInfo.InfoValue,Condition: InfoType = 'Flag' 属性为'N', //RegId IMES_PAK..DeliveryInfo.InfoValue,Condition: InfoType = 'RegId'属性不等于'SCN' 时,需要生成Box Ship Label Pdf Document //if ((flag == "N") && (regId != "SCN")) //UC Update 2012/03/28 不再限制RegId <> ‘SCN’ 才需要产生PDF if (flag == "N") { CurrentSession.AddValue(Session.SessionKeys.DeliveryNo, curDelivery.DeliveryNo); /* //Save PDF File Name string PdfFileName=curDelivery.DeliveryNo+ "-"+carton.CartonSN+"-[BoxShipLabel].pdf"; carton.SetExtendedProperty("PdfFileName", PdfFileName,this.Editor); // var pdffilename = dn + "-" + key + "-[BoxShipLabel].pdf" */ CurrentSession.AddValue("CreatePDF", "pdf"); } else { CurrentSession.AddValue("CreatePDF", ""); } //Change Delivery Status -> 88 IList<Delivery> dnList = (IList<Delivery>)CurrentSession.GetValue(Session.SessionKeys.DeliveryList); if (dnList == null || dnList.Count == 0) { dnList = new List<Delivery>(); foreach (DeliveryCarton item in bindDNList) { if (curDelivery.DeliveryNo == item.DeliveryNo) { dnList.Add(curDelivery); } else { dnList.Add(deliveryRep.Find(item.DeliveryNo)); } } } foreach (Delivery item in dnList) { int dvQty = productRep.GetCombinedPalletQtyByDN(item.DeliveryNo); var dn = (from p in bindDNList where p.DeliveryNo == item.DeliveryNo select p).ToList(); if (dn.Count>0) { dvQty= dvQty+ dn[0].AssignQty; } int dnQty = item.Qty; string dnStatus = item.Status; if (dvQty == dnQty && dnStatus != "88") { item.Status = "88"; item.Editor = CurrentSession.Editor; item.Udt = DateTime.Now; DeliveryLog log = new DeliveryLog(0, item.DeliveryNo, "88", CurrentSession.Station, CurrentSession.Line, CurrentSession.Editor, DateTime.Now); item.AddLog(log); deliveryRep.Update(item, CurrentSession.UnitOfWork); } } CurrentSession.AddValue(ExtendSession.SessionKeys.PalletLoc, loc); CurrentSession.AddValue(Session.SessionKeys.Product,prodList[0]); CurrentSession.AddValue(Session.SessionKeys.IsBT, 0); return base.DoExecute(executionContext); }
/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { List<string> errpara = new List<string>(); IList<IProduct> prodList = CurrentSession.GetValue(Session.SessionKeys.ProdList) as IList<IProduct>; IList<DeliveryCarton> bindDNList = (IList<DeliveryCarton>)CurrentSession.GetValue(ExtendSession.SessionKeys.BindDNList); Pallet curPallet = (Pallet)CurrentSession.GetValue(Session.SessionKeys.Pallet); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IDeliveryRepository deliveryRep = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>(); IPalletRepository palletRep = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>(); ICartonRepository cartonRep = RepositoryFactory.GetInstance().GetRepository<ICartonRepository, Carton>(); Carton carton = (Carton)CurrentSession.GetValue(Session.SessionKeys.Carton); Delivery curDelivery = deliveryRep.Find(bindDNList[0].DeliveryNo); CurrentSession.AddValue(Session.SessionKeys.Delivery, curDelivery); //a. 取Delivery 的下列属性并保存到对应的变量中: string BoxId = ""; string flag = (string)curDelivery.GetExtendedProperty("Flag"); //b. 取Pallet 的UCC 属性(IMES_PAK..Pallet.UCC),并保存到变量@ucc 中 //IF EXISTS (SELECT *FROM ShipBoxDet NOLOCK WHERE DeliveryNo=@dn and PLT<>@plt and SnoId=@id) //BEGIN //UPDATE ShipBoxDet SET SnoId='' ,Udt=GETDATE() WHERE DeliveryNo=@dn and SnoId=@id //END string ucc = curPallet.UCC; //c.如果Product 曾经结合过其它栈板,需要先解除与其他栈板的结合 foreach (DeliveryCarton item in bindDNList) { Boolean bindflag = deliveryRep.CheckExistShipBoxDetExceptPlt(item.DeliveryNo, curPallet.PalletNo, carton.CartonSN); if (bindflag) { deliveryRep.UpdateShipBoxDetForClearSnoidDefered(CurrentSession.UnitOfWork, carton.CartonSN, item.DeliveryNo); } } IList<ShipBoxDetInfo> shipList; IList<string> boxIdList; ShipBoxDetInfo shipInfo; //d.当@Flag='N' or @ucc<>'' 时(所谓自动单情况),按照如下方法分配Box Id if ((flag == "N") || !string.IsNullOrEmpty(ucc)) { //a)使用DeliveryNo=@dn and PLT=@plt and SnoId=@id 查询ShipBoxDet 表存在记录时, shipList = deliveryRep.GetShipBoxDetList(curDelivery.DeliveryNo, curPallet.PalletNo,carton.CartonSN); if (shipList.Count != 0) { //取查询到的记录的BoxId 字段值保存到变量@BoxId 中,并更新该记录的Udt 字段值为当前时间 shipInfo = shipList[0]; BoxId = shipInfo.boxId; ShipBoxDetInfo setvalue = new ShipBoxDetInfo(); ShipBoxDetInfo conf = new ShipBoxDetInfo(); conf.deliveryNo = curDelivery.DeliveryNo; conf.plt = curPallet.PalletNo; conf.snoId = carton.CartonSN; setvalue.udt = DateTime.Now; deliveryRep.UpdateShipBoxDetInfoDefered(CurrentSession.UnitOfWork, setvalue, conf); //如果尚未结合过,则结合@BoxId,记录到IMES_FA..ProductInfo (InfoValue = @BoxId, //InfoType 当@ucc<>''and LEN(@BoxId)=20 时,记录为'UCC',否则记录为'BoxId') if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20)) { foreach (Product item in prodList) { item.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } else { foreach (Product item in prodList) { item.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } ////ii. 更新Product结合的Pallet (IMES_FA..Product.PalletNo) 为@plt //ProductIDList.Add(curProduct.ProId); //productRep.BindPalletDefered(CurrentSession.UnitOfWork, curProduct.PalletNo, ProductIDList); carton.BoxId = BoxId; } else { //b)使用DeliveryNo=@dn and PLT=@plt and SnoId=@id 查询ShipBoxDet 表不存在记录时, //使用DeliveryNo=@dn and PLT=@plt and SnoId='' 查询ShipBoxDet 表, //取查询到的记录的BoxId 字段值保存到变量@BoxId 中 boxIdList = deliveryRep.GetAndUpdateShipBoxDet(curDelivery.DeliveryNo, curPallet.PalletNo, carton.CartonSN); if (boxIdList.Count == 0) { errpara.Add(this.Key);//无可用Box Id,请联系FIS! throw new FisException("PAK102", errpara); } BoxId = boxIdList[0]; //i. 如果ISNULL(@BoxId, '') = '',则报告错误:“无可用Box Id,请联系FIS!” if (string.IsNullOrEmpty(BoxId)) { errpara.Add(this.Key);//无可用Box Id,请联系FIS! throw new FisException("PAK102", errpara); } else { //ii. 如果ISNULL(@BoxId, '') <> '', //A. Update ShipBoxDet 记录结合Product 信息 //Condition: DeliveryNo=@dn and PLT=@plt and BoxId=@BoxId SET:SnoId=@id,Udt=GETDATE() //deliveryRep.UpdateShipBoxDetForSetSnoIdDefered(CurrentSession.UnitOfWork,curProduct.ProId,curDelivery.DeliveryNo,curPallet.PalletNo, BoxId); //B. 如果Product 已经结合过Box Id / UCC (两者只会结合一个,Box Id / UCC 存放在IMES_FA..ProductInfo.Value, //Condition: InfoType = 'BoxId' 或者 'UCC'),则需要更新该记录的InfoValue = @BoxId, Editor, Udt = Getdate(); deliveryRep.UpdateAssignBoxIdEditorDefered(CurrentSession.UnitOfWork, curDelivery.DeliveryNo, curPallet.PalletNo, carton.CartonSN); if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20)) { foreach (Product item in prodList) { item.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } else { foreach (Product item in prodList) { item.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } //C. 更新Product结合的Pallet (IMES_FA..Product.PalletNo) 为@plt //ProductIDList.Add(curProduct.ProId); //productRep.BindPalletDefered(CurrentSession.UnitOfWork, curProduct.PalletNo, ProductIDList); carton.BoxId = BoxId; } } } else //e 当@Flag<>'N' and @ucc='' 时(所谓手动单情况),按照如下方法分配Box Id { //a) 使用DeliveryNo=@dn and PLT=@plt and SnoId=@id 查询ShipBoxDet 表存在记录时,取查询到的记录的BoxId 字段值保存到变量@BoxId 中, //并更新该记录的Udt 字段值为当前时间 //i. 如果Product 已经结合过Box Id / UCC (两者只会结合一个,Box Id / UCC 存放在IMES_FA..ProductInfo.Value,Condition: InfoType = 'BoxId' 或者 'UCC'), //则需要更新该记录的InfoValue = @BoxId, Editor, Udt = Getdate();如果尚未结合过,则结合@BoxId,记录到IMES_FA..ProductInfo (InfoValue = @BoxId,InfoType 当@ucc<>'' and LEN(@BoxId)=20 时,记录为'UCC',否则记录为'BoxId') //ii. 更新Product结合的Pallet (IMES_FA..Product.PalletNo) 为@plt shipList = deliveryRep.GetShipBoxDetList(curDelivery.DeliveryNo, curPallet.PalletNo, carton.CartonSN); if (shipList.Count > 0) { shipInfo = shipList[0]; BoxId = shipInfo.boxId; ShipBoxDetInfo setvalue = new ShipBoxDetInfo(); ShipBoxDetInfo conf = new ShipBoxDetInfo(); conf.deliveryNo = curDelivery.DeliveryNo; conf.plt = curPallet.PalletNo; conf.snoId = carton.CartonSN; setvalue.udt = DateTime.Now; deliveryRep.UpdateShipBoxDetInfoDefered(CurrentSession.UnitOfWork, setvalue, conf); if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20)) { foreach (Product item in prodList) { item.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } else { foreach (Product item in prodList) { item.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } carton.BoxId = BoxId; } else { //Mantis #0000954 // a) 如果使用DeliveryNo=@dn and PLT=@plt and SnoId='' 查询ShipBoxDet 表存在记录时,按照下列方法,分配Box Id //i. 使用DeliveryNo=@dn and PLT=@plt and SnoId='' 查询ShipBoxDet 表,取记录的BoxId 字段值保存到@BoxId 变量中 //ii. Update ShipBoxDet 记录结合Product 信息 Condition: DeliveryNo=@dn and PLT=@plt and BoxId=@BoxId SET:SnoId=@id,Udt=GETDATE() //iii. 如果Product 已经结合过Box Id / UCC (两者只会结合一个,Box Id / UCC 存放在IMES_FA..ProductInfo.Value,Condition: InfoType = 'BoxId' 或者 'UCC'), // 则需要更新该记录的InfoValue = @BoxId, Editor, Udt = Getdate();如果尚未结合过,则结合@BoxId,记录到IMES_FA..ProductInfo // (InfoValue = @BoxId,InfoType 当@ucc<>'' and LEN(@BoxId)=20 时,记录为'UCC',否则记录为'BoxId') //iv. 更新Product结合的Pallet (IMES_FA..Product.PalletNo) 为@plt //shipList = deliveryRep.GetShipBoxDetList(curDelivery.DeliveryNo, curPallet.PalletNo, ""); boxIdList = deliveryRep.GetAndUpdateShipBoxDet(curDelivery.DeliveryNo, curPallet.PalletNo, carton.CartonSN); //if (shipList.Count != 0) if (boxIdList.Count != 0) { //shipInfo = shipList[0]; //BoxId = shipInfo.boxId; //deliveryRep.UpdateShipBoxDetForSetSnoIdDefered(CurrentSession.UnitOfWork, curProduct.ProId, curDelivery.DeliveryNo, curPallet.PalletNo, BoxId); deliveryRep.UpdateAssignBoxIdEditorDefered(CurrentSession.UnitOfWork, curDelivery.DeliveryNo, curPallet.PalletNo, carton.CartonSN); BoxId = boxIdList[0]; if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20)) { foreach (Product item in prodList) { item.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } else { foreach (Product item in prodList) { item.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } carton.BoxId = BoxId; } else { //b) 如果使用DeliveryNo=@dn and PLT=@plt and SnoId='' 查询ShipBoxDet 表不存在记录时,按照下列方法,分配Box Id //i. 使用DeliveryNo=@dn and SnoId='' 查询ShipBoxDet 表,按照PLT, BoxId 升序排序,取TOP 1 记录的PLT / BoxId 字段值保存到@plt / @BoxId 变量中 //ii. 如果ISNULL(@BoxId, '') = '',则报告错误:“无可用Box Id,请联系FIS!” //iii. Update ShipBoxDet 记录结合Product 信息 Condition: DeliveryNo=@dn and PLT=@plt and BoxId=@BoxId SET:SnoId=@id,Udt=GETDATE() //iv. 如果Product 已经结合过Box Id / UCC (两者只会结合一个,Box Id / UCC 存放在IMES_FA..ProductInfo.Value,Condition: InfoType = 'BoxId' 或者 'UCC'), // 则需要更新该记录的InfoValue = @BoxId, Editor, Udt = Getdate();如果尚未结合过,则结合@BoxId,记录到IMES_FA..ProductInfo // (InfoValue = @BoxId,InfoType 当@ucc<>'' and LEN(@BoxId)=20 时,记录为'UCC',否则记录为'BoxId') //v. 更新Product结合的Pallet (IMES_FA..Product.PalletNo) 为@plt //shipList = deliveryRep.GetShipBoxDetList(curDelivery.DeliveryNo, curPallet.PalletNo, "");//?? boxIdList = deliveryRep.GetAndUpdateShipBoxDet(curDelivery.DeliveryNo, curPallet.PalletNo, carton.CartonSN); //if (shipList.Count == 0) if (boxIdList.Count == 0) { errpara.Add(this.Key);//无可用Box Id,请联系FIS! throw new FisException("PAK102", errpara); } //shipInfo = shipList[0]; //BoxId = shipInfo.boxId; BoxId = boxIdList[0]; if (string.IsNullOrEmpty(BoxId)) { errpara.Add(this.Key);//无可用Box Id,请联系FIS! throw new FisException("PAK102", errpara); } else { //deliveryRep.UpdateShipBoxDetForSetSnoIdDefered(CurrentSession.UnitOfWork, curProduct.ProId, curDelivery.DeliveryNo, curPallet.PalletNo, BoxId); // ProductIDList.Add(curProduct.ProId); //productRep.BindPalletDefered(CurrentSession.UnitOfWork, curProduct.PalletNo, ProductIDList); deliveryRep.UpdateAssignBoxIdEditorDefered(CurrentSession.UnitOfWork, curDelivery.DeliveryNo, curPallet.PalletNo, carton.CartonSN); if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20)) { foreach (Product item in prodList) { item.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } else { foreach (Product item in prodList) { item.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor); productRep.Update(item, CurrentSession.UnitOfWork); } } carton.BoxId = BoxId; } } } } //f. 当与分配的Delivery (@dn)结合的所有Product (IMES_FA..Product.DeliveryNo)数量与Delivery 定义数量(IMES_PAK..Delivery.Qty)相等, //并都已经结合了Pallet(IMES_FA..Product.PalletNo)时,更新Delivery 的状态为'88' //curDelivery.IsDNFull() //int combinePLTQty = (CurrentSession.GetValue("HasAssignPLTQrty") == null ? 0 : (int)CurrentSession.GetValue("HasAssignPLTQrty")); foreach (IProduct item in prodList) { item.PalletNo = curPallet.PalletNo; productRep.Update(item, CurrentSession.UnitOfWork); } IList<Delivery> dnList = new List<Delivery>(); foreach (DeliveryCarton item in bindDNList) { //int dvQty = productRep.GetCombinedPalletQtyByDN(item.DeliveryNo) + item.AssignQty; int dvQty = productRep.GetCombinedQtyByDN(item.DeliveryNo) + item.AssignQty; int dnQty = 0; string dnStatus = ""; Delivery dn; if (curDelivery.DeliveryNo == item.DeliveryNo) { dn = curDelivery; dnQty = curDelivery.Qty; dnStatus = curDelivery.Status; } else { dn = deliveryRep.Find(item.DeliveryNo); dnQty = dn.Qty; dnStatus = dn.Status; } dnList.Add(dn); if (dvQty == dnQty && dnStatus!="87") { dn.Status = "87"; dn.Editor = CurrentSession.Editor; dn.Udt = DateTime.Now; DeliveryLog log = new DeliveryLog(0, item.DeliveryNo, "87", CurrentSession.Station, CurrentSession.Line, CurrentSession.Editor, DateTime.Now); dn.AddLog(log); deliveryRep.Update(dn, CurrentSession.UnitOfWork); } } foreach (DeliveryCarton item in bindDNList) { //item.Status = DeliveryCartonState.Assign; carton.SetDeliveryInCarton(item); } carton.Status = carton.FullQty > carton.Qty ? CartonStatusEnum.Partial : CartonStatusEnum.Full; cartonRep.Update(carton, CurrentSession.UnitOfWork); CurrentSession.AddValue(Session.SessionKeys.DeliveryList, dnList); return base.DoExecute(executionContext); }
/// <summary> /// 根据DeliveryNo记录DeliveryLog /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext){ Delivery thisDelivery = (Delivery)CurrentSession.GetValue(Session.SessionKeys.Delivery); string deliveryNo = thisDelivery.DeliveryNo; IDeliveryRepository currentRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>(); DeliveryLog thisLog = new DeliveryLog(0, deliveryNo, thisDelivery.Status, Station, Line, Editor, DateTime.Now); thisDelivery.AddLog(thisLog); currentRepository.Update(thisDelivery, CurrentSession.UnitOfWork); return base.DoExecute(executionContext); }
/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { Product currentProduct = (Product)CurrentSession.GetValue(Session.SessionKeys.Product); ICartonRepository cartonRep = RepositoryFactory.GetInstance().GetRepository<ICartonRepository, Carton>(); IProductRepository prodRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IPalletRepository palletRep = RepositoryFactory.GetInstance().GetRepository<IPalletRepository>(); IDeliveryRepository dnRep = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>(); Carton carton = (Carton)CurrentSession.GetValue(Session.SessionKeys.Carton); string dnNo = (string)CurrentSession.GetValue(Session.SessionKeys.DeliveryNo); IList<IProduct> prodList = (IList<IProduct>)CurrentSession.GetValue(Session.SessionKeys.ProdList); IList<Delivery> dnList = (IList<Delivery>)CurrentSession.GetValue(Session.SessionKeys.DeliveryList); IList<CartonProductInfo> cartonProdInfoList = (IList<CartonProductInfo>)CurrentSession.GetValue(ExtendSession.SessionKeys.CartonProductInfoList); if (UnPackCategory == UnPackEnum.Pallet && UnPackBy == UnPackByEnum.Delivery) { throw new Exception("Not Support UnPackPalletByDN function!!"); } IList<string> nameList = InfoTypeList.Split(new char[] { ',', ';' }).ToList(); var typeList = (from p in nameList where string.IsNullOrEmpty(p) == false select p).ToList(); var cartonSNList = (from p in prodList select p.CartonSN).Distinct().ToList(); #region unpack by Delivery if (UnPackBy == UnPackByEnum.Delivery) { #region //1.Upack Product prodRep.UnPackProductByDeliveryNoDefered(CurrentSession.UnitOfWork, dnNo); //2.Unpack ProductInfo foreach (string InfoType in typeList) { //Clear productInfo prodRep.UnPackProductInfoByDeliveryNoDefered(CurrentSession.UnitOfWork, InfoType, dnNo); } //3. unpack EDi Packing Data palletRep.UnPackPackingDataByDeliveryNoDefered(CurrentSession.UnitOfWork, dnNo); //4.unpack EDI ODMSessionData palletRep.UnPackPakOdmSessionByDeliveryNoDefered(CurrentSession.UnitOfWork, dnNo); //5.unpackShipBoxDet dnRep.UpdateSnoidForShipBoxDetDefered(CurrentSession.UnitOfWork, "", dnNo); //6.Update DeliveryStatus below doing this action //7.update carton status to UnPack by DN cartonRep.unBindCartonByDnDefered(CurrentSession.UnitOfWork, dnNo,CurrentSession.Editor); #endregion } #endregion #region unpack by Carton IList<string> custSNList = new List<string>(); //1.Update Product foreach (Product item in prodList) { if (UnPackCategory == UnPackEnum.Delivery) { //1.Clear Product item.DeliveryNo = ""; item.PalletNo = ""; item.CartonSN = ""; item.CartonWeight = 0; item.UnitWeight = 0; if (typeList.Count > 0) { //2.Clear productInfo prodRep.RemoveProductInfosByTypeDefered(CurrentSession.UnitOfWork, item.ProId, typeList); } custSNList.Add(item.CartonSN); } else { item.PalletNo = ""; } prodRep.Update(item, CurrentSession.UnitOfWork); } if (UnPackCategory == UnPackEnum.Delivery) { #region unpack DN //3.Clear EDI PackingDtaa if (cartonProdInfoList != null && cartonProdInfoList.Count > 0) { var boxIdList = (from p in cartonProdInfoList select p.BoxId).Distinct().ToList(); foreach (string boxId in boxIdList) { cartonRep.RemoveEdiPackingDataDefered(CurrentSession.UnitOfWork, boxId); } } else if (UnPackBy== UnPackByEnum.Carton) { cartonRep.RemoveEdiPackingDataDefered(CurrentSession.UnitOfWork, carton.BoxId); } if (custSNList.Count > 0) { //4.Clear EDI ODMSession cartonRep.RemoveEdiODMSessionDefered(CurrentSession.UnitOfWork, custSNList); } //5.ClearSnoIdInShipBoxDet foreach (string sn in cartonSNList) { cartonRep.ClearSnoIdInShipBoxDetDefered(CurrentSession.UnitOfWork, //carton.CartonSN, sn, CurrentSession.Editor); if (UnPackBy == UnPackByEnum.Carton) { //7.update carton status to UnPack cartonRep.unBindCartonDefered(CurrentSession.UnitOfWork, sn, CurrentSession.Editor); } } //6.Update DeliveryStatus foreach (Delivery item in dnList) { if (item.Status != "00") { item.Status = "00"; DeliveryLog log = new DeliveryLog(0, item.DeliveryNo, "00", CurrentSession.Station, CurrentSession.Line, CurrentSession.Editor, DateTime.Now); item.AddLog(log); dnRep.Update(item, CurrentSession.UnitOfWork); } } #endregion } else { #region unpack pallet //Update DeliveryStatus foreach (Delivery item in dnList) { if (item.Status != "00") { int qty=prodRep.GetCombinedQtyByDN(item.DeliveryNo); if (item.Qty > qty) { item.Status = "00"; DeliveryLog log = new DeliveryLog(0, item.DeliveryNo, "00", CurrentSession.Station, CurrentSession.Line, CurrentSession.Editor, DateTime.Now); item.AddLog(log); dnRep.Update(item, CurrentSession.UnitOfWork); } else if(item.Status != "87") { item.Status = "87"; DeliveryLog log = new DeliveryLog(0, item.DeliveryNo, "87", CurrentSession.Station, CurrentSession.Line, CurrentSession.Editor, DateTime.Now); item.AddLog(log); dnRep.Update(item, CurrentSession.UnitOfWork); } } } //Update Carton.UnpackPalletNo & clear Carton.PalletNo carton.UnPackPalletNo = carton.PalletNo; carton.PalletNo = ""; cartonRep.Update(carton, CurrentSession.UnitOfWork); #endregion } #endregion // update pallet location if (UnPackBy == UnPackByEnum.Delivery) { IList<string> pnList = dnRep.GetPalletNoListByDeliveryNo(dnNo); bool isMultiDn = false; if (cartonProdInfoList != null && cartonProdInfoList.Count > 0) { isMultiDn = true; } // need check logical foreach (string pn in pnList) { //mantis1666: Unpack DN by DN,清除棧板庫位時若unpack 的 DN為棧板唯一的DN才能清庫位 //在Pallet 結合DN最後一筆時,才能清空Pallet Location IList<string> combineDnList = prodRep.GetDeliveryNoListByPalletNo(pn); int palletQty=2; if (isMultiDn) { palletQty = palletQty +(from p in cartonProdInfoList where p.PalletNo == pn select new { p.PalletNo, p.DeliveryNo }).Distinct().ToList().Count; } if (combineDnList.Count < palletQty) { PakLocMasInfo setVal = new PakLocMasInfo(); PakLocMasInfo cond = new PakLocMasInfo(); setVal.editor = Editor; setVal.pno = ""; cond.pno = pn; cond.tp = "PakLoc"; palletRep.UpdatePakLocMasInfoDefered(CurrentSession.UnitOfWork, setVal, cond); } } } else { IList<string> cartonSNList1 = cartonRep.GetCartonSNListByPalletNo(carton.PalletNo, false); if (cartonSNList1.Count < 2) { PakLocMasInfo setVal = new PakLocMasInfo(); PakLocMasInfo cond = new PakLocMasInfo(); setVal.editor = Editor; setVal.pno = ""; cond.pno = carton.PalletNo; cond.tp = "PakLoc"; palletRep.UpdatePakLocMasInfoDefered(CurrentSession.UnitOfWork, setVal, cond); } } return base.DoExecute(executionContext); }