//查询用户 protected void Button1_Click(object sender, EventArgs e) { //输入异常检查 string strIn = TextBox1.Text.Trim(); //有点问题,数字挂字母?? Regex r=new Regex(@"\d{1,100}"); if(r.IsMatch(strIn) & (strIn.Length<5|strIn.Length>6)) { if (Session["lang"].ToString() == "zh-cn") Response.Write("<script>alert('PSID的长度必须是5或者6!');window.location.href='./Query_employee.aspx'</script>"); else Response.Write("<script>alert('The length of PSID must be 5 or 6!');window.location.href='./Query_employee.aspx'</script>"); return; } Query qr = new Query(); DataTable dt = new DataTable(); DataTable dtEmployeeExist = new DataTable(); //Query by PSID or Name if (r.IsMatch(strIn)) { dt = qr.QueryByPSID(strIn); Session["PSID"] = strIn; dtEmployeeExist = qr.GetEmployeeByPSID(strIn); } else { dt = qr.QueryByName(strIn); Operation op = new Operation(); Session["PSID"] = op.NameToPSID(strIn); dtEmployeeExist = qr.GetEmployeeByName(strIn); } //该employee不存在的处理 if (dtEmployeeExist.Rows.Count == 0) { if (Session["lang"].ToString() == "zh-cn") Response.Write("<script>alert('" + TextBox1.Text.Trim() + " 不存在!');window.location.href='./Query_employee.aspx'</script>"); else Response.Write("<script>alert('" + TextBox1.Text.Trim() + " does not exist!');window.location.href='./Query_employee.aspx'</script>"); return; } //有该employee,但借阅记录为空的处理 if (dt.Rows.Count == 0) { if (Session["lang"].ToString() == "zh-cn") Response.Write("<script>alert('" + TextBox1.Text.Trim() + " 没有借阅任何图书!');window.location.href='./Query_employee.aspx'</script>"); else Response.Write("<script>alert('" + TextBox1.Text.Trim() + " did not borrow any book!');window.location.href='./Query_employee.aspx'</script>"); return; } GridView1.DataSource = dt; GridView1.DataBind(); }