m0_53629929 2021-06-26 02:34 采纳率: 0%
浏览 12

基于asp.net的投票管理系统,能帮我看一下错误和需要改进的地方吗

public partial class jfjcsq : System.Web.UI.Page{    DBHelp db = new DBHelp();   

protected void Page_Load(object sender, EventArgs e)    { 

      if (!IsPostBack)     

  {            bind();        } 

  }    //绑定数据表格 

  protected void bind()    {     

  string sql = "select*from TB_JFCRSQ";        //数据集作用于gridview     

  DataSet ds = db.getDataSet(sql);        this.GridView1.DataSource = ds;        this.GridView1.DataBind();   

  protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 

  {        this.GridView1.PageIndex = e.NewPageIndex;       

bind(); 

  } 

  protected void Button1_Click(object sender, EventArgs e)    {     

  string sql = this.union();     

  DataSet ds = db.getDataSet(sql);        this.GridView1.DataSource = ds;        this.GridView1.DataBind();   

}   

public string union()    {       

string sql = "select * from  TB_JFCRSQ where 1=1";   

    if (this.TextBox1.Text != "")     

  {            sql += "  and lfsy like '%" + this.TextBox1.Text + "%'";        } 

      if (this.TextBox2.Text != "")   

    {            sql += "  and lfname like '%" + this.TextBox2.Text + "%'  ";        }     

  if (this.TextBox3.Text != "")     

  {            sql += "  and jrjfsj ='" + this.TextBox3.Text + "'  ";        }   

    return sql;   

}   

protected void Button2_Click(object sender, EventArgs e)    {   

string lfsy = this.TextBox1.Text;     

string lfname = this.TextBox2.Text;       

string jrjfsj = this.TextBox3.Text;       

string lkjfsq = this.TextBox4.Text;            string sql = "insert into TB_JFCRSQ(lfsy,lfname,jrjfsj,lkjfsq)values('" + lfsy + "','" + lfname + "','" + jrjfsj + "','" + lkjfsq + "')";           

int result = db.exec(sql);           

if (result > 0)         

  {              Response.Write("<script>alert('添加成功')</script>");               

bind();           

}           

else            {                Response.Write("<script>alert('添加失败')</script>");            }     }    //用来把数据库里的资产状态数字变为中文的方法   

public string Show(string state)    {       

string strState = null;       

switch (state)       

{           case "1":  strState = "待审核";                break;        case "2":  strState = "审核通过";        break;            case "3":   strState = "驳回";          break;            default: break;       

}       

return strState;   

}   

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)    {       

string sql = "delete from TB_JFCRSQ  where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";       

int result = db.exec(sql);       

bind();   

}   

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    {        //如果是绑定数据行           

if (e.Row.RowType == DataControlRowType.DataRow)        {           

if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)           

{                ((LinkButton)e.Row.Cells[9].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");            }     

  }       

if (e.Row.RowType == DataControlRowType.DataRow)        {            //当鼠标停留时更改背景色              e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");            //当鼠标移开时还原背景色              e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");        }   

}   

protected void Button3_Click(object sender, EventArgs e)   

{       

bind();   

}

}

  • 写回答

1条回答 默认 最新

  • 关注

    请描述一下现在的问题,还有把代码格式化一下。

    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备