示例#1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(LBOMData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into LBOM(");
            strSql.Append(@"materialNo,isDel,isrtEmpId,isrtDt,updtEmpId,updtDt)");
            strSql.Append(" values (");
            strSql.Append(@"@materialNo,@isDel,@isrtEmpId,@isrtDt,@updtEmpId,@updtDt)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@materialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@isDel", SqlDbType.Bit),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int),
                    new SqlParameter("@updtDt", SqlDbType.DateTime)
                };
            parameters[0].Value = model.materialNo;
            parameters[1].Value = model.isDel;
            parameters[2].Value = model.isrtEmpId;
            parameters[3].Value = model.isrtDt == string.Empty ? null : model.isrtDt;
            parameters[4].Value = model.updtEmpId;
            parameters[5].Value = model.updtDt == string.Empty ? null : model.updtDt;

            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;
        }
示例#2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(LBOMData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update LBOM set ");
            strSql.Append("materialNo=@materialNo,");
            strSql.Append("isDel=@isDel,");
            strSql.Append("isrtEmpId=@isrtEmpId,");
            strSql.Append("isrtDt=@isrtDt,");
            strSql.Append("updtEmpId=@updtEmpId,");
            strSql.Append("updtDt=@updtDt");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int),
                    new SqlParameter("@materialNo", SqlDbType.VarChar,20),
                    new SqlParameter("@isDel", SqlDbType.Bit),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int),
                    new SqlParameter("@updtDt", SqlDbType.DateTime)
                };
            parameters[0].Value = model.id;
            parameters[1].Value = model.materialNo;
            parameters[2].Value = model.isDel;
            parameters[3].Value = model.isrtEmpId;
            parameters[4].Value = model.isrtDt == string.Empty ? null : model.isrtDt;
            parameters[5].Value = model.updtEmpId;
            parameters[6].Value = model.updtDt == string.Empty ? null : model.updtDt;

            try
            {
                SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
示例#3
0
    /// <summary>
    /// 数据保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        LBOMData model = new LBOMData();
        LBOMBC bOMBC = new LBOMBC();
        LBOMBB bOMBB = new LBOMBB();
        try
        {

            #region 检查表单数据是否正确
            if (string.IsNullOrEmpty(materialNo.Text.Trim()))
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "alertMsg", "alert(\"请选择物料!\");", true);
                return;
            }

            model = bOMBB.GetModel(materialNo.Text.Trim());
            int num = 0;
            foreach (DataRow dr in this.DtResult.Rows)
            {
                if (!int.TryParse(dr["num"].ToString(), out num))
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alertMsg", "alert(\"物料清单明细数量不能为0!\");", true);
                    return;
                }
                DataRow[] drs = this.DtResult.Select(" materialno='" + dr["materialno"].ToString() + "' and isdel=0");
                if (drs.Length > 1)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alertMsg", "alert(\"物料清单明细存在重复项!\");", true);
                    return;
                }
            }

            if (this.State == "1")
            {
                if (model != null)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alertMsg", "alert(\"物料清单已经存在!\");", true);
                    return;
                }
            #endregion
                model = new LBOMData();
                model.materialNo = materialNo.Text;
                model.isrtDt = DateTime.Now.ToString();
                model.isrtEmpId = this.currentUser.empId;
                this.State = "2";
            }
            else if (this.State == "2")
            {

                model.materialNo = materialNo.Text;
                model.updtDt = DateTime.Now.ToString();
                model.updtEmpId = this.currentUser.empId;

            }
            if (bOMBC.SaveBOMBill(model, this.DtResult))
            {
                this.IdValue = model.id;
                this.ClientScript.RegisterStartupScript(this.GetType(), "alertMsg", "alert(\"保存成功\");location.replace(\"LBOMList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main\");", true);

            }
            else
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "alertMsg", "alert(\"保存失败\");", true);
            }

        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            bOMBC.Dispose();
            bOMBB.Dispose();
        }

        // Response.Redirect("LBOMList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main", false);
    }
示例#4
0
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// 得到一个model
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns>model</returns>
        public LBOMData GetModel(string materialNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select id,materialNo,isDel,isrtEmpId,isrtDt,updtEmpId,updtDt from LBOM");
            strSql.Append(" where materialNo = @materialNo ");
            SqlParameter[] parameters = {
                    new SqlParameter("@materialNo",materialNo)
                };

            LBOMData model = new LBOMData();
            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["isDel"] != DBNull.Value)
                {
                    model.isDel = Convert.ToBoolean(row["isDel"]);
                }
                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"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }
示例#5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 /// <param name="model">model</param>
 public bool ModifyRecord(LBOMData model)
 {
     return this.bOMDB.ModifyRecord(model);
 }
示例#6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(LBOMData model)
 {
     return this.bOMDB.AddRecord(model);
 }
示例#7
0
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// 保存BOM
        /// </summary>
        /// <param name="arrangeBillModel"></param>
        /// <param name="dtArrange"></param>
        /// <param name="isSubmit"></param>
        /// <returns></returns>
        public bool SaveBOMBill(LBOMData  lBOMmodel, DataTable  data)
        {
            bool ret = false;
            LBOMBB  lbomBB = new LBOMBB(connection);
            LBOMDetailBB lbomDetailBB = new LBOMDetailBB(connection);
            SqlTransaction trans = null;

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TranSave");
                    lbomDetailBB.Transaction = trans;
                    lbomBB.Transaction = trans;
                }
                else
                {
                    lbomDetailBB.Transaction = this.transaction;
                    lbomBB.Transaction = this.transaction;
                }

                if (lBOMmodel.id == 0)//新增物料清单
                {
                    #region 新增物料清单

                    //新增物料清单信息
                    int bomid = lbomBB.AddRecord(lBOMmodel);

                    foreach (DataRow dr in data.Rows)
                    {
                        if (dr["isdel"].ToString() == "0")//未删除
                        {
                            LBOMDetailData model = new LBOMDetailData();
                            model.BOMId = bomid;
                            model.isrtDt = lBOMmodel.isrtDt;
                            model.isrtEmpId = lBOMmodel.isrtEmpId;
                            model.materialNo = dr["materialNo"].ToString();
                            model.num = Convert.ToInt32(dr["num"]);
                            lbomDetailBB.AddRecord(model);
                        }
                    }

                    #endregion 新增物料清单
                }
                else
                {
                    #region 修改物料清单信息

                    //修改物料清单信息
                    lbomBB.ModifyRecord(lBOMmodel);

                    foreach (DataRow dr in data.Rows)
                    {
                        if (Convert.ToInt32(dr["id"]) > 0 && dr["isdel"].ToString() == "1")//删除方法
                        {
                            lbomDetailBB.DeleteRecord(Convert.ToInt32(dr["id"]));
                        }
                        else if (Convert.ToInt32(dr["id"]) > 0 && dr["isdel"].ToString() == "0")//修改
                        {
                            LBOMDetailData model = lbomDetailBB.GetModel(Convert.ToInt32(dr["id"]));
                            model.BOMId = lBOMmodel.id;
                            model.isrtDt = lBOMmodel.isrtDt;
                            model.isrtEmpId = lBOMmodel.isrtEmpId;
                            model.materialNo = dr["materialNo"].ToString();
                            model.updtDt = lBOMmodel.updtDt;
                            model.updtEmpId = lBOMmodel.updtEmpId;
                            model.num = Convert.ToInt32(dr["num"]);

                            lbomDetailBB.ModifyRecord(model);
                        }
                        else if (Convert.ToInt32(dr["id"]) == 0 && dr["isdel"].ToString() == "0")//添加
                        {
                            LBOMDetailData model = new LBOMDetailData();
                            model.BOMId = lBOMmodel.id;
                            model.isrtDt = lBOMmodel.isrtDt;
                            model.isrtEmpId = lBOMmodel.isrtEmpId;
                            model.materialNo = dr["materialNo"].ToString();
                            model.num = Convert.ToInt32(dr["num"]);
                            lbomDetailBB.AddRecord(model);
                        }
                    }

                    #endregion 修改物料清单信息
                }

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch
            {
                if (transaction == null) trans.Rollback("TranSave");
                throw new Exception("保存物料清单信息出错了!");
            }
            finally
            {
                lbomBB.Dispose();
                lbomDetailBB.Dispose();

            }

            return ret;
        }
示例#8
0
        /// <summary>
        /// 更新一条"物料清单"信息
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(LBOMData model)
        {
            bool ret = false;
            SqlTransaction trans = null;
            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransModify");
                    this.bOMBB.Transaction = trans;
                    this.errorDiaryBB.Transaction = trans;
                    this.operatDiaryBB.Transaction = trans;
                }

                this.bOMBB.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;
        }
示例#9
0
        /// <summary>
        /// 增加一条"物料清单"信息
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(LBOMData model)
        {
            int id = 0;
            SqlTransaction trans = null;
            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransAdd");
                    this.bOMBB.Transaction = trans;
                    this.errorDiaryBB.Transaction = trans;
                    this.operatDiaryBB.Transaction = trans;
                }

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