/// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(BArrangeBillFactDetailData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into BArrangeBillFactDetail(");
            strSql.Append(@"mainId,boxNo,region,isrtEmpId,isrtDt)");
            strSql.Append(" values (");
            strSql.Append(@"@mainId,@boxNo,@region,@isrtEmpId,@isrtDt)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@mainId", SqlDbType.VarChar,20),
                    new SqlParameter("@boxNo", SqlDbType.VarChar,20),
                    new SqlParameter("@region", SqlDbType.VarChar,10),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime)
                };
            parameters[0].Value = model.mainId;
            parameters[1].Value = model.boxNo;
            parameters[2].Value = model.region;
            parameters[3].Value = model.isrtEmpId;
            parameters[4].Value = model.isrtDt == string.Empty ? null : model.isrtDt;

            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(BArrangeBillFactDetailData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update BArrangeBillFactDetail set ");
            strSql.Append("mainId=@mainId,");
            strSql.Append("boxNo=@boxNo,");
            strSql.Append("region=@region,");
            strSql.Append("isrtEmpId=@isrtEmpId,");
            strSql.Append("isrtDt=@isrtDt");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int),
                    new SqlParameter("@mainId", SqlDbType.VarChar,20),
                    new SqlParameter("@boxNo", SqlDbType.VarChar,20),
                    new SqlParameter("@region", SqlDbType.VarChar,10),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime)
                };
            parameters[0].Value = model.id;
            parameters[1].Value = model.mainId;
            parameters[2].Value = model.boxNo;
            parameters[3].Value = model.region;
            parameters[4].Value = model.isrtEmpId;
            parameters[5].Value = model.isrtDt == string.Empty ? null : model.isrtDt;

            try
            {
                SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 /// <param name="model">model</param>
 public bool ModifyRecord(BArrangeBillFactDetailData model)
 {
     return this.arrangeBillFactDetailDB.ModifyRecord(model);
 }
        /// <summary>
        /// 得到一个model
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns>model</returns>
        public BArrangeBillFactDetailData GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select id,mainId,boxNo,region,isrtEmpId,isrtDt from BArrangeBillFactDetail");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int)
                };
            parameters[0].Value = id;

            BArrangeBillFactDetailData model = new BArrangeBillFactDetailData();
            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["mainId"] != DBNull.Value)
                {
                    model.mainId = Convert.ToString(row["mainId"]);
                }
                if (row["boxNo"] != DBNull.Value)
                {
                    model.boxNo = Convert.ToString(row["boxNo"]);
                }
                if (row["region"] != DBNull.Value)
                {
                    model.region = Convert.ToString(row["region"]);
                }
                if (row["isrtEmpId"] != DBNull.Value)
                {
                    model.isrtEmpId = Convert.ToInt32(row["isrtEmpId"]);
                }
                if (row["isrtDt"] != DBNull.Value)
                {
                    model.isrtDt = Convert.ToString(row["isrtDt"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(BArrangeBillFactDetailData model)
 {
     return this.arrangeBillFactDetailDB.AddRecord(model);
 }
        //*****************************************************************************
        //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>
        /// 更新一条"排托收货单明细"信息
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(BArrangeBillFactDetailData model)
        {
            bool ret = false;
            SqlTransaction trans = null;
            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransModify");
                    this.arrangeBillFactDetailBB.Transaction = trans;
                    this.errorDiaryBB.Transaction = trans;
                    this.operatDiaryBB.Transaction = trans;
                }

                this.arrangeBillFactDetailBB.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;
        }
        /// <summary>
        /// 增加一条"排托收货单明细"信息
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(BArrangeBillFactDetailData model)
        {
            int id = 0;
            SqlTransaction trans = null;
            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransAdd");
                    this.arrangeBillFactDetailBB.Transaction = trans;
                    this.errorDiaryBB.Transaction = trans;
                    this.operatDiaryBB.Transaction = trans;
                }

                id = this.arrangeBillFactDetailBB.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="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;
        }