protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtoption_id.Text)) { strErr += "option_id格式错误!\\n"; } if (!PageValidate.IsDecimal(txtan_int.Text)) { strErr += "an_int格式错误!\\n"; } if (this.txtan_text.Text.Trim().Length == 0) { strErr += "an_text不能为空!\\n"; } if (this.txtopen_id.Text.Trim().Length == 0) { strErr += "open_id不能为空!\\n"; } if (this.txtname.Text.Trim().Length == 0) { strErr += "name不能为空!\\n"; } if (!PageValidate.IsDateTime(txttime.Text)) { strErr += "time格式错误!\\n"; } if (this.txtbeizhu.Text.Trim().Length == 0) { strErr += "beizhu不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int option_id = int.Parse(this.txtoption_id.Text); decimal an_int = decimal.Parse(this.txtan_int.Text); string an_text = this.txtan_text.Text; string open_id = this.txtopen_id.Text; string name = this.txtname.Text; DateTime time = DateTime.Parse(this.txttime.Text); string beizhu = this.txtbeizhu.Text; Maticsoft.Model.inv_answer model = new Maticsoft.Model.inv_answer(); model.option_id = option_id; model.an_int = an_int; model.an_text = an_text; model.open_id = open_id; model.name = name; model.time = time; model.beizhu = beizhu; Maticsoft.BLL.inv_answer bll = new Maticsoft.BLL.inv_answer(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
private void ShowInfo(int id) { Maticsoft.BLL.inv_answer bll = new Maticsoft.BLL.inv_answer(); Maticsoft.Model.inv_answer model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.lbloption_id.Text = model.option_id.ToString(); this.lblan_int.Text = model.an_int.ToString(); this.lblan_text.Text = model.an_text; this.lblopen_id.Text = model.open_id; this.lblname.Text = model.name; this.lbltime.Text = model.time.ToString(); this.lblbeizhu.Text = model.beizhu; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.inv_answer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update inv_answer set "); strSql.Append("option_id=@option_id,"); strSql.Append("an_int=@an_int,"); strSql.Append("an_text=@an_text,"); strSql.Append("open_id=@open_id,"); strSql.Append("name=@name,"); strSql.Append("time=@time,"); strSql.Append("beizhu=@beizhu,"); strSql.Append("que_id=@que_id"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@option_id", SqlDbType.Int, 4), new SqlParameter("@an_int", SqlDbType.Float, 8), new SqlParameter("@an_text", SqlDbType.NChar, 10), new SqlParameter("@open_id", SqlDbType.NChar, 50), new SqlParameter("@name", SqlDbType.NChar, 50), new SqlParameter("@time", SqlDbType.DateTime), new SqlParameter("@beizhu", SqlDbType.NChar, 50), new SqlParameter("@que_id", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.option_id; parameters[1].Value = model.an_int; parameters[2].Value = model.an_text; parameters[3].Value = model.open_id; parameters[4].Value = model.name; parameters[5].Value = model.time; parameters[6].Value = model.beizhu; parameters[7].Value = model.que_id; parameters[8].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.inv_answer DataRowToModel(DataRow row) { Maticsoft.Model.inv_answer model = new Maticsoft.Model.inv_answer(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["option_id"] != null && row["option_id"].ToString() != "") { model.option_id = int.Parse(row["option_id"].ToString()); } if (row["an_int"] != null && row["an_int"].ToString() != "") { model.an_int = decimal.Parse(row["an_int"].ToString()); } if (row["an_text"] != null) { model.an_text = row["an_text"].ToString(); } if (row["open_id"] != null) { model.open_id = row["open_id"].ToString(); } if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["time"] != null && row["time"].ToString() != "") { model.time = DateTime.Parse(row["time"].ToString()); } if (row["beizhu"] != null) { model.beizhu = row["beizhu"].ToString(); } if (row["que_id"] != null && row["que_id"].ToString() != "") { model.que_id = int.Parse(row["que_id"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.inv_answer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into inv_answer("); strSql.Append("option_id,an_int,an_text,open_id,name,time,beizhu,que_id)"); strSql.Append(" values ("); strSql.Append("@option_id,@an_int,@an_text,@open_id,@name,@time,@beizhu,@que_id)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@option_id", SqlDbType.Int, 4), new SqlParameter("@an_int", SqlDbType.Float, 8), new SqlParameter("@an_text", SqlDbType.NChar, 10), new SqlParameter("@open_id", SqlDbType.NChar, 50), new SqlParameter("@name", SqlDbType.NChar, 50), new SqlParameter("@time", SqlDbType.DateTime), new SqlParameter("@beizhu", SqlDbType.NChar, 50), new SqlParameter("@que_id", SqlDbType.Int, 4) }; parameters[0].Value = model.option_id; parameters[1].Value = model.an_int; parameters[2].Value = model.an_text; parameters[3].Value = model.open_id; parameters[4].Value = model.name; parameters[5].Value = model.time; parameters[6].Value = model.beizhu; parameters[7].Value = model.que_id; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.inv_answer GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,option_id,an_int,an_text,open_id,name,time,beizhu,que_id from inv_answer "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Maticsoft.Model.inv_answer model = new Maticsoft.Model.inv_answer(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }