/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.dafenbiao model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dafenbiao("); strSql.Append("leibie,text)"); strSql.Append(" values ("); strSql.Append("@leibie,@text)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@leibie", SqlDbType.NChar, 10), new SqlParameter("@text", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.leibie; parameters[1].Value = model.text; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.dafenbiao model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dafenbiao set "); strSql.Append("leibie=@leibie,"); strSql.Append("text=@text"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@leibie", SqlDbType.NChar, 10), new SqlParameter("@text", SqlDbType.NVarChar, 50), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.leibie; parameters[1].Value = model.text; parameters[2].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtleibie.Text.Trim().Length == 0) { strErr += "leibie不能为空!\\n"; } if (this.txttext.Text.Trim().Length == 0) { strErr += "text不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); string leibie = this.txtleibie.Text; string text = this.txttext.Text; Maticsoft.Model.dafenbiao model = new Maticsoft.Model.dafenbiao(); model.id = id; model.leibie = leibie; model.text = text; Maticsoft.BLL.dafenbiao bll = new Maticsoft.BLL.dafenbiao(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtleibie.Text.Trim().Length == 0) { strErr += "leibie不能为空!\\n"; } if (this.txttext.Text.Trim().Length == 0) { strErr += "text不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string leibie = this.txtleibie.Text; string text = this.txttext.Text; Maticsoft.Model.dafenbiao model = new Maticsoft.Model.dafenbiao(); model.leibie = leibie; model.text = text; Maticsoft.BLL.dafenbiao bll = new Maticsoft.BLL.dafenbiao(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
private void ShowInfo(int id) { Maticsoft.BLL.dafenbiao bll = new Maticsoft.BLL.dafenbiao(); Maticsoft.Model.dafenbiao model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.txtleibie.Text = model.leibie; this.txttext.Text = model.text; }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.dafenbiao DataRowToModel(DataRow row) { Maticsoft.Model.dafenbiao model = new Maticsoft.Model.dafenbiao(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["leibie"] != null) { model.leibie = row["leibie"].ToString(); } if (row["text"] != null) { model.text = row["text"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.dafenbiao GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,leibie,text from dafenbiao "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Maticsoft.Model.dafenbiao model = new Maticsoft.Model.dafenbiao(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }