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();
}
}