/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.atbiao model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update atbiao set "); strSql.Append("ids=@ids,"); strSql.Append("total=@total"); strSql.Append(" where id=@id and data_num=@data_num "); SqlParameter[] parameters = { new SqlParameter("@ids", SqlDbType.VarChar, 8000), new SqlParameter("@total", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.VarChar, 20), new SqlParameter("@data_num", SqlDbType.Int, 4) }; parameters[0].Value = model.ids; parameters[1].Value = model.total; parameters[2].Value = model.id; parameters[3].Value = model.data_num; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.atbiao model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into atbiao("); strSql.Append("id,data_num,ids,total)"); strSql.Append(" values ("); strSql.Append("@id,@data_num,@ids,@total)"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.VarChar, 20), new SqlParameter("@data_num", SqlDbType.Int, 4), new SqlParameter("@ids", SqlDbType.VarChar, 8000), new SqlParameter("@total", SqlDbType.Int, 4) }; parameters[0].Value = model.id; parameters[1].Value = model.data_num; parameters[2].Value = model.ids; parameters[3].Value = model.total; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.atbiao GetModel(string id, int data_num) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,data_num,ids,total from atbiao "); strSql.Append(" where id=@id and data_num=@data_num "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.VarChar, 20), new SqlParameter("@data_num", SqlDbType.Int, 4) }; parameters[0].Value = id; parameters[1].Value = data_num; Maticsoft.Model.atbiao model = new Maticsoft.Model.atbiao(); 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.txtids.Text.Trim().Length == 0) { strErr += "ids不能为空!\\n"; } if (!PageValidate.IsNumber(txttotal.Text)) { strErr += "total格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string id = this.lblid.Text; int data_num = int.Parse(this.lbldata_num.Text); string ids = this.txtids.Text; int total = int.Parse(this.txttotal.Text); Maticsoft.Model.atbiao model = new Maticsoft.Model.atbiao(); model.id = id; model.data_num = data_num; model.ids = ids; model.total = total; Maticsoft.BLL.atbiao bll = new Maticsoft.BLL.atbiao(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
private void ShowInfo(string id, int data_num) { Maticsoft.BLL.atbiao bll = new Maticsoft.BLL.atbiao(); Maticsoft.Model.atbiao model = bll.GetModel(id, data_num); this.lblid.Text = model.id; this.lbldata_num.Text = model.data_num.ToString(); this.lblids.Text = model.ids; this.lbltotal.Text = model.total.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.atbiao DataRowToModel(DataRow row) { Maticsoft.Model.atbiao model = new Maticsoft.Model.atbiao(); if (row != null) { if (row["id"] != null) { model.id = row["id"].ToString(); } if (row["data_num"] != null && row["data_num"].ToString() != "") { model.data_num = int.Parse(row["data_num"].ToString()); } if (row["ids"] != null) { model.ids = row["ids"].ToString(); } if (row["total"] != null && row["total"].ToString() != "") { model.total = int.Parse(row["total"].ToString()); } } return(model); }