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.hufen model = new Maticsoft.Model.hufen(); model.id = id; model.data_num = data_num; model.ids = ids; model.total = total; Maticsoft.BLL.hufen bll = new Maticsoft.BLL.hufen(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.hufen model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update hufen set "); strSql.Append("ids=SQL2012ids,"); strSql.Append("total=SQL2012total"); strSql.Append(" where id=SQL2012id and data_num=SQL2012data_num "); SqlParameter[] parameters = { new SqlParameter("SQL2012ids", SqlDbType.VarChar, 8000), new SqlParameter("SQL2012total", SqlDbType.Int, 4), new SqlParameter("SQL2012id", SqlDbType.VarChar, 20), new SqlParameter("SQL2012data_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.hufen model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hufen("); strSql.Append("id,data_num,ids,total)"); strSql.Append(" values ("); strSql.Append("SQL2012id,SQL2012data_num,SQL2012ids,SQL2012total)"); SqlParameter[] parameters = { new SqlParameter("SQL2012id", SqlDbType.VarChar, 20), new SqlParameter("SQL2012data_num", SqlDbType.Int, 4), new SqlParameter("SQL2012ids", SqlDbType.VarChar, 8000), new SqlParameter("SQL2012total", 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.hufen GetModel(string id, int data_num) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,data_num,ids,total from hufen "); strSql.Append(" where id=SQL2012id and data_num=SQL2012data_num "); SqlParameter[] parameters = { new SqlParameter("SQL2012id", SqlDbType.VarChar, 20), new SqlParameter("SQL2012data_num", SqlDbType.Int, 4) }; parameters[0].Value = id; parameters[1].Value = data_num; Maticsoft.Model.hufen model = new Maticsoft.Model.hufen(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void ShowInfo(string id, int data_num) { Maticsoft.BLL.hufen bll = new Maticsoft.BLL.hufen(); Maticsoft.Model.hufen model = bll.GetModel(id, data_num); this.lblid.Text = model.id; this.lbldata_num.Text = model.data_num.ToString(); this.txtids.Text = model.ids; this.txttotal.Text = model.total.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.hufen DataRowToModel(DataRow row) { Maticsoft.Model.hufen model = new Maticsoft.Model.hufen(); 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); }