usingSystem;usingSystem.Web;usingDAL;usingSystem.Data;usingSystem.Data.SqlClient;public classtable : IHttpHandler {public voidProcessRequest (HttpContext context) {
context.Response.ContentType= "text/plain";//如果ID不为空就是做删除
if (context.Request.QueryString["id"]!=null)
{int id = int.Parse(context.Request.QueryString["id"].ToString());int r = SQLHelper.ExecuteNonQuery("delete Users where ID=@0", CommandType.Text, id);if (r>0)
{
Common(context);
}
}else{//如果name不为空就做添加
if (context.Request.QueryString["name"]!=null)
{string name = context.Request.QueryString["name"].ToString();string pwd = context.Request.QueryString["pwd"].ToString();bool sex = bool.Parse(context.Request.QueryString["sex"].ToString());int adminID = int.Parse(context.Request.QueryString["adminID"].ToString());int i = SQLHelper.ExecuteNonQuery("insert into Users values(@0,@1,@2,@3)", CommandType.Text, name, pwd,adminID,sex );if (i>0)
{
Common(context);
}
}//都为空就是获取表
else{
Common(context);
}
}
}public voidCommon(HttpContext context)
{
SqlDataReader dr= SQLHelper.ExecuteReader("select * from Users", CommandType.Text);string newTable = "
ID | UserName | Password | Sex | AdminID | 删除 |
---|
//加载 数据行的字符串while(dr.Read())
{string sex = "checked='checked'";if (dr[4].ToString().ToLower() == "false")
sex= "";
newTable+= "
" + dr[0] + "" + dr[1] + "" + dr[2] + " " + dr[3] + "" +"
";//}
dr.Close();
//加载 添加行的字符串
newTable+= "
"disabled='disabled' />
"class='aspNetDisabled'>
"+"" +
"Admin"+
"Guest"+
"User" +
"
" + "";newTable+= "
";//一张完整的表的字符串
context.Response.Write(newTable);
}public boolIsReusable {get{return false;
}
}
}