protected void dataBind()
 {
     administratorBLL AdminBLL = new administratorBLL();
     DataSet ds = AdminBLL.GetList("");
     GridView1.DataSource = ds;
     GridView1.DataBind();
 }
 protected void submit_Click(object sender, EventArgs e)
 {
     string userName = Tools.safeUserInput(username.Text.Trim());
     string passWord = Tools.safeUserInput(password.Text.Trim());
     if (userName.Length < 1) { MessageBox.Show(this, "用户名不能为空"); return; }
     if (passWord.Length < 1) { MessageBox.Show(this, "密码不能为空"); return; }
     administratorBLL adminbll = new administratorBLL();
     string loginMessage = adminbll.Login(userName, passWord);
     if (loginMessage.Equals("1"))
     {
         string stuIdStr = adminbll.GetModel(userName).id.ToString();
         Session["status"] = "true";
         Session["UserId"] = stuIdStr;
         Session["type"] = "1";
         MessageBox.ShowAndRedirect(this, "登录成功!", "student.aspx");
     }
     else
     {
         if (loginMessage.Equals("2"))
         {
             string stuIdStr = adminbll.GetModel(userName).id.ToString();
             Session["status"] = "true";
             Session["UserId"] = stuIdStr;
             Session["type"] = "2";
             MessageBox.ShowAndRedirect(this, "登录成功!", "student.aspx");
         }
         else
         {
             Session["status"] = "false";
             Session["UserId"] = "0";
             Session["type"] = "0";
             MessageBox.ShowAndRedirect(this, loginMessage, "logout.aspx");
         }
     }
 }
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     administratorBLL AdminBLL = new administratorBLL();
     MessageBox.Show(this, "确定删除!");
     if (AdminBLL.Delete(Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()))) MessageBox.Show(this, "删除成功!");
     else MessageBox.Show(this, "删除失败!");
     dataBind();
 }
 private void initial()
 {
     int userId = Convert.ToInt32(Session["UserId"]);
     administratorBLL adminbll = new administratorBLL();
     string username = adminbll.GetModel(userId).userName;
     if (username != null) userName = username;
     if (Session["type"].ToString().Equals("1")) {
         Panel1.Visible = true;
         Panel2.Visible = false;
     }
     if (Session["type"].ToString().Equals("2"))
     {
         Panel2.Visible = true;
         Panel1.Visible = false;
     }
 }
 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
     administratorBLL AdminBLL = new administratorBLL();
     administrator Admin = new administrator();
     Admin.id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
     Admin.userName = Tools.safeUserInput(((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim());
     Admin.passWord = Tools.encrypt(((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim());
     Admin.type = Tools.safeUserInput(((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim());
     if (AdminBLL.Update(Admin))
     {
         MessageBox.Show(this, "更新成功!");
         GridView1.EditIndex = -1;
         dataBind();
     }
     else
     {
         MessageBox.Show(this, "更新失败!");
         GridView1.EditIndex = -1;
     }
 }
 protected void Button1_Click(object sender, EventArgs e)
 {
     administratorBLL AdminBLL=new administratorBLL();
     administrator Admin = AdminBLL.GetModel(Convert.ToInt32(Session["UserId"]));
     string passwordStr1 = Tools.safeUserInput(passWordTB1.Text.Trim());
     string passwordStr2 = Tools.safeUserInput(passWordTB2.Text.Trim());
     if (passwordStr1.Length < 1 || passwordStr2.Length < 1)
     {
         MessageBox.Show(this, "密码不能为空!");
         return;
     }
     else {
         if (passwordStr1.Equals(passwordStr2))
         {
             Admin.passWord = Tools.encrypt(passwordStr1);
             AdminBLL.Update(Admin);
             MessageBox.Show(this, "修改成功!");
         }
         else {
             MessageBox.Show(this, "两次密码不同!");
             return;
         }
     }
 }
 protected void Unnamed2_Click(object sender, EventArgs e)
 {
     string userNameStr=Tools.safeUserInput(TextBox1.Text.ToString().Trim());
     string passWordStr = Tools.safeUserInput(TextBox2.Text.ToString().Trim());
     if(userNameStr.Length<1){
     MessageBox.Show(this,"用户名不能为空!");
         return;
     }
     if(passWordStr.Length<1){
     MessageBox.Show(this,"密码不能为空!");
         return;
     }
     administratorBLL AdminBLL = new administratorBLL();
     if (AdminBLL.Exists(userNameStr)) {
         MessageBox.Show(this, "用户名已存在!");
         return;
     }
     administrator Admin = new administrator();
     Admin.userName = userNameStr;
     Admin.passWord = Tools.encrypt(passWordStr);
     Admin.type = DropDownList1.SelectedItem.Value;
     try
     {
         AdminBLL.Add(Admin);
     }
     catch {
         MessageBox.Show(this, "添加失败!");
     }
     MessageBox.Show(this, "添加成功!");
     dataBind();
 }