/// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(BArrangeBillBoxResultChangeData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into BArrangeBillBoxResultChange(");
            strSql.Append(@"boxNo,checkResult,checkResultDt,checkResultEmpId,preCheckResult,preCheckResultDt,preCheckResultEmpId,mark)");
            strSql.Append(" values (");
            strSql.Append(@"@boxNo,@checkResult,@checkResultDt,@checkResultEmpId,@preCheckResult,@preCheckResultDt,@preCheckResultEmpId,@mark)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@boxNo", SqlDbType.VarChar,20),
                    new SqlParameter("@checkResult", SqlDbType.Bit),
                    new SqlParameter("@checkResultDt", SqlDbType.DateTime),
                    new SqlParameter("@checkResultEmpId", SqlDbType.Int),
                    new SqlParameter("@preCheckResult", SqlDbType.Bit),
                    new SqlParameter("@preCheckResultDt", SqlDbType.DateTime),
                    new SqlParameter("@preCheckResultEmpId", SqlDbType.Int),
                    new SqlParameter("@mark", SqlDbType.NVarChar,500)
                };
            parameters[0].Value = model.boxNo;
            parameters[1].Value = model.checkResult;
            parameters[2].Value = model.checkResultDt == string.Empty ? null : model.checkResultDt;
            parameters[3].Value = model.checkResultEmpId;
            parameters[4].Value = model.preCheckResult;
            parameters[5].Value = model.preCheckResultDt == string.Empty ? null : model.preCheckResultDt;
            parameters[6].Value = model.preCheckResultEmpId;
            parameters[7].Value = model.mark;

            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(BArrangeBillBoxResultChangeData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update BArrangeBillBoxResultChange set ");
            strSql.Append("boxNo=@boxNo,");
            strSql.Append("checkResult=@checkResult,");
            strSql.Append("checkResultDt=@checkResultDt,");
            strSql.Append("checkResultEmpId=@checkResultEmpId,");
            strSql.Append("preCheckResult=@preCheckResult,");
            strSql.Append("preCheckResultDt=@preCheckResultDt,");
            strSql.Append("preCheckResultEmpId=@preCheckResultEmpId,");
            strSql.Append("mark=@mark");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int),
                    new SqlParameter("@boxNo", SqlDbType.VarChar,20),
                    new SqlParameter("@checkResult", SqlDbType.Bit),
                    new SqlParameter("@checkResultDt", SqlDbType.DateTime),
                    new SqlParameter("@checkResultEmpId", SqlDbType.Int),
                    new SqlParameter("@preCheckResult", SqlDbType.Bit),
                    new SqlParameter("@preCheckResultDt", SqlDbType.DateTime),
                    new SqlParameter("@preCheckResultEmpId", SqlDbType.Int),
                    new SqlParameter("@mark", SqlDbType.NVarChar,500)
                };
            parameters[0].Value = model.id;
            parameters[1].Value = model.boxNo;
            parameters[2].Value = model.checkResult;
            parameters[3].Value = model.checkResultDt == string.Empty ? null : model.checkResultDt;
            parameters[4].Value = model.checkResultEmpId;
            parameters[5].Value = model.preCheckResult;
            parameters[6].Value = model.preCheckResultDt == string.Empty ? null : model.preCheckResultDt;
            parameters[7].Value = model.preCheckResultEmpId;
            parameters[8].Value = model.mark;

            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 BArrangeBillBoxResultChangeData GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select id,boxNo,checkResult,checkResultDt,checkResultEmpId,preCheckResult,preCheckResultDt,preCheckResultEmpId,mark from BArrangeBillBoxResultChange");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int)
                };
            parameters[0].Value = id;

            BArrangeBillBoxResultChangeData model = new BArrangeBillBoxResultChangeData();
            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["boxNo"] != DBNull.Value)
                {
                    model.boxNo = Convert.ToString(row["boxNo"]);
                }
                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["preCheckResult"] != DBNull.Value)
                {
                    model.preCheckResult = Convert.ToBoolean(row["preCheckResult"]);
                }
                if (row["preCheckResultDt"] != DBNull.Value)
                {
                    model.preCheckResultDt = Convert.ToString(row["preCheckResultDt"]);
                }
                if (row["preCheckResultEmpId"] != DBNull.Value)
                {
                    model.preCheckResultEmpId = Convert.ToInt32(row["preCheckResultEmpId"]);
                }
                if (row["mark"] != DBNull.Value)
                {
                    model.mark = Convert.ToString(row["mark"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 /// <param name="model">model</param>
 public bool ModifyRecord(BArrangeBillBoxResultChangeData model)
 {
     return this.arrangeBillBoxResultChangeDB.ModifyRecord(model);
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(BArrangeBillBoxResultChangeData model)
 {
     return this.arrangeBillBoxResultChangeDB.AddRecord(model);
 }
Exemplo n.º 6
0
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// 物料箱检测结果转换
        /// </summary>
        /// <param name="dtBox"></param>
        /// <param name="isRegular"></param>
        /// <param name="strMark"></param>
        /// <returns></returns>
        public bool ConvertBox(DataTable dtBox, bool isRegular, string strMark)
        {
            bool ret = false;
            BArrangeBillBoxResultChangeBB arrangeBillBoxResultChangeBB = new BArrangeBillBoxResultChangeBB(this.connection);
            SCommBB commBB = new SCommBB(this.connection);
            SqlTransaction trans = null;

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

                BArrangeBillBoxResultChangeData arrangeBillBoxResultChangeModel = new BArrangeBillBoxResultChangeData();

                foreach (DataRow dataRow in dtBox.Rows)
                {
                    string strBoxNo = "";
                    DataTable dtArrangeBox = new DataTable();

                    strBoxNo = dataRow["boxNo"].ToString();//箱号
                    dtArrangeBox = this.arrangeBillBoxBB.GetList("boxNo='" + strBoxNo + "'").Tables[0];

                    //更改原箱的检测结果
                    commBB.ExecuteSql("update dbo.BArrangeBillBox set checkResult='" + isRegular
                        + "',checkResultDt='" + System.DateTime.Now.ToString() + "',checkResultEmpId=" + this.empId + " where boxNo='" + strBoxNo + "'");

                    //新增箱变更记录
                    arrangeBillBoxResultChangeModel = new BArrangeBillBoxResultChangeData();

                    arrangeBillBoxResultChangeModel.boxNo = strBoxNo;//箱号
                    arrangeBillBoxResultChangeModel.checkResult = isRegular;//是否合格
                    arrangeBillBoxResultChangeModel.checkResultDt = System.DateTime.Now.ToString();//判定时间
                    arrangeBillBoxResultChangeModel.checkResultEmpId = this.empId;//判定人员
                    arrangeBillBoxResultChangeModel.preCheckResult = Convert.ToBoolean(dtArrangeBox.Rows[0]["checkResult"]);//上一次判定结果
                    arrangeBillBoxResultChangeModel.preCheckResultDt = dtArrangeBox.Rows[0]["checkResultDt"].ToString();//上一次判定时间
                    arrangeBillBoxResultChangeModel.preCheckResultEmpId = Convert.ToInt32(dtArrangeBox.Rows[0]["checkResultEmpId"]);//上一次判定人员

                    arrangeBillBoxResultChangeBB.AddRecord(arrangeBillBoxResultChangeModel);
                }

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

            return ret;
        }