/// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="connection">数据连接</param>
 public BArrangeBillFactBC(SqlConnection connection)
 {
     this.connection = connection;
     this.arrangeBillFactBB = new BArrangeBillFactBB(this.connection);
     this.errorDiaryBB = new SErrorDiaryBB(this.connection);
     this.operatDiaryBB = new SOperatDiaryBB(this.connection);
 }
 /// <summary>
 /// 构造函数
 /// </summary>
 public BArrangeBillFactBC()
 {
     this.selfConn = true;
     this.connection = new SqlConnection(HS.Config.SqlDataObject.GetSqlConnectionString);
     this.connection.Open();
     this.arrangeBillFactBB = new BArrangeBillFactBB(this.connection);
     this.errorDiaryBB = new SErrorDiaryBB(this.connection);
     this.operatDiaryBB = new SOperatDiaryBB(this.connection);
 }
        //*****************************************************************************
        //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;
        }