/// <summary> /// 更新一条数据 /// </summary> public bool Update(TB_AccountPeriod model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update TB_AccountPeriod set "); if (model.AccountName != null) { strSql.Append("AccountName=" + model.AccountName + ","); } if (model.AccountXiShu != null) { strSql.Append("AccountXiShu=" + model.AccountXiShu + ","); } if (model.Remark != null) { strSql.Append("Remark='" + model.Remark + "',"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where Id=" + model.Id + ""); bool rowsAffected = DBHelp.ExeCommand(strSql.ToString()); return(rowsAffected); }
protected void btnUpdate_Click(object sender, EventArgs e) { if (this.FormCheck()) { try { string sqlCheck = string.Format("select count(*) from TB_AccountPeriod where AccountName={0} and Id<>{1}", txtAccountName.Text, Request["Id"]); if (Convert.ToInt32(DBHelp.ExeScalar(sqlCheck)) > 0) { base.ClientScript.RegisterStartupScript(base.GetType(), null, string.Format("<script>alert('账期[{0}],已经存在!');</script>", txtAccountName.Text)); return; } TB_AccountPeriod per = getModel(); if (this.accSer.Update(per)) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('修改成功!');</script>"); } else { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('修改失败!');</script>"); } } catch (Exception ex) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('" + ex.Message + "!');</script>"); } } }
/// <summary> /// 得到一个对象实体 /// </summary> public TB_AccountPeriod GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); strSql.Append(" Id,AccountName,AccountXiShu,Remark "); strSql.Append(" from TB_AccountPeriod "); strSql.Append(" where Id=" + ID + ""); TB_AccountPeriod model = null; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlCommand objCommand = new SqlCommand(strSql.ToString(), conn); using (SqlDataReader objReader = objCommand.ExecuteReader()) { if (objReader.Read()) { model = ReaderBind(objReader); } } } return(model); }
public TB_AccountPeriod getModel() { TB_AccountPeriod model = new TB_AccountPeriod(); model.AccountName = Convert.ToInt32(txtAccountName.Text); model.AccountXiShu = Convert.ToInt32(txtAccountXiShu.Text); model.Remark = txtRemark.Text; if (Request["Id"] != null) { model.Id = Convert.ToInt32(Request["Id"]); } return(model); }
protected void Page_Load(object sender, EventArgs e) { if (!base.IsPostBack) { if (base.Request["Id"] != null) { this.btnAdd.Visible = false; TB_AccountPeriod model = this.accSer.GetModel(Convert.ToInt32(base.Request["Id"])); txtAccountName.Text = model.AccountName.ToString(); txtAccountXiShu.Text = model.AccountXiShu.ToString(); txtRemark.Text = model.Remark; } else { this.btnUpdate.Visible = false; } } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(TB_AccountPeriod model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.AccountName != null) { strSql1.Append("AccountName,"); strSql2.Append("" + model.AccountName + ","); } if (model.AccountXiShu != null) { strSql1.Append("AccountXiShu,"); strSql2.Append("" + model.AccountXiShu + ","); } if (model.Remark != null) { strSql1.Append("Remark,"); strSql2.Append("'" + model.Remark + "',"); } strSql.Append("insert into TB_AccountPeriod("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); strSql.Append(";select @@IDENTITY"); object obj = DBHelp.ExeScalar(strSql.ToString()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 对象实体绑定数据 /// </summary> public TB_AccountPeriod ReaderBind(IDataReader dataReader) { TB_AccountPeriod model = new TB_AccountPeriod(); object ojb; ojb = dataReader["Id"]; if (ojb != null && ojb != DBNull.Value) { model.Id = (int)ojb; } ojb = dataReader["AccountName"]; if (ojb != null && ojb != DBNull.Value) { model.AccountName = (decimal)ojb; } ojb = dataReader["AccountXiShu"]; if (ojb != null && ojb != DBNull.Value) { model.AccountXiShu = (decimal)ojb; } model.Remark = dataReader["Remark"].ToString(); return(model); }