/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LCustData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into LCust("); strSql.Append(@"custNo,custNm,custSort,shippingMark,TradTerm,BLReleTerm,traySort,area,receiveAddress,factAddress, requestBill,isrtEmpId,isrtDt,updtEmpId,updtDt)"); strSql.Append(" values ("); strSql.Append(@"@custNo,@custNm,@custSort,@shippingMark,@TradTerm,@BLReleTerm,@traySort,@area,@receiveAddress,@factAddress, @requestBill,@isrtEmpId,@isrtDt,@updtEmpId,@updtDt)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@custNo", SqlDbType.VarChar,20), new SqlParameter("@custNm", SqlDbType.NVarChar,50), new SqlParameter("@custSort", SqlDbType.Char,1), new SqlParameter("@shippingMark", SqlDbType.NVarChar,50), new SqlParameter("@TradTerm", SqlDbType.NVarChar,50), new SqlParameter("@BLReleTerm", SqlDbType.NVarChar,50), new SqlParameter("@traySort", SqlDbType.NVarChar,50), new SqlParameter("@area", SqlDbType.NVarChar,50), new SqlParameter("@receiveAddress", SqlDbType.NVarChar,100), new SqlParameter("@factAddress", SqlDbType.NVarChar,100), new SqlParameter("@requestBill", SqlDbType.NVarChar,100), new SqlParameter("@isrtEmpId", SqlDbType.Int), new SqlParameter("@isrtDt", SqlDbType.DateTime), new SqlParameter("@updtEmpId", SqlDbType.Int), new SqlParameter("@updtDt", SqlDbType.DateTime) }; parameters[0].Value = model.custNo; parameters[1].Value = model.custNm; parameters[2].Value = model.custSort; parameters[3].Value = model.shippingMark; parameters[4].Value = model.TradTerm; parameters[5].Value = model.BLReleTerm; parameters[6].Value = model.traySort; parameters[7].Value = model.area; parameters[8].Value = model.receiveAddress; parameters[9].Value = model.factAddress; parameters[10].Value = model.requestBill; parameters[11].Value = model.isrtEmpId; parameters[12].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[13].Value = model.updtEmpId; parameters[14].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="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { LCustData model = new LCustData(); LCustBB custBB = new LCustBB(); try { if (this.State == "1") { this.SetModel(ref model); model.isrtDt = DateTime.Now.ToString(); model.isrtEmpId = this.currentUser.empId; this.IdValue = custBB.AddRecord(model); } else if (this.State == "2") { model = custBB.GetModel(this.IdValue); this.SetModel(ref model); model.updtDt = DateTime.Now.ToString(); model.updtEmpId = this.currentUser.empId; custBB.ModifyRecord(model); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { custBB.Dispose(); } Response.Redirect("LCustList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main", false); }
/// <summary> /// 展示数据 /// </summary> /// <param name="id">记录Id</param> private void ShowInfo(int id) { LCustBB custBB = new LCustBB(); LCustData model = new LCustData(); try { model = custBB.GetModel(id); this.custNo.Text = model.custNo; this.custNm.Text = model.custNm; this.custSort.Text = model.custSort; this.shippingMark.Text = model.shippingMark; this.TradTerm.Text = model.TradTerm; this.BLReleTerm.Text = model.BLReleTerm; this.traySort.Text = model.traySort; this.area.Text = model.area; this.receiveAddress.Text = model.receiveAddress; this.factAddress.Text = model.factAddress; this.requestBill.Text = model.requestBill; } finally { custBB.Dispose(); } }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LCustData model) { return this.custDB.ModifyRecord(model); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LCustData model) { return this.custDB.AddRecord(model); }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LCustData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update LCust set "); strSql.Append("custNo=@custNo,"); strSql.Append("custNm=@custNm,"); strSql.Append("custSort=@custSort,"); strSql.Append("shippingMark=@shippingMark,"); strSql.Append("TradTerm=@TradTerm,"); strSql.Append("BLReleTerm=@BLReleTerm,"); strSql.Append("traySort=@traySort,"); strSql.Append("area=@area,"); strSql.Append("receiveAddress=@receiveAddress,"); strSql.Append("factAddress=@factAddress,"); strSql.Append("requestBill=@requestBill,"); 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("@custNo", SqlDbType.VarChar,20), new SqlParameter("@custNm", SqlDbType.NVarChar,50), new SqlParameter("@custSort", SqlDbType.Char,1), new SqlParameter("@shippingMark", SqlDbType.NVarChar,50), new SqlParameter("@TradTerm", SqlDbType.NVarChar,50), new SqlParameter("@BLReleTerm", SqlDbType.NVarChar,50), new SqlParameter("@traySort", SqlDbType.NVarChar,50), new SqlParameter("@area", SqlDbType.NVarChar,50), new SqlParameter("@receiveAddress", SqlDbType.NVarChar,100), new SqlParameter("@factAddress", SqlDbType.NVarChar,100), new SqlParameter("@requestBill", SqlDbType.NVarChar,100), 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.custNo; parameters[2].Value = model.custNm; parameters[3].Value = model.custSort; parameters[4].Value = model.shippingMark; parameters[5].Value = model.TradTerm; parameters[6].Value = model.BLReleTerm; parameters[7].Value = model.traySort; parameters[8].Value = model.area; parameters[9].Value = model.receiveAddress; parameters[10].Value = model.factAddress; parameters[11].Value = model.requestBill; parameters[12].Value = model.isrtEmpId; parameters[13].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[14].Value = model.updtEmpId; parameters[15].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 LCustData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select id,custNo,custNm,custSort,shippingMark,TradTerm,BLReleTerm,traySort,area,receiveAddress,factAddress, requestBill,isrtEmpId,isrtDt,updtEmpId,updtDt from LCust"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; LCustData model = new LCustData(); 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["custNo"] != DBNull.Value) { model.custNo = Convert.ToString(row["custNo"]); } if (row["custNm"] != DBNull.Value) { model.custNm = Convert.ToString(row["custNm"]); } if (row["custSort"] != DBNull.Value) { model.custSort = Convert.ToString(row["custSort"]); } if (row["shippingMark"] != DBNull.Value) { model.shippingMark = Convert.ToString(row["shippingMark"]); } if (row["TradTerm"] != DBNull.Value) { model.TradTerm = Convert.ToString(row["TradTerm"]); } if (row["BLReleTerm"] != DBNull.Value) { model.BLReleTerm = Convert.ToString(row["BLReleTerm"]); } if (row["traySort"] != DBNull.Value) { model.traySort = Convert.ToString(row["traySort"]); } if (row["area"] != DBNull.Value) { model.area = Convert.ToString(row["area"]); } if (row["receiveAddress"] != DBNull.Value) { model.receiveAddress = Convert.ToString(row["receiveAddress"]); } if (row["factAddress"] != DBNull.Value) { model.factAddress = Convert.ToString(row["factAddress"]); } if (row["requestBill"] != DBNull.Value) { model.requestBill = Convert.ToString(row["requestBill"]); } 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 LCustData model) { model.custNo = this.custNo.Text; model.custNm = this.custNm.Text; model.custSort = this.custSort.Text; model.shippingMark = this.shippingMark.Text; model.TradTerm = this.TradTerm.Text; model.BLReleTerm = this.BLReleTerm.Text; model.traySort = this.traySort.Text; model.area = this.area.Text; model.receiveAddress = this.receiveAddress.Text; model.factAddress = this.factAddress.Text; model.requestBill = this.requestBill.Text; }