protected void Button1_Click(object sender, EventArgs e) { string AddUserID = TB_UserID.Text.Trim().ToString(); //string AddPassword = TB_Password.Text.ToString().Trim(); string AddRoleID = ""; //AddRoleID = GetRolesID(); AddRoleID = Dr_SelRole.SelectedValue.ToString(); try { if (TB_UserID.Text.Trim().ToString() == "") //如果不加.Trim()函数,那么输入空格也会成为合法输入,这样显然不符合逻辑。 { this.Lb_UserID.Text = "不能空"; return; } //if (TB_Password.Text == "") //{ // this.Lb_Password.Visible = true; // return; //} else { this.Lb_UserID.Text = " "; // this.Lb_Password.Visible = false; } if (users.Exists(AddUserID)) //此用账号已经存在 { this.Lb_UserID.Text = "此用账号已被使用"; this.TB_UserID.Text = ""; TB_UserID.Focus(); return; } else { string temp_password = txtPwd.Text.Trim().ToString(); string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(temp_password, "MD5"); bool flag = false; flag = users.AddUser(AddUserID, pwd, AddRoleID); //增加用户 if (flag == true) { this.Lb_UserID.Text = "添加成功"; } bind(); } } catch (Exception ee) { Response.Write("<script>alert('添加失败,系统错误')</script>"); } }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) //编辑更新 { try { sr_User users = new sr_User(); string UserID = ""; //新的用户ID string RoleID = ""; //用户角色的ID string OldID = Session["temp"].ToString(); Session.Remove("temp"); //把未更改时 gridview的ID值拿出来后 可以删掉Session["temp"] String tempRole = Session["tempRole"].ToString(); Session.Remove("tempRole"); //把gridview的角色Role值拿出来后 可以删掉Session["tempRole"] string Password; Password = users.GetPassword(OldID); //获得要插进去的密码 if (tempRole == "教师") { RoleID = "ZQUSR4000"; } else if (tempRole == "管理员") { RoleID = "ZQUSR3000"; } else if (tempRole == "系统管理员") { RoleID = "ZQUSR2000"; } UserID = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim(); //新的ID if (users.Exists(UserID)) //此账号已经存在 { Response.Write("<script>alert('此账号已被使用,请改为另外账号')</script>"); return; } else //更新账号==插进一条新的信息删除旧的信息 { // users.UpdateIDPwd(UserID,RoleID, OldID); //插进一条新的信息删除旧的信息(必须还要插进去密码)!! users.UpdateIDPwd(UserID, Password, RoleID, OldID); //更新一条新的信息删除、旧的信息 } } catch (Exception ee) { Response.Write("<script>alert('抱歉更改失败,建议删除此记录重新添加')</script>"); } finally { GridView1.EditIndex = -1; bind(); } }
protected void login1_Click(object sender, ImageClickEventArgs e) { string UserID = "", temppwd = "", Role = ""; UserID = user.Text.Trim().ToString(); temppwd = password.Text.Trim().ToString(); string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(temppwd, "MD5"); Role = chknumber.SelectedValue; sr_User users = new sr_User(); //if (UserID == "") //{ // //Response.Write("<script>alert('用户名不能为空')</script>"); // user.Focus(); // return; //} //else if (temppwd == "") //{ // Response.Write("<script>alert('密码不能为空')</script>"); // password.Focus(); // return; //} if (!users.Exists(UserID)) { Response.Write("<script>alert('不存在此用户')</script>"); return; } if (!users.isExistUser(UserID, pwd, Role)) { Response.Write("<script>alert('密码或角色错误')</script>"); return; } if (!users.StatusIsTrue(UserID)) { Response.Write("<script>alert('此用户已被屏蔽')</script>"); return; } else//如果可以登录进去 { Session["UserID"] = UserID; Session["UserName"] = users.GetUserName(UserID); Session["Role"] = Role; Session["Unit"] = users.GetUserUnit(UserID); int LoginTimes; LoginTimes = users.GetLogins(UserID); //得到登录次数 if (LoginTimes == 0) //如果是第一次登录 { Response.Write(" <script> alert( '你首次登陆,请先完善信息');location.href= 'YongHuGuanLi/WanShanXinXi.aspx'; </script> "); } else { switch (Role) { case "教师": Response.Redirect("Teacher.aspx"); break; case "管理员": Response.Redirect("Secretary.aspx"); break; case "系统管理员": Response.Redirect("KeYuan.aspx"); break; case "超级管理员": Response.Redirect("Chief.aspx"); break; default: break; } } } //else //{ // Response.Write("<script>alert('不存在此用户或此用户不合法')</script>"); // user.Text = ""; // password.Text = ""; // user.Focus(); // return; //} }
protected void Button2_Click(object sender, EventArgs e) { sr_User users = new sr_User(); string UserID01 = TextBox1.Text.Trim().ToString(); string UserID02 = TextBox2.Text.Trim().ToString(); string UserID03 = TextBox3.Text.Trim().ToString(); string UserID04 = TextBox4.Text.Trim().ToString(); string UserID05 = TextBox5.Text.Trim().ToString(); string UserID06 = TextBox6.Text.Trim().ToString(); string UserID07 = TextBox7.Text.Trim().ToString(); string UserID08 = TextBox8.Text.Trim().ToString(); string UserID09 = TextBox9.Text.Trim().ToString(); string UserID10 = TextBox10.Text.Trim().ToString(); string UserID11 = TextBox11.Text.Trim().ToString(); string UserID12 = TextBox12.Text.Trim().ToString(); string UserID13 = TextBox13.Text.Trim().ToString(); string UserID14 = TextBox14.Text.Trim().ToString(); string UserID15 = TextBox15.Text.Trim().ToString(); string AddRoleID = ""; //AddRoleID = GetRolesID(); AddRoleID = Dr_SelRole.SelectedValue.ToString(); // string temp_password = txtPwd.Text.Trim().ToString(); string temp_Pwd = txtPwd.Text.Trim().ToString(); string temp_password = FormsAuthentication.HashPasswordForStoringInConfigFile(temp_Pwd, "MD5"); int lenght = 15; string[] strUserIDs = new String[lenght]; string WrongInputNum = ""; int count = 0; int emptyID = 0; strUserIDs[0] = UserID01; strUserIDs[1] = UserID02; strUserIDs[2] = UserID03; strUserIDs[3] = UserID04; strUserIDs[4] = UserID05; strUserIDs[5] = UserID06; strUserIDs[6] = UserID07; strUserIDs[7] = UserID08; strUserIDs[8] = UserID09; strUserIDs[9] = UserID10; strUserIDs[10] = UserID11; strUserIDs[11] = UserID12; strUserIDs[12] = UserID13; strUserIDs[13] = UserID14; strUserIDs[14] = UserID15; this.LbResult.Text = " "; for (int i = 0; i < lenght; i++) { if (strUserIDs[i] != "") { if (!users.Exists(strUserIDs[i])) { users.AddUser(strUserIDs[i], temp_password, AddRoleID); //增加用户 count++; } else { WrongInputNum += (i + 1).ToString() + ","; } } else { emptyID++; } // this.LbResult.Text +=(i+1).ToString()+":"+ strUserIDs[i]+","; } if (emptyID == 15) //输入全为空 { this.LbResult.Text = " 抱歉,输入不能全为空"; return; } if (count == 15) //输入不为空 且 输入账号不重复,即添加了全部数据 { this.LbResult.Text = " 恭喜已成功添加全部数据"; TextBox1.Focus(); clearTextBox(); } else //添加了少于15条的数据 { this.LbResult.Text = " 总共添加" + count + "条数据"; if (WrongInputNum != "") //输入存在重复账号 { this.LbResult.Text += " 注意:账号" + WrongInputNum + "的数据已被使用,请重新输入"; } else //有些输入为空,但输入不为空的都没有输入重复账号 { TextBox1.Focus(); clearTextBox(); } } bind(); }