예제 #1
0
        public void DeletePackageItem(Sender sender, string Barcode, Guid WorkFlowID, bool IsRemovePackage)
        {
            try
            {
                using (ObjectProxy op = new ObjectProxy(true))
                {
                    //包装数据
                    OrderDetail subOrder = new OrderDetail();
                    subOrder.BarcodeNo = Barcode;
                    if (op.LoadOrderDetailByBarcodeNo(subOrder) == 0)
                    {
                        throw new PException("【{0}】条码数据不存在。", Barcode);
                    }

                    Guid PackageID = Guid.Empty;
                    List <PackageDetail> PackageDetails = op.LoadPackageDetailsByItemID(subOrder.ItemID);
                    PackageDetail        packageDetail  = PackageDetails.Find(p => p.IsPackaged = true);
                    if (packageDetail != null)
                    {
                        PackageID = packageDetail.PakageID;
                        packageDetail.IsPackaged = false;
                        packageDetail.PakageID   = Guid.Empty;
                        packageDetail.LayerNum   = 0;
                        op.UpdatePackageDetailByDetailID(packageDetail);
                    }
                    else
                    {
                        throw new PException("【{0}】没有打包数据。", Barcode);
                    }

                    if (IsRemovePackage)
                    {
                        op.DeletePackageByPackageID(PackageID);
                    }
                    else
                    {
                        Package package = new Package();
                        package.PackageID = PackageID;
                        if (op.LoadPackageByPackageID(package) == 0)
                        {
                            throw new PException("【{0}】没有打包数据。", Barcode);
                        }
                        else
                        {
                            package.ItemsQty -= 1;
                            package.Weight   -= subOrder.MadeLength * subOrder.MadeWidth * subOrder.MadeHeight * 0.000008M;
                            op.UpdatePackageByPackageID(package);
                        }
                    }

                    //生产流程
                    List <OrderMadeState> lists_oms = op.LoadOrderMadeStatesByItemID_WorkFlowID(subOrder.ItemID, WorkFlowID);
                    if (lists_oms.Count > 0)
                    {
                        op.DeleteOrderMadeStateByDetailID(lists_oms[0].DetailID);
                    }

                    //生产状态:数量减少
                    OrderWorkFlow owf = new OrderWorkFlow();
                    owf.ItemID           = subOrder.ItemID;
                    owf.SourceWorkFlowID = WorkFlowID;
                    if (op.LoadOrderWorkFlowByItemID_SourceWorkFlowID(owf) != 0)
                    {
                        owf.MadeQty -= 1;
                        op.UpdateOrderWorkFlowByItemID_SourceWorkFlowID(owf);
                    }

                    //生产进度
                    OrderScheduling os = new OrderScheduling();
                    os.CabinetID  = subOrder.CabinetID;
                    os.WorkFlowID = WorkFlowID;
                    if (op.LoadOrderSchedulingByCabinetID_WorkFlowID(os) != 0)
                    {
                        os.MadeTotalQty    -= 1;
                        os.MadeTotalAreal  -= subOrder.MadeLength * subOrder.MadeWidth * 0.000001M;
                        os.MadeTotalLength -= (subOrder.MadeLength + subOrder.MadeWidth) * 2 * 0.001M;
                        op.UpdateOrderSchedulingByMadeID(os);
                    }

                    op.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                throw ex;
            }
        }