/// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(BArrangeBillDetailData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into BArrangeBillDetail(");
            strSql.Append(@"arrangeBillNo,arriveBillNo,financeBillNo,palletIndex,materialNo,boxNum,region,isrtEmpId,isrtDt,updtEmpId,
                            updtDt,instantState)");
            strSql.Append(" values (");
            strSql.Append(@"@arrangeBillNo,@arriveBillNo,@financeBillNo,@palletIndex,@materialNo,@boxNum,@region,@isrtEmpId,@isrtDt,@updtEmpId,
                            @updtDt,@instantState)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@arrangeBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@arriveBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@financeBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@palletIndex", SqlDbType.Int),
                    new SqlParameter("@materialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@boxNum", SqlDbType.Int),
                    new SqlParameter("@region", SqlDbType.Int),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int),
                    new SqlParameter("@updtDt", SqlDbType.DateTime),
                    new SqlParameter("@instantState", SqlDbType.NVarChar,20)
                };
            parameters[0].Value = model.arrangeBillNo;
            parameters[1].Value = model.arriveBillNo;
            parameters[2].Value = model.financeBillNo;
            parameters[3].Value = model.palletIndex;
            parameters[4].Value = model.materialNo;
            parameters[5].Value = model.boxNum;
            parameters[6].Value = model.region;
            parameters[7].Value = model.isrtEmpId;
            parameters[8].Value = model.isrtDt == string.Empty ? null : model.isrtDt;
            parameters[9].Value = model.updtEmpId;
            parameters[10].Value = model.updtDt == string.Empty ? null : model.updtDt;
            parameters[11].Value = model.instantState;

            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;
        }
Ejemplo n.º 2
0
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// 保存排托单信息
        /// </summary>
        /// <param name="arrangeBillModel">排托单实例</param>
        /// <param name="dtArrange">排托明细数据源</param>
        /// <param name="isSubmit">是否提交</param>
        /// <returns></returns>
        public bool SaveBArrangeBill(BArrangeBillData arrangeBillModel, DataTable dtArrange, bool isSubmit)
        {
            bool ret = false;
            BArrangeBillBB arrangeBillBB = new BArrangeBillBB(connection);
            BArriveBillBB arriveBillBB = new BArriveBillBB(connection);
            BArrangeBillDetailBB arrangeBillDetailBB = new BArrangeBillDetailBB(connection);
            SqlTransaction trans = null;

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TranSave");
                    arrangeBillBB.Transaction = trans;
                    arriveBillBB.Transaction = trans;
                    arrangeBillDetailBB.Transaction = trans;
                }
                else
                {
                    arrangeBillDetailBB.Transaction = this.transaction;
                    arriveBillBB.Transaction = this.transaction;
                    arrangeBillBB.Transaction = this.transaction;
                }

                BArriveBillData arriveBillModel = arriveBillBB.GetModel(arrangeBillModel.arriveBillNo);

                if (arrangeBillModel.id == 0)//新增排托单
                {
                    #region 新增排托单

                    if (isSubmit)//提交
                    {
                        arriveBillModel.instantState = "03";//排托单已提交
                        arriveBillModel.commitDt = arrangeBillModel.commitDt;
                        arriveBillModel.commitEmpId = arrangeBillModel.commitEmpId;
                    }
                    else//未提交
                    {
                        arriveBillModel.instantState = "02";//已生成排托单
                    }

                    //更改到货单状态
                    arriveBillBB.ModifyRecord(arriveBillModel);

                    //新增排托单信息
                    arrangeBillBB.AddRecord(arrangeBillModel);

                    foreach (DataRow dr in dtArrange.Rows)
                    {
                        if (dr["isdel"].ToString() == "0")//未删除
                        {
                            BArrangeBillDetailData model = new BArrangeBillDetailData();

                            model.arrangeBillNo = dr["arrangeBillNo"].ToString();
                            model.arriveBillNo = dr["arriveBillNo"].ToString();
                            model.boxNum = Convert.ToInt32(dr["boxNum"]);
                            model.financeBillNo = dr["financeBillNo"].ToString();
                            model.isrtDt = arrangeBillModel.isrtDt;
                            model.instantState = "01";
                            model.isrtEmpId = arrangeBillModel.isrtEmpId;
                            model.materialNo = dr["materialNo"].ToString();
                            model.palletIndex = Convert.ToInt32(dr["palletIndex"]);
                            model.region = Convert.ToInt32(dr["region"].ToString());

                            arrangeBillDetailBB.AddRecord(model);
                        }
                    }

                    #endregion 新增排托单
                }
                else
                {
                    #region 修改排托单信息

                    if (isSubmit)//提交
                    {
                        arriveBillModel.instantState = "03";//排托单已提交
                        arriveBillModel.commitDt = arrangeBillModel.commitDt;
                        arriveBillModel.commitEmpId = arrangeBillModel.commitEmpId;
                    }
                    else//未提交
                    {
                        arriveBillModel.instantState = "02";//已生成排托单
                    }

                    //更改到货单状态
                    arriveBillBB.ModifyRecord(arriveBillModel);

                    //修改排托单信息
                    arrangeBillBB.ModifyRecord(arrangeBillModel);

                    foreach (DataRow dr in dtArrange.Rows)
                    {
                        if (Convert.ToInt32(dr["id"]) > 0 && dr["isdel"].ToString() == "1")//删除方法
                        {
                            arrangeBillDetailBB.DeleteRecord(Convert.ToInt32(dr["id"]));
                        }
                        else if (Convert.ToInt32(dr["id"]) > 0 && dr["isdel"].ToString() == "0")//修改
                        {
                            BArrangeBillDetailData model = arrangeBillDetailBB.GetModel(Convert.ToInt32(dr["id"]));

                            model.boxNum = Convert.ToInt32(dr["boxNum"]);
                            model.region = Convert.ToInt32(dr["region"]);
                            model.updtDt = DateTime.Now.ToString();
                            model.updtEmpId = arrangeBillModel.updtEmpId;

                            arrangeBillDetailBB.ModifyRecord(model);
                        }
                        else if (Convert.ToInt32(dr["id"]) == 0 && dr["isdel"].ToString() == "0")//添加
                        {
                            BArrangeBillDetailData model = new BArrangeBillDetailData();

                            model.arrangeBillNo = dr["arrangeBillNo"].ToString();
                            model.arriveBillNo = dr["arriveBillNo"].ToString();
                            model.boxNum = Convert.ToInt32(dr["boxNum"]);
                            model.financeBillNo = dr["financeBillNo"].ToString();
                            model.isrtDt = arrangeBillModel.isrtDt;
                            model.instantState = "01";
                            model.isrtEmpId = arrangeBillModel.isrtEmpId;
                            model.materialNo = dr["materialNo"].ToString();
                            model.palletIndex = Convert.ToInt32(dr["palletIndex"]);
                            model.region = Convert.ToInt32(dr["region"].ToString());

                            arrangeBillDetailBB.AddRecord(model);
                        }
                    }

                    #endregion 修改排托单信息
                }

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch
            {
                if (transaction == null) trans.Rollback("TranSave");
                throw new Exception("新增排拖单出错了!");
            }
            finally
            {
                arrangeBillBB.Dispose();
                arriveBillBB.Dispose();
                arrangeBillDetailBB.Dispose();
            }

            return ret;
        }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 /// <param name="model">model</param>
 public bool ModifyRecord(BArrangeBillDetailData model)
 {
     return this.arrangeBillDetailDB.ModifyRecord(model);
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(BArrangeBillDetailData model)
 {
     return this.arrangeBillDetailDB.AddRecord(model);
 }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(BArrangeBillDetailData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update BArrangeBillDetail set ");
            strSql.Append("arrangeBillNo=@arrangeBillNo,");
            strSql.Append("arriveBillNo=@arriveBillNo,");
            strSql.Append("financeBillNo=@financeBillNo,");
            strSql.Append("palletIndex=@palletIndex,");
            strSql.Append("materialNo=@materialNo,");
            strSql.Append("boxNum=@boxNum,");
            strSql.Append("region=@region,");
            strSql.Append("isrtEmpId=@isrtEmpId,");
            strSql.Append("isrtDt=@isrtDt,");
            strSql.Append("updtEmpId=@updtEmpId,");
            strSql.Append("updtDt=@updtDt,");
            strSql.Append("instantState=@instantState");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int),
                    new SqlParameter("@arrangeBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@arriveBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@financeBillNo", SqlDbType.VarChar,20),
                    new SqlParameter("@palletIndex", SqlDbType.Int),
                    new SqlParameter("@materialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@boxNum", SqlDbType.Int),
                    new SqlParameter("@region", SqlDbType.Int),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int),
                    new SqlParameter("@updtDt", SqlDbType.DateTime),
                    new SqlParameter("@instantState", SqlDbType.NVarChar,20)
                };
            parameters[0].Value = model.id;
            parameters[1].Value = model.arrangeBillNo;
            parameters[2].Value = model.arriveBillNo;
            parameters[3].Value = model.financeBillNo;
            parameters[4].Value = model.palletIndex;
            parameters[5].Value = model.materialNo;
            parameters[6].Value = model.boxNum;
            parameters[7].Value = model.region;
            parameters[8].Value = model.isrtEmpId;
            parameters[9].Value = model.isrtDt == string.Empty ? null : model.isrtDt;
            parameters[10].Value = model.updtEmpId;
            parameters[11].Value = model.updtDt == string.Empty ? null : model.updtDt;
            parameters[12].Value = model.instantState;

            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 BArrangeBillDetailData GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select id,arrangeBillNo,arriveBillNo,financeBillNo,palletIndex,materialNo,boxNum,region,isrtEmpId,isrtDt,updtEmpId,
                            updtDt,instantState from BArrangeBillDetail");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int)
                };
            parameters[0].Value = id;

            BArrangeBillDetailData model = new BArrangeBillDetailData();
            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["arrangeBillNo"] != DBNull.Value)
                {
                    model.arrangeBillNo = Convert.ToString(row["arrangeBillNo"]);
                }
                if (row["arriveBillNo"] != DBNull.Value)
                {
                    model.arriveBillNo = Convert.ToString(row["arriveBillNo"]);
                }
                if (row["financeBillNo"] != DBNull.Value)
                {
                    model.financeBillNo = Convert.ToString(row["financeBillNo"]);
                }
                if (row["palletIndex"] != DBNull.Value)
                {
                    model.palletIndex = Convert.ToInt32(row["palletIndex"]);
                }
                if (row["materialNo"] != DBNull.Value)
                {
                    model.materialNo = Convert.ToString(row["materialNo"]);
                }
                if (row["boxNum"] != DBNull.Value)
                {
                    model.boxNum = Convert.ToInt32(row["boxNum"]);
                }
                if (row["region"] != DBNull.Value)
                {
                    model.region = Convert.ToInt32(row["region"]);
                }
                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["instantState"] != DBNull.Value)
                {
                    model.instantState = Convert.ToString(row["instantState"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 更新一条"排托单明细"信息
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(BArrangeBillDetailData model)
        {
            bool ret = false;
            SqlTransaction trans = null;
            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransModify");
                    this.arrangeBillDetailBB.Transaction = trans;
                    this.errorDiaryBB.Transaction = trans;
                    this.operatDiaryBB.Transaction = trans;
                }

                this.arrangeBillDetailBB.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(BArrangeBillDetailData model)
        {
            int id = 0;
            SqlTransaction trans = null;
            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransAdd");
                    this.arrangeBillDetailBB.Transaction = trans;
                    this.errorDiaryBB.Transaction = trans;
                    this.operatDiaryBB.Transaction = trans;
                }

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