/// <summary>
 /// 增加一条数据
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(BArrangeBillBoxData model)
 {
     return this.arrangeBillBoxDB.AddRecord(model);
 }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 /// <param name="model">model</param>
 public bool ModifyRecord(BArrangeBillBoxData model)
 {
     return this.arrangeBillBoxDB.ModifyRecord(model);
 }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(BArrangeBillBoxData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into BArrangeBillBox(");
            strSql.Append(@"arriveBillNo,financeBillNo,arrangeBillNo,stockUpBillNo,boxNo,oldBoxNo,materialNo,oldMaterialNo,checkResult,checkResultDt,
                            checkResultEmpId,factNum,weight,weightResult,noPassReasonId,noPassMark,palletNo,region,oldPalletNo,oldRegion,
                            wareNo,wareLocatorNo,preWareNo,preWareLocatorNo,isBoxArrange,isPalletUsing,acceptEmpId,acceptDt,isrtEmpId,isrtDt,
                            updtEmpId,updtDt,outStockDt,outStockEmpId,inStockDt,inStockEmpId,mark,isOutStocking,financeBillId,financeBillLineNum,
                            isSapInStock,isSapOutStock)");
            strSql.Append(" values (");
            strSql.Append(@"@arriveBillNo,@financeBillNo,@arrangeBillNo,@stockUpBillNo,@boxNo,@oldBoxNo,@materialNo,@oldMaterialNo,@checkResult,@checkResultDt,
                            @checkResultEmpId,@factNum,@weight,@weightResult,@noPassReasonId,@noPassMark,@palletNo,@region,@oldPalletNo,@oldRegion,
                            @wareNo,@wareLocatorNo,@preWareNo,@preWareLocatorNo,@isBoxArrange,@isPalletUsing,@acceptEmpId,@acceptDt,@isrtEmpId,@isrtDt,
                            @updtEmpId,@updtDt,@outStockDt,@outStockEmpId,@inStockDt,@inStockEmpId,@mark,@isOutStocking,@financeBillId,@financeBillLineNum,
                            @isSapInStock,@isSapOutStock)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@arriveBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@financeBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@arrangeBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@stockUpBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@boxNo", SqlDbType.VarChar,20),
                    new SqlParameter("@oldBoxNo", SqlDbType.VarChar,20),
                    new SqlParameter("@materialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@oldMaterialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@checkResult", SqlDbType.Bit),
                    new SqlParameter("@checkResultDt", SqlDbType.DateTime),
                    new SqlParameter("@checkResultEmpId", SqlDbType.Int),
                    new SqlParameter("@factNum", SqlDbType.Float),
                    new SqlParameter("@weight", SqlDbType.Float),
                    new SqlParameter("@weightResult", SqlDbType.NVarChar,20),
                    new SqlParameter("@noPassReasonId", SqlDbType.Int),
                    new SqlParameter("@noPassMark", SqlDbType.NVarChar,500),
                    new SqlParameter("@palletNo", SqlDbType.VarChar,20),
                    new SqlParameter("@region", SqlDbType.VarChar,10),
                    new SqlParameter("@oldPalletNo", SqlDbType.VarChar,20),
                    new SqlParameter("@oldRegion", SqlDbType.VarChar,10),
                    new SqlParameter("@wareNo", SqlDbType.VarChar,20),
                    new SqlParameter("@wareLocatorNo", SqlDbType.VarChar,20),
                    new SqlParameter("@preWareNo", SqlDbType.VarChar,20),
                    new SqlParameter("@preWareLocatorNo", SqlDbType.VarChar,20),
                    new SqlParameter("@isBoxArrange", SqlDbType.Bit),
                    new SqlParameter("@isPalletUsing", SqlDbType.Bit),
                    new SqlParameter("@acceptEmpId", SqlDbType.Int),
                    new SqlParameter("@acceptDt", SqlDbType.DateTime),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int),
                    new SqlParameter("@updtDt", SqlDbType.DateTime),
                    new SqlParameter("@outStockDt", SqlDbType.DateTime),
                    new SqlParameter("@outStockEmpId", SqlDbType.Int),
                    new SqlParameter("@inStockDt", SqlDbType.DateTime),
                    new SqlParameter("@inStockEmpId", SqlDbType.Int),
                    new SqlParameter("@mark", SqlDbType.NVarChar,500),
                    new SqlParameter("@isOutStocking", SqlDbType.Bit),
                    new SqlParameter("@financeBillId", SqlDbType.VarChar,20),
                    new SqlParameter("@financeBillLineNum", SqlDbType.Int),
                    new SqlParameter("@isSapInStock", SqlDbType.Bit),
                    new SqlParameter("@isSapOutStock", SqlDbType.Bit)
                };
            parameters[0].Value = model.arriveBillNo;
            parameters[1].Value = model.financeBillNo;
            parameters[2].Value = model.arrangeBillNo;
            parameters[3].Value = model.stockUpBillNo;
            parameters[4].Value = model.boxNo;
            parameters[5].Value = model.oldBoxNo;
            parameters[6].Value = model.materialNo;
            parameters[7].Value = model.oldMaterialNo;
            parameters[8].Value = model.checkResult;
            parameters[9].Value = model.checkResultDt == string.Empty ? null : model.checkResultDt;
            parameters[10].Value = model.checkResultEmpId;
            parameters[11].Value = model.factNum;
            parameters[12].Value = model.weight;
            parameters[13].Value = model.weightResult;
            parameters[14].Value = model.noPassReasonId;
            parameters[15].Value = model.noPassMark;
            parameters[16].Value = model.palletNo;
            parameters[17].Value = model.region;
            parameters[18].Value = model.oldPalletNo;
            parameters[19].Value = model.oldRegion;
            parameters[20].Value = model.wareNo;
            parameters[21].Value = model.wareLocatorNo;
            parameters[22].Value = model.preWareNo;
            parameters[23].Value = model.preWareLocatorNo;
            parameters[24].Value = model.isBoxArrange;
            parameters[25].Value = model.isPalletUsing;
            parameters[26].Value = model.acceptEmpId;
            parameters[27].Value = model.acceptDt == string.Empty ? null : model.acceptDt;
            parameters[28].Value = model.isrtEmpId;
            parameters[29].Value = model.isrtDt == string.Empty ? null : model.isrtDt;
            parameters[30].Value = model.updtEmpId;
            parameters[31].Value = model.updtDt == string.Empty ? null : model.updtDt;
            parameters[32].Value = model.outStockDt == string.Empty ? null : model.outStockDt;
            parameters[33].Value = model.outStockEmpId;
            parameters[34].Value = model.inStockDt == string.Empty ? null : model.inStockDt;
            parameters[35].Value = model.inStockEmpId;
            parameters[36].Value = model.mark;
            parameters[37].Value = model.isOutStocking;
            parameters[38].Value = model.financeBillId;
            parameters[39].Value = model.financeBillLineNum;
            parameters[40].Value = model.isSapInStock;
            parameters[41].Value = model.isSapOutStock;

            int id = 0;
            try
            {
                object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

                if (ret != null && ret != DBNull.Value)
                {
                    id = Convert.ToInt32(ret);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return id;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(BArrangeBillBoxData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update BArrangeBillBox set ");
            strSql.Append("arriveBillNo=@arriveBillNo,");
            strSql.Append("financeBillNo=@financeBillNo,");
            strSql.Append("arrangeBillNo=@arrangeBillNo,");
            strSql.Append("stockUpBillNo=@stockUpBillNo,");
            strSql.Append("boxNo=@boxNo,");
            strSql.Append("oldBoxNo=@oldBoxNo,");
            strSql.Append("materialNo=@materialNo,");
            strSql.Append("oldMaterialNo=@oldMaterialNo,");
            strSql.Append("checkResult=@checkResult,");
            strSql.Append("checkResultDt=@checkResultDt,");
            strSql.Append("checkResultEmpId=@checkResultEmpId,");
            strSql.Append("factNum=@factNum,");
            strSql.Append("weight=@weight,");
            strSql.Append("weightResult=@weightResult,");
            strSql.Append("noPassReasonId=@noPassReasonId,");
            strSql.Append("noPassMark=@noPassMark,");
            strSql.Append("palletNo=@palletNo,");
            strSql.Append("region=@region,");
            strSql.Append("oldPalletNo=@oldPalletNo,");
            strSql.Append("oldRegion=@oldRegion,");
            strSql.Append("wareNo=@wareNo,");
            strSql.Append("wareLocatorNo=@wareLocatorNo,");
            strSql.Append("preWareNo=@preWareNo,");
            strSql.Append("preWareLocatorNo=@preWareLocatorNo,");
            strSql.Append("isBoxArrange=@isBoxArrange,");
            strSql.Append("isPalletUsing=@isPalletUsing,");
            strSql.Append("acceptEmpId=@acceptEmpId,");
            strSql.Append("acceptDt=@acceptDt,");
            strSql.Append("isrtEmpId=@isrtEmpId,");
            strSql.Append("isrtDt=@isrtDt,");
            strSql.Append("updtEmpId=@updtEmpId,");
            strSql.Append("updtDt=@updtDt,");
            strSql.Append("outStockDt=@outStockDt,");
            strSql.Append("outStockEmpId=@outStockEmpId,");
            strSql.Append("inStockDt=@inStockDt,");
            strSql.Append("inStockEmpId=@inStockEmpId,");
            strSql.Append("mark=@mark,");
            strSql.Append("isOutStocking=@isOutStocking,");
            strSql.Append("financeBillId=@financeBillId,");
            strSql.Append("financeBillLineNum=@financeBillLineNum,");
            strSql.Append("isSapInStock=@isSapInStock,");
            strSql.Append("isSapOutStock=@isSapOutStock");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int),
                    new SqlParameter("@arriveBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@financeBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@arrangeBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@stockUpBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@boxNo", SqlDbType.VarChar,20),
                    new SqlParameter("@oldBoxNo", SqlDbType.VarChar,20),
                    new SqlParameter("@materialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@oldMaterialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@checkResult", SqlDbType.Bit),
                    new SqlParameter("@checkResultDt", SqlDbType.DateTime),
                    new SqlParameter("@checkResultEmpId", SqlDbType.Int),
                    new SqlParameter("@factNum", SqlDbType.Float),
                    new SqlParameter("@weight", SqlDbType.Float),
                    new SqlParameter("@weightResult", SqlDbType.NVarChar,20),
                    new SqlParameter("@noPassReasonId", SqlDbType.Int),
                    new SqlParameter("@noPassMark", SqlDbType.NVarChar,500),
                    new SqlParameter("@palletNo", SqlDbType.VarChar,20),
                    new SqlParameter("@region", SqlDbType.VarChar,10),
                    new SqlParameter("@oldPalletNo", SqlDbType.VarChar,20),
                    new SqlParameter("@oldRegion", SqlDbType.VarChar,10),
                    new SqlParameter("@wareNo", SqlDbType.VarChar,20),
                    new SqlParameter("@wareLocatorNo", SqlDbType.VarChar,20),
                    new SqlParameter("@preWareNo", SqlDbType.VarChar,20),
                    new SqlParameter("@preWareLocatorNo", SqlDbType.VarChar,20),
                    new SqlParameter("@isBoxArrange", SqlDbType.Bit),
                    new SqlParameter("@isPalletUsing", SqlDbType.Bit),
                    new SqlParameter("@acceptEmpId", SqlDbType.Int),
                    new SqlParameter("@acceptDt", SqlDbType.DateTime),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int),
                    new SqlParameter("@updtDt", SqlDbType.DateTime),
                    new SqlParameter("@outStockDt", SqlDbType.DateTime),
                    new SqlParameter("@outStockEmpId", SqlDbType.Int),
                    new SqlParameter("@inStockDt", SqlDbType.DateTime),
                    new SqlParameter("@inStockEmpId", SqlDbType.Int),
                    new SqlParameter("@mark", SqlDbType.NVarChar,500),
                    new SqlParameter("@isOutStocking", SqlDbType.Bit),
                    new SqlParameter("@financeBillId", SqlDbType.VarChar,20),
                    new SqlParameter("@financeBillLineNum", SqlDbType.Int),
                    new SqlParameter("@isSapInStock", SqlDbType.Bit),
                    new SqlParameter("@isSapOutStock", SqlDbType.Bit)
                };
            parameters[0].Value = model.id;
            parameters[1].Value = model.arriveBillNo;
            parameters[2].Value = model.financeBillNo;
            parameters[3].Value = model.arrangeBillNo;
            parameters[4].Value = model.stockUpBillNo;
            parameters[5].Value = model.boxNo;
            parameters[6].Value = model.oldBoxNo;
            parameters[7].Value = model.materialNo;
            parameters[8].Value = model.oldMaterialNo;
            parameters[9].Value = model.checkResult;
            parameters[10].Value = model.checkResultDt == string.Empty ? null : model.checkResultDt;
            parameters[11].Value = model.checkResultEmpId;
            parameters[12].Value = model.factNum;
            parameters[13].Value = model.weight;
            parameters[14].Value = model.weightResult;
            parameters[15].Value = model.noPassReasonId;
            parameters[16].Value = model.noPassMark;
            parameters[17].Value = model.palletNo;
            parameters[18].Value = model.region;
            parameters[19].Value = model.oldPalletNo;
            parameters[20].Value = model.oldRegion;
            parameters[21].Value = model.wareNo;
            parameters[22].Value = model.wareLocatorNo;
            parameters[23].Value = model.preWareNo;
            parameters[24].Value = model.preWareLocatorNo;
            parameters[25].Value = model.isBoxArrange;
            parameters[26].Value = model.isPalletUsing;
            parameters[27].Value = model.acceptEmpId;
            parameters[28].Value = model.acceptDt == string.Empty ? null : model.acceptDt;
            parameters[29].Value = model.isrtEmpId;
            parameters[30].Value = model.isrtDt == string.Empty ? null : model.isrtDt;
            parameters[31].Value = model.updtEmpId;
            parameters[32].Value = model.updtDt == string.Empty ? null : model.updtDt;
            parameters[33].Value = model.outStockDt == string.Empty ? null : model.outStockDt;
            parameters[34].Value = model.outStockEmpId;
            parameters[35].Value = model.inStockDt == string.Empty ? null : model.inStockDt;
            parameters[36].Value = model.inStockEmpId;
            parameters[37].Value = model.mark;
            parameters[38].Value = model.isOutStocking;
            parameters[39].Value = model.financeBillId;
            parameters[40].Value = model.financeBillLineNum;
            parameters[41].Value = model.isSapInStock;
            parameters[42].Value = model.isSapOutStock;

            try
            {
                SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// 保存扫描箱体信息
        /// </summary>
        /// <param name="strArriveBillNo">到货单号</param>
        /// <param name="strFinanceBillNo">采购订单号</param>
        /// <param name="strPalletIndex">托盘序号</param>
        /// <param name="strRegion">托内区域</param>
        /// <param name="strBoxNo">箱号</param>
        /// <param name="strMaterialNo">物料号</param>
        /// <returns></returns>
        public bool SaveRecord(string strArriveBillNo, string strFinanceBillNo, string strPalletIndex, 
            string strRegion, string strBoxNo, string strMaterialNo)
        {
            bool ret = false;
            SqlTransaction trans = null;
            LWareLocatorBB wareLocatorBB = new LWareLocatorBB();
            BArrangeBillFactBB arrangeBillFactBB = new BArrangeBillFactBB();
            BArrangeBillBoxBB arrangeBillBoxBB = new BArrangeBillBoxBB(this.connection);
            SCommBB commBB = new SCommBB(this.connection);

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransSave");
                    this.arrangeBillFactDetailBB.Transaction = trans;
                    arrangeBillBoxBB.Transaction = trans;
                    commBB.Transaction = trans;
                }
                else
                {
                    this.arrangeBillFactDetailBB.Transaction = this.transaction;
                    arrangeBillBoxBB.Transaction = this.transaction;
                    commBB.Transaction = this.transaction;
                }

                BArrangeBillFactDetailData arrangeBillFactDetailModel = new BArrangeBillFactDetailData();
                BArrangeBillBoxData arrangeBillBoxModel = new BArrangeBillBoxData();
                DataSet ds = new DataSet();
                DataTable dtWareLocator = new DataTable();
                string mainId = "0", strPalletNo = "";
                StringBuilder strSql = new StringBuilder();

                //获取排托实际信息
                ds = arrangeBillFactBB.GetList("arriveBillNo='" + strArriveBillNo + "' and financeBillNo='"
                    + strFinanceBillNo + "' and palletIndex='" + strPalletIndex + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    mainId = ds.Tables[0].Rows[0]["id"].ToString();
                    strPalletNo = ds.Tables[0].Rows[0]["palletNo"].ToString();
                }

                //获取排托区下线库位信息
                strSql.Append(@"select wareLocator.wareNo,wareLocator.downWareLocatorNo as wareLocatorNo ");
                strSql.Append(@"from dbo.BArrangeBillBox as arriveBox ");
                strSql.Append(@"left join dbo.LWareLocator as wareLocator on wareLocator.wareLocatorNo=arriveBox.wareLocatorNo ");
                strSql.Append(@"where arriveBox.boxNo='" + strBoxNo + "'");

                dtWareLocator = commBB.Query(strSql.ToString()).Tables[0];

                //保存排托收货单明细信息
                arrangeBillFactDetailModel.mainId = mainId;//排托收货单ID
                arrangeBillFactDetailModel.boxNo = strBoxNo;//箱号
                arrangeBillFactDetailModel.region = strRegion;//区域
                arrangeBillFactDetailModel.isrtEmpId = this.empId;
                arrangeBillFactDetailModel.isrtDt = System.DateTime.Now.ToString();

                arrangeBillFactDetailBB.AddRecord(arrangeBillFactDetailModel);

                //更改扫描箱信息
                commBB.ExecuteSql("update dbo.BArrangeBillBox set arrangeBillNo='" + "PT" + strArriveBillNo
                    + "',preWareNo=wareNo,preWareLocatorNo=wareLocatorNo,oldPalletNo=palletNo,oldRegion=region,palletNo='" + strPalletNo
                    + "',region='" + strRegion + "',wareNo='" + dtWareLocator.Rows[0]["wareNo"].ToString()
                    + "',wareLocatorNo='" + dtWareLocator.Rows[0]["wareLocatorNo"].ToString()
                    + "',isrtEmpId='" + this.empId.ToString()
                    + "',isrtDt='" + System.DateTime.Now.ToString()
                    + "',isBoxArrange=1 where boxNo='" + strBoxNo + "'");

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch (Exception ex)
            {
                if (this.transaction == null) trans.Rollback("TransSave");
                throw ex;
            }
            finally
            {
                wareLocatorBB.Dispose();
                arrangeBillFactBB.Dispose();
                arrangeBillBoxBB.Dispose();
                commBB.Dispose();
            }

            return ret;
        }
        /// <summary>
        /// 得到一个model
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns>model</returns>
        public BArrangeBillBoxData GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select id,arriveBillNo,financeBillNo,arrangeBillNo,stockUpBillNo,boxNo,oldBoxNo,materialNo,oldMaterialNo,checkResult,checkResultDt,
                            checkResultEmpId,factNum,weight,weightResult,noPassReasonId,noPassMark,palletNo,region,oldPalletNo,oldRegion,
                            wareNo,wareLocatorNo,preWareNo,preWareLocatorNo,isBoxArrange,isPalletUsing,acceptEmpId,acceptDt,isrtEmpId,isrtDt,
                            updtEmpId,updtDt,outStockDt,outStockEmpId,inStockDt,inStockEmpId,mark,isOutStocking,financeBillId,financeBillLineNum,
                            isSapInStock,isSapOutStock from BArrangeBillBox");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int)
                };
            parameters[0].Value = id;

            BArrangeBillBoxData model = new BArrangeBillBoxData();
            DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow row = ds.Tables[0].Rows[0];
                if (row["id"] != DBNull.Value)
                {
                    model.id = Convert.ToInt32(row["id"]);
                }
                if (row["arriveBillNo"] != DBNull.Value)
                {
                    model.arriveBillNo = Convert.ToString(row["arriveBillNo"]);
                }
                if (row["financeBillNo"] != DBNull.Value)
                {
                    model.financeBillNo = Convert.ToString(row["financeBillNo"]);
                }
                if (row["arrangeBillNo"] != DBNull.Value)
                {
                    model.arrangeBillNo = Convert.ToString(row["arrangeBillNo"]);
                }
                if (row["stockUpBillNo"] != DBNull.Value)
                {
                    model.stockUpBillNo = Convert.ToString(row["stockUpBillNo"]);
                }
                if (row["boxNo"] != DBNull.Value)
                {
                    model.boxNo = Convert.ToString(row["boxNo"]);
                }
                if (row["oldBoxNo"] != DBNull.Value)
                {
                    model.oldBoxNo = Convert.ToString(row["oldBoxNo"]);
                }
                if (row["materialNo"] != DBNull.Value)
                {
                    model.materialNo = Convert.ToString(row["materialNo"]);
                }
                if (row["oldMaterialNo"] != DBNull.Value)
                {
                    model.oldMaterialNo = Convert.ToString(row["oldMaterialNo"]);
                }
                if (row["checkResult"] != DBNull.Value)
                {
                    model.checkResult = Convert.ToBoolean(row["checkResult"]);
                }
                if (row["checkResultDt"] != DBNull.Value)
                {
                    model.checkResultDt = Convert.ToString(row["checkResultDt"]);
                }
                if (row["checkResultEmpId"] != DBNull.Value)
                {
                    model.checkResultEmpId = Convert.ToInt32(row["checkResultEmpId"]);
                }
                if (row["factNum"] != DBNull.Value)
                {
                    model.factNum = Convert.ToDouble(row["factNum"]);
                }
                if (row["weight"] != DBNull.Value)
                {
                    model.weight = Convert.ToDouble(row["weight"]);
                }
                if (row["weightResult"] != DBNull.Value)
                {
                    model.weightResult = Convert.ToString(row["weightResult"]);
                }
                if (row["noPassReasonId"] != DBNull.Value)
                {
                    model.noPassReasonId = Convert.ToInt32(row["noPassReasonId"]);
                }
                if (row["noPassMark"] != DBNull.Value)
                {
                    model.noPassMark = Convert.ToString(row["noPassMark"]);
                }
                if (row["palletNo"] != DBNull.Value)
                {
                    model.palletNo = Convert.ToString(row["palletNo"]);
                }
                if (row["region"] != DBNull.Value)
                {
                    model.region = Convert.ToString(row["region"]);
                }
                if (row["oldPalletNo"] != DBNull.Value)
                {
                    model.oldPalletNo = Convert.ToString(row["oldPalletNo"]);
                }
                if (row["oldRegion"] != DBNull.Value)
                {
                    model.oldRegion = Convert.ToString(row["oldRegion"]);
                }
                if (row["wareNo"] != DBNull.Value)
                {
                    model.wareNo = Convert.ToString(row["wareNo"]);
                }
                if (row["wareLocatorNo"] != DBNull.Value)
                {
                    model.wareLocatorNo = Convert.ToString(row["wareLocatorNo"]);
                }
                if (row["preWareNo"] != DBNull.Value)
                {
                    model.preWareNo = Convert.ToString(row["preWareNo"]);
                }
                if (row["preWareLocatorNo"] != DBNull.Value)
                {
                    model.preWareLocatorNo = Convert.ToString(row["preWareLocatorNo"]);
                }
                if (row["isBoxArrange"] != DBNull.Value)
                {
                    model.isBoxArrange = Convert.ToBoolean(row["isBoxArrange"]);
                }
                if (row["isPalletUsing"] != DBNull.Value)
                {
                    model.isPalletUsing = Convert.ToBoolean(row["isPalletUsing"]);
                }
                if (row["acceptEmpId"] != DBNull.Value)
                {
                    model.acceptEmpId = Convert.ToInt32(row["acceptEmpId"]);
                }
                if (row["acceptDt"] != DBNull.Value)
                {
                    model.acceptDt = Convert.ToString(row["acceptDt"]);
                }
                if (row["isrtEmpId"] != DBNull.Value)
                {
                    model.isrtEmpId = Convert.ToInt32(row["isrtEmpId"]);
                }
                if (row["isrtDt"] != DBNull.Value)
                {
                    model.isrtDt = Convert.ToString(row["isrtDt"]);
                }
                if (row["updtEmpId"] != DBNull.Value)
                {
                    model.updtEmpId = Convert.ToInt32(row["updtEmpId"]);
                }
                if (row["updtDt"] != DBNull.Value)
                {
                    model.updtDt = Convert.ToString(row["updtDt"]);
                }
                if (row["outStockDt"] != DBNull.Value)
                {
                    model.outStockDt = Convert.ToString(row["outStockDt"]);
                }
                if (row["outStockEmpId"] != DBNull.Value)
                {
                    model.outStockEmpId = Convert.ToInt32(row["outStockEmpId"]);
                }
                if (row["inStockDt"] != DBNull.Value)
                {
                    model.inStockDt = Convert.ToString(row["inStockDt"]);
                }
                if (row["inStockEmpId"] != DBNull.Value)
                {
                    model.inStockEmpId = Convert.ToInt32(row["inStockEmpId"]);
                }
                if (row["mark"] != DBNull.Value)
                {
                    model.mark = Convert.ToString(row["mark"]);
                }
                if (row["isOutStocking"] != DBNull.Value)
                {
                    model.isOutStocking = Convert.ToBoolean(row["isOutStocking"]);
                }
                if (row["financeBillId"] != DBNull.Value)
                {
                    model.financeBillId = Convert.ToString(row["financeBillId"]);
                }
                if (row["financeBillLineNum"] != DBNull.Value)
                {
                    model.financeBillLineNum = Convert.ToInt32(row["financeBillLineNum"]);
                }
                if (row["isSapInStock"] != DBNull.Value)
                {
                    model.isSapInStock = Convert.ToBoolean(row["isSapInStock"]);
                }
                if (row["isSapOutStock"] != DBNull.Value)
                {
                    model.isSapOutStock = Convert.ToBoolean(row["isSapOutStock"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 增加一条"排托单箱体"信息
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(BArrangeBillBoxData model)
        {
            int id = 0;
            SqlTransaction trans = null;
            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransAdd");
                    this.arrangeBillBoxBB.Transaction = trans;
                    this.errorDiaryBB.Transaction = trans;
                    this.operatDiaryBB.Transaction = trans;
                }

                id = this.arrangeBillBoxBB.AddRecord(model);

                SOperatDiaryData operatDiaryData = new SOperatDiaryData();
                operatDiaryData.empId = this.empId;
                operatDiaryData.functionId = "";
                operatDiaryData.recordId = id.ToString();
                operatDiaryData.operateContent = "排托单箱体增加一条id为“" + id.ToString() + "”的记录";
                this.operatDiaryBB.AddRecord(operatDiaryData);

                if (this.transaction == null) trans.Commit();
            }
            catch (Exception ex)
            {
                if (this.transaction == null) trans.Rollback("TransAdd");
                SErrorDiaryData errorDiaryData = new SErrorDiaryData();
                errorDiaryData.empId = this.empId;
                errorDiaryData.functionId = "";
                errorDiaryData.errorText = "排托单箱体增加记录时报错:" + ex.Message;
                this.errorDiaryBB.AddRecord(errorDiaryData);
                throw ex;
            }
            finally
            {
            }
            return id;
        }
        /// <summary>
        /// 更新一条"排托单箱体"信息
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(BArrangeBillBoxData model)
        {
            bool ret = false;
            SqlTransaction trans = null;
            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransModify");
                    this.arrangeBillBoxBB.Transaction = trans;
                    this.errorDiaryBB.Transaction = trans;
                    this.operatDiaryBB.Transaction = trans;
                }

                this.arrangeBillBoxBB.ModifyRecord(model);

                SOperatDiaryData operatDiaryData = new SOperatDiaryData();
                operatDiaryData.empId = this.empId;
                operatDiaryData.functionId = "";
                operatDiaryData.recordId = model.id.ToString();
                operatDiaryData.operateContent = "排托单箱体修改一条id为“" + model.id.ToString() + "”的记录";
                this.operatDiaryBB.AddRecord(operatDiaryData);

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch (Exception ex)
            {
                if (this.transaction == null) trans.Rollback("TransModify");
                SErrorDiaryData errorDiaryData = new SErrorDiaryData();
                errorDiaryData.empId = this.empId;
                errorDiaryData.functionId = "";
                errorDiaryData.errorText = "排托单箱体修改记录“" + model.id.ToString() + "”时报错:" + ex.Message;
                this.errorDiaryBB.AddRecord(errorDiaryData);
                throw ex;
            }
            finally
            {
            }
            return ret;
        }
Example #9
0
    public void SaveTSArriveBox(int arriveDetailId, string strArriveBillNo, string strFinanceBillNo, string strMaterialNo,
        string strBoxNo, string strPalletNo, int factNum, int isrtEmpId, string strWareLocatorNo)
    {
        TSBarriveDetailBB arriveDetailBB = new TSBarriveDetailBB();
        BArrangeBillBoxBB arrangeBillBoxBB = new BArrangeBillBoxBB();
        SCommBB commBB = new SCommBB();

        try
        {
            TSBarriveDetailData arriveDetailModel = new TSBarriveDetailData();
            BArrangeBillBoxData arrangeBillBoxModel = new BArrangeBillBoxData();
            DataTable dtWareLocator = new DataTable();

            //获取某库位信息
            dtWareLocator = this.GetWareLocatorInfo(strWareLocatorNo);

            //获取到货单明细实例
            arriveDetailModel = arriveDetailBB.GetModel(arriveDetailId);

            arrangeBillBoxModel.arriveBillNo = strArriveBillNo;//到货单号
            arrangeBillBoxModel.financeBillNo = strFinanceBillNo;//采购单号
            //arrangeBillBoxModel.financeBillId = arriveDetailModel.financeBillId;//采购订单ID
            //arrangeBillBoxModel.financeBillLineNum = arriveDetailModel.financeBillLineNum;//采购订单行号
            arrangeBillBoxModel.materialNo = strMaterialNo;//物料号
            arrangeBillBoxModel.boxNo = strBoxNo;//箱号
            arrangeBillBoxModel.palletNo = strPalletNo;//托盘号
            arrangeBillBoxModel.wareNo = dtWareLocator.Rows[0]["wareNo"].ToString();//库区
            arrangeBillBoxModel.wareLocatorNo = strWareLocatorNo;//库位
            arrangeBillBoxModel.isBoxArrange = false;//箱子是否已经排托
            arrangeBillBoxModel.isPalletUsing = false;//托盘是否占用
            arrangeBillBoxModel.acceptEmpId = isrtEmpId;//收货人
            arrangeBillBoxModel.acceptDt = System.DateTime.Now.ToString();//收货时间
            arrangeBillBoxModel.factNum = factNum;//收货数量

            arrangeBillBoxBB.AddRecord(arrangeBillBoxModel);

            //锁定库位
            commBB.ExecuteSql("update dbo.LWareLocator set isUsing=1 where wareLocatorNo='" + strWareLocatorNo + "'");
        }
        finally
        {
            arriveDetailBB.Dispose();
            arrangeBillBoxBB.Dispose();
            commBB.Dispose();
        }
    }
Example #10
0
        /// <summary>
        /// 其他出入库 保存 
        /// 解决因为使用CpickoutPlan导致的保存不了DocEntry 从而导致拣货完成后 没有保存的时候 看到的数据有问题。
        /// </summary>
        /// <param name="pickOutPlanID"></param>
        /// <param name="strStockUpBillNo"></param>
        /// <param name="palletIndex"></param>
        /// <param name="strNewPalletNo"></param>
        /// <param name="strOldBoxNo"></param>
        /// <param name="strNewBoxNo"></param>
        /// <param name="pickOutNum"></param>
        /// <param name="strOperType"></param>
        /// <returns></returns>
        public bool SaveOtherPickOutInfo_DE(int pickOutPlanID, string strStockUpBillNo, int palletIndex, string strNewPalletNo,
           string strOldBoxNo, string strNewBoxNo, int pickOutNum, string strOperType)
        {
            bool ret = false;
            SqlTransaction trans = null;
            SCommBB commBB = new SCommBB(this.connection);
            BArrangeBillBoxBB arrangeBillBoxBB = new BArrangeBillBoxBB(this.connection);
            CDEPickOutBoxBB DEPickOutBoxBB = new CDEPickOutBoxBB(this.connection);
            LMaterialBB materialBB = new LMaterialBB();
            LWareBB wareBB = new LWareBB();
            UStockOutInDetailBB stockOutInDetailBB = new UStockOutInDetailBB(this.connection);
            OtherOutInPickOutPlanBB pickOutPlanBB = new OtherOutInPickOutPlanBB();

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TranSave");
                    this.stockBB.Transaction = trans;
                    commBB.Transaction = trans;
                    arrangeBillBoxBB.Transaction = trans;
                    DEPickOutBoxBB.Transaction = trans;
                    stockOutInDetailBB.Transaction = trans;
                }
                else
                {
                    this.stockBB.Transaction = this.transaction;
                    commBB.Transaction = this.transaction;
                    arrangeBillBoxBB.Transaction = this.transaction;
                    DEPickOutBoxBB.Transaction = this.transaction;
                    stockOutInDetailBB.Transaction = this.transaction;
                }

                DataTable dtArrangeBillBox = new DataTable();
                DataTable dtPallet = new DataTable();
                DataTable dtMaterial = new DataTable();
                DataTable dtStock = new DataTable();
                CDEPickOutBoxData DEPickOutBoxModel = new CDEPickOutBoxData();
                UStockOutInDetailData stockOutInDetailModel = new UStockOutInDetailData();
                UStockData stockModel = new UStockData();
                OtherOutInPickOutPlanData pickOutPlanModel = new OtherOutInPickOutPlanData();
                string strSql = "", strPreWareLocatorNo = "";
                int stockNum = 0;
                object obj = null;

                //获取箱信息
                dtArrangeBillBox = arrangeBillBoxBB.GetVList("boxNo='" + strOldBoxNo + "'").Tables[0];
                if (dtArrangeBillBox.Rows.Count == 0)
                {
                    return false;
                }

                //获取当前托盘上的库存明细
                obj = commBB.ExecuteScalar("select count(1) from dbo.UStock where palletNo='" + strNewPalletNo + "' and num>0");
                if (obj != null)
                {
                    stockNum = Convert.ToInt32(obj);
                }

                //扫描箱所在库位
                strPreWareLocatorNo = dtArrangeBillBox.Rows[0]["wareLocatorNo"].ToString();

                //获取托盘上的正式物料箱
                dtPallet = arrangeBillBoxBB.GetVList("palletNo='" + strNewPalletNo + "' and isnull(wareNo,'')<>''").Tables[0];

                //获取箱内物料信息
                dtMaterial = materialBB.GetList("materialNo='" + dtArrangeBillBox.Rows[0]["materialNo"].ToString() + "'").Tables[0];

                //获取拣货计划实例
                pickOutPlanModel = pickOutPlanBB.GetModel(pickOutPlanID);

                //增加出入库明细-原箱出库
                dtStock = stockBB.GetList("boxNo='" + strOldBoxNo + "'").Tables[0];
                if (dtStock.Rows.Count > 0)//原箱有库存
                {
                    //保存出入库明细数据-出库
                    stockOutInDetailModel = new UStockOutInDetailData();

                    stockOutInDetailModel.billNo = strStockUpBillNo;//单据编号
                    stockOutInDetailModel.outInType = "08";//拆托合托
                    stockOutInDetailModel.isOut = true;//是否出库
                    stockOutInDetailModel.stockDt = System.DateTime.Today.ToString();//库存日期
                    stockOutInDetailModel.dt = System.DateTime.Today.ToString();//操作日期
                    stockOutInDetailModel.wareNo = dtArrangeBillBox.Rows[0]["wareNo"].ToString();//仓库
                    stockOutInDetailModel.wareLocatorNo = dtArrangeBillBox.Rows[0]["wareLocatorNo"].ToString();//库位
                    stockOutInDetailModel.salverNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//托盘号
                    stockOutInDetailModel.boxNo = strOldBoxNo;//箱号
                    stockOutInDetailModel.materialNo = dtArrangeBillBox.Rows[0]["materialNo"].ToString();//物料编号
                    stockOutInDetailModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                    stockOutInDetailModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                    stockOutInDetailModel.num = pickOutNum;//数量
                    stockOutInDetailModel.nextBoxNo = strNewBoxNo;//拆箱目的箱号
                    stockOutInDetailModel.isrtEmpId = this.empId;
                    stockOutInDetailModel.isrtDt = System.DateTime.Now.ToString();

                    stockOutInDetailBB.AddRecord(stockOutInDetailModel);
                }

                //更改正式库存信息
                commBB.ExecuteSql("update dbo.UStock set num=num-" + pickOutNum.ToString() + " where boxNo='" + strOldBoxNo + "'");

                #region 拣货信息赋值

                DEPickOutBoxModel = new CDEPickOutBoxData();

                DEPickOutBoxModel.boxNo = strNewBoxNo;//新箱号
                DEPickOutBoxModel.oldBoxNo = strOldBoxNo;//原箱号
                DEPickOutBoxModel.materialNo = dtArrangeBillBox.Rows[0]["materialNo"].ToString();//物料编号
                DEPickOutBoxModel.num = pickOutNum;//拣货数量
                DEPickOutBoxModel.palletNo = strNewPalletNo;//新托盘号
                DEPickOutBoxModel.region = "";//新区域
                DEPickOutBoxModel.oldPalletNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//原托盘号
                DEPickOutBoxModel.oldRegion = dtArrangeBillBox.Rows[0]["region"].ToString();//原区域
                DEPickOutBoxModel.preWareNo = dtArrangeBillBox.Rows[0]["wareNo"].ToString();//原库区
                DEPickOutBoxModel.preWareLocatorNo = dtArrangeBillBox.Rows[0]["wareLocatorNo"].ToString(); //原库位
                DEPickOutBoxModel.stockUpBillNo = strStockUpBillNo;//备货单编号
                DEPickOutBoxModel.palletIndex = palletIndex;//托盘序号

                if (pickOutPlanModel != null)
                {
                    DEPickOutBoxModel.absEntry = 0;//此处暂时将提货单ID设为0
                    DEPickOutBoxModel.saleBillNo = pickOutPlanModel.saleBillNo;
                    DEPickOutBoxModel.lineNum = pickOutPlanModel.lineNum;
                    DEPickOutBoxModel.DocEntry = pickOutPlanModel.DocEntry;
                }

                DEPickOutBoxModel.isrtEmpId = this.EmpID;//添加人
                DEPickOutBoxModel.isrtDt = System.DateTime.Now.ToString();//添加时间

                #endregion 拣货信息赋值

                //添加库存明细--高位货架上的托盘
                if ((dtPallet.Rows.Count > 0 && dtPallet.Rows[0]["wareType"].ToString() == "03"
                    && strOperType == "02" && dtPallet.Rows[0]["wareLocatorNo"].ToString() != ""
                    && dtPallet.Rows[0]["wareSortNo"].ToString() != "D"
                    && dtPallet.Rows[0]["wareSortNo"].ToString() != "E")
                    || (stockNum > 0 && DEPickOutBoxModel.oldPalletNo != ""))
                {
                    #region 放置托盘在正式库区

                    #region 保存拣货信息

                    DEPickOutBoxModel.wareNo = dtPallet.Rows[0]["wareNo"].ToString();//新库区
                    DEPickOutBoxModel.wareLocatorNo = dtPallet.Rows[0]["wareLocatorNo"].ToString();//新库位
                    DEPickOutBoxModel.isOutStock = true;//是否出库
                    DEPickOutBoxModel.updtDt = System.DateTime.Now.ToString();//更改时间
                    DEPickOutBoxModel.updtEmpId = this.EmpID;//更改人员

                    #endregion 保存拣货信息

                    #region 保存库存明细数据

                    dtStock = stockBB.GetList("boxNo='" + strNewBoxNo + "' and num>0").Tables[0];
                    if (dtStock.Rows.Count == 0)//没有库存
                    {
                        //增加库存明细
                        stockModel = new UStockData();

                        stockModel.wareNo = dtPallet.Rows[0]["wareNo"].ToString();//仓库
                        stockModel.wareLocatorNo = dtPallet.Rows[0]["wareLocatorNo"].ToString();//库位
                        stockModel.stockDt = System.DateTime.Today.ToString();//库存日期
                        stockModel.palletNo = strNewPalletNo;//托盘号
                        stockModel.materialNo = dtArrangeBillBox.Rows[0]["materialNo"].ToString();//物料编号
                        stockModel.boxNo = strNewBoxNo;//箱号
                        stockModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                        stockModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                        stockModel.num = pickOutNum;//数量
                        stockModel.isOutStocking = false;//是否正在出库
                        stockModel.stockMark = "拆托合托";

                        stockBB.AddRecord(stockModel);
                    }
                    else//已有库存
                    {
                        strSql = "update dbo.UStock set num=num+" + pickOutNum.ToString() + " where boxNo='" + strNewBoxNo + "'";
                        commBB.ExecuteSql(strSql);
                    }

                    //增加出入库明细-新箱入库
                    stockOutInDetailModel = new UStockOutInDetailData();

                    stockOutInDetailModel.billNo = strStockUpBillNo;//单据编号
                    stockOutInDetailModel.outInType = "08";//拆托合托
                    stockOutInDetailModel.isOut = false;//是否出库
                    stockOutInDetailModel.stockDt = System.DateTime.Today.ToString();//库存日期
                    stockOutInDetailModel.dt = System.DateTime.Today.ToString();//操作日期
                    stockOutInDetailModel.wareNo = dtPallet.Rows[0]["wareNo"].ToString();//仓库
                    stockOutInDetailModel.wareLocatorNo = dtPallet.Rows[0]["wareLocatorNo"].ToString();//库位
                    stockOutInDetailModel.salverNo = strNewPalletNo;//托盘号
                    stockOutInDetailModel.boxNo = strNewBoxNo;//箱号
                    stockOutInDetailModel.materialNo = dtArrangeBillBox.Rows[0]["materialNo"].ToString();//物料编号
                    stockOutInDetailModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                    stockOutInDetailModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                    stockOutInDetailModel.num = pickOutNum;//数量
                    stockOutInDetailModel.nextBoxNo = "";//拆箱目的箱号
                    stockOutInDetailModel.isrtEmpId = this.empId;
                    stockOutInDetailModel.isrtDt = System.DateTime.Now.ToString();

                    stockOutInDetailBB.AddRecord(stockOutInDetailModel);

                    #endregion 保存库存明细数据

                    //更改排托箱入库信息
                    commBB.ExecuteSql("update dbo.BArrangeBillBox set inStockDt=getDate(),inStockEmpId="
                        + this.EmpID.ToString() + ",inStockNum='" + stockOutInDetailModel.num.ToString()
                        + "',isOutStocking=0 where boxNo='" + stockOutInDetailModel.boxNo
                        + "' and isnull(wareNo,'')<>'' and inStockDt is null");

                    #endregion 放置托盘在正式库区
                }
                else
                {
                    #region 保存流利货架拣货或非正式库拆托组托信息或拆到空托盘

                    if (DEPickOutBoxModel.oldPalletNo != "")//非正式库拆托组托或拆到空托盘
                    {
                        if (dtPallet.Rows.Count > 0
                            && dtPallet.Rows[0]["wareNo"].ToString().IndexOf("GLHJ") == -1
                            && dtPallet.Rows[0]["wareLocatorNo"].ToString() != "")//新托盘上已有物料箱,将物料放到原有托盘
                        {
                            DEPickOutBoxModel.wareNo = dtPallet.Rows[0]["wareNo"].ToString();//新库区
                            DEPickOutBoxModel.wareLocatorNo = dtPallet.Rows[0]["wareLocatorNo"].ToString();//新库位
                        }
                        else
                        {
                            DEPickOutBoxModel.wareNo = dtArrangeBillBox.Rows[0]["wareNo"].ToString();//新库区
                            DEPickOutBoxModel.wareLocatorNo = "";//放到空托盘
                        }

                        //是否出库
                        if (DEPickOutBoxModel.wareLocatorNo != "")//非正式库拆托组托
                        {
                            DEPickOutBoxModel.isOutStock = true;//是否出库
                            DEPickOutBoxModel.updtDt = System.DateTime.Now.ToString();//更改时间
                            DEPickOutBoxModel.updtEmpId = this.EmpID;//更改人员
                        }
                        else
                        {
                            //拆到空托盘
                            DEPickOutBoxModel.isOutStock = false;
                        }
                    }
                    else//流利货架拣货
                    {
                        DEPickOutBoxModel.wareNo = dtArrangeBillBox.Rows[0]["wareNo"].ToString();//新库区
                        DEPickOutBoxModel.wareLocatorNo = dtArrangeBillBox.Rows[0]["wareLocatorNo"].ToString();//新库位
                        DEPickOutBoxModel.isOutStock = false;//是否出库
                    }

                    #endregion 保存流利货架拣货或非正式库拆托组托信息或拆到空托盘
                }

                //保存拣货信息
                DEPickOutBoxBB.AddRecord(DEPickOutBoxModel);

                //拣货处理逻辑更改为:根据实际需要数量进行拣货
                //处理情况分为:整箱拣货、拆箱拣货
                if (strNewBoxNo == strOldBoxNo)//整箱拣货
                {
                    if (DEPickOutBoxModel.oldPalletNo != ""
                        || dtArrangeBillBox.Rows[0]["wareNo"] == DBNull.Value
                        || dtArrangeBillBox.Rows[0]["wareNo"].ToString() == "")//非流利货架或已出库箱重新入库
                    {
                        //物料箱库位赋值
                        commBB.ExecuteSql("update dbo.BArrangeBillBox set oldPalletNo=palletNo,palletNo='"
                                + strNewPalletNo + "',region=oldRegion,oldRegion='',preWareNo=wareNo,preWareLocatorNo=wareLocatorNo,wareNo='"
                                + DEPickOutBoxModel.wareNo + "',wareLocatorNo='" + DEPickOutBoxModel.wareLocatorNo + "',stockUpBillNo='" + strStockUpBillNo
                                + "' where boxNo='" + strOldBoxNo + "'");
                    }
                    else
                    {
                        //流利货架,库位赋空值
                        commBB.ExecuteSql("update dbo.BArrangeBillBox set oldPalletNo=palletNo,palletNo='"
                                + strNewPalletNo + "',region=oldRegion,oldRegion='',preWareNo=wareNo,preWareLocatorNo=wareLocatorNo,wareNo='"
                                + DEPickOutBoxModel.wareNo + "',wareLocatorNo='',stockUpBillNo='" + strStockUpBillNo
                                + "' where boxNo='" + strOldBoxNo + "'");
                    }
                }

                //如果原箱剩余数量为0,清空原箱的托盘号、库区、库位
                dtArrangeBillBox = arrangeBillBoxBB.GetVList("boxNo='" + strOldBoxNo + "'").Tables[0];
                if (Convert.ToInt32(dtArrangeBillBox.Rows[0]["leavingNum"]) == 0)
                {
                    commBB.ExecuteSql(@"update dbo.BArrangeBillBox set oldPalletNo=palletNo,palletNo='',preWareNo=wareNo,preWareLocatorNo=wareLocatorNo,
                                            wareNo='',wareLocatorNo='',stockUpBillNo='" + strStockUpBillNo
                                        + "' where boxNo='" + strOldBoxNo + "'");
                }

                #region 新增新的排托箱

                DataTable dtArrangeBillBoxNew = new DataTable();

                dtArrangeBillBoxNew = arrangeBillBoxBB.GetList("boxNo='" + strNewBoxNo + "'").Tables[0];

                //新增新的排托箱
                if (dtArrangeBillBoxNew.Rows.Count == 0)
                {
                    BArrangeBillBoxData newArrangeBillBoxModel = new BArrangeBillBoxData();

                    newArrangeBillBoxModel.arriveBillNo = "";//到货单号
                    newArrangeBillBoxModel.financeBillNo = dtArrangeBillBox.Rows[0]["financeBillNo"].ToString();//采购订单号
                    newArrangeBillBoxModel.arrangeBillNo = "";//排托单号
                    newArrangeBillBoxModel.stockUpBillNo = strStockUpBillNo;//备货单编号
                    newArrangeBillBoxModel.boxNo = strNewBoxNo;//箱号
                    newArrangeBillBoxModel.oldBoxNo = strOldBoxNo;//原箱号
                    newArrangeBillBoxModel.materialNo = dtArrangeBillBox.Rows[0]["materialNo"].ToString();//物料编号
                    newArrangeBillBoxModel.factNum = 0;//数量,赋0值通过拣货清单计算实际数量
                    newArrangeBillBoxModel.palletNo = strNewPalletNo;//托盘号
                    newArrangeBillBoxModel.region = "";//区域
                    newArrangeBillBoxModel.oldPalletNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//原托盘号
                    newArrangeBillBoxModel.oldRegion = dtArrangeBillBox.Rows[0]["region"].ToString();//原托内区域
                    newArrangeBillBoxModel.wareNo = dtArrangeBillBox.Rows[0]["wareNo"].ToString();//库区

                    if (DEPickOutBoxModel.oldPalletNo != "")//非流利货架
                    {
                        newArrangeBillBoxModel.wareLocatorNo = DEPickOutBoxModel.wareLocatorNo;//库位
                    }
                    else//流利货架
                    {
                        newArrangeBillBoxModel.wareLocatorNo = "";//库位
                    }

                    newArrangeBillBoxModel.preWareNo = dtArrangeBillBox.Rows[0]["wareNo"].ToString();//原库区
                    newArrangeBillBoxModel.preWareLocatorNo = dtArrangeBillBox.Rows[0]["wareLocatorNo"].ToString();//原库位
                    newArrangeBillBoxModel.isBoxArrange = true;//是否排托
                    newArrangeBillBoxModel.isPalletUsing = true;//托盘是否正在使用
                    newArrangeBillBoxModel.acceptEmpId = this.EmpID;//接收人
                    newArrangeBillBoxModel.acceptDt = System.DateTime.Now.ToString();//接收时间
                    newArrangeBillBoxModel.checkResult = Convert.ToBoolean(dtArrangeBillBox.Rows[0]["checkResult"]);//校验结果
                    newArrangeBillBoxModel.isOutStocking = false;//是否正在出库
                    newArrangeBillBoxModel.noPassReasonId = Convert.ToInt32(dtArrangeBillBox.Rows[0]["noPassReasonId"]);//不合格原因
                    newArrangeBillBoxModel.noPassMark = dtArrangeBillBox.Rows[0]["noPassMark"].ToString();//不合格备注

                    arrangeBillBoxBB.AddRecord(newArrangeBillBoxModel);
                }

                #endregion 新增新的排托箱

                //库存明细数量为0,删除信息
                strSql = "delete from dbo.UStock where num=0";
                commBB.ExecuteSql(strSql);

                //更改库存中原箱的是否锁定状态
                strSql = "update dbo.UStock set isOutStocking=0 where id in (select top 1 id from dbo.UStock where wareLocatorNo='" + strPreWareLocatorNo
                    + "' and materialNo='" + dtArrangeBillBox.Rows[0]["materialNo"].ToString() + "' and isOutStocking=1 order by id)";
                commBB.ExecuteSql(strSql);

                //更改原箱的是否锁定状态
                strSql = "update dbo.BArrangeBillBox set isOutStocking=0 where id in (select top 1 id from dbo.BArrangeBillBox where wareLocatorNo='" + strPreWareLocatorNo
                    + "' and materialNo='" + dtArrangeBillBox.Rows[0]["materialNo"].ToString() + "' and isOutStocking=1 order by id)";
                commBB.ExecuteSql(strSql);

                //释放库位,首先判断原托盘上是否有物料
                strSql = @"update dbo.LWareLocator set isUsing=0
                           where not exists(select 1 from dbo.BArrangeBillBox as t where t.wareLocatorNo=dbo.LWareLocator.wareLocatorNo)
                           and isUsing=1 and isDel=0
                           and wareLocatorNo='" + strPreWareLocatorNo + "'";
                commBB.ExecuteSql(strSql);

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch
            {
                if (transaction == null) trans.Rollback("TranSave");
                throw new Exception("保存信息失败!");
            }
            finally
            {
                commBB.Dispose();
                arrangeBillBoxBB.Dispose();
                DEPickOutBoxBB.Dispose();
                materialBB.Dispose();
                wareBB.Dispose();
                stockOutInDetailBB.Dispose();
                pickOutPlanBB.Dispose();
            }

            return ret;
        }
Example #11
0
        /// <summary>
        /// 质检区拆托合托功能 不涉及到出入库操作
        /// </summary>
        /// <param name="pickOutPlanID"></param>
        /// <param name="strStockUpBillNo"></param>
        /// <param name="palletIndex"></param>
        /// <param name="strNewPalletNo"></param>
        /// <param name="strOldBoxNo"></param>
        /// <param name="strNewBoxNo"></param>
        /// <param name="pickOutNum"></param>
        /// <param name="strOperType"></param>
        /// <returns></returns>
        public bool SavePickOutInfo_DECheck(int pickOutPlanID, string strStockUpBillNo, int palletIndex, string strNewPalletNo,
          string strOldBoxNo, string strNewBoxNo, int pickOutNum, string strOperType,int checkEmpID)
        {
            bool ret = false;
            SqlTransaction trans = null;
            SCommBB commBB = new SCommBB(this.connection);
            BArrangeBillBoxBB arrangeBillBoxBB = new BArrangeBillBoxBB(this.connection);
            LMaterialBB materialBB = new LMaterialBB();
            LWareBB wareBB = new LWareBB();
            bool checkResult = false;//质检结果,拆出来的全是不合格的

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TranSave");
                    this.stockBB.Transaction = trans;
                    commBB.Transaction = trans;
                    arrangeBillBoxBB.Transaction = trans;

                }
                else
                {
                    this.stockBB.Transaction = this.transaction;
                    commBB.Transaction = this.transaction;
                    arrangeBillBoxBB.Transaction = this.transaction;

                }

                DataTable dtArrangeBillBox = new DataTable();
                DataTable dtPallet = new DataTable();
                DataTable dtMaterial = new DataTable();
                DataTable dtStock = new DataTable();
                string  strPreWareLocatorNo = "";

                //获取箱信息
                dtArrangeBillBox = arrangeBillBoxBB.GetVList("boxNo='" + strOldBoxNo + "'").Tables[0];
                if (dtArrangeBillBox.Rows.Count == 0)
                {
                    return false;
                }

                //扫描箱所在库位
                strPreWareLocatorNo = dtArrangeBillBox.Rows[0]["wareLocatorNo"].ToString();

                //获取托盘上的正式物料箱
                dtPallet = arrangeBillBoxBB.GetVList("palletNo='" + strNewPalletNo + "' and isnull(wareNo,'')<>''").Tables[0];

                //获取箱内物料信息
                dtMaterial = materialBB.GetList("materialNo='" + dtArrangeBillBox.Rows[0]["materialNo"].ToString() + "'").Tables[0];

                //更改原箱的信息,增加新箱的信息

                        commBB.ExecuteSql("update dbo.BArrangeBillBox set FactNum = "+dtArrangeBillBox.Rows[0]["factNum"]+"-"+pickOutNum+" where boxNo='" + strOldBoxNo + "'");

                //增加新箱信息
                        BArrangeBillBoxData newArrangeBillBoxModel = new BArrangeBillBoxData();
                        newArrangeBillBoxModel.arriveBillNo = dtArrangeBillBox.Rows[0]["arriveBillNo"].ToString();//到货单号
                        newArrangeBillBoxModel.financeBillNo = dtArrangeBillBox.Rows[0]["financeBillNo"].ToString();//采购订单号
                        newArrangeBillBoxModel.arrangeBillNo = "";//排托单号
                        newArrangeBillBoxModel.stockUpBillNo = "";//备货单编号
                        newArrangeBillBoxModel.boxNo = strNewBoxNo;//箱号
                        newArrangeBillBoxModel.oldBoxNo = strOldBoxNo;//原箱号
                        newArrangeBillBoxModel.materialNo = dtArrangeBillBox.Rows[0]["materialNo"].ToString();//物料编号
                        newArrangeBillBoxModel.factNum = double.Parse(pickOutNum.ToString());
                        newArrangeBillBoxModel.palletNo = strNewPalletNo;//托盘号
                        newArrangeBillBoxModel.region = "";//区域
                        newArrangeBillBoxModel.oldPalletNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//原托盘号
                        newArrangeBillBoxModel.oldRegion = dtArrangeBillBox.Rows[0]["region"].ToString();//原托内区域
                        newArrangeBillBoxModel.wareNo = dtArrangeBillBox.Rows[0]["wareNo"].ToString();//库区
                        newArrangeBillBoxModel.wareLocatorNo = dtArrangeBillBox.Rows[0]["wareLocatorNo"].ToString();//库区
                        newArrangeBillBoxModel.checkResult = checkResult;
                        newArrangeBillBoxModel.checkResultDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        newArrangeBillBoxModel.checkResultEmpId = checkEmpID;

                        arrangeBillBoxBB.AddRecord(newArrangeBillBoxModel);
                        if (this.transaction == null) trans.Commit();
                        ret = true;
            }
            catch
            {
                if (transaction == null) trans.Rollback("TranSave");
                throw new Exception("保存信息失败!");
            }
            finally
            {
                commBB.Dispose();
                arrangeBillBoxBB.Dispose();

                materialBB.Dispose();
                wareBB.Dispose();

            }

            return ret;
        }
Example #12
0
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// 保存排托出库信息
        /// </summary>
        /// <param name="stockUpDetailID">备货单明细ID</param>
        /// <param name="strNewPalletNo">新托盘号</param>
        /// <param name="strOldBoxNo">原箱号</param>
        /// <param name="strNewBoxNo">新箱号</param>
        /// <param name="num">数量</param>
        /// <returns></returns>
        public bool SaveOutStockInfo(int stockUpDetailID, string strNewPalletNo, string strOldBoxNo,
            string strNewBoxNo, double num)
        {
            bool ret = false;
            SqlTransaction trans = null;
            BArrangeBillBoxBB arraneBillBoxBB = new BArrangeBillBoxBB(this.connection);
            BForkliftTaskBC forkliftTaskBC = new BForkliftTaskBC(this.connection);
            CDEPickOutBoxBB DEPickOutBoxBB = new CDEPickOutBoxBB(this.connection);
            CStockUpDetailBB stockUpDetailBB = new CStockUpDetailBB(this.connection);
            CSaleDetailBB saleDetailBB = new CSaleDetailBB(this.connection);
            SCommBB commBB = new SCommBB(this.connection);
            UStockBB stockBB = new UStockBB(this.connection);
            UStockOutInDetailBB stockOutInDetailBB = new UStockOutInDetailBB(this.connection);
            LMaterialBB materialBB = new LMaterialBB(this.connection);

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransSaveOutStockInfo");
                    this.pickOutBillBB.Transaction = trans;
                    arraneBillBoxBB.Transaction = trans;
                    forkliftTaskBC.Transaction = trans;
                    DEPickOutBoxBB.Transaction = trans;
                    stockUpDetailBB.Transaction = trans;
                    saleDetailBB.Transaction = trans;
                    commBB.Transaction = trans;
                    stockBB.Transaction = trans;
                    stockOutInDetailBB.Transaction = trans;
                    materialBB.Transaction = trans;
                }
                else
                {
                    this.pickOutBillBB.Transaction = this.transaction;
                    arraneBillBoxBB.Transaction = this.transaction;
                    forkliftTaskBC.Transaction = this.transaction;
                    DEPickOutBoxBB.Transaction = this.transaction;
                    stockUpDetailBB.Transaction = this.transaction;
                    saleDetailBB.Transaction = this.transaction;
                    commBB.Transaction = this.transaction;
                    stockBB.Transaction = this.transaction;
                    stockOutInDetailBB.Transaction = this.transaction;
                    materialBB.Transaction = this.transaction;
                }

                CStockUpDetailData stockUpDetailModel = new CStockUpDetailData();
                vCStockUpDetailData vStockUpDetailModel = new vCStockUpDetailData();
                DataTable dtArrangeBillBox = new DataTable();
                DataTable dtDEPickOutBox = new DataTable();
                DataTable dtWareLocator = new DataTable();
                DataTable dtStockUpDetail = new DataTable();
                string strSql = "", strPrePalletNo = "", strPreWareLocatorNo = "";

                //获取备货单明细实例
                stockUpDetailModel = stockUpDetailBB.GetModel(stockUpDetailID);

                //拆托拣货箱信息
                dtDEPickOutBox = DEPickOutBoxBB.GetVList("boxNo='" + strOldBoxNo + "'").Tables[0];

                //普通拣货箱信息
                dtArrangeBillBox = arraneBillBoxBB.GetVList("boxNo='" + strOldBoxNo + "' and wareNo<>''").Tables[0];

                //扫描箱以前所在库位
                if (dtArrangeBillBox.Rows[0]["preWareLocatorNo"].ToString() != "")
                {
                    strPrePalletNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//原托盘条码号
                    strPreWareLocatorNo = dtArrangeBillBox.Rows[0]["preWareLocatorNo"].ToString();//物料箱以前所在库位
                }

                //获取排托区下线库位信息
                strSql = @"select wareLocator.wareNo,wareLocator.downWareLocatorNo as wareLocatorNo
                           from dbo.BArrangeBillBox as arrangeBillBoxBox
                           left join dbo.LWareLocator as wareLocator on wareLocator.wareLocatorNo=arrangeBillBoxBox.wareLocatorNo
                           where arrangeBillBoxBox.boxNo='" + strOldBoxNo + "'";

                dtWareLocator = commBB.Query(strSql).Tables[0];

                #region 新增销售拣货单信息

                CPickOutBillData pickOutBillModel = new CPickOutBillData();

                //新增销售拣货单信息
                pickOutBillModel.stockUpDetailID = stockUpDetailID;//备货单明细ID

                //从哪个拣货库区、库位赋值
                if (dtDEPickOutBox.Rows.Count > 0)
                {
                    pickOutBillModel.wareNo = dtDEPickOutBox.Rows[0]["preWareNo"].ToString();//以前的仓库编号
                    pickOutBillModel.wareLocatorNo = dtDEPickOutBox.Rows[0]["preWareLocatorNo"].ToString();//以前的库位编号
                }
                else
                {
                    pickOutBillModel.wareNo = dtArrangeBillBox.Rows[0]["preWareNo"].ToString();//以前的仓库编号
                    pickOutBillModel.wareLocatorNo = dtArrangeBillBox.Rows[0]["preWareLocatorNo"].ToString();//以前的库位编号
                }

                pickOutBillModel.preWareNo = "";//以前的仓库编号
                pickOutBillModel.preWareLocatorNo = "";//以前的库位编号
                pickOutBillModel.oldPalletNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//原托盘号
                pickOutBillModel.oldRegion = dtArrangeBillBox.Rows[0]["region"].ToString();//原托内区域
                pickOutBillModel.oldBoxNo = strOldBoxNo;//原箱号
                pickOutBillModel.newBoxNo = strNewBoxNo;//新箱号
                pickOutBillModel.num = num;//数量
                pickOutBillModel.isrtEmpId = this.empId;//添加人
                pickOutBillModel.isrtDt = System.DateTime.Now.ToString();//添加时间
                pickOutBillModel.instantState = "01";//未发货

                pickOutBillBB.AddRecord(pickOutBillModel);

                #endregion 新增销售拣货单信息

                #region 新增新的排托箱

                DataTable dtArrangeBillBoxNew = new DataTable();

                dtArrangeBillBoxNew = arraneBillBoxBB.GetVList("boxNo='" + strNewBoxNo + "'").Tables[0];

                //新增新的排托箱
                if (dtArrangeBillBoxNew.Rows.Count == 0)
                {
                    BArrangeBillBoxData newArrangeBillBoxModel = new BArrangeBillBoxData();

                    newArrangeBillBoxModel.arriveBillNo = "";//到货单号
                    newArrangeBillBoxModel.financeBillNo = dtArrangeBillBox.Rows[0]["financeBillNo"].ToString();//采购订单号
                    newArrangeBillBoxModel.arrangeBillNo = "";//排托单号
                    newArrangeBillBoxModel.stockUpBillNo = stockUpDetailModel.stockUpBillNo;//备货单编号
                    newArrangeBillBoxModel.boxNo = strNewBoxNo;//箱号
                    newArrangeBillBoxModel.oldBoxNo = strOldBoxNo;//原箱号
                    newArrangeBillBoxModel.materialNo = stockUpDetailModel.materialNo;//转换后物料编号
                    newArrangeBillBoxModel.oldMaterialNo = dtArrangeBillBox.Rows[0]["materialNo"].ToString();//转换前物料编号
                    newArrangeBillBoxModel.factNum = 0;//数量赋0,通过拣货箱明细计算数量
                    newArrangeBillBoxModel.palletNo = strNewPalletNo;//托盘号
                    newArrangeBillBoxModel.region = "";//区域
                    newArrangeBillBoxModel.oldPalletNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//原托盘号
                    newArrangeBillBoxModel.oldRegion = dtArrangeBillBox.Rows[0]["region"].ToString();//原托内区域

                    //新箱库区、库位赋值,值为下线线体
                    if (dtWareLocator.Rows.Count > 0
                       && dtWareLocator.Rows[0]["wareLocatorNo"] != DBNull.Value
                       && dtWareLocator.Rows[0]["wareLocatorNo"].ToString() != "")
                    {
                        newArrangeBillBoxModel.wareNo = dtWareLocator.Rows[0]["wareNo"].ToString();//库区
                        newArrangeBillBoxModel.wareLocatorNo = dtWareLocator.Rows[0]["wareLocatorNo"].ToString();//库位
                    }

                    newArrangeBillBoxModel.preWareNo = "";//原库区
                    newArrangeBillBoxModel.preWareLocatorNo = "";//原库位
                    newArrangeBillBoxModel.isBoxArrange = true;//是否排托
                    newArrangeBillBoxModel.isPalletUsing = true;//托盘是否正在使用
                    newArrangeBillBoxModel.acceptEmpId = this.EmpID;//接收人
                    newArrangeBillBoxModel.acceptDt = System.DateTime.Now.ToString();//接收时间
                    newArrangeBillBoxModel.isOutStocking = false;//是否正在出库

                    arraneBillBoxBB.AddRecord(newArrangeBillBoxModel);
                }

                #endregion 新增新的排托箱

                #region 库存所有操作

                DataTable dtStock = new DataTable();
                DataTable dtMaterial = new DataTable();
                UStockOutInDetailData stockOutInDetailModel = new UStockOutInDetailData();

                //更改正式库存信息
                commBB.ExecuteSql("update dbo.UStock set num=num-" + num.ToString() + " where boxNo='" + strOldBoxNo + "'");

                //增加出入库明细-拣货箱出库
                dtStock = stockBB.GetList("boxNo='" + strOldBoxNo + "'").Tables[0];
                if (dtStock.Rows.Count > 0)//原箱有库存
                {
                    dtMaterial = materialBB.GetList("materialNo='" + dtStock.Rows[0]["materialNo"].ToString() + "'").Tables[0];

                    //保存出入库明细数据
                    stockOutInDetailModel = new UStockOutInDetailData();

                    stockOutInDetailModel.billNo = stockUpDetailModel.stockUpBillNo;//单据编号
                    stockOutInDetailModel.outInType = "06";//销售出库
                    stockOutInDetailModel.isOut = true;//是否出库
                    stockOutInDetailModel.stockDt = System.DateTime.Today.ToString();//库存日期
                    stockOutInDetailModel.dt = System.DateTime.Today.ToString();//操作日期
                    stockOutInDetailModel.wareNo = dtStock.Rows[0]["wareNo"].ToString();//仓库
                    stockOutInDetailModel.wareLocatorNo = dtStock.Rows[0]["wareLocatorNo"].ToString();//库位
                    stockOutInDetailModel.salverNo = dtStock.Rows[0]["palletNo"].ToString();//托盘号
                    stockOutInDetailModel.boxNo = strOldBoxNo;//箱号
                    stockOutInDetailModel.materialNo = dtStock.Rows[0]["materialNo"].ToString();//物料编号
                    stockOutInDetailModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                    stockOutInDetailModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                    stockOutInDetailModel.num = num;//数量
                    stockOutInDetailModel.isrtEmpId = this.empId;
                    stockOutInDetailModel.isrtDt = System.DateTime.Now.ToString();

                    stockOutInDetailBB.AddRecord(stockOutInDetailModel);
                }

                #endregion 库存所有操作

                #region 更改备货单明细的新托盘号、状态

                //更改备货单明细的新托盘号、状态
                vStockUpDetailModel = stockUpDetailBB.GetVModel(stockUpDetailID);

                stockUpDetailModel.palletNo = strNewPalletNo;//新托盘号

                if (vStockUpDetailModel.num > vStockUpDetailModel.factNum)
                {
                    stockUpDetailModel.instantState = "02";//更改状态为“备货中”
                }
                else
                {
                    stockUpDetailModel.instantState = "03";//更改状态为“备货完成”
                }

                stockUpDetailBB.ModifyRecord(stockUpDetailModel);

                #endregion 更改备货单明细的新托盘号、状态

                #region 生成从拣货区到打托区叉车任务

                bool isFinish = true;

                //如果某个托盘的备货单明细已经全部备货完成,生成托盘的叉车任务
                strSql = @"select palletNo,instantState from dbo.CStockUpDetail where stockUpBillNo='" + stockUpDetailModel.stockUpBillNo
                    + "' and palletIndex='" + stockUpDetailModel.palletIndex.ToString() + "'";

                dtStockUpDetail = commBB.Query(strSql).Tables[0];

                foreach (DataRow row in dtStockUpDetail.Rows)
                {
                    if (row["instantState"].ToString() == "01" || row["instantState"].ToString() == "02")
                    {
                        isFinish = false;
                        break;
                    }
                }

                if (isFinish)
                {
                    //保存从拣货区到打托区叉车任务
                    forkliftTaskBC.SaveForkliftTask(dtStockUpDetail.Rows[0]["palletNo"].ToString(), "", "", "14", this.empId);
                }

                #endregion 生成从拣货区到打托区叉车任务

                #region 更改备货单状态

                //如果备货单明细的状态全部为“03 备货完成”,更改备货单状态为“08 备货完成”
                strSql = @"update dbo.CStockUpBill set instantState='08'
                           where not exists(select 1 from dbo.CStockUpDetail as t where t.stockUpBillNo=dbo.CStockUpBill.stockUpBillNo and instantState<>'03')";

                commBB.ExecuteSql(strSql);

                #endregion 更改备货单状态

                #region 更改箱锁定状态

                int stockId = 0, boxId = 0;
                object obj = null;

                //查找库存
                obj = commBB.ExecuteScalar("select top 1 id from dbo.UStock where boxNo='" + strOldBoxNo + "' and num>0 and isOutStocking=1");
                if (obj == null)
                {
                    obj = commBB.ExecuteScalar("select top 1 id from dbo.UStock where palletNo='" + strPrePalletNo + "' and num>0 and isOutStocking=1 order by id");
                    if (obj != null)
                    {
                        stockId = Convert.ToInt32(obj);
                    }
                }
                else
                {
                    stockId = Convert.ToInt32(obj);
                }

                //查找物料箱
                obj = commBB.ExecuteScalar("select top 1 id from dbo.BArrangeBillBox where boxNo='" + strOldBoxNo + "' and wareNo<>'' and isOutStocking=1");
                if (obj == null)
                {
                    obj = commBB.ExecuteScalar("select top 1 id from dbo.BArrangeBillBox where palletNo='" + strPrePalletNo + "' and wareNo<>'' and isOutStocking=1 order by id");
                    if (obj != null)
                    {
                        boxId = Convert.ToInt32(obj);
                    }
                }
                else
                {
                    boxId = Convert.ToInt32(obj);
                }

                //更改库存中原箱的是否锁定状态
                strSql = "update dbo.UStock set isOutStocking=0 where id='" + stockId.ToString() + "'";
                commBB.ExecuteSql(strSql);

                //更改原箱的是否锁定状态
                strSql = "update dbo.BArrangeBillBox set isOutStocking=0 where id='" + boxId.ToString() + "'";
                commBB.ExecuteSql(strSql);

                #endregion 更改箱锁定状态

                #region 如果原箱剩余数量为零,更改原箱的托盘号

                if (strNewBoxNo == strOldBoxNo)
                {
                    if (dtWareLocator.Rows.Count > 0
                        && dtWareLocator.Rows[0]["wareLocatorNo"] != DBNull.Value
                        && dtWareLocator.Rows[0]["wareLocatorNo"].ToString() != "")
                    {
                        strSql = @"update dbo.BArrangeBillBox set oldMaterialNo=materialNo,materialNo='" + stockUpDetailModel.materialNo
                            + "',oldPalletNo=palletNo,palletNo='" + strNewPalletNo + "',preWareNo=wareNo,preWareLocatorNo=wareLocatorNo,wareNo='"
                            + dtWareLocator.Rows[0]["wareNo"].ToString() + "',wareLocatorNo='" + dtWareLocator.Rows[0]["wareLocatorNo"].ToString()
                            + "',oldRegion=region,region='' where boxNo='" + strOldBoxNo + "'";

                        commBB.ExecuteSql(strSql);
                    }
                }

                //如果箱内剩余数量为0,清空托盘号和库区、库位信息
                dtArrangeBillBox = arraneBillBoxBB.GetVList("boxNo='" + strOldBoxNo + "'").Tables[0];
                if (Convert.ToInt32(dtArrangeBillBox.Rows[0]["leavingNum"]) == 0)
                {
                    commBB.ExecuteSql(@"update dbo.BArrangeBillBox set oldPalletNo=palletNo,palletNo='',preWareNo=wareNo,preWareLocatorNo=wareLocatorNo,
                                        wareNo='',wareLocatorNo='' where boxNo='" + strOldBoxNo + "'");
                }

                #endregion 如果原箱剩余数量为零,更改原箱的托盘号

                #region 原库位释放

                //释放库位,首先判断原托盘上是否有物料
                strSql = @"update dbo.LWareLocator set isUsing=0
                           where not exists(select 1 from dbo.BArrangeBillBox as t where t.palletNo='"
                    + strPrePalletNo + "' and isnull(t.wareNo,'')<>'') and wareLocatorNo='"
                    + strPreWareLocatorNo + "' and isUsing=1 and isDel=0";

                commBB.ExecuteSql(strSql);

                #endregion 原库位释放

                #region 出入库所有操作

                //库存明细数量为0,删除信息
                strSql = "delete from dbo.UStock where num=0";
                commBB.ExecuteSql(strSql);

                #endregion 出入库所有操作

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch (Exception ex)
            {
                if (this.transaction == null) trans.Rollback("TransSaveOutStockInfo");
                throw ex;
            }
            finally
            {
                arraneBillBoxBB.Dispose();
                forkliftTaskBC.Dispose();
                stockUpDetailBB.Dispose();
                commBB.Dispose();
                saleDetailBB.Dispose();
                DEPickOutBoxBB.Dispose();
                stockBB.Dispose();
                stockOutInDetailBB.Dispose();
                materialBB.Dispose();
            }

            return ret;
        }
        /// <summary>
        /// 保存非标准箱入质检区信息
        /// </summary>
        /// <param name="strPalletNo">托盘号</param>
        /// <returns></returns>
        public bool SaveNoStandBoxInCheckInfo(string strPalletNo)
        {
            bool ret = false;
            SqlTransaction trans = null;
            SCommBB commBB = new SCommBB(this.connection);
            BForkliftTaskBB forkliftTaskBB = new BForkliftTaskBB(this.connection);
            BArrangeBillBoxBB arrangeBillBoxBB = new BArrangeBillBoxBB(this.connection);
            BArrangeBillFactDetailBB arrangeBillFactDetailBB = new BArrangeBillFactDetailBB(this.connection);

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransSave");
                    this.arrangeBillFactBB.Transaction = trans;
                    commBB.Transaction = trans;
                    forkliftTaskBB.Transaction = trans;
                    arrangeBillBoxBB.Transaction = trans;
                    arrangeBillFactDetailBB.Transaction = trans;
                }
                else
                {
                    this.arrangeBillFactBB.Transaction = this.transaction;
                    commBB.Transaction = this.transaction;
                    forkliftTaskBB.Transaction = this.transaction;
                    arrangeBillBoxBB.Transaction = this.transaction;
                    arrangeBillFactDetailBB.Transaction = this.transaction;
                }

                DataTable dtArrangeBillBox = new DataTable();
                string strArriveBillNo = "", strFinanceBillNo = "";
                BArrangeBillFactData arrangeBillFactModel = new BArrangeBillFactData();
                BArrangeBillFactDetailData arrangeBillFactDetailModel = new BArrangeBillFactDetailData();
                BArrangeBillBoxData arrangeBillBoxModel = new BArrangeBillBoxData();
                int mainId = 0;

                //获取到货箱信息
                dtArrangeBillBox = arrangeBillBoxBB.GetList("palletNo='" + strPalletNo + "' and isnull(wareNo,'')<>''").Tables[0];
                if (dtArrangeBillBox.Rows.Count > 0)
                {
                    strArriveBillNo = dtArrangeBillBox.Rows[0]["arriveBillNo"].ToString();//到货单号
                    strFinanceBillNo = dtArrangeBillBox.Rows[0]["financeBillNo"].ToString();//采购单号
                }

                #region 维护排托收货单信息

                //维护排托收货单信息
                arrangeBillFactModel.arrangeBillNo = "PT" + strArriveBillNo;//排托单号
                arrangeBillFactModel.arriveBillNo = strArriveBillNo;//到货单号
                arrangeBillFactModel.financeBillNo = strFinanceBillNo;//采购订单号
                arrangeBillFactModel.palletIndex = "0";//托盘序号
                arrangeBillFactModel.palletNo = strPalletNo;//托盘条码号
                arrangeBillFactModel.isTally = false;//是否已理货
                arrangeBillFactModel.isrtEmpId = this.empId;//添加人
                arrangeBillFactModel.isrtDt = System.DateTime.Now.ToString();//添加时间
                arrangeBillFactModel.instantState = "02";//状态

                mainId = arrangeBillFactBB.AddRecord(arrangeBillFactModel);

                #endregion 维护排托收货单信息

                #region 维护排托箱信息

                foreach (DataRow row in dtArrangeBillBox.Rows)
                {
                    //保存排托收货单明细信息
                    arrangeBillFactDetailModel = new BArrangeBillFactDetailData();

                    arrangeBillFactDetailModel.mainId = mainId.ToString();//排托收货单ID
                    arrangeBillFactDetailModel.boxNo = row["boxNo"].ToString();//箱号
                    arrangeBillFactDetailModel.region = "0";//区域
                    arrangeBillFactDetailModel.isrtEmpId = this.empId;
                    arrangeBillFactDetailModel.isrtDt = System.DateTime.Now.ToString();

                    arrangeBillFactDetailBB.AddRecord(arrangeBillFactDetailModel);

                    //更改到货箱排托标志
                    commBB.ExecuteSql("update dbo.BArrangeBillBox set isBoxArrange=1 where boxNo='" + row["boxNo"].ToString() + "'");
                }

                #endregion 维护排托箱信息

                #region 生成叉车任务

                BForkliftTaskData forkliftTaskModel = new BForkliftTaskData();

                if (dtArrangeBillBox.Rows.Count > 0)
                {
                    forkliftTaskModel = new BForkliftTaskData();

                    forkliftTaskModel.taskType = "10";//任务类型为:从收货区到质检区
                    forkliftTaskModel.palletNo = strPalletNo;//托盘号
                    forkliftTaskModel.preWareNo = dtArrangeBillBox.Rows[0]["wareNo"].ToString();//源库区
                    forkliftTaskModel.preLocatorNo = dtArrangeBillBox.Rows[0]["wareLocatorNo"].ToString();//源库位
                    forkliftTaskModel.effectDt = System.DateTime.Now.ToString();//生效时间
                    forkliftTaskModel.isDeal = false;//是否处理

                    forkliftTaskBB.AddRecord(forkliftTaskModel);
                }

                #endregion 生成叉车任务

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch (Exception ex)
            {
                if (this.transaction == null) trans.Rollback("TransSave");
                throw ex;
            }
            finally
            {
                commBB.Dispose();
                forkliftTaskBB.Dispose();
                arrangeBillBoxBB.Dispose();
                arrangeBillFactDetailBB.Dispose();
            }

            return ret;
        }