/// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(BWeigtHistoryData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into BWeigtHistory(");
            strSql.Append(@"materialNo,dt,weight,isrtEmpId,isrtDt)");
            strSql.Append(" values (");
            strSql.Append(@"@materialNo,@dt,@weight,@isrtEmpId,@isrtDt)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@materialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@dt", SqlDbType.DateTime),
                    new SqlParameter("@weight", SqlDbType.Float),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime)
                };
            parameters[0].Value = model.materialNo;
            parameters[1].Value = model.dt == string.Empty ? null : model.dt;
            parameters[2].Value = model.weight;
            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(BWeigtHistoryData model)
 {
     return this.weigtHistoryDB.ModifyRecord(model);
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(BWeigtHistoryData model)
 {
     return this.weigtHistoryDB.AddRecord(model);
 }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(BWeigtHistoryData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update BWeigtHistory set ");
            strSql.Append("materialNo=@materialNo,");
            strSql.Append("dt=@dt,");
            strSql.Append("weight=@weight,");
            strSql.Append("isrtEmpId=@isrtEmpId,");
            strSql.Append("isrtDt=@isrtDt");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int),
                    new SqlParameter("@materialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@dt", SqlDbType.DateTime),
                    new SqlParameter("@weight", SqlDbType.Float),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime)
                };
            parameters[0].Value = model.id;
            parameters[1].Value = model.materialNo;
            parameters[2].Value = model.dt == string.Empty ? null : model.dt;
            parameters[3].Value = model.weight;
            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>
        /// 得到一个model
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns>model</returns>
        public BWeigtHistoryData GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select id,materialNo,dt,weight,isrtEmpId,isrtDt from BWeigtHistory");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int)
                };
            parameters[0].Value = id;

            BWeigtHistoryData model = new BWeigtHistoryData();
            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["materialNo"] != DBNull.Value)
                {
                    model.materialNo = Convert.ToString(row["materialNo"]);
                }
                if (row["dt"] != DBNull.Value)
                {
                    model.dt = Convert.ToString(row["dt"]);
                }
                if (row["weight"] != DBNull.Value)
                {
                    model.weight = Convert.ToDouble(row["weight"]);
                }
                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;
            }
        }
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// 保存产品检测结果
        /// </summary>
        /// <param name="productCheckDetailModel">产品检测结果实例</param>
        /// <returns></returns>
        public bool SaveRecord(BProductCheckDetailData productCheckDetailModel, string strCheckItemNo, string strMaterialNo)
        {
            bool ret = false;
            SqlTransaction trans = null;
            BWeigtHistoryBB weightHistoryBB = new BWeigtHistoryBB(this.connection);
            SCommBB commBB = new SCommBB(this.connection);

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

                StringBuilder strSql = new StringBuilder();
                BWeigtHistoryData weightHistoryModel = new BWeigtHistoryData();

                //保存产品检测结果实例
                this.productCheckDetailBB.AddRecord(productCheckDetailModel);

                //更改产品检测单状态为“检测中”
                strSql.Append("update checkBill set instantState='03' ");
                strSql.Append("from dbo.BCheckBill as checkBill ");
                strSql.Append("left join dbo.BCheckDetail as checkDetail on checkDetail.checkBillId=checkBill.Id ");
                strSql.Append("where checkDetail.id=" + productCheckDetailModel.checkDetailId.ToString());

                commBB.ExecuteSql(strSql.ToString());

                //如果为称重,向称重记录表插入一条数据
                if (strCheckItemNo == "1004")
                {
                    weightHistoryModel.materialNo = strMaterialNo;//物料编号
                    weightHistoryModel.dt = productCheckDetailModel.checkDt;//称重时间
                    weightHistoryModel.weight = productCheckDetailModel.weight;//称重
                    weightHistoryModel.isrtDt = System.DateTime.Now.ToString();//添加时间
                    weightHistoryModel.isrtEmpId = this.empId;//添加人

                    weightHistoryBB.AddRecord(weightHistoryModel);
                }

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

            return ret;
        }