/// <summary> /// 增加一条数据 /// </summary> public int Add(CHSS.Model.CBusinessAgent model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CBusinessAgent("); strSql.Append("BusiDescription,BusiAddDate,BusiName,BusiPhone,UID)"); strSql.Append(" values ("); strSql.Append("@BusiDescription,@BusiAddDate,@BusiName,@BusiPhone,@UID)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@BusiDescription", SqlDbType.NVarChar, 200), new SqlParameter("@BusiAddDate", SqlDbType.NVarChar, 20), new SqlParameter("@BusiName", SqlDbType.NVarChar, 20), new SqlParameter("@BusiPhone", SqlDbType.NChar, 11), new SqlParameter("@UID", SqlDbType.Int, 4) }; parameters[0].Value = model.BusiDescription; parameters[1].Value = model.BusiAddDate; parameters[2].Value = model.BusiName; parameters[3].Value = model.BusiPhone; parameters[4].Value = model.UID; object obj = DBHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CHSS.Model.CBusinessAgent DataRowToModel(DataRow row) { CHSS.Model.CBusinessAgent model = new CHSS.Model.CBusinessAgent(); if (row != null) { if (row["BID"] != null && row["BID"].ToString() != "") { model.BID = int.Parse(row["BID"].ToString()); } if (row["BusiDescription"] != null) { model.BusiDescription = row["BusiDescription"].ToString(); } if (row["BusiAddDate"] != null) { model.BusiAddDate = row["BusiAddDate"].ToString(); } if (row["BusiName"] != null) { model.BusiName = row["BusiName"].ToString(); } if (row["BusiPhone"] != null) { model.BusiPhone = row["BusiPhone"].ToString(); } if (row["UID"] != null && row["UID"].ToString() != "") { model.UID = int.Parse(row["UID"].ToString()); } } return(model); }
private void ShowInfo(int BID) { CHSS.BLL.CBusinessAgent bll = new CHSS.BLL.CBusinessAgent(); CHSS.Model.CBusinessAgent model = bll.GetModel(BID); this.txtBID.Text = model.BID.ToString(); this.txtBusiDescription.Text = model.BusiDescription; this.txtBusiAddDate.Text = model.BusiAddDate; this.txtBusiName.Text = model.BusiName; this.txtBusiPhone.Text = model.BusiPhone; }
protected void btnSave_Click(object sender, EventArgs e) { string BusiDescription = this.txtBusiDescription.Text; string BusiAddDate = this.txtBusiAddDate.Text; string BusiName = this.txtBusiName.Text; string BusiPhone = this.txtBusiPhone.Text; int UID = int.Parse(Session["UID"].ToString()); CHSS.Model.CBusinessAgent model = new CHSS.Model.CBusinessAgent(); model.BusiDescription = BusiDescription; model.BusiAddDate = BusiAddDate; model.BusiName = BusiName; model.BusiPhone = BusiPhone; model.UID = UID; CHSS.BLL.CBusinessAgent bll = new CHSS.BLL.CBusinessAgent(); bll.Add(model); Response.Redirect("Show.aspx?id=" + (bll.GetMaxId() - 1)); }
public void btnSave_Click(object sender, EventArgs e) { int BID = int.Parse(this.txtBID.Text); string BusiDescription = this.txtBusiDescription.Text; string BusiAddDate = this.txtBusiAddDate.Text; string BusiName = this.txtBusiName.Text; string BusiPhone = this.txtBusiPhone.Text; int UID = int.Parse(Session["UID"].ToString()); CHSS.Model.CBusinessAgent model = new CHSS.Model.CBusinessAgent(); model.BID = BID; model.BusiDescription = BusiDescription; model.BusiAddDate = BusiAddDate; model.BusiName = BusiName; model.BusiPhone = BusiPhone; model.UID = UID; CHSS.BLL.CBusinessAgent bll = new CHSS.BLL.CBusinessAgent(); bll.Update(model); Response.Redirect("Show.aspx?id=" + BID); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(CHSS.Model.CBusinessAgent model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CBusinessAgent set "); strSql.Append("BusiDescription=@BusiDescription,"); strSql.Append("BusiAddDate=@BusiAddDate,"); strSql.Append("BusiName=@BusiName,"); strSql.Append("BusiPhone=@BusiPhone,"); strSql.Append("UID=@UID"); strSql.Append(" where BID=@BID"); SqlParameter[] parameters = { new SqlParameter("@BusiDescription", SqlDbType.NVarChar, 200), new SqlParameter("@BusiAddDate", SqlDbType.NVarChar, 20), new SqlParameter("@BusiName", SqlDbType.NVarChar, 20), new SqlParameter("@BusiPhone", SqlDbType.NChar, 11), new SqlParameter("@UID", SqlDbType.Int, 4), new SqlParameter("@BID", SqlDbType.Int, 4) }; parameters[0].Value = model.BusiDescription; parameters[1].Value = model.BusiAddDate; parameters[2].Value = model.BusiName; parameters[3].Value = model.BusiPhone; parameters[4].Value = model.UID; parameters[5].Value = model.BID; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CHSS.Model.CBusinessAgent GetModel(int BID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 BID,BusiDescription,BusiAddDate,BusiName,BusiPhone,UID from CBusinessAgent "); strSql.Append(" where BID=@BID"); SqlParameter[] parameters = { new SqlParameter("@BID", SqlDbType.Int, 4) }; parameters[0].Value = BID; CHSS.Model.CBusinessAgent model = new CHSS.Model.CBusinessAgent(); DataSet ds = DBHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }