/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.forum_q model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update forum_q set "); strSql.Append("name=@name,"); strSql.Append("team=@team,"); strSql.Append("question=@question,"); strSql.Append("time=@time,"); strSql.Append("password=@password,"); strSql.Append("peixunban=@peixunban,"); strSql.Append("fenshu=@fenshu,"); strSql.Append("style=@style,"); strSql.Append("beizhu=@beizhu,"); strSql.Append("beizhu2=@beizhu2"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.NChar, 50), new SqlParameter("@team", SqlDbType.NChar, 50), new SqlParameter("@question", SqlDbType.Text), new SqlParameter("@time", SqlDbType.DateTime), new SqlParameter("@password", SqlDbType.Int, 4), new SqlParameter("@peixunban", SqlDbType.Int, 4), new SqlParameter("@fenshu", SqlDbType.Int, 4), new SqlParameter("@style", SqlDbType.Int, 4), new SqlParameter("@beizhu", SqlDbType.NChar, 10), new SqlParameter("@beizhu2", SqlDbType.Text), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.name; parameters[1].Value = model.team; parameters[2].Value = model.question; parameters[3].Value = model.time; parameters[4].Value = model.password; parameters[5].Value = model.peixunban; parameters[6].Value = model.fenshu; parameters[7].Value = model.style; parameters[8].Value = model.beizhu; parameters[9].Value = model.beizhu2; parameters[10].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.forum_q DataRowToModel(DataRow row) { Maticsoft.Model.forum_q model = new Maticsoft.Model.forum_q(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["team"] != null) { model.team = row["team"].ToString(); } if (row["question"] != null) { model.question = row["question"].ToString(); } if (row["time"] != null && row["time"].ToString() != "") { model.time = DateTime.Parse(row["time"].ToString()); } if (row["password"] != null && row["password"].ToString() != "") { model.password = int.Parse(row["password"].ToString()); } if (row["peixunban"] != null && row["peixunban"].ToString() != "") { model.peixunban = int.Parse(row["peixunban"].ToString()); } if (row["fenshu"] != null && row["fenshu"].ToString() != "") { model.fenshu = int.Parse(row["fenshu"].ToString()); } if (row["style"] != null && row["style"].ToString() != "") { model.style = int.Parse(row["style"].ToString()); } if (row["beizhu"] != null) { model.beizhu = row["beizhu"].ToString(); } if (row["beizhu2"] != null) { model.beizhu2 = row["beizhu2"].ToString(); } } return(model); }
private void ShowInfo(int id) { Maticsoft.BLL.forum_q bll = new Maticsoft.BLL.forum_q(); Maticsoft.Model.forum_q model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.lblname.Text = model.name; this.lblteam.Text = model.team; this.lblquestion.Text = model.question; this.lbltime.Text = model.time.ToString(); this.lblpassword.Text = model.password.ToString(); this.lblpeixunban.Text = model.peixunban.ToString(); this.lblfenshu.Text = model.fenshu.ToString(); this.lblstyle.Text = model.style.ToString(); this.lblbeizhu.Text = model.beizhu; this.lblbeizhu2.Text = model.beizhu2; }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.forum_q model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into forum_q("); strSql.Append("name,team,question,time,password,peixunban,fenshu,style,beizhu,beizhu2)"); strSql.Append(" values ("); strSql.Append("@name,@team,@question,@time,@password,@peixunban,@fenshu,@style,@beizhu,@beizhu2)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.NChar, 50), new SqlParameter("@team", SqlDbType.NChar, 50), new SqlParameter("@question", SqlDbType.Text), new SqlParameter("@time", SqlDbType.DateTime), new SqlParameter("@password", SqlDbType.Int, 4), new SqlParameter("@peixunban", SqlDbType.Int, 4), new SqlParameter("@fenshu", SqlDbType.Int, 4), new SqlParameter("@style", SqlDbType.Int, 4), new SqlParameter("@beizhu", SqlDbType.NChar, 10), new SqlParameter("@beizhu2", SqlDbType.Text) }; parameters[0].Value = model.name; parameters[1].Value = model.team; parameters[2].Value = model.question; parameters[3].Value = model.time; parameters[4].Value = model.password; parameters[5].Value = model.peixunban; parameters[6].Value = model.fenshu; parameters[7].Value = model.style; parameters[8].Value = model.beizhu; parameters[9].Value = model.beizhu2; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.forum_q GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,name,team,question,time,password,peixunban,fenshu,style,beizhu,beizhu2 from forum_q "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Maticsoft.Model.forum_q model = new Maticsoft.Model.forum_q(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtname.Text.Trim().Length == 0) { strErr += "name不能为空!\\n"; } if (this.txtteam.Text.Trim().Length == 0) { strErr += "team不能为空!\\n"; } if (this.txtquestion.Text.Trim().Length == 0) { strErr += "question不能为空!\\n"; } if (!PageValidate.IsDateTime(txttime.Text)) { strErr += "time格式错误!\\n"; } if (!PageValidate.IsNumber(txtpassword.Text)) { strErr += "password格式错误!\\n"; } if (!PageValidate.IsNumber(txtpeixunban.Text)) { strErr += "peixunban格式错误!\\n"; } if (!PageValidate.IsNumber(txtfenshu.Text)) { strErr += "fenshu格式错误!\\n"; } if (!PageValidate.IsNumber(txtstyle.Text)) { strErr += "style格式错误!\\n"; } if (this.txtbeizhu.Text.Trim().Length == 0) { strErr += "beizhu不能为空!\\n"; } if (this.txtbeizhu2.Text.Trim().Length == 0) { strErr += "beizhu2不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string name = this.txtname.Text; string team = this.txtteam.Text; string question = this.txtquestion.Text; DateTime time = DateTime.Parse(this.txttime.Text); int password = int.Parse(this.txtpassword.Text); int peixunban = int.Parse(this.txtpeixunban.Text); int fenshu = int.Parse(this.txtfenshu.Text); int style = int.Parse(this.txtstyle.Text); string beizhu = this.txtbeizhu.Text; string beizhu2 = this.txtbeizhu2.Text; Maticsoft.Model.forum_q model = new Maticsoft.Model.forum_q(); model.name = name; model.team = team; model.question = question; model.time = time; model.password = password; model.peixunban = peixunban; model.fenshu = fenshu; model.style = style; model.beizhu = beizhu; model.beizhu2 = beizhu2; Maticsoft.BLL.forum_q bll = new Maticsoft.BLL.forum_q(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }