/// <summary> /// 数据保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { LBOMDetailData model = new LBOMDetailData(); LBOMDetailBB bOMDetailBB = new LBOMDetailBB(); try { if (this.State == "1") { this.SetModel(ref model); model.isrtDt = DateTime.Now.ToString(); model.isrtEmpId = this.currentUser.empId; this.IdValue = bOMDetailBB.AddRecord(model); } else if (this.State == "2") { model = bOMDetailBB.GetModel(this.IdValue); this.SetModel(ref model); model.updtDt = DateTime.Now.ToString(); model.updtEmpId = this.currentUser.empId; bOMDetailBB.ModifyRecord(model); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { bOMDetailBB.Dispose(); } Response.Redirect("LBOMDetailList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main", false); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LBOMDetailData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into LBOMDetail("); strSql.Append(@"BOMId,materialNo,num,isDel,isrtEmpId,isrtDt,updtEmpId,updtDt)"); strSql.Append(" values ("); strSql.Append(@"@BOMId,@materialNo,@num,@isDel,@isrtEmpId,@isrtDt,@updtEmpId,@updtDt)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@BOMId", SqlDbType.Int), new SqlParameter("@materialNo", SqlDbType.VarChar,20), new SqlParameter("@num", SqlDbType.Float), 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.BOMId; parameters[1].Value = model.materialNo; parameters[2].Value = model.num; parameters[3].Value = model.isDel; parameters[4].Value = model.isrtEmpId; parameters[5].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[6].Value = model.updtEmpId; parameters[7].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; }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LBOMDetailData model) { return this.bOMDetailDB.ModifyRecord(model); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LBOMDetailData model) { return this.bOMDetailDB.AddRecord(model); }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LBOMDetailData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update LBOMDetail set "); strSql.Append("BOMId=@BOMId,"); strSql.Append("materialNo=@materialNo,"); strSql.Append("num=@num,"); 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("@BOMId", SqlDbType.Int), new SqlParameter("@materialNo", SqlDbType.VarChar,20), new SqlParameter("@num", SqlDbType.Float), 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.BOMId; parameters[2].Value = model.materialNo; parameters[3].Value = model.num; parameters[4].Value = model.isDel; parameters[5].Value = model.isrtEmpId; parameters[6].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[7].Value = model.updtEmpId; parameters[8].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; }
/// <summary> /// 得到一个model /// </summary> /// <param name="id">主键值</param> /// <returns>model</returns> public LBOMDetailData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select id,BOMId,materialNo,num,isDel,isrtEmpId,isrtDt,updtEmpId,updtDt from LBOMDetail"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; LBOMDetailData model = new LBOMDetailData(); 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["BOMId"] != DBNull.Value) { model.BOMId = Convert.ToInt32(row["BOMId"]); } if (row["materialNo"] != DBNull.Value) { model.materialNo = Convert.ToString(row["materialNo"]); } if (row["num"] != DBNull.Value) { model.num = Convert.ToDouble(row["num"]); } 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; } }
/// <summary> /// 实体类赋值 /// </summary> /// <param name="model">实体类实例</param> private void SetModel(ref LBOMDetailData model) { if (this.id.Text != "") { model.id = Convert.ToInt32(this.id.Text); } else { model.id = 0; } if (this.BOMId.Text != "") { model.BOMId = Convert.ToInt32(this.BOMId.Text); } else { model.BOMId = 0; } model.materialNo = this.materialNo.Text; if (this.num.Text != "") { model.num = Convert.ToDouble(this.num.Text); } else { model.num = 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; }