예제 #1
0
        /// <summary>
        /// 保存其它单据时检查匹配性
        /// </summary>
        public void RSaveOtherCheck(IOFormDts p_MainDts, BaseEntity p_BE, IDBTransAccess sqlTrans)
        {
            this.CheckCorrect(p_BE);
            IOFormDtsPack entity = (IOFormDtsPack)p_BE;

            if (entity.BoxNo == string.Empty)
            {
                throw new Exception("异常,没有读取到码单箱号");
            }
            PackBoxRule pbrule   = new PackBoxRule();
            PackBox     pbentity = pbrule.RGetEntityByBoxNo(entity.BoxNo, sqlTrans);

            if (pbentity.BoxStatusID != (int)EnumBoxStatus.入库)
            {
                throw new Exception("异常,码单箱号" + entity.BoxNo + "当前未处于入库状态,不允许操作");
            }
            if (pbentity.ItemCode != p_MainDts.ItemCode || pbentity.ColorNum != p_MainDts.ColorNum ||
                pbentity.ColorName != p_MainDts.ColorName)//|| pbentity.GoodsLevel != p_MainDts.GoodsLevel 先不管等级
            {
                throw new Exception("异常,码单箱号" + entity.BoxNo + "和单据明细属性不匹配");
            }
        }
예제 #2
0
        /// <summary>
        /// 新增(传入事务处理)
        /// </summary>
        /// <param name="p_BE">要新增的实体</param>
        /// <param name="sqlTrans">事务类</param>
        public void RAdd(IOForm p_MainEntity, IOFormDts p_MainDts, BaseEntity p_BE, IDBTransAccess sqlTrans)
        {
            try
            {
                this.CheckCorrect(p_BE);
                IOFormDtsPack entity = (IOFormDtsPack)p_BE;

                PackBox pbentity = new PackBox(sqlTrans);
                pbentity.SourceTypeID = (int)PackBoxSourceType.入库单;
                pbentity.BoxStatusID  = (int)EnumBoxStatus.未入库;
                CopyEntityData(p_MainDts, entity, pbentity);
                //if (entity.BoxNo != string.Empty && p_MainEntity.Remark == "EIN")//仅仅在导数据时使用到
                if (entity.BoxNo != string.Empty)//仅仅在导数据时使用到
                {
                    pbentity.CreateTime = p_MainEntity.FormDate;
                    pbentity.BoxNo      = entity.BoxNo;
                }
                pbentity.DID    = p_MainDts.ID;
                pbentity.SubSeq = entity.SubSeq;
                PackBoxRule pbrule = new PackBoxRule();
                pbrule.RAdd(pbentity, sqlTrans);



                entity.DID   = p_MainDts.ID; //20141009 zhoufc
                entity.BoxNo = pbentity.BoxNo;
                this.RAdd(entity, sqlTrans); //后插入的原因是箱号是在插入箱号实体时生成的
            }
            catch (BaseException)
            {
                throw;
            }
            catch (Exception E)
            {
                throw new BaseException(E.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="p_BE">要修改的实体</param>
        /// <param name="sqlTrans">事务类</param>
        public void RUpdate(IOFormDts p_MainDts, BaseEntity p_BE, IDBTransAccess sqlTrans)
        {
            try
            {
                this.CheckCorrect(p_BE);
                IOFormDtsPack entity = (IOFormDtsPack)p_BE;
                this.RUpdate(p_BE, sqlTrans);

                PackBoxRule pbrule   = new PackBoxRule();
                PackBox     pbentity = pbrule.RGetEntityByBoxNo(entity.BoxNo, sqlTrans); //获得箱单实体

                CopyEntityData(p_MainDts, entity, pbentity);                             //拷贝数据

                pbrule.RUpdate(pbentity, sqlTrans);                                      //更新
            }
            catch (BaseException)
            {
                throw;
            }
            catch (Exception E)
            {
                throw new BaseException(E.Message);
            }
        }
예제 #4
0
        /// <summary>
        /// 保存(传入事务处理)
        /// </summary>
        /// <param name="p_BE">要新增的实体</param>
        /// <param name="sqlTrans">事务类</param>
        public void RSave(int p_ID, int p_MainID, int p_Seq, BaseEntity[] p_BE, bool p_UpdateFlag, IDBTransAccess sqlTrans)
        {
            try
            {
                string sql = "";
                if (p_UpdateFlag)                //修改状态下首先清除被删除的码单明细
                {
                    string idStr = string.Empty; //ID字符串
                    idStr = "0";
                    for (int i = 0; i < p_BE.Length; i++)
                    {
                        IOFormDtsPack entity = (IOFormDtsPack)p_BE[i];
                        if (entity.ID != 0)//有ID
                        {
                            if (idStr != string.Empty)
                            {
                                idStr += ",";
                            }
                            idStr += entity.ID.ToString();
                        }
                    }

                    if (idStr != string.Empty)
                    {
                        sql = "DELETE FROM WH_PackBox WHERE BoxNo IN (SELECT BoxNo FROM WH_IOFormDtsPack WHERE DID=" + SysString.ToDBString(p_ID) + " AND ID NOT IN(" + idStr + ") )";
                        sqlTrans.ExecuteNonQuery(sql);                                                                                  //执行条形码删除

                        sql = "DELETE FROM WH_IOFormDtsPack WHERE DID=" + SysString.ToDBString(p_ID) + " AND ID NOT IN(" + idStr + ")"; //WH_IOFormDtsPack WH_PackBox
                        sqlTrans.ExecuteNonQuery(sql);
                    }
                }
                else//新增状态
                {
                    sql = "SELECT TOP 1 ID FROM WH_IOFormDtsPack WHERE DID=" + SysString.ToDBString(p_ID);
                    DataTable dt = sqlTrans.Fill(sql);
                    if (dt.Rows.Count > 0)
                    {
                        throw new BaseException("不能重复保存!");
                    }
                }


                IOForm p_Main = new IOForm(sqlTrans);
                p_Main.ID = p_MainID;
                p_Main.SelectByID();

                IOFormDts p_MainDts = new IOFormDts(sqlTrans);
                p_MainDts.ID = p_ID;
                p_MainDts.SelectByID();



                IOFormDtsPackRule rule     = new IOFormDtsPackRule();
                PackBoxRule       Brule    = new PackBoxRule();
                decimal           Qty      = 0;
                decimal           Weight   = 0;
                decimal           Yard     = 0;
                decimal           PieceQty = 0;
                for (int i = 0; i < p_BE.Length; i++)
                {
                    FormNoControlRule frule  = new FormNoControlRule();
                    IOFormDtsPack     entity = (IOFormDtsPack)p_BE[i];
                    int boxNoCreateTypeID    = 0;//箱号条码来源
                    if (entity.ID == 0)
                    {
                        if (entity.BoxNo == string.Empty)//没有箱号条码
                        {
                            entity.BoxNo = frule.RGetFormNo((int)FormNoControlEnum.码单箱号, sqlTrans);
                            rule.RAdd(entity, sqlTrans);
                            frule.RAddSort((int)FormNoControlEnum.码单箱号, sqlTrans);
                        }
                        else//有箱号条码说明是验布产生的条码
                        {
                            boxNoCreateTypeID = 1;//验布来源
                        }
                    }
                    else
                    {
                        rule.RUpdate(entity, sqlTrans);
                    }


                    PackBox entityBox = new PackBox();
                    if (entity.ID != 0)//仓库明细已生成,则寻找箱号ID 此处判断其实无意义,经过上面的代码肯定有ID值了
                    {
                        sql = "SELECT ID FROM WH_PackBox WHERE BoxNo=" + SysString.ToDBString(entity.BoxNo);
                        DataTable dtPackBox = sqlTrans.Fill(sql);
                        if (dtPackBox.Rows.Count != 0)//如果找到条码
                        {
                            entityBox.ID = SysConvert.ToInt32(dtPackBox.Rows[0]["ID"]);
                        }
                        else//如果未找到条码
                        {
                            entityBox.CreateSourceID = boxNoCreateTypeID;////原始条码表加个字段表示来源 0:表示入库录入
                        }
                    }
                    entityBox.BoxNo         = entity.BoxNo;
                    entityBox.WHID          = p_MainDts.WHID;
                    entityBox.SectionID     = p_MainDts.SectionID;
                    entityBox.SBitID        = p_MainDts.SBitID;
                    entityBox.ColorName     = p_MainDts.ColorName;
                    entityBox.ColorNum      = p_MainDts.ColorNum;
                    entityBox.CompanyTypeID = p_MainDts.CompanyTypeID;
                    entityBox.GoodsCode     = p_MainDts.GoodsCode;
                    // entityBox.GoodsLevel = p_MainDts.GoodsLevel;
                    entityBox.ItemCode    = p_MainDts.ItemCode;
                    entityBox.ItemModel   = p_MainDts.ItemModel;
                    entityBox.ItemName    = p_MainDts.ItemName;
                    entityBox.ItemStd     = p_MainDts.ItemStd;
                    entityBox.JarNum      = p_MainDts.JarNum;
                    entityBox.Batch       = p_MainDts.Batch;
                    entityBox.VendorBatch = p_MainDts.VendorBatch;
                    entityBox.MWeight     = p_MainDts.MWeight;
                    entityBox.MWidth      = p_MainDts.MWidth;
                    entityBox.Qty         = entity.Qty;
                    entityBox.Weight      = entity.Weight;
                    entityBox.Yard        = entity.Yard;
                    entityBox.GoodsLevel  = entity.GoodsLevel;
                    entityBox.Unit        = p_MainDts.Unit;
                    entityBox.BoxStatusID = (int)EnumBoxStatus.未入库;
                    entityBox.DID         = p_ID;
                    entityBox.InFormNo    = p_Main.FormNo;
                    entityBox.OrderFormNo = p_MainDts.DtsOrderFormNo; //合同号明细
                    entityBox.SubSeq      = entity.SubSeq;            //卷号

                    if (entityBox.ID == 0)                            //没有ID则新增
                    {
                        Brule.RAdd(entityBox, sqlTrans);
                    }
                    else//有ID则修改
                    {
                        Brule.RUpdate(entityBox, sqlTrans);
                    }

                    Qty    += entity.Qty;
                    Weight += entity.Weight;
                    Yard   += entity.Yard;
                    PieceQty++;
                }

                //if (PieceQty == 0)
                //{
                //    throw new BaseException("请填写细码后点击保存");
                //}

                sql  = "UPDATE WH_IOFormDts SET Qty=" + SysString.ToDBString(Qty);
                sql += ",Weight=" + SysString.ToDBString(Weight);
                sql += ",Yard=" + SysString.ToDBString(Yard);
                sql += ",PieceQty=" + SysString.ToDBString(PieceQty);
                sql += ",PackFlag=1 ";
                sql += " WHERE ID=" + SysString.ToDBString(p_ID);
                sqlTrans.ExecuteNonQuery(sql);
                sql  = "UPDATE WH_IOFormDts SET Amount=ISNULL(SinglePrice,0)*(";
                sql += "CASE";
                sql += " WHEN Unit='RMB/KG' OR Unit='USD/KG' THEN ISNULL(Weight,0)";
                sql += " WHEN Unit='RMB/Y' OR Unit='USD/Y' THEN ISNULL(Yard,0) ";
                sql += " WHEN Unit='RMB/M' OR Unit='USD/M' THEN ISNULL(Qty,0) ";
                sql += " ELSE 0 END)";
                sql += " WHERE ID=" + SysString.ToDBString(p_ID);
                sqlTrans.ExecuteNonQuery(sql);
            }
            catch (BaseException)
            {
                throw;
            }
            catch (Exception E)
            {
                throw new BaseException(E.Message);
            }
        }
예제 #5
0
        /// <summary>
        /// 保存(传入事务处理)
        /// </summary>
        /// <param name="p_Entity"></param>
        /// <param name="p_BE"></param>
        /// <param name="sqlTrans"></param>
        public void RSave(IOForm p_Entity, IOFormDts[] p_EntityDts, ArrayList list, IDBTransAccess sqlTrans)
        {
            try
            {
                string sql = string.Empty;

                int FormListTopType = IOFormDtsRule.GetFormListTopTypeByFormListID(p_Entity.HeadType, sqlTrans);//顶层单据类型
                //if (FormListTopType != (int)WHFormList.入库 && FormListTopType != (int)WHFormList.期初入库)//如果不是入库类型的单据
                if (FormListTopType != (int)WHFormList.入库 && FormListTopType != (int)WHFormList.期初入库 &&
                    FormListTopType != (int)WHFormList.面料入库单 && FormListTopType != (int)WHFormList.坯布入库单)    //如果不是入库类型的单据
                {
                    RSaveOther(p_Entity, p_EntityDts, list, sqlTrans);
                    return;
                }


                sql  = "SELECT BoxNo FROM WH_IOFormDtsPack WHERE MainID=" + p_Entity.ID.ToString();
                sql += " AND ID NOT IN" + string.Format("({0})", GetIDExist(list));
                DataTable dtDelete = sqlTrans.Fill(sql);  //删除表结构
                if (dtDelete.Rows.Count != 0)             //有需要删除的数据
                {
                    foreach (DataRow dr in dtDelete.Rows) //校验是否可以删除
                    {
                        PackBoxRule pbrule = new PackBoxRule();
                        pbrule.RCheckDelete(dr["BoxNo"].ToString(), sqlTrans);//检测调用
                    }

                    sql  = "DELETE FROM WH_PackBox WHERE BoxNo IN(SELECT BoxNo FROM WH_IOFormDtsPack WHERE MainID=" + p_Entity.ID.ToString();
                    sql += " AND ID NOT IN" + string.Format("({0})", GetIDExist(list)) + ")";//删除码单明细数据
                    sqlTrans.ExecuteNonQuery(sql);

                    sql  = "DELETE FROM WH_IOFormDtsPack WHERE MainID=" + p_Entity.ID.ToString();
                    sql += " AND ID NOT IN" + string.Format("({0})", GetIDExist(list));
                    sqlTrans.ExecuteNonQuery(sql);//删除原单据里应该删除的明细数据,即数据库里有但是UI里已经删除的数据
                }
                for (int i = 0; i < list.Count; i++)
                {
                    IOFormDtsPack entitydts    = (IOFormDtsPack)list[i];
                    int           ioformdtsdex = -1;
                    for (int m = 0; m < p_EntityDts.Length; m++)
                    {
                        if (p_EntityDts[m].Seq == entitydts.Seq)//找到相同的SEQ了
                        {
                            ioformdtsdex = m;
                            break;
                        }
                    }
                    if (ioformdtsdex == -1)//未找到,异常
                    {
                        throw new Exception("码单输入异常,未找到单据明细,行号:" + entitydts.Seq);
                    }


                    if (entitydts.ID != 0)//ID不为0说明数据库中已经存在
                    {
                        PackBoxRule pbrule = new PackBoxRule();
                        pbrule.RCheckUpdate(entitydts.BoxNo, sqlTrans);//检测调用
                        this.RUpdate(p_EntityDts[ioformdtsdex], entitydts, sqlTrans);
                    }
                    else
                    {
                        entitydts.MainID = p_Entity.ID;
                        this.RAdd(p_Entity, p_EntityDts[ioformdtsdex], entitydts, sqlTrans);
                    }
                }
            }
            catch (BaseException)
            {
                throw;
            }
            catch (Exception E)
            {
                throw new BaseException(E.Message);
            }
        }
예제 #6
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="p_FormID">单据ID</param>
        /// <param name="p_Type">0/1/2/3:弃审/审核</param>
        public void RSubmit(int p_FormID, int p_Type, IDBTransAccess sqlTrans)
        {
            try
            {
                int       p_TempType = p_Type;//处理状态
                string    sql        = string.Empty;
                PackBoxKP entity     = new PackBoxKP(sqlTrans);
                entity.ID = p_FormID;
                entity.SelectByID();
                if (entity.SubmitFlag == p_Type)//如果相同异常
                {
                    throw new Exception("单据状态重复设置,请关闭程序重新打开操作");
                }


                //开匹数据提交

                PackBoxRule pbrule         = new PackBoxRule();
                PackBox     pbentitysource = pbrule.RGetEntityByBoxNo(entity.BoxNo, sqlTrans);
                if (pbentitysource.ID != 0)
                {
                    if (pbentitysource.BoxStatusID == (int)EnumBoxStatus.入库)
                    {
                        if (p_Type == (int)YesOrNo.Yes)//开匹操作
                        {
                            if ((pbentitysource.Qty <= entity.TargetQty && pbentitysource.Qty != 0 && entity.TargetQty != 0) || (pbentitysource.Weight <= entity.TargetWeight && pbentitysource.Weight != 0 && entity.TargetWeight != 0) || (pbentitysource.Yard <= entity.TargetYard && pbentitysource.Yard != 0 && entity.TargetYard != 0))
                            {
                                throw new Exception("操作错误,源条码数量或者码数或者公斤数小于等于开匹目标数量或者码数或者公斤数!");
                            }

                            entity.Qty    = pbentitysource.Qty;//赋值主表数量,防止调整过数量
                            entity.Weight = pbentitysource.Weight;
                            entity.Yard   = pbentitysource.Yard;
                            PackBox pbentity = new PackBox(sqlTrans);//目标箱号实体
                            pbentity.SelectByID();
                            CopyEntityData(pbentitysource, pbentity);
                            pbentity.SourceTypeID = (int)PackBoxSourceType.开匹;
                            pbentity.BoxStatusID  = (int)EnumBoxStatus.入库;
                            pbentity.Qty          = entity.TargetQty;
                            pbentity.Weight       = entity.TargetWeight;
                            pbentity.Yard         = entity.Yard;
                            pbentity.SourceBoxNo  = pbentitysource.BoxNo;
                            pbrule.RAdd(pbentity, sqlTrans);

                            pbentitysource.Qty    = pbentitysource.Qty - pbentity.Qty;//修改源箱号数量
                            pbentitysource.Weight = pbentitysource.Weight - pbentity.Weight;
                            pbentitysource.Yard   = pbentitysource.Yard - pbentity.Yard;
                            pbentitysource.KPFlag = (int)YesOrNo.Yes;//修改源箱号开匹标志
                            pbrule.RUpdate(pbentitysource, sqlTrans);
                            entity.TargetBoxNo = pbentity.BoxNo;

                            //插入开匹明细数据
                            PackBoxKPDtsRule dtsRule    = new PackBoxKPDtsRule();
                            PackBoxKPDts     entitydts1 = new PackBoxKPDts(sqlTrans);
                            entitydts1.MainID       = entity.ID;
                            entitydts1.Seq          = 1;
                            entitydts1.BoxNo        = entity.BoxNo;
                            entitydts1.ColorNO      = entity.ColorNO;
                            entitydts1.ColorName    = entity.ColorName;
                            entitydts1.SourceQty    = pbentitysource.Qty + pbentity.Qty;       //主数据更新时把数据删除了
                            entitydts1.SourceWeight = pbentitysource.Weight + pbentity.Weight; //主数据更新时把数据删除了
                            entitydts1.SourceYard   = pbentitysource.Yard + pbentity.Yard;     //主数据更新时把数据删除了
                            entitydts1.Qty          = pbentitysource.Qty;                      //主数据更新时把数据删除了
                            entitydts1.Weight       = pbentitysource.Weight;                   //主数据更新时把数据删除了
                            entitydts1.Yard         = pbentitysource.Yard;                     //主数据更新时把数据删除了
                            dtsRule.RAdd(entitydts1, sqlTrans);

                            PackBoxKPDts entitydts2 = new PackBoxKPDts(sqlTrans);
                            entitydts2.MainID    = entity.ID;
                            entitydts2.Seq       = 2;
                            entitydts2.BoxNo     = entity.TargetBoxNo;
                            entitydts2.ColorNO   = entity.ColorNO;
                            entitydts2.ColorName = entity.ColorName;
                            entitydts2.SourceQty = 0;
                            entitydts2.Qty       = entity.TargetQty;
                            entitydts2.Weight    = entity.TargetWeight;
                            entitydts2.Yard      = entity.TargetYard;
                            dtsRule.RAdd(entitydts2, sqlTrans);
                            #region 查找仓库结算类型
                            string    sqlCal       = "SELECT FieldName FROM UV1_WH_WH WHERE WHID=" + SysString.ToDBString(pbentity.WHID);//获得仓库结算类型字段
                            DataTable dt           = sqlTrans.Fill(sqlCal);
                            string    FieldNamestr = string.Empty;
                            if (dt.Rows.Count != 0)
                            {
                                FieldNamestr += SysConvert.ToString(dt.Rows[0]["FieldName"]);
                            }
                            sql  = "UPDATE WH_Storge SET PieceQty=PieceQty+1 WHERE 1=1";
                            sql += " AND WHID=" + SysString.ToDBString(pbentity.WHID);
                            sql += " AND SectionID=" + SysString.ToDBString(pbentity.SectionID);
                            sql += " AND SBitID=" + SysString.ToDBString(pbentity.SBitID);
                            int CalFieldName = (int)WHCalMethodFieldName.ItemCode;
                            if (FieldNamestr != string.Empty)
                            {
                                string[] FieldName = FieldNamestr.Split('+');
                                for (int i = 0; i < FieldName.Length; i++)
                                {
                                    string    sqlFieldName = "SELECT ID FROM Enum_WHCalMethodFieldName WHERE Name=" + SysString.ToDBString(FieldName[i]);//找到库存结算字段对应的ID
                                    DataTable dtFieldName  = sqlTrans.Fill(sqlFieldName);
                                    if (dtFieldName.Rows.Count != 0 && dtFieldName.Rows[0]["ID"].ToString() != "")
                                    {
                                        CalFieldName = SysConvert.ToInt32(dtFieldName.Rows[0]["ID"]);
                                    }
                                    switch (CalFieldName)
                                    {
                                    case (int)WHCalMethodFieldName.ItemCode:    //产品编码
                                        sql += " AND ISNULL(ItemCode,'')=" + SysString.ToDBString(pbentity.ItemCode);
                                        break;

                                    case (int)WHCalMethodFieldName.ColorNum:    //色号
                                        sql += " AND ISNULL(ColorNum,'')=" + SysString.ToDBString(pbentity.ColorNum);
                                        break;

                                    case (int)WHCalMethodFieldName.ColorName:    //颜色
                                        sql += " AND ISNULL(ColorName,'')=" + SysString.ToDBString(pbentity.ColorName);
                                        break;

                                    case (int)WHCalMethodFieldName.Batch:       //批号
                                        sql += " AND ISNULL(Batch,'')=" + SysString.ToDBString(pbentity.Batch);
                                        break;

                                    case (int)WHCalMethodFieldName.VendorBatch:      //客户批号
                                        sql += " AND ISNULL(VendorBatch,'')=" + SysString.ToDBString(pbentity.VendorBatch);
                                        break;

                                    case (int)WHCalMethodFieldName.JarNum:      //缸号
                                        sql += " AND ISNULL(JarNum,'')=" + SysString.ToDBString(pbentity.JarNum);
                                        break;

                                    case (int)WHCalMethodFieldName.MWidth:    //门幅
                                        sql += " AND ISNULL(MWidth,'')=" + SysString.ToDBString(pbentity.MWidth);
                                        break;

                                    case (int)WHCalMethodFieldName.MWeight:    //克重
                                        sql += " AND ISNULL(MWeight,'')=" + SysString.ToDBString(pbentity.MWeight);
                                        break;

                                    case (int)WHCalMethodFieldName.DtsOrderFormNo:    //克重
                                        sql += " AND ISNULL(OrderFormNo,0)=" + SysString.ToDBString(pbentity.OrderFormNo);
                                        break;

                                    default:
                                        throw new Exception("结算异常,结算定义的字段底层未对应:" + CalFieldName + ",请联系管理员");
                                    }
                                }
                            }
                            #endregion
                            sqlTrans.ExecuteNonQuery(sql);
                        }
                        else//撤销开匹操作
                        {
                            PackBox pbentity = pbrule.RGetEntityByBoxNo(entity.TargetBoxNo, sqlTrans);//目标箱号实体
                            if (pbentitysource.ID == 0)
                            {
                                throw new Exception("操作错误,未找到目标条码");
                            }
                            //开始检验是否允许撤销提交
                            if (pbentity.WHID == pbentitysource.WHID && pbentity.SectionID == pbentitysource.SectionID &&
                                pbentity.SBitID == pbentitysource.SBitID)
                            {
                            }
                            else//库区有改变
                            {
                                throw new Exception("操作错误,开匹后的条码的移库了,必须撤销删除移库单后再进行移库操作");
                            }
                            #region 判断开匹后的条码有没有再次被开匹
                            sql = "SELECT * FROM WH_PackBox WHERE SourceBoxNo =" + SysString.ToDBString(pbentity.BoxNo);
                            DataTable dtSource = sqlTrans.Fill(sql);
                            if (dtSource.Rows.Count > 0)
                            {
                                throw new Exception("操作错误,开匹后的条码又开过匹,必须撤销该条码的开匹后再进行撤销");
                            }
                            #endregion
                            #region 判断开匹后的条码的状态
                            sql = "SELECT BoxStatusID FROM WH_PackBox WHERE BoxNo=" + SysString.ToDBString(pbentity.BoxNo);
                            DataTable dtBoxStatus = sqlTrans.Fill(sql);
                            if (dtBoxStatus.Rows.Count != 0)
                            {
                                if (SysConvert.ToInt32(dtBoxStatus.Rows[0]["BoxStatusID"]) != (int)EnumBoxStatus.入库)
                                {
                                    throw new Exception("条码" + pbentity.BoxNo + "状态未处于入库状态,不能撤销");
                                }
                            }
                            #endregion
                            //结束检验是否允许撤销提交
                            //pbrule.RCheckDelete(entity.TargetBoxNo, sqlTrans);//校验是否允许删除
                            pbrule.RDelete(pbentity, sqlTrans);

                            pbentitysource.Qty    = pbentitysource.Qty + pbentity.Qty;//修改源箱号数量
                            pbentitysource.Weight = pbentitysource.Weight + pbentity.Weight;
                            pbentitysource.Yard   = pbentitysource.Yard + pbentity.Yard;
                            #region 判断该匹是否有其开匹
                            sql = "SELECT * FROM WH_PackBox WHERE SourceBoxNo =" + SysString.ToDBString(pbentitysource.BoxNo);
                            DataTable dtpbentitysource = sqlTrans.Fill(sql);
                            if (dtpbentitysource.Rows.Count == 0)
                            {
                                pbentitysource.KPFlag = (int)YesOrNo.No;//修改源箱号开匹标志
                            }
                            #endregion
                            pbrule.RUpdate(pbentitysource, sqlTrans);
                            entity.TargetBoxNo = "";                                       //目标箱号
                            sql = "DELETE FROM WH_PackBoxKPDts WHERE MainID=" + entity.ID; //删除开匹明细数据
                            sqlTrans.ExecuteNonQuery(sql);

                            #region 查找仓库结算类型
                            string    sqlCal       = "SELECT FieldName FROM UV1_WH_WH WHERE WHID=" + SysString.ToDBString(pbentity.WHID);//获得仓库结算类型字段
                            DataTable dt           = sqlTrans.Fill(sqlCal);
                            string    FieldNamestr = string.Empty;
                            if (dt.Rows.Count != 0)
                            {
                                FieldNamestr += SysConvert.ToString(dt.Rows[0]["FieldName"]);
                            }
                            sql  = "UPDATE WH_Storge SET PieceQty=PieceQty-1 WHERE 1=1";
                            sql += " AND WHID=" + SysString.ToDBString(pbentity.WHID);
                            sql += " AND SectionID=" + SysString.ToDBString(pbentity.SectionID);
                            sql += " AND SBitID=" + SysString.ToDBString(pbentity.SBitID);
                            int CalFieldName = (int)WHCalMethodFieldName.ItemCode;
                            if (FieldNamestr != string.Empty)
                            {
                                string[] FieldName = FieldNamestr.Split('+');
                                for (int i = 0; i < FieldName.Length; i++)
                                {
                                    string    sqlFieldName = "SELECT ID FROM Enum_WHCalMethodFieldName WHERE Name=" + SysString.ToDBString(FieldName[i]);//找到库存结算字段对应的ID
                                    DataTable dtFieldName  = sqlTrans.Fill(sqlFieldName);
                                    if (dtFieldName.Rows.Count != 0 && dtFieldName.Rows[0]["ID"].ToString() != "")
                                    {
                                        CalFieldName = SysConvert.ToInt32(dtFieldName.Rows[0]["ID"]);
                                    }
                                    switch (CalFieldName)
                                    {
                                    case (int)WHCalMethodFieldName.ItemCode:    //产品编码
                                        sql += " AND ISNULL(ItemCode,'')=" + SysString.ToDBString(pbentity.ItemCode);
                                        break;

                                    case (int)WHCalMethodFieldName.ColorNum:    //色号
                                        sql += " AND ISNULL(ColorNum,'')=" + SysString.ToDBString(pbentity.ColorNum);
                                        break;

                                    case (int)WHCalMethodFieldName.ColorName:    //颜色
                                        sql += " AND ISNULL(ColorName,'')=" + SysString.ToDBString(pbentity.ColorName);
                                        break;

                                    case (int)WHCalMethodFieldName.Batch:       //批号
                                        sql += " AND ISNULL(Batch,'')=" + SysString.ToDBString(pbentity.Batch);
                                        break;

                                    case (int)WHCalMethodFieldName.VendorBatch:      //客户批号
                                        sql += " AND ISNULL(VendorBatch,'')=" + SysString.ToDBString(pbentity.VendorBatch);
                                        break;

                                    case (int)WHCalMethodFieldName.JarNum:      //缸号
                                        sql += " AND ISNULL(JarNum,'')=" + SysString.ToDBString(pbentity.JarNum);
                                        break;

                                    case (int)WHCalMethodFieldName.MWidth:    //门幅
                                        sql += " AND ISNULL(MWidth,'')=" + SysString.ToDBString(pbentity.MWidth);
                                        break;

                                    case (int)WHCalMethodFieldName.MWeight:    //克重
                                        sql += " AND ISNULL(MWeight,'')=" + SysString.ToDBString(pbentity.MWeight);
                                        break;

                                    case (int)WHCalMethodFieldName.DtsOrderFormNo:    //克重
                                        sql += " AND ISNULL(OrderFormNo,0)=" + SysString.ToDBString(pbentity.OrderFormNo);
                                        break;

                                    default:
                                        throw new Exception("结算异常,结算定义的字段底层未对应:" + CalFieldName + ",请联系管理员");
                                    }
                                }
                            }
                            #endregion
                            sqlTrans.ExecuteNonQuery(sql);
                        }
                    }
                    else
                    {
                        throw new Exception("操作错误,源条码不处于入库状态");
                    }
                }
                else
                {
                    throw new Exception("操作错误,未找到源条码");
                }

                entity.SubmitFlag = p_Type;
                this.RUpdate(entity, sqlTrans);//更新主表状态
            }
            catch (BaseException)
            {
                throw;
            }
            catch (Exception E)
            {
                throw new BaseException(E.Message);
            }
        }