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