예제 #1
0
        /// <summary>
        /// 备份Product / ProductStatus / Product_Part / ProductInfo 表中将被解绑的记录
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            IDeliveryRepository currentRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
            IProductRepository productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();

            Session session = CurrentSession;
            string DN = (string)session.GetValue(Session.SessionKeys.DeliveryNo);

            IList<IProduct> productList = (IList<IProduct>)session.GetValue(Session.SessionKeys.ProdNoList);

            IProduct currentProduct = null;
            foreach (IProduct ele in productList)
            {
                currentProduct = ele;
                productList.Remove(ele);
                break;
            }
            if (productList.Count == 0)
            {
                session.AddValue(Session.SessionKeys.IsComplete, true);
            }
            session.AddValue(Session.SessionKeys.ProdNoList, productList);
            session.AddValue(Session.SessionKeys.Product, currentProduct);
            IList<string> itemTypes = new List<string>();

            itemTypes.Add("CKK");

            productRepository.BackUpProductInfoDefered(session.UnitOfWork, currentProduct.ProId, this.Editor, "CKK");

            productRepository.RemoveProductInfosByTypeDefered(session.UnitOfWork, currentProduct.ProId, itemTypes);



            //// Delete CartonInfo

            carton.ICartonSSCCRepository cartRep = RepositoryFactory.GetInstance().GetRepository<carton.ICartonSSCCRepository, IMES.FisObject.PAK.CartonSSCC.CartonSSCC>();

            CartonInfoInfo infoCond = new CartonInfoInfo();

            infoCond.cartonNo = currentProduct.CartonSN;

            cartRep.DeleteCartonInfoDefered(session.UnitOfWork, infoCond);



            //Delete Product_Part 

           
            string[] prodList = new string[1];

            prodList[0] = currentProduct.ProId;

            ProductPart tmp = new ProductPart();

            tmp.Station = "8C";
            productRepository.BackUpProductPartDefered(session.UnitOfWork, prodList, tmp, this.Editor);
            productRepository.DeleteProductPartsDefered(session.UnitOfWork, prodList, tmp);

            
            //Update Product       

            productRepository.BackUpProductStatusDefered(session.UnitOfWork, currentProduct.ProId, this.Editor);

            productRepository.BackUpProductDefered(session.UnitOfWork, currentProduct.ProId, this.Editor);
            currentProduct.CartonSN = string.Empty;
            currentProduct.PalletNo = string.Empty;
            currentProduct.DeliveryNo = string.Empty;
            currentProduct.Udt = DateTime.Now;
            productRepository.Update(currentProduct, session.UnitOfWork);


            Delivery oldDelivery = currentRepository.Find(DN);
            if (oldDelivery != null)
            {
                oldDelivery.Status = "00";
                currentRepository.Update(oldDelivery, session.UnitOfWork);
                #region 清空Pallet weight
                IPalletRepository currentPltRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>();
                IList<string> palletNoList = currentRepository.GetPalletNoListByDeliveryNo(DN);
                foreach (string pn in palletNoList)
                {
                    //mantis1666: Unpack DN by DN,清除棧板庫位時若unpack 的 DN為棧板唯一的DN才能清庫位
                    //在Pallet 結合DN最後一筆時,才能清空Pallet Location 
                    Pallet pallet = currentPltRepository.Find(pn);
                    IList<string> dnList = productRepository.GetDeliveryNoListByPalletNo(pn);
                    if (dnList.Count < 2)
                    {
                        PakLocMasInfo setVal = new PakLocMasInfo();
                        PakLocMasInfo cond = new PakLocMasInfo();
                        setVal.editor = Editor;
                        setVal.pno = "";
                        cond.pno = pn;
                        cond.tp = "PakLoc";
                        currentPltRepository.UpdatePakLocMasInfoDefered(session.UnitOfWork, setVal, cond);
                        //Clear Floor in Pallet                    
                        pallet.Floor = "";
                        //Clear Floor in Pallet                    
                    }

                    //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);
                    currentPltRepository.Update(pallet, session.UnitOfWork);

                }

                #endregion
            }
            return base.DoExecute(executionContext);
        }
예제 #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext)
        { 
            IProduct product = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product);
            IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();
            IDeliveryRepository deliveryRep = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
            IPalletRepository palletRep = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>();
            carton.ICartonSSCCRepository cartRep = RepositoryFactory.GetInstance().GetRepository<carton.ICartonSSCCRepository, IMES.FisObject.PAK.CartonSSCC.CartonSSCC>();

            try
            {
                //2.	Assign Pallet
                //Assign Pallet 的方法:
                //1.	找到与Product.DeliveryNo 结合的Pallets  
                //2.	取其中尚未完成Combine PO in Carton 的Pallets
                //3.	按照Pallet No 正序,和Pallet 已经完成Combine PO in Carton 的数量逆序排序,取第一个Pallet
                //DECLARE @dn char(16)
                //DECLARE @pea float
                //DECLARE @pea2 int
                //SELECT @pea = InfoValue FROM DeliveryInfo (NOLOCK) WHERE DeliveryNo=@dn AND InfoType = ‘CQty’
                string peastr;
                Delivery dev = deliveryRep.Find(product.DeliveryNo);
                peastr = (string)dev.GetExtendedProperty("CQty");

                int pea = 0;
                if (string.IsNullOrEmpty(peastr))
                {
                    pea = 0;
                }
                else
                {
                    decimal tmp = Convert.ToDecimal(peastr);
                    pea = Convert.ToInt32(tmp);
                }
                

                //SET @pea2=CONVERT(int, @pea)
                //CREATE TABLE #plt (Plt char(14), qty int, tot int)
                //CREATE TABLE #Pltamount (Plt char(14), qty int)

                //INSERT #plt 
	            //SELECT PalletNo, DeliveryQty, 0 
		        //FROM Delivery_Pallet (NOLOCK) 
		        //WHERE DeliveryNo=@dn 
                IList<DeliveryPalletInfo> palletList = deliveryRep.GetDeliveryPalletListByDN(product.DeliveryNo);

                //INSERT #Pltamount
	            //SELECT PalletNo, COUNT(ProductID) as Qty
		        //FROM Product (NOLOCK)
		        //WHERE DeliveryNo = @dn 
                IList<IProduct> mountList = productRep.GetProductListByDeliveryNo(product.DeliveryNo);

                //UPDATE #plt SET tot = b.qty FROM #plt a,#Pltamount b
                //WHERE a.Plt=b.Plt
                //SELECT * FROM #plt

                //DELETE FROM #plt WHERE @pea2 * CONVERT(int, qty) – CONVERT(int, tot) < 1
                //SELECT * FROM #plt
                 for (int i = palletList.Count-1; i >= 0; i--)
                {
                    DeliveryPalletInfo node = palletList[i];
                    IList <ProductModel> proList = productRep.GetProductByDnPallet(product.DeliveryNo,node.palletNo);

                    if ((proList != null) && (proList.Count > 0))
                    {
                        int tot = proList.Count;
                        int qty = node.deliveryQty;
                        node.id = tot;
                        if (pea*qty - tot <1)
                        {
                            //ITC-1414-0116
                            palletList.RemoveAt(i);
                        }
                    }
                }
                //SELECT TOP 1 Plt as [Pallet No]
	            //FROM #plt 
	            //ORDER BY Plt, tot DESC
                 var tmpList = from item in palletList orderby item.palletNo, item.id descending select item;
                 IList<DeliveryPalletInfo> orderList = tmpList.ToList<DeliveryPalletInfo>();

                 string palletNo = orderList[0].palletNo;

                //3.	Assign Location by Pallet
                //IF EXISTS(SELECT SnoId FROM PAK_LocMas (NOLOCK)WHERE Tp='PakLoc' AND Pno=@PalletNo) 
                //BEGIN
	            //    SELECT @loc=SnoId FROM PAK_LocMas(NOLOCK) WHERE Tp='PakLoc' AND Pno=@PalletNo
                //END
                //ELSE
                //BEGIN
	            //IF EXISTS(SELECT SnoId FROM PAK_LocMas(NOLOCK) WHERE Tp='PakLoc' AND Pno='' )
	            //BEGIN
		        //SELECT @loc=SnoId FROM PAK_LocMas(NOLOCK) WHERE Tp='PakLoc' AND Pno='' ORDER BY CONVERT(int, SnoId)
		        //UPDATE PAK_LocMas SET Pno=@PalletNo,Udt=GETDATE() WHERE Tp='PakLoc' AND SnoId=@loc
	            //END
	            //ELSE	
	            //BEGIN
		        //SELECT @loc='Others'
	            //END	
                //END

                //@PalletNo – 上文分配的Pallet No
                //@loc – 系统分配的库位
                 string loc = "";
                 IList<PakLocMasInfo> macList = palletRep.GetPakLocMasList(palletNo, "PakLoc");
                 if (macList.Count > 0)
                 {
                     loc = macList[0].snoId;
                 }
                 else
                 {
                     macList = palletRep.GetPakLocMasList("", "PakLoc");
                     if (macList.Count > 0)
                     {
                         PakLocMasInfo locInfo = macList[0];
                         foreach (var item in macList)
                         {
                             if (Convert.ToInt64(locInfo.snoId) > Convert.ToInt64(item.snoId))
                             {
                                 locInfo = item;
                             }
                         }
                         loc = locInfo.snoId;

                         PakLocMasInfo sitem= new PakLocMasInfo();
                         PakLocMasInfo cond= new PakLocMasInfo();
                         sitem.pno= palletNo;
                         sitem.udt = DateTime.Now;
                         cond.tp = "PakLoc";
                         cond.snoId = loc;
                         palletRep.UpdatePakLocMasInfoDefered(CurrentSession.UnitOfWork,sitem,cond );

                     }
                     else
                     {
                         loc = "Others";
                     }
                 }
                 CurrentSession.AddValue("Location",loc);

                //4.	Product结合Pallet and Carton    
                //将页面上[Products in Carton] 中的每一个Product和上文系统分配的Pallet 以及上文生成的Carton No 进行结合 – Update Product
                //Product.PalletNo – Pallet No
                //Product.CartonSN – Carton No

                 IList<IProduct> productList = (List<IProduct>)CurrentSession.GetValue(Session.SessionKeys.ProdList);
                 foreach (var item in productList)
                 {
                     item.PalletNo = palletNo;
                     item.CartonSN = product.CartonSN;
                     //productRep.Update(item,CurrentSession.UnitOfWork);
                     productRep.UpdateForBindDNAndPalletDefered(CurrentSession.UnitOfWork, (Product)item);
                 }

                //ITC-1414-0070
                //ITC-1414-0120
                //5.	更新CartonStatus 的状态为95 (Station = ‘95’ ,Status= ‘1’),记录CartonLog
                CartonStatusInfo sinfo = new CartonStatusInfo();
                CartonStatusInfo sconf = new CartonStatusInfo();
                sconf.cartonNo = product.CartonSN;

                sinfo.editor = Editor;
                sinfo.line = Line;
                sinfo.station ="95";//Station;
                sinfo.status = 1;//pass
                sinfo.udt = DateTime.Now;
                cartRep.UpdateCartonStatusDefered(CurrentSession.UnitOfWork,sinfo,sconf);

                CartonLogInfo linfo = new CartonLogInfo();
                linfo.cartonNo = product.CartonSN;
                linfo.editor = Editor;
                linfo.line = Line;
                linfo.station = "95";
                linfo.status = 1;//pass
                linfo.cdt = DateTime.Now;
                cartRep.AddCartonLogInfoDefered(CurrentSession.UnitOfWork, linfo);

                 //6.更新Carton上所有Product 的ProductStatus 的状态为Combine Po In Carton for Docking 的站号(Station = Combine Po In Carton for Docking 的站号,Status= ‘1’),并记录ProductLog
                 string line = string.IsNullOrEmpty(this.Line) ? product.Status.Line : this.Line;

                 var newStatus = new IMES.FisObject.FA.Product.ProductStatus();
                 newStatus.Editor = Editor;
                 newStatus.Line = line;
                 newStatus.StationId = Station;
                 newStatus.Status = IMES.FisObject.Common.Station.StationStatus.Pass;

                 IList<string> ProductIDList = (IList<string>)CurrentSession.GetValue(Session.SessionKeys.NewScanedProductIDList);
                 productRep.UpdateProductListStatusDefered(CurrentSession.UnitOfWork, newStatus, ProductIDList);

                 foreach (var item in productList)
                 {
                     var productLog = new ProductLog
                     {
                         Model = item.Model,
                         Status = IMES.FisObject.Common.Station.StationStatus.Pass,
                         Editor = Editor,
                         Line = line,
                         Station = Station,
                         Cdt = DateTime.Now
                     };

                     item.AddLog(productLog);
                     productRep.Update(item, CurrentSession.UnitOfWork);
                 }
            }
            catch (Exception)
            {
                throw;
            }
            
            return base.DoExecute(executionContext);
        }
예제 #3
0
        /// <summary>
        /// 执行根据DeliveryNo修改所有属于该DeliveryNo的Product状态的操作
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            Session session = CurrentSession;
            string CurrentDeliveryNo = (string)session.GetValue(Session.SessionKeys.DeliveryNo);


            IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();
            IDeliveryRepository currentDeliveryRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository>();
            IPalletRepository currentPalletRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository>();

            /*
             * Answer to: ITC-1360-0845
             * Description: Update PAKLocMas info.
             */
            IList<string> pnList = currentDeliveryRepository.GetPalletNoListByDeliveryNo(CurrentDeliveryNo);
            currentProductRepository.UnPackProductByDeliveryNoDefered(session.UnitOfWork, CurrentDeliveryNo);
            foreach (string pn in pnList)
            {
                //mantis1666: Unpack DN by DN,清除棧板庫位時若unpack 的 DN為棧板唯一的DN才能清庫位
                //在Pallet 結合DN最後一筆時,才能清空Pallet Location 
                Pallet pallet = currentPalletRepository.Find(pn);
                IList<string>  dnList=currentProductRepository.GetDeliveryNoListByPalletNo(pn);
                if (dnList.Count < 2)
                {
                    PakLocMasInfo setVal = new PakLocMasInfo();
                    PakLocMasInfo cond = new PakLocMasInfo();
                    setVal.editor = Editor;
                    setVal.pno = "";
                    cond.pno = pn;
                    cond.tp = "PakLoc";
                    currentPalletRepository.UpdatePakLocMasInfoDefered(session.UnitOfWork, setVal, cond);
                    //Clear Floor in Pallet                    
                    pallet.Floor = "";                   
                    //Clear Floor in Pallet                    
                }

                //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);
            }
            return base.DoExecute(executionContext);
        }
예제 #4
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);
        }
예제 #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public IList<string> GetLocFloorList()
 {
     IList<string> retlist = new List<string>();
     try
     {
         
         IPalletRepository palletRep = RepositoryFactory.GetInstance().GetRepository<IPalletRepository>();
         PakLocMasInfo cond = new PakLocMasInfo();
         retlist = palletRep.GetFlListFromPakLacMas(cond);             
         return retlist;
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #6
0
        /// <summary>
        /// 执行根据DeliveryNo修改所有属于该DeliveryNo的Product状态的操作
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            string CurrentDeliveryNo = (string)CurrentSession.GetValue(Session.SessionKeys.DeliveryNo);


            IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();
            IDeliveryRepository currentDeliveryRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository>();
            IPalletRepository currentPalletRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository>();

            /*
             * Answer to: ITC-1360-0845
             * Description: Update PAKLocMas info.
             */
            IList<string> pnList = currentDeliveryRepository.GetPalletNoListByDeliveryNo(CurrentDeliveryNo);
            currentProductRepository.UnPackProductByDeliveryNoDefered(CurrentSession.UnitOfWork, CurrentDeliveryNo);
            foreach (string pn in pnList)
            {
                PakLocMasInfo setVal = new PakLocMasInfo();
                PakLocMasInfo cond = new PakLocMasInfo();
                setVal.editor = Editor;
                setVal.pno = "";
                cond.pno = pn;
                cond.tp = "PakLoc";
                currentPalletRepository.UpdatePakLocMasInfoDefered(CurrentSession.UnitOfWork, setVal, cond);
            }
            return base.DoExecute(executionContext);
        }
예제 #7
0
파일: DeleteDN.cs 프로젝트: wra222/testgit
        /// <summary>
        /// 
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            Session session = CurrentSession;
            string dn = (string)session.GetValue(Session.SessionKeys.DeliveryNo);
            string ship = (string)session.GetValue("ShipmentNo");
            string prj = (string)session.GetValue("Project");            

            IDeliveryRepository currentDNRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
            IPalletRepository currentPltRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>();

            if (dn != null && dn != "")
            {
                session.AddValue("ShipmentNo", currentDNRepository.Find(dn).ShipmentNo);
                IList<string> pnList = currentDNRepository.GetPalletNoListByDnAndWithSoloDn(dn);
                currentDNRepository.DeleteDeliveryAttrLogByDnDefered(session.UnitOfWork, dn);
                currentDNRepository.DeleteDeliveryAttrsByDnDefered(session.UnitOfWork, dn);
                currentDNRepository.DeleteDeliveryInfoByDnDefered(session.UnitOfWork, dn);
                currentDNRepository.DeleteDeliveryPalletByDnDefered(session.UnitOfWork, dn);
                currentDNRepository.DeleteDeliveryByDnDefered(session.UnitOfWork, dn);

                currentDNRepository.RemoveDeliveryExDefered(session.UnitOfWork, dn);

                //currentDNRepository.DeleteDnDefered(CurrentSession.UnitOfWork, dn);   //Includes above three calls.
                currentDNRepository.DeletePalletAttrLogDefered(session.UnitOfWork, pnList);
                currentPltRepository.DeletePalletAttrsDefered(session.UnitOfWork, pnList);
                currentPltRepository.DeletePalletsDefered(session.UnitOfWork, pnList);
                if (prj != null && prj == "Docking")
                {
                    //Call SP:Docking_DeleteDeliveryOfPC to delete DN related records.
                    //SP in-args:
                    //  @DeliveryNo char(20)
                    IProductRepository productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();
                    productRepository.ExecSpForNonQuery(SqlHelper.ConnectionString_PAK,
                                                               "Docking_DeleteDeliveryOfPC",
                                                               new SqlParameter("DeliveryNo", dn));
                }

                #region 清空Pallet weight
                IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();
                IList<string> palletNoList = currentDNRepository.GetPalletNoListByDeliveryNo(dn);
                foreach (string pn in palletNoList)
                {
                    //mantis1666: Unpack DN by DN,清除棧板庫位時若unpack 的 DN為棧板唯一的DN才能清庫位
                    //在Pallet 結合DN最後一筆時,才能清空Pallet Location 
                    Pallet pallet = currentPltRepository.Find(pn);
                    IList<string> dnList = currentProductRepository.GetDeliveryNoListByPalletNo(pn);
                    if (dnList.Count < 2)
                    {
                        PakLocMasInfo setVal = new PakLocMasInfo();
                        PakLocMasInfo cond = new PakLocMasInfo();
                        setVal.editor = Editor;
                        setVal.pno = "";
                        cond.pno = pn;
                        cond.tp = "PakLoc";
                        currentPltRepository.UpdatePakLocMasInfoDefered(session.UnitOfWork, setVal, cond);
                        //Clear Floor in Pallet                    
                        pallet.Floor = "";
                        //Clear Floor in Pallet                    
                    }

                    //Clear  weight in Pallet 
                    pallet.Weight = 0;
                    pallet.Weight_L = 0;                   
                    if (!pnList.Contains(pn))
                    {
                        PalletLog palletLog = new PalletLog { PalletNo = pallet.PalletNo, Station = "RETURN", Line = "Weight:0", Cdt = DateTime.Now, Editor = this.Editor };
                        pallet.AddLog(palletLog);
                        currentPltRepository.Update(pallet, session.UnitOfWork);
                    }
                }
              
                #endregion
            }
            else if (ship != null && ship != "")
            {
                IList<string> pnList = currentDNRepository.GetPalletNoListByShipmentAndWithSoloShipment(ship);
                currentDNRepository.DeleteDeliveryAttrLogByShipmentNoDefered(session.UnitOfWork, ship);
                currentDNRepository.DeleteDeliveryAttrsByShipmentNoDefered(session.UnitOfWork, ship);
                currentDNRepository.DeleteDeliveryInfoByShipmentNoDefered(session.UnitOfWork, ship);
                currentDNRepository.DeleteDeliveryPalletByShipmentNoDefered(session.UnitOfWork, ship);
                currentDNRepository.DeleteDeliveryByShipmentNoDefered(session.UnitOfWork, ship);

                currentDNRepository.RemoveDeliveryExDefered(session.UnitOfWork, ship);

                currentDNRepository.DeletePalletAttrLogDefered(session.UnitOfWork, pnList);
                currentPltRepository.DeletePalletAttrsDefered(session.UnitOfWork, pnList);
                currentPltRepository.DeletePalletsDefered(session.UnitOfWork, pnList);
                if (prj != null && prj == "Docking")
                {
                    //Call SP:Docking_DeleteShipmentOfPC to delete Shipment related records.
                    //SP in-args:
                    //  @ShipmentNo char(20)
                    IProductRepository productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();
                    productRepository.ExecSpForNonQuery(SqlHelper.ConnectionString_PAK,
                                                               "Docking_DeleteShipmentOfPC",
                                                               new SqlParameter("ShipmentNo", ship));
                }

                #region 清空Pallet weight
                IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();
                IList<string> palletNoList = currentDNRepository.GetPalletNoListByShipmentNo(ship);
                foreach (string pn in palletNoList)
                {
                    //mantis1666: Unpack DN by DN,清除棧板庫位時若unpack 的 DN為棧板唯一的DN才能清庫位
                    //在Pallet 結合DN最後一筆時,才能清空Pallet Location 
                    Pallet pallet = currentPltRepository.Find(pn);
                    IList<string> dnList = currentProductRepository.GetDeliveryNoListByPalletNo(pn);
                    if (dnList.Count < 2)
                    {
                        PakLocMasInfo setVal = new PakLocMasInfo();
                        PakLocMasInfo cond = new PakLocMasInfo();
                        setVal.editor = Editor;
                        setVal.pno = "";
                        cond.pno = pn;
                        cond.tp = "PakLoc";
                        currentPltRepository.UpdatePakLocMasInfoDefered(session.UnitOfWork, setVal, cond);
                        //Clear Floor in Pallet                    
                        pallet.Floor = "";
                        //Clear Floor in Pallet                    
                    }

                    //Clear  weight in Pallet 
                    pallet.Weight = 0;
                    pallet.Weight_L = 0;
                    if (!pnList.Contains(pn))
                    {
                        PalletLog palletLog = new PalletLog { PalletNo = pallet.PalletNo, Station = "RETURN", Line = "Weight:0", Cdt = DateTime.Now, Editor = this.Editor };
                        pallet.AddLog(palletLog);
                        currentPltRepository.Update(pallet, session.UnitOfWork);
                    }
                }

                #endregion
            }
            
            return base.DoExecute(executionContext);
        }
예제 #8
0
        /// <summary>
        /// 执行根据DeliveryNo修改所有属于该DeliveryNo的Product状态的操作
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            string Delivery = (string)CurrentSession.GetValue(Session.SessionKeys.DeliveryNo);
            Delivery CurrentDelivery = (Delivery)CurrentSession.GetValue(Session.SessionKeys.Delivery);

            IDeliveryRepository DeliveryRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
            IProductRepository repProduct = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();
            ////
           

            IList<string> nameList = new List<string>();
            nameList.Add("UCC");
            nameList.Add("BoxId");
            repProduct.BackUpProductByDnPure( Delivery, Editor);
            repProduct.BackUpProductInfoByDn( Delivery, Editor, nameList);
            repProduct.BackUpProductStatusByDnPure( Delivery, Editor);
           
            ////
            ProductStatus newStatus = new ProductStatus();
            newStatus.Editor = Editor;
            newStatus.Line = Line;
            newStatus.StationId = Station;
            newStatus.Status = StationStatus.Pass;
            newStatus.ReworkCode = "";

            repProduct.UpdateUnPackProductStatusByDn(newStatus, Delivery);
            carton.ICartonSSCCRepository cartRep = RepositoryFactory.GetInstance().GetRepository<carton.ICartonSSCCRepository, IMES.FisObject.PAK.CartonSSCC.CartonSSCC>();
            IPalletRepository palletRep = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>();

            ////
            ProductLog newLog = new ProductLog();
            newLog.Editor = Editor;
            newLog.Line = Line;
            newLog.Station = Station;
            newLog.Status = StationStatus.Pass;

            repProduct.WriteUnPackProductLogByDn(Delivery,newLog);

            //////
            repProduct.UnPackProductInfoByDeliveryNoAndInfoType("UCC",Delivery);
            repProduct.UnPackProductInfoByDeliveryNoAndInfoType("BoxId", Delivery);
            
            ////////
            if (Station != "8U")
            {
                IList<IProduct> lstProduct = repProduct.GetProductObjListByDn(Delivery);
                if (lstProduct != null && lstProduct.Count > 0)
                {
                    foreach(IProduct tmp in lstProduct)
                    {
                        string carton = tmp.CartonSN;
                        DM.CartonInfoInfo condition = new DM.CartonInfoInfo();
                        condition.cartonNo = carton;
                        cartRep.DeleteCartonInfo(condition);

                        //mantis 1395
                        DM.CartonStatusInfo cond = new DM.CartonStatusInfo();
                        DM.CartonStatusInfo sv = new DM.CartonStatusInfo();
                        cond.cartonNo = tmp.CartonSN;
                        sv.station = Station;
                        sv.status = 1;
                        sv.editor = Editor;
                        sv.udt = DateTime.Now;
                        cartRep.UpdateCartonStatusDefered(CurrentSession.UnitOfWork, sv, cond);

                        DM.CartonLogInfo item = new DM.CartonLogInfo();
                        item.cartonNo = tmp.CartonSN;
                        item.cdt = DateTime.Now;
                        item.editor = Editor;
                        item.line = tmp.Status.Line;
                        item.station = Station;
                        item.status = 1;
                        cartRep.AddCartonLogInfoDefered(CurrentSession.UnitOfWork, item);
                        //mantis 1395


                        string palletNo = tmp.PalletNo;
                        DM.PakLocMasInfo setValue = new DM.PakLocMasInfo();
                        DM.PakLocMasInfo pakLoc_condition = new DM.PakLocMasInfo();
                        setValue.pno = "";
                        setValue.editor = Editor;
                        pakLoc_condition.pno = palletNo;
                        pakLoc_condition.tp = "PakLoc";
                        palletRep.UpdatePakLocMasInfo(setValue, pakLoc_condition);
                    }
                }
            }

            if (Station != "8U")
                repProduct.UnPackProductByDn(Delivery);
            else
                repProduct.UnPackProductByDnWithoutCartonSN(Delivery);

    /////////////////////
            CurrentDelivery.Status = "00";
            CurrentDelivery.Editor = this.Editor;
            CurrentDelivery.Udt = DateTime.Now;
            DeliveryRepository.Update(CurrentDelivery, CurrentSession.UnitOfWork);
    /////////////////////


            return base.DoExecute(executionContext);
        }
예제 #9
0
        /// <summary>
        /// Update PAK_LocMas
        ///         Condition:
        ///         PAK_LocMas.Pno = @PalletNo and Tp = 'PakLoc'
        ///         更新如下字段:
        /// 	        PAK_LocMas.Pno = ''
        ///	            Editor
        ///	            Udt
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            string CurrentPalletNo = (string)CurrentSession.GetValue(Session.SessionKeys.PalletNo);

            IPalletRepository iPallletRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>();

            PakLocMasInfo cond = new PakLocMasInfo();
            cond.pno = CurrentPalletNo;
            cond.tp = "PakLoc";

            PakLocMasInfo setVal = new PakLocMasInfo();
            setVal.pno = "";
            setVal.editor = Editor;
            setVal.udt = DateTime.Now;

            iPallletRepository.UpdatePakLocMasInfoDefered(CurrentSession.UnitOfWork, setVal, cond);
            
            return base.DoExecute(executionContext);
        }
예제 #10
0
        /// <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);

        }
예제 #11
0
        /// <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);

        }
예제 #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            //Product currentProduct = (Product)CurrentSession.GetValue(Session.SessionKeys.Product);
            Session session =CurrentSession;
            ICartonRepository cartonRep = RepositoryFactory.GetInstance().GetRepository<ICartonRepository, Carton>();
            IProductRepository prodRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();

            IList<string> nameList = InfoTypeList.Split(new char[] { ',', ';' }).ToList();

            if (UnPackBy == UnPackByEnum.Carton)
            {
                Carton carton = (Carton)session.GetValue(Session.SessionKeys.Carton);
                IList<IProduct> prodList = (IList<IProduct>)session.GetValue(Session.SessionKeys.ProdList);
                string palletNo = null;
                IList<String> deliveryNoList = prodList.Where(y => !string.IsNullOrEmpty(y.DeliveryNo))
                                                                        .Select(x => x.DeliveryNo).Distinct().ToList();
                foreach (Product item in prodList)
                {
                    if (!string.IsNullOrEmpty(item.PalletNo))
                    {
                        palletNo = item.PalletNo;
                    }
                    prodRep.BackUpProductDefered(session.UnitOfWork, item.ProId, CurrentSession.Editor);

                    prodRep.BackUpProductStatusDefered(session.UnitOfWork, item.ProId, CurrentSession.Editor);

                    foreach (string name in nameList)
                    {
                        prodRep.BackUpProductInfoDefered(session.UnitOfWork, item.ProId, CurrentSession.Editor, name);
                    }

                    if (IsBckupProductPart)
                    {
                        prodRep.BackUpProductPartDefered(session.UnitOfWork, item.ProId, CurrentSession.Editor);
                    }
                }

                #region 清空Pallet weight
                if (!string.IsNullOrEmpty(palletNo))
                {
                    IPalletRepository currentPalletRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository>();
                    //IList<string> dnList = prodRep.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 = "RE", Line = "Weight:0", Cdt = DateTime.Now, Editor = this.Editor };
                    pallet.AddLog(palletLog);
                    currentPalletRepository.Update(pallet, session.UnitOfWork);
                    //Clear weight in Pallet
                    if (deliveryNoList.Count > 0)
                    {
                        session.AddValue(Session.SessionKeys.DeliveryNoList, deliveryNoList);
                    }
                }
                else if (deliveryNoList.Count > 0)
                {
                    session.AddValue(Session.SessionKeys.DeliveryNoList, deliveryNoList);
                }
                #endregion

            }
            else
            {
                //Backup DN 相關的ProductID的資料
                string dnNo = (string)session.GetValue(Session.SessionKeys.DeliveryNo);

                prodRep.BackUpProductByDnDefered(session.UnitOfWork, dnNo, session.Editor);

                prodRep.BackUpProductStatusByDnDefered(session.UnitOfWork, dnNo, session.Editor);

                prodRep.BackUpProductInfoByDnDefered(session.UnitOfWork, dnNo, session.Editor, nameList);
                prodRep.BackUpProductPartByDnDefered(session.UnitOfWork, dnNo, session.Editor);


                //此DN與其他DN相關的ProductID (剩餘相關CartonSNProductID)
                IList<IProduct> prodList = (IList<IProduct>)session.GetValue(Session.SessionKeys.ProdList);

                foreach (Product item in prodList)
                {
                    prodRep.BackUpProductDefered(session.UnitOfWork, item.ProId, session.Editor);

                    prodRep.BackUpProductStatusDefered(session.UnitOfWork, item.ProId, session.Editor);

                    foreach (string name in nameList)
                    {
                        prodRep.BackUpProductInfoDefered(session.UnitOfWork, item.ProId, session.Editor, name);
                    }

                    if (IsBckupProductPart)
                    {
                        prodRep.BackUpProductPartDefered(session.UnitOfWork, item.ProId, session.Editor);
                    }
                }

                #region 清空 Reset Pallet weight
                IDeliveryRepository currentDeliveryRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository>();
                IPalletRepository currentPalletRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository>();
                IList<string> pnList = currentDeliveryRepository.GetPalletNoListByDeliveryNo(dnNo);
                foreach (string pn in pnList)
                {
                    //mantis1666: Unpack DN by DN,清除棧板庫位時若unpack 的 DN為棧板唯一的DN才能清庫位
                    //在Pallet 結合DN最後一筆時,才能清空Pallet Location 
                    Pallet pallet = currentPalletRepository.Find(pn);
                    IList<string> dnList = prodRep.GetDeliveryNoListByPalletNo(pn);
                    if (dnList.Count < 2)
                    {
                        PakLocMasInfo setVal = new PakLocMasInfo();
                        PakLocMasInfo cond = new PakLocMasInfo();
                        setVal.editor = Editor;
                        setVal.pno = "";
                        cond.pno = pn;
                        cond.tp = "PakLoc";
                        currentPalletRepository.UpdatePakLocMasInfoDefered(session.UnitOfWork, setVal, cond);
                        //Clear Floor in Pallet                    
                        pallet.Floor = "";
                        //Clear Floor in Pallet                    
                    }

                    //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);
                }
                #endregion
            }
            return base.DoExecute(executionContext);

        }
예제 #13
0
        /// <summary>
        /// Get Pallet Object and put it into Session.SessionKeys.Pallet
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            var currentProduct = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product);
            string palletNo = currentProduct.PalletNo;
            IDeliveryRepository DeliveryRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
            IPalletRepository PalletRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>();
            List<string> erpara = new List<string>();
           // FisException ex;
            string pno = "WHLoc";

            string loc = "";
            IList<PakLocMasInfo> macList = PalletRepository.GetPakLocMasList(palletNo, pno);
            if (macList.Count > 0)
            {
                loc = macList[0].snoId;
            }
            else
            {
                macList = PalletRepository.GetPakLocMasList("", pno);
                if (macList.Count > 0)
                {
                    loc = loc = macList[0].snoId;

                    PakLocMasInfo sitem = new PakLocMasInfo();
                    PakLocMasInfo cond = new PakLocMasInfo();
                    sitem.pno = palletNo;
                    sitem.udt = DateTime.Now;
                    cond.tp = pno;
                    cond.snoId = loc;
                    PalletRepository.UpdatePakLocMasInfoDefered(CurrentSession.UnitOfWork, sitem, cond);

                }
                else
                {
                    loc = "Others";
                }
            }

            CurrentSession.AddValue(Session.SessionKeys.DOCType, loc);
            return base.DoExecute(executionContext);
        }