/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.fenzu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update fenzu set "); strSql.Append("qishu=@qishu,"); strSql.Append("zushu=@zushu,"); strSql.Append("zuming=@zuming"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@qishu", SqlDbType.NChar, 10), new SqlParameter("@zushu", SqlDbType.Int, 4), new SqlParameter("@zuming", SqlDbType.NVarChar, 50), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.qishu; parameters[1].Value = model.zushu; parameters[2].Value = model.zuming; parameters[3].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.fenzu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into fenzu("); strSql.Append("qishu,zushu,zuming)"); strSql.Append(" values ("); strSql.Append("@qishu,@zushu,@zuming)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@qishu", SqlDbType.NChar, 10), new SqlParameter("@zushu", SqlDbType.Int, 4), new SqlParameter("@zuming", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.qishu; parameters[1].Value = model.zushu; parameters[2].Value = model.zuming; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void ShowInfo(int id) { Maticsoft.BLL.fenzu bll = new Maticsoft.BLL.fenzu(); Maticsoft.Model.fenzu model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.lblqishu.Text = model.qishu; this.lblzushu.Text = model.zushu.ToString(); this.lblzuming.Text = model.zuming; }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtqishu.Text.Trim().Length == 0) { strErr += "qishu不能为空!\\n"; } if (!PageValidate.IsNumber(txtzushu.Text)) { strErr += "zushu格式错误!\\n"; } if (this.txtzuming.Text.Trim().Length == 0) { strErr += "zuming不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); string qishu = this.txtqishu.Text; int zushu = int.Parse(this.txtzushu.Text); string zuming = this.txtzuming.Text; Maticsoft.Model.fenzu model = new Maticsoft.Model.fenzu(); model.id = id; model.qishu = qishu; model.zushu = zushu; model.zuming = zuming; Maticsoft.BLL.fenzu bll = new Maticsoft.BLL.fenzu(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; //if(this.txtqishu.Text.Trim().Length==0) //{ // strErr+="qishu不能为空!\\n"; //} //if(!PageValidate.IsNumber(txtzushu.Text)) //{ // strErr+="zushu格式错误!\\n"; //} if (this.txtzuming.Text.Trim().Length == 0) { strErr += "zuming不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } //string qishu = this.DropDownList2.SelectedValue; int zushu = int.Parse(this.DropDownList1.SelectedValue); string zuming = this.txtzuming.Text; Maticsoft.Model.fenzu model = new Maticsoft.Model.fenzu(); model.qishu = Label2.Text.ToString().Trim(); model.zushu = zushu; model.zuming = zuming; Maticsoft.BLL.fenzu bll = new Maticsoft.BLL.fenzu(); bll.Add(model); string add_str = "add.aspx?qishu=" + Label2.Text + "&name=" + Label1.Text; Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", add_str); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.fenzu DataRowToModel(DataRow row) { Maticsoft.Model.fenzu model = new Maticsoft.Model.fenzu(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["qishu"] != null) { model.qishu = row["qishu"].ToString(); } if (row["zushu"] != null && row["zushu"].ToString() != "") { model.zushu = int.Parse(row["zushu"].ToString()); } if (row["zuming"] != null) { model.zuming = row["zuming"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.fenzu GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,qishu,zushu,zuming from fenzu "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Maticsoft.Model.fenzu model = new Maticsoft.Model.fenzu(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }