/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.account_detail model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update account_detail set "); strSql.Append("wuzi=@wuzi,"); strSql.Append("danwei=@danwei,"); strSql.Append("danjia=@danjia,"); strSql.Append("shuliang=@shuliang,"); strSql.Append("account_id=@account_id,"); strSql.Append("wuzi_id=@wuzi_id,"); strSql.Append("beizhu=@beizhu,"); strSql.Append("beizhu2=@beizhu2,"); strSql.Append("beizhu3=@beizhu3"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@wuzi", SqlDbType.NChar, 50), new SqlParameter("@danwei", SqlDbType.NChar, 10), new SqlParameter("@danjia", SqlDbType.Money, 8), new SqlParameter("@shuliang", SqlDbType.Int, 4), new SqlParameter("@account_id", SqlDbType.Int, 4), new SqlParameter("@wuzi_id", SqlDbType.Int, 4), new SqlParameter("@beizhu", SqlDbType.NChar, 50), new SqlParameter("@beizhu2", SqlDbType.NChar, 50), new SqlParameter("@beizhu3", SqlDbType.NChar, 50), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.wuzi; parameters[1].Value = model.danwei; parameters[2].Value = model.danjia; parameters[3].Value = model.shuliang; parameters[4].Value = model.account_id; parameters[5].Value = model.wuzi_id; parameters[6].Value = model.beizhu; parameters[7].Value = model.beizhu2; parameters[8].Value = model.beizhu3; parameters[9].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(int id) { Maticsoft.BLL.account_detail bll = new Maticsoft.BLL.account_detail(); Maticsoft.Model.account_detail model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.txtwuzi.Text = model.wuzi; this.txtdanwei.Text = model.danwei; this.txtdanjia.Text = model.danjia.ToString(); this.txtshuliang.Text = model.shuliang.ToString(); this.txtaccount_id.Text = model.account_id.ToString(); this.txtwuzi_id.Text = model.wuzi_id.ToString(); this.txtbeizhu.Text = model.beizhu; this.txtbeizhu2.Text = model.beizhu2; this.txtbeizhu3.Text = model.beizhu3; }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.account_detail DataRowToModel(DataRow row) { Maticsoft.Model.account_detail model = new Maticsoft.Model.account_detail(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["wuzi"] != null) { model.wuzi = row["wuzi"].ToString(); } if (row["danwei"] != null) { model.danwei = row["danwei"].ToString(); } if (row["danjia"] != null && row["danjia"].ToString() != "") { model.danjia = decimal.Parse(row["danjia"].ToString()); } if (row["shuliang"] != null && row["shuliang"].ToString() != "") { model.shuliang = int.Parse(row["shuliang"].ToString()); } if (row["account_id"] != null && row["account_id"].ToString() != "") { model.account_id = int.Parse(row["account_id"].ToString()); } if (row["wuzi_id"] != null && row["wuzi_id"].ToString() != "") { model.wuzi_id = int.Parse(row["wuzi_id"].ToString()); } if (row["beizhu"] != null) { model.beizhu = row["beizhu"].ToString(); } if (row["beizhu2"] != null) { model.beizhu2 = row["beizhu2"].ToString(); } if (row["beizhu3"] != null) { model.beizhu3 = row["beizhu3"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.account_detail model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into account_detail("); strSql.Append("wuzi,danwei,danjia,shuliang,account_id,wuzi_id,beizhu,beizhu2,beizhu3)"); strSql.Append(" values ("); strSql.Append("@wuzi,@danwei,@danjia,@shuliang,@account_id,@wuzi_id,@beizhu,@beizhu2,@beizhu3)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@wuzi", SqlDbType.NChar, 50), new SqlParameter("@danwei", SqlDbType.NChar, 10), new SqlParameter("@danjia", SqlDbType.Money, 8), new SqlParameter("@shuliang", SqlDbType.Int, 4), new SqlParameter("@account_id", SqlDbType.Int, 4), new SqlParameter("@wuzi_id", SqlDbType.Int, 4), new SqlParameter("@beizhu", SqlDbType.NChar, 50), new SqlParameter("@beizhu2", SqlDbType.NChar, 50), new SqlParameter("@beizhu3", SqlDbType.NChar, 50) }; parameters[0].Value = model.wuzi; parameters[1].Value = model.danwei; parameters[2].Value = model.danjia; parameters[3].Value = model.shuliang; parameters[4].Value = model.account_id; parameters[5].Value = model.wuzi_id; parameters[6].Value = model.beizhu; parameters[7].Value = model.beizhu2; parameters[8].Value = model.beizhu3; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.account_detail GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,wuzi,danwei,danjia,shuliang,account_id,wuzi_id,beizhu,beizhu2,beizhu3 from account_detail "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Maticsoft.Model.account_detail model = new Maticsoft.Model.account_detail(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtwuzi.Text.Trim().Length == 0) { strErr += "wuzi不能为空!\\n"; } if (this.txtdanwei.Text.Trim().Length == 0) { strErr += "danwei不能为空!\\n"; } if (!PageValidate.IsDecimal(txtdanjia.Text)) { strErr += "danjia格式错误!\\n"; } if (!PageValidate.IsNumber(txtshuliang.Text)) { strErr += "shuliang格式错误!\\n"; } if (!PageValidate.IsNumber(txtaccount_id.Text)) { strErr += "account_id格式错误!\\n"; } if (!PageValidate.IsNumber(txtwuzi_id.Text)) { strErr += "wuzi_id格式错误!\\n"; } if (this.txtbeizhu.Text.Trim().Length == 0) { strErr += "beizhu不能为空!\\n"; } if (this.txtbeizhu2.Text.Trim().Length == 0) { strErr += "beizhu2不能为空!\\n"; } if (this.txtbeizhu3.Text.Trim().Length == 0) { strErr += "beizhu3不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); string wuzi = this.txtwuzi.Text; string danwei = this.txtdanwei.Text; decimal danjia = decimal.Parse(this.txtdanjia.Text); int shuliang = int.Parse(this.txtshuliang.Text); int account_id = int.Parse(this.txtaccount_id.Text); int wuzi_id = int.Parse(this.txtwuzi_id.Text); string beizhu = this.txtbeizhu.Text; string beizhu2 = this.txtbeizhu2.Text; string beizhu3 = this.txtbeizhu3.Text; Maticsoft.Model.account_detail model = new Maticsoft.Model.account_detail(); model.id = id; model.wuzi = wuzi; model.danwei = danwei; model.danjia = danjia; model.shuliang = shuliang; model.account_id = account_id; model.wuzi_id = wuzi_id; model.beizhu = beizhu; model.beizhu2 = beizhu2; model.beizhu3 = beizhu3; Maticsoft.BLL.account_detail bll = new Maticsoft.BLL.account_detail(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }