private void ShowInfo(int id) { Maticsoft.BLL.wuzi bll = new Maticsoft.BLL.wuzi(); Maticsoft.Model.wuzi model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.lblname.Text = model.name; this.lblgongyingshang.Text = model.gongyingshang; this.lblperson.Text = model.person; this.lblphone.Text = model.phone; this.lblbeizhu.Text = model.beizhu; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.wuzi model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wuzi set "); strSql.Append("name=@name,"); strSql.Append("gongyingshang=@gongyingshang,"); strSql.Append("person=@person,"); strSql.Append("phone=@phone,"); strSql.Append("beizhu=@beizhu,"); strSql.Append("danjia=@danjia,"); strSql.Append("beizhu2=@beizhu2,"); strSql.Append("style=@style,"); strSql.Append("danwei=@danwei"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@gongyingshang", SqlDbType.NVarChar, 50), new SqlParameter("@person", SqlDbType.NVarChar, 50), new SqlParameter("@phone", SqlDbType.NVarChar, 50), new SqlParameter("@beizhu", SqlDbType.NVarChar, 50), new SqlParameter("@danjia", SqlDbType.Money, 8), new SqlParameter("@beizhu2", SqlDbType.Text), new SqlParameter("@style", SqlDbType.Int, 4), new SqlParameter("@danwei", SqlDbType.NChar, 10), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.name; parameters[1].Value = model.gongyingshang; parameters[2].Value = model.person; parameters[3].Value = model.phone; parameters[4].Value = model.beizhu; parameters[5].Value = model.danjia; parameters[6].Value = model.beizhu2; parameters[7].Value = model.style; parameters[8].Value = model.danwei; parameters[9].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.txtname.Text.Trim().Length == 0) { strErr += "name不能为空!\\n"; } if (this.txtgongyingshang.Text.Trim().Length == 0) { strErr += "gongyingshang不能为空!\\n"; } if (this.txtperson.Text.Trim().Length == 0) { strErr += "person不能为空!\\n"; } if (this.txtphone.Text.Trim().Length == 0) { strErr += "phone不能为空!\\n"; } if (this.txtbeizhu.Text.Trim().Length == 0) { strErr += "beizhu不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); string name = this.txtname.Text; string gongyingshang = this.txtgongyingshang.Text; string person = this.txtperson.Text; string phone = this.txtphone.Text; string beizhu = this.txtbeizhu.Text; Maticsoft.Model.wuzi model = new Maticsoft.Model.wuzi(); model.id = id; model.name = name; model.gongyingshang = gongyingshang; model.person = person; model.phone = phone; model.beizhu = beizhu; Maticsoft.BLL.wuzi bll = new Maticsoft.BLL.wuzi(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.wuzi DataRowToModel(DataRow row) { Maticsoft.Model.wuzi model = new Maticsoft.Model.wuzi(); 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["gongyingshang"] != null) { model.gongyingshang = row["gongyingshang"].ToString(); } if (row["person"] != null) { model.person = row["person"].ToString(); } if (row["phone"] != null) { model.phone = row["phone"].ToString(); } if (row["beizhu"] != null) { model.beizhu = row["beizhu"].ToString(); } if (row["danjia"] != null && row["danjia"].ToString() != "") { model.danjia = decimal.Parse(row["danjia"].ToString()); } if (row["beizhu2"] != null) { model.beizhu2 = row["beizhu2"].ToString(); } if (row["style"] != null && row["style"].ToString() != "") { model.style = int.Parse(row["style"].ToString()); } if (row["danwei"] != null) { model.danwei = row["danwei"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.wuzi model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wuzi("); strSql.Append("name,gongyingshang,person,phone,beizhu,danjia,beizhu2,style,danwei)"); strSql.Append(" values ("); strSql.Append("@name,@gongyingshang,@person,@phone,@beizhu,@danjia,@beizhu2,@style,@danwei)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@gongyingshang", SqlDbType.NVarChar, 50), new SqlParameter("@person", SqlDbType.NVarChar, 50), new SqlParameter("@phone", SqlDbType.NVarChar, 50), new SqlParameter("@beizhu", SqlDbType.NVarChar, 50), new SqlParameter("@danjia", SqlDbType.Money, 8), new SqlParameter("@beizhu2", SqlDbType.Text), new SqlParameter("@style", SqlDbType.Int, 4), new SqlParameter("@danwei", SqlDbType.NChar, 10) }; parameters[0].Value = model.name; parameters[1].Value = model.gongyingshang; parameters[2].Value = model.person; parameters[3].Value = model.phone; parameters[4].Value = model.beizhu; parameters[5].Value = model.danjia; parameters[6].Value = model.beizhu2; parameters[7].Value = model.style; parameters[8].Value = model.danwei; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.wuzi GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,name,gongyingshang,person,phone,beizhu,danjia,beizhu2,style,danwei from wuzi "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Maticsoft.Model.wuzi model = new Maticsoft.Model.wuzi(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }