/// <summary> /// 增加一条数据 /// </summary> public int Add(AgreementModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into AgreementClass("); strSql.Append("GameID,Title,Describe)"); strSql.Append(" values ("); strSql.Append("@GameID,@Title,@Describe)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@GameID", SqlDbType.Int, 4), new SqlParameter("@Title", SqlDbType.VarChar, 0), new SqlParameter("@Describe", SqlDbType.VarChar, 0) }; parameters[0].Value = model.GameID; parameters[1].Value = model.Title; parameters[2].Value = model.Describe; object obj = SqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); string Title = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("Title")).Text; string Describe = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("Describe")).Text; AgreementModel mode = new AgreementModel(); mode.AgreementID = id; mode.Title = Title; mode.Describe = Describe; AgreementBLL Pinfo = new AgreementBLL(); if (Pinfo.Update(mode)) { GridView1.EditIndex = -1; BindData(); } } catch (Exception erro) { Response.Write("错误信息:" + erro.Message); } }
protected void butSubmit_Click(object sender, EventArgs e) { try { AgreementBLL con = new AgreementBLL(); AgreementModel model = new AgreementModel(); model.Title = Title.Text.Trim(); model.Describe = Describe.Text.Trim(); model.GameID = Convert.ToInt32(Request.QueryString["gameid"]); if (con.Add(model) > 0) { Page.RegisterStartupScript("", "<script language=javascript>alert('添加成功!')</script>"); } } catch(Exception ex) { Page.RegisterStartupScript("", "<script language=javascript>alert('添加失败,填写重复!')</script>"); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(AgreementModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update AgreementClass set "); strSql.Append("Title=@Title,Describe=@Describe"); strSql.Append(" where AgreementID=@AgreementID"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.VarChar, 0), new SqlParameter("@Describe", SqlDbType.VarChar, 0),new SqlParameter("@AgreementID", SqlDbType.VarChar, 0) }; parameters[0].Value = model.Title; parameters[1].Value = model.Describe; parameters[2].Value = model.AgreementID; int rows = SqlHelper.ExecuteNonQuery(connectionString,CommandType.Text,strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(AgreementModel model) { return dal.Update(model); }
/// <summary> /// 添加一条数据 /// </summary> public int Add(AgreementModel model) { return dal.Add(model); }