Beispiel #1
0
        /// <summary>
        /// 执行根据DeliveryNo修改所有属于该DeliveryNo的Product状态的操作
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            Product currentProduct = ((Product)CurrentSession.GetValue(Session.SessionKeys.Product));
            var productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();
            IDeliveryRepository deliveryRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
            string unpackType = ((string)CurrentSession.GetValue(Session.SessionKeys.CN));
            bool isPallet = ((bool)CurrentSession.GetValue(Session.SessionKeys.Pallet));
            productRepository.BackUpProduct(currentProduct.ProId,this.Editor);

            ShipBoxDetInfo setValue = new ShipBoxDetInfo();
            ShipBoxDetInfo condition = new ShipBoxDetInfo();
            setValue.snoId = "";
            condition.snoId = currentProduct.ProId;

            deliveryRepository.UpdateShipBoxDetInfo(setValue, condition);

            if (unpackType == "ALL")
            {
                currentProduct.PizzaID = string.Empty;
                currentProduct.CartonSN = string.Empty;
            }
            currentProduct.PalletNo = string.Empty;
            if (!isPallet)
            {
                currentProduct.DeliveryNo = string.Empty;
            }
            currentProduct.CartonWeight = 0;
            currentProduct.UnitWeight = 0;

            productRepository.Update(currentProduct, CurrentSession.UnitOfWork);

            productRepository.BackUpProductStatus(currentProduct.ProId, this.Editor);

            return base.DoExecute(executionContext);
        }
Beispiel #2
0
        /// <summary>
        /// Box Id / UCC 分配原则
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            List<string> errpara = new List<string>();
            Product curProduct = (Product)CurrentSession.GetValue(Session.SessionKeys.Product);
            Delivery curDelivery = (Delivery)CurrentSession.GetValue(Session.SessionKeys.Delivery);
            Pallet curPallet = (Pallet)CurrentSession.GetValue(Session.SessionKeys.Pallet);

            IList<string> ProductIDList = new List<string>();

            IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();
            IDeliveryRepository deliveryRep = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
            IPalletRepository palletRep = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>();

            CurrentSession.AddValue("CreatePDF", "");
            IList<ProductBTInfo> btList = productRep.GetProductBT(curProduct.ProId);
            if (btList.Count > 0 && Station.Trim() == "92")
            {
                return base.DoExecute(executionContext);
            }

            string proBoxId = (string)curProduct.GetExtendedProperty("BoxId");
            string proUCC = (string)curProduct.GetExtendedProperty("UCC");

            //a.	取Delivery 的下列属性并保存到对应的变量中:
            string BoxId = "";
            string shipment = curDelivery.ShipmentNo;
            string model = curDelivery.ModelName;
            int qut = curDelivery.Qty;
            DateTime shipDate = curDelivery.ShipDate;
            string emea = (string)curDelivery.GetExtendedProperty("EmeaCarrier");
            string carrier = (string)curDelivery.GetExtendedProperty("Carrier");
            string regId = (string)curDelivery.GetExtendedProperty("RegId");
            string deport = (string)curDelivery.GetExtendedProperty("Deport");
            string flag = (string)curDelivery.GetExtendedProperty("Flag");
            string boxId = (string)curDelivery.GetExtendedProperty("BoxId");
            string boxReg = (string)curDelivery.GetExtendedProperty("BoxReg");
            string shipWay = (string)curDelivery.GetExtendedProperty("ShipWay");
            string palletLayer = (string)curDelivery.GetExtendedProperty("PalletLayer");

             string locWC="";

            if (regId != null && regId.Length == 3)
            { 
                regId = regId.Substring(1, 2); 
            }  
            else
            { 
                regId = ""; 
            }
            //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 曾经结合过其它栈板,需要先解除与其他栈板的结合
            Boolean bindflag = deliveryRep.CheckExistShipBoxDetExceptPlt(curDelivery.DeliveryNo, curPallet.PalletNo, curProduct.ProId);
            if (bindflag)
            {
                deliveryRep.UpdateShipBoxDetForClearSnoidDefered(CurrentSession.UnitOfWork, curProduct.ProId, curDelivery.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, curProduct.ProId);
                
                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 = curProduct.ProId;

                    setvalue.udt = DateTime.Now;
                    deliveryRep.UpdateShipBoxDetInfoDefered(CurrentSession.UnitOfWork, setvalue, conf);

                    //i.如果Product 已经结合过Box Id / UCC (两者只会结合一个)
                    if (!string.IsNullOrEmpty(proBoxId) || !string.IsNullOrEmpty(proUCC))
                    {
                        //则需要更新该记录的InfoValue = @BoxId, Editor, Udt = Getdate();
                        if (!string.IsNullOrEmpty(proBoxId))
                        {
                            curProduct.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor);
                        }
                        else
                        {
                            curProduct.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor);
                        }
                    }
                    else
                    {
                        //如果尚未结合过,则结合@BoxId,记录到IMES_FA..ProductInfo (InfoValue = @BoxId, 
                        //InfoType 当@ucc<>''and LEN(@BoxId)=20 时,记录为'UCC',否则记录为'BoxId')
                        if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20))
                        {
                            curProduct.SetExtendedProperty("UCC",BoxId,CurrentSession.Editor);
                        }
                        else
                        {
                            curProduct.SetExtendedProperty("BoxId",BoxId,CurrentSession.Editor);
                        }
                    }
                    
                    //ii.	更新Product结合的Pallet (IMES_FA..Product.PalletNo) 为@plt
                    ProductIDList.Add(curProduct.ProId);
                    productRep.BindPalletDefered(CurrentSession.UnitOfWork, curProduct.PalletNo, ProductIDList);
                }
                else
                {
                    //b)使用DeliveryNo=@dn and PLT=@plt and SnoId=@id 查询ShipBoxDet 表不存在记录时,
                    //使用DeliveryNo=@dn and PLT=@plt and SnoId='' 查询ShipBoxDet 表,
                    //取查询到的记录的BoxId 字段值保存到变量@BoxId 中

                    //shipList = deliveryRep.GetShipBoxDetList(curDelivery.DeliveryNo, curPallet.PalletNo, "");
                    boxIdList = deliveryRep.GetAndUpdateShipBoxDet(curDelivery.DeliveryNo, curPallet.PalletNo, curProduct.ProId);
                    //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];

                    //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, curProduct.ProId);
                        if (!string.IsNullOrEmpty(proBoxId) || !string.IsNullOrEmpty(proUCC))
                        {
                            if (!string.IsNullOrEmpty(proBoxId))
                            {
                                curProduct.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor);
                            }
                            else
                            {
                                curProduct.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor);
                            }
                            curProduct.Udt = DateTime.Now;
                        }
                        else
                        {
                            //如果尚未结合过,则结合@BoxId,记录到IMES_FA..ProductInfo 
                            //(InfoValue = @BoxId,InfoType 当@ucc<>'' and LEN(@BoxId)=20 时,记录为'UCC',否则记录为'BoxId')
                            if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20))
                            {
                                curProduct.SetExtendedProperty("UCC",BoxId,CurrentSession.Editor);
                            }
                            else
                            {
                                curProduct.SetExtendedProperty("BoxId",BoxId,CurrentSession.Editor);
                            }
                        }
                        
                        //C.	更新Product结合的Pallet (IMES_FA..Product.PalletNo) 为@plt
                        //ProductIDList.Add(curProduct.ProId);
                        //productRep.BindPalletDefered(CurrentSession.UnitOfWork, curProduct.PalletNo, ProductIDList);
                        curProduct.Udt = DateTime.Now;
                        curProduct.PalletNo = curPallet.PalletNo;
                        productRep.Update(curProduct, CurrentSession.UnitOfWork);
                    }
                }
            }
            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, curProduct.ProId);
                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 = curProduct.ProId;
                    
                    setvalue.udt = DateTime.Now;
                    deliveryRep.UpdateShipBoxDetInfoDefered(CurrentSession.UnitOfWork,setvalue,conf);

                    if (!string.IsNullOrEmpty(proBoxId) || !string.IsNullOrEmpty(proUCC))
                    {
                        //则需要更新该记录的InfoValue = @BoxId, Editor, Udt = Getdate();
                        if (!string.IsNullOrEmpty(proBoxId))
                        {
                            curProduct.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor);
                        }
                        else
                        {
                            curProduct.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20))
                        {
                            curProduct.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor);
                        }
                        else
                        {
                            curProduct.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor);
                        }
                    }
                    curProduct.Udt = DateTime.Now;
                    curProduct.PalletNo = curPallet.PalletNo;
                    productRep.Update(curProduct, CurrentSession.UnitOfWork);
                }
                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, curProduct.ProId);
                    //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, curProduct.ProId);
                        BoxId = boxIdList[0];
                        if (!string.IsNullOrEmpty(proBoxId) || !string.IsNullOrEmpty(proUCC))
                        {
                            //则需要更新该记录的InfoValue = @BoxId, Editor, Udt = Getdate();
                            if (!string.IsNullOrEmpty(proBoxId))
                            {
                                curProduct.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor);
                            }
                            else
                            {
                                curProduct.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor);
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20))
                            {
                                curProduct.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor);
                            }
                            else
                            {
                                curProduct.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor);
                            }
                        }
                        curProduct.Udt = DateTime.Now;
                        curProduct.PalletNo = curPallet.PalletNo;
                        productRep.Update(curProduct, CurrentSession.UnitOfWork);
                    }
                    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, curProduct.ProId);
                        //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, curProduct.ProId);

                            if (!string.IsNullOrEmpty(proBoxId) || !string.IsNullOrEmpty(proUCC))
                            {
                                //则需要更新该记录的InfoValue = @BoxId, Editor, Udt = Getdate();
                                if (!string.IsNullOrEmpty(proBoxId))
                                {
                                    curProduct.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor);
                                }
                                else
                                {
                                    curProduct.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor);
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(ucc) && (BoxId.Length == 20))
                                {
                                    curProduct.SetExtendedProperty("UCC", BoxId, CurrentSession.Editor);
                                }
                                else
                                {
                                    curProduct.SetExtendedProperty("BoxId", BoxId, CurrentSession.Editor);
                                }
                            }
                            curProduct.Udt = DateTime.Now; 
                            curProduct.PalletNo = curPallet.PalletNo;
                            productRep.Update(curProduct, CurrentSession.UnitOfWork);
                        }
                    }
                }
            }

            //f.	当与分配的Delivery (@dn)结合的所有Product (IMES_FA..Product.DeliveryNo)数量与Delivery 定义数量(IMES_PAK..Delivery.Qty)相等,
            //并都已经结合了Pallet(IMES_FA..Product.PalletNo)时,更新Delivery 的状态为'88'
            //curDelivery.IsDNFull()

            //2012-01-10 Vincent Change caculate combine pallet logical
            //int dvQty = productRep.GetCombinedQtyByDN(curDelivery.DeliveryNo);
            
            //string oldDnFlag = (string)CurrentSession.GetValue("HasDN");
            //if (oldDnFlag != "Y")
            //{
            //    dvQty++;
            //}

            int combinePLTQty = (CurrentSession.GetValue("HasAssignPLTQrty")==null?0:(int)CurrentSession.GetValue("HasAssignPLTQrty")) ;
            int dvQty = productRep.GetCombinedPalletQtyByDN(curDelivery.DeliveryNo) + combinePLTQty;
            if (dvQty == curDelivery.Qty)
            {
                curDelivery.Status = "88";
                curDelivery.Editor = CurrentSession.Editor;
                curDelivery.Udt = DateTime.Now;
                deliveryRep.Update(curDelivery, CurrentSession.UnitOfWork);
            }
            
            // g.下文描述的是针对不同的情况,如何获取需要提示用户的信息 
            //a)	取Delivery 的PalletQty (IMES_PAK..DeliveryInfo.InfoValue,Condition: InfoType = 'PalletQty')属性值,
            //并取其整数部分保存到@paletqty 变量中;如果该属性不存在,则令@paletqty = 60
            string paletqty = (string)curDelivery.GetExtendedProperty("PalletQty");
            
            if (string.IsNullOrEmpty(paletqty))
            {
                paletqty = "60";
            }
           
            //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;

            //*********** Add by Benson for CQ Begin  ***********
            
       
            IList<PalletType> lstPalletType = IMES.Infrastructure.Utility.Common.CommonUti.GetPalletType(curPallet.PalletNo, curDelivery.DeliveryNo);
        //    IList<PalletType> lstPalletType = palletTypeRepository.GetPalletType(ShipWay, RegId, StdPltFullQty, pltDeliveryQty);
            if (lstPalletType.Count == 0)
            {
                 pclor="";
                 emeastr="Other";
            }
            else
            { 
                pclor=lstPalletType[0].Code.Trim();
                emeastr=lstPalletType[0].Type.Trim();
            }


            //*********** Add by Benson for CQ End  ***********


            //  *********** Marked by Benson Begin ***********
            /* 
            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"))
            {
                // 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 = "";
            }
             */
            //  *********** Marked by Benson End ***********
            
            //h.下文描述的是分配库位
            //Model 的第10,11码是”29” 或者”39” 的产品是出货日本的产品;否则,是非出货日本的产品
            //PAK_LocMas.WC = ‘JP’ 的为日本专用库位
            //出货日本的Pallet优先分配出货日本专用库位,当出货日本专用库位用完时,出货日本的Pallet 方可使用普通库位

            if (pqty <= 6)
            { locWC = "Virtual"; }
            
            string jpmodel =curProduct.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")
            {
                 //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;
                string pdline;
                ProductModel newModel = new ProductModel();
                if (!string.IsNullOrEmpty(curProduct.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 == 1 )
                {
                    // 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;
                        pdline = curProduct.ProId.Substring(0,1);
                        palletRep.UpdatePakLocMasByIdDefered(CurrentSession.UnitOfWork,
                                                                                       macList[0].id,
                                                                                       curPallet.PalletNo,
                                                                                       pdline,
                                                                                       this.Editor);
                        //palletRep.UpdatePakLocMasForPdLineDefered(CurrentSession.UnitOfWork,pdline,curPallet.PalletNo,"PakLoc");
                    }
                     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;
                            pdline = curProduct.ProId.Substring(0,1);
                            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 Vincent disable below code
                    //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);
                    //        macList = palletRep.GetPakLocMasList(normalconf);
                    //    }
                    //}                 
                    //else
                    //{
                    //    //macList = palletRep.GetPakLocMasList(normalconf, neqconf);//(curPallet.PalletNo, "PakLoc", floor);
                    //    macList = palletRep.GetPakLocMasList(normalconf);

                    //}
                    //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 Vincent disable Code
                //    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);

            /*SqlParameter[] paramsArray = new SqlParameter[8];

            paramsArray[0] = new SqlParameter("@snoID", SqlDbType.Char);
            paramsArray[0].Value = curProduct.ProId;
            paramsArray[1] = new SqlParameter("@Model", SqlDbType.Char);
            paramsArray[1].Value = curProduct.Model;
            paramsArray[2] = new SqlParameter("@Delivery", SqlDbType.Char);
            paramsArray[2].Value = curDelivery.DeliveryNo;
            paramsArray[3] = new SqlParameter("@Pallet", SqlDbType.Char);
            paramsArray[3].Value = curPallet.PalletNo;
            paramsArray[4] = new SqlParameter("@Location", SqlDbType.VarChar);
            paramsArray[4].Value = loc;
            paramsArray[5] = new SqlParameter("@pltqty", SqlDbType.Int);
            paramsArray[5].Value = pqty;
            paramsArray[6] = new SqlParameter("@BoxId", SqlDbType.VarChar);
            paramsArray[6].Value = boxId;
            paramsArray[7] = new SqlParameter("@UCC", SqlDbType.VarChar);
            paramsArray[7].Value = ucc;

            SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString_PAK, CommandType.StoredProcedure, "op_PackingData", paramsArray);*/

            ////Lock The XXX: 2012.04.20 LiuDong
            //if (!string.IsNullOrEmpty(loc))
            //{
            //    Guid gUiD = Guid.Empty;
            //    var identity = new ConcurrentLocksInfo();
            //    identity.clientAddr = "N/A";
            //    identity.customer = CurrentSession.Customer;
            //    identity.descr = string.Format("ThreadID: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
            //    identity.editor = CurrentSession.Editor;
            //    identity.line = CurrentSession.Line;
            //    identity.station = CurrentSession.Station;
            //    identity.timeoutSpan4Hold = new TimeSpan(0, 0, 3).Ticks;
            //    identity.timeoutSpan4Wait = new TimeSpan(0, 0, 5).Ticks;
            //    gUiD = productRep.GrabLockByTransThread("Loc", loc, identity);
            //    CurrentSession.AddValue(Session.SessionKeys.lockToken_Loc, gUiD);
            //}
            ////Lock The XXX: 2012.04.20 LiuDong

            ////Lock The XXX: 2012.04.20 LiuDong
            //if (!string.IsNullOrEmpty(boxId))
            //{
            //    Guid gUiD = Guid.Empty;
            //    var identity = new ConcurrentLocksInfo();
            //    identity.clientAddr = "N/A";
            //    identity.customer = CurrentSession.Customer;
            //    identity.descr = string.Format("ThreadID: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
            //    identity.editor = CurrentSession.Editor;
            //    identity.line = CurrentSession.Line;
            //    identity.station = CurrentSession.Station;
            //    identity.timeoutSpan4Hold = new TimeSpan(0, 0, 3).Ticks;
            //    identity.timeoutSpan4Wait = new TimeSpan(0, 0, 5).Ticks;
            //    gUiD = productRep.GrabLockByTransThread("Box", boxId, identity);
            //    CurrentSession.AddValue(Session.SessionKeys.lockToken_Box, gUiD);
            //}
            ////Lock The XXX: 2012.04.20 LiuDong


            ////Lock The XXX: 2012.04.20 LiuDong
            //if (!string.IsNullOrEmpty(ucc))
            //{
            //    Guid gUiD = Guid.Empty;
            //    var identity = new ConcurrentLocksInfo();
            //    identity.clientAddr = "N/A";
            //    identity.customer = CurrentSession.Customer;
            //    identity.descr = string.Format("ThreadID: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
            //    identity.editor = CurrentSession.Editor;
            //    identity.line = CurrentSession.Line;
            //    identity.station = CurrentSession.Station;
            //    identity.timeoutSpan4Hold = new TimeSpan(0, 0, 3).Ticks;
            //    identity.timeoutSpan4Wait = new TimeSpan(0, 0, 5).Ticks;
            //    gUiD = productRep.GrabLockByTransThread("Ucc", ucc, identity);
            //    CurrentSession.AddValue(Session.SessionKeys.lockToken_Ucc, gUiD);
            //}
            ////Lock The XXX: 2012.04.20 LiuDong


            palletRep.CallOp_PackingDataDefered(CurrentSession.UnitOfWork, curProduct.ProId, curProduct.Model, curDelivery.DeliveryNo,
                                            curPallet.PalletNo, loc, pqty, 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("CreatePDF", "pdf");
            }
            else
            {
                CurrentSession.AddValue("CreatePDF", "");
            }

            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);
          
        }
Beispiel #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            IDeliveryRepository deliveryRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
            IList<Delivery> deliveryList = CurrentSession.GetValue("DeliveryList") as IList<Delivery>;
            IList<Pallet> palletList = CurrentSession.GetValue("PalletList") as IList<Pallet>;
            IList<Pallet> notSavePalletList = CurrentSession.GetValue("NotSavePalletList") as IList<Pallet>;
            IList<DeliveryPalletInfo> dpList = CurrentSession.GetValue("DeliveryPalletList") as IList<DeliveryPalletInfo>;

            //Hashtable hOffset = new Hashtable();
            foreach (Delivery eleDlv in deliveryList)
            {
                IList<DeliveryInfo> infoList = eleDlv.DeliveryInfoes;
                string boxreg = "";
                string regid = "";
                string deport = "";
                string flag = "";
                string consolidated = "";
                string invoice = "";
                string ucc = "";
                foreach (DeliveryInfo info in infoList)
                {
                    if (info.InfoType == "BoxReg")
                    {
                        boxreg = info.InfoValue;
                        continue;
                    }
                    if (info.InfoType == "RegId")
                    {
                        regid = info.InfoValue;
                        continue;
                    }
                    if (info.InfoType == "Deport")
                    {
                        deport = info.InfoValue;
                        continue;
                    }
                    if (info.InfoType == "Flag")
                    {
                        flag = info.InfoValue;
                        continue;
                    }
                    if (info.InfoType == "UCC")
                    {
                        ucc = info.InfoValue;
                        continue;
                    }
                    if (info.InfoType == "Consolidated")
                    {
                        consolidated = info.InfoValue;
                        continue;
                    }
                    if (info.InfoType == "Invoice")
                    {
                        invoice = info.InfoValue;
                        continue;
                    }
                }
                    
                string prefix = "";
                if (boxreg != "")
                {
                    prefix = boxreg + "-";
                }
                else
                {
                    if (regid == "SNA" || regid == "SCA") prefix = "H410-";
                    else if (regid == "SNL") prefix = "LA" + deport;
                    else if (regid == "SNU" || regid == "SCU") prefix = "D7" + deport;
                    else if (regid == "SNE" || regid == "SCE") prefix = "63D7-";
                    else if (regid == "SAF" || regid == "SCN") prefix = "H4FN-0";
                    else if (regid == "SLA" || regid == "SCL") prefix = "LDIN";
                    /*else
                    {
                        List<string> erpara = new List<string>();
                        erpara.Add(eleDlv.DeliveryNo);
                        throw new FisException("CHK255", erpara);
                    }*/
                }

                foreach (DeliveryPalletInfo eleDP in dpList)
                {
                    if (eleDlv.DeliveryNo != eleDP.deliveryNo) continue;

                    if (deliveryRepository.CheckExistShipBoxDet(eleDP.deliveryNo, eleDP.palletNo))
                    {
                        List<string> erpara = new List<string>();
                        throw new FisException("CHK256", erpara);
                    }

                    Pallet findPlt = null;
                    foreach (Pallet elePlt in palletList)
                    {
                        if (eleDP.palletNo == elePlt.PalletNo)
                        {
                            findPlt = elePlt;
                            break;
                        }
                    }

                    if (findPlt == null)
                    {
                        foreach (Pallet elePlt in notSavePalletList)
                        {
                            if (eleDP.palletNo == elePlt.PalletNo)
                            {
                                findPlt = elePlt;
                                break;
                            }
                        }
                    }

                    if (findPlt == null) continue;

                    if (flag == "N" && ucc != "X")
                    {
                        if (prefix == "")
                        {
                            List<string> erpara = new List<string>();
                            erpara.Add(eleDlv.DeliveryNo);
                            throw new FisException("CHK255", erpara);
                        }
                        /*
                         * Answer to: ITC-1360-1135
                         * Description: Generate BoxId in turn.
                         */
                        /*
                         * Answer to: ITC-1360-1285
                         * Description: Bad casting from int to short.
                         */
                        /*
                        short offset = 0;
                        if (hOffset.Contains(prefix))
                        {
                            offset = (short)hOffset[prefix];
                            hOffset[prefix] = (short)(offset + eleDP.deliveryQty);
                        }
                        else
                        {
                            hOffset.Add(prefix, eleDP.deliveryQty);
                        }
                        IList<SnoCtrlBoxIdSQInfo> boxIdList = deliveryRepository.GetSnoCtrlBoxIdSQListByCust(prefix, (int)eleDP.deliveryQty, (int)offset);
                        */
                        try
                        {
                            SqlTransactionManager.Begin();
                            lock (_syncRoot_GetSeq)
                            {
                                IList<SnoCtrlBoxIdSQInfo> boxIdList = deliveryRepository.GetSnoCtrlBoxIdSQListByCust(prefix, (int)eleDP.deliveryQty, 0);
                                /*
                                 * Answer to: ITC-1360-1144
                                 * Description: Exception process with no efficient BoxId.
                                 */
                                if (boxIdList.Count < eleDP.deliveryQty)
                                {
                                    List<string> erpara = new List<string>();
                                    erpara.Add(prefix);
                                    throw new FisException("PAK094", erpara);
                                }

                                foreach (SnoCtrlBoxIdSQInfo item in boxIdList)
                                {
                                    ShipBoxDetInfo sbd = new ShipBoxDetInfo();
                                    if (consolidated == "")
                                    {
                                        sbd.shipment = eleDlv.DeliveryNo.Substring(0, 10);
                                    }
                                    else
                                    {
                                        sbd.shipment = consolidated.Substring(0, 10);
                                    }
                                    sbd.invioce = invoice;
                                    sbd.deliveryNo = eleDlv.DeliveryNo;
                                    sbd.plt = findPlt.PalletNo;
                                    sbd.boxId = item.boxId;
                                    sbd.snoId = "";
                                    sbd.editor = Editor;
                                    deliveryRepository.InsertShipBoxDetDefered(CurrentSession.UnitOfWork, sbd);
                                    //deliveryRepository.DeleteSnoCtrlBoxIdSQInfoDefered(CurrentSession.UnitOfWork, item);
                                    deliveryRepository.DeleteSnoCtrlBoxIdSQInfo(item);
                                }
                                SqlTransactionManager.Commit();
                            }
                        }
                        catch (Exception e)
                        {
                            SqlTransactionManager.Rollback();
                            throw e;
                        }
                        finally
                        {
                            SqlTransactionManager.Dispose();
                            SqlTransactionManager.End();
                        }
                    }
                    else if (ucc == "X")
                    {
                        if (findPlt.PalletNo.StartsWith("NA"))
                        {
                            ShipBoxDetInfo sbd = new ShipBoxDetInfo();
                            if (consolidated == "")
                            {
                                sbd.shipment = eleDlv.DeliveryNo.Substring(0, 10);
                            }
                            else
                            {
                                sbd.shipment = consolidated.Substring(0, 10);
                            }
                            sbd.invioce = invoice;
                            sbd.deliveryNo = eleDlv.DeliveryNo;
                            sbd.plt = findPlt.PalletNo;
                            sbd.boxId = findPlt.UCC;
                            sbd.snoId = "";
                            sbd.editor = Editor;
                            deliveryRepository.InsertShipBoxDetDefered(CurrentSession.UnitOfWork, sbd);
                        }
                        else
                        {
                            IList<string> uccidList = GetUCCIDList(eleDP.deliveryQty);
                            foreach (string uccid in uccidList)
                            {
                                ShipBoxDetInfo sbd = new ShipBoxDetInfo();
                                if (consolidated == "")
                                {
                                    sbd.shipment = eleDlv.DeliveryNo.Substring(0, 10);
                                }
                                else
                                {
                                    sbd.shipment = consolidated.Substring(0, 10);
                                }
                                sbd.invioce = invoice;
                                sbd.deliveryNo = eleDlv.DeliveryNo;
                                sbd.plt = findPlt.PalletNo;
                                sbd.boxId = uccid;
                                sbd.snoId = "";
                                sbd.editor = Editor;
                                deliveryRepository.InsertShipBoxDetDefered(CurrentSession.UnitOfWork, sbd);
                            }
                        }
                    }
                    else if (flag == "C")
                    {
                        for (int i = 1; i <= eleDP.deliveryQty; i++)
                        {
                            ShipBoxDetInfo sbd = new ShipBoxDetInfo();
                            if (consolidated == "")
                            {
                                sbd.shipment = eleDlv.DeliveryNo.Substring(0, 10);
                            }
                            else
                            {
                                sbd.shipment = consolidated.Substring(0, 10);
                            }
                            sbd.invioce = invoice;
                            sbd.deliveryNo = eleDlv.DeliveryNo;
                            sbd.plt = findPlt.PalletNo;
                            sbd.boxId = i.ToString();
                            sbd.snoId = "";
                            sbd.editor = Editor;
                            deliveryRepository.InsertShipBoxDetDefered(CurrentSession.UnitOfWork, sbd);
                        }
                    }
                }
            }
            return base.DoExecute(executionContext);
        }
Beispiel #5
0
        /// <summary>
        /// 执行根据DeliveryNo修改所有属于该DeliveryNo的Product状态的操作
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            Session session = CurrentSession;
            Product currentProduct = ((Product)session.GetValue(Session.SessionKeys.Product));
            var productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();
            IDeliveryRepository deliveryRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
            string unpackType = ((string)session.GetValue(Session.SessionKeys.CN));
            bool isPallet = ((bool)session.GetValue(Session.SessionKeys.Pallet));
            productRepository.BackUpProduct(currentProduct.ProId,this.Editor);

            ShipBoxDetInfo setValue = new ShipBoxDetInfo();
            ShipBoxDetInfo condition = new ShipBoxDetInfo();
            setValue.snoId = "";
            setValue.editor = this.Editor;
            condition.snoId = currentProduct.ProId;
            deliveryRepository.UpdateShipBoxDetInfo(setValue, condition);
            string palletNo = currentProduct.PalletNo;
            string deliveryNo = currentProduct.DeliveryNo;

            if (unpackType == "ALL")
            {
                currentProduct.PizzaID = string.Empty;
                currentProduct.CartonSN = string.Empty;
            }
            currentProduct.PalletNo = string.Empty;
            if (!isPallet)
            {
                currentProduct.DeliveryNo = string.Empty;
            }
            currentProduct.CartonWeight = 0;
            if (!currentProduct.IsBT)
            { currentProduct.UnitWeight = 0; }
            
           
            #region 清空Pallet weight
            if (!string.IsNullOrEmpty(palletNo))
            {
                //Don't  change PAKLocMAS 
                IPalletRepository currentPalletRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository>();
                //IList<string> dnList = productRepository.GetDeliveryNoListByPalletNo(palletNo);
                Pallet pallet = currentPalletRepository.Find(palletNo);
                //if (dnList.Count < 2)
                //{
                //    PakLocMasInfo setVal = new PakLocMasInfo();
                //    PakLocMasInfo cond = new PakLocMasInfo();
                //    setVal.editor = Editor;
                //    setVal.pno = "";
                //    cond.pno = palletNo;
                //    cond.tp = "PakLoc";
                //    currentPalletRepository.UpdatePakLocMasInfoDefered(session.UnitOfWork, setVal, cond);
                //    //Clear Floor in Pallet
                //    pallet.Floor = "";
                //}

                //Clear  weight in Pallet 
                pallet.Weight = 0;
                pallet.Weight_L = 0;
                PalletLog palletLog = new PalletLog { PalletNo = pallet.PalletNo, Station = "RETURN", Line = "Weight:0", Cdt = DateTime.Now, Editor = this.Editor };
                pallet.AddLog(palletLog);
                currentPalletRepository.Update(pallet, session.UnitOfWork);
                //Clear weight in Pallet
               if (!string.IsNullOrEmpty(deliveryNo))
               {
                    session.AddValue(Session.SessionKeys.DeliveryNo, deliveryNo);
               }
            }
            else if (!string.IsNullOrEmpty(deliveryNo))
            {
                session.AddValue(Session.SessionKeys.DeliveryNo, deliveryNo);
            }
            #endregion

            productRepository.Update(currentProduct, session.UnitOfWork);

            productRepository.BackUpProductStatus(currentProduct.ProId, this.Editor);

            return base.DoExecute(executionContext);
        }