Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UserID"] == null)  //如果用户还没登陆跳到登陆页面
                {
                    Response.Redirect("../login.aspx");
                }
                else
                {
                    sr_User users = new sr_User();
                    ZQUSR.Model.sr_User model = users.GetModel(Session["UserID"].ToString());

                    Lb_UserID.Text = model.PK_UserID;
                    Lb_UserName.Text = model.UserName;
                    Lb_UserSex.Text = model.Sex;
                    Lb_UserUnit.Text = model.Unit;
                    Lb_UserEducation.Text = model.Education;
                    Lb_UserZhiCheng.Text = model.ZhiCheng;
                    Lb_UserTel.Text = model.Telephone;
                    int i = int.Parse(model.InOffice.ToString());
                    if (i == 1)
                        Lb_UserInOffice.Text = "在职";
                    else
                        Lb_UserInOffice.Text = "不在职";
                    Lb_UserEmail.Text = model.Email;
                    Lb_UserLoginTimes.Text = model.Logins.ToString();
                }
            }
        }
        protected void Btn_save_Click(object sender, EventArgs e)
        {
            sr_User users = new sr_User();
            string UserID = Session["UserID"].ToString();
            string UserName = TB_UserName.Text.ToString().Trim();
            string Sex = DropDL_Sex.SelectedValue;
            string Unit = TB_Unit.SelectedValue;
            string Education = DropDL_Degree.SelectedValue;
            string ZhiCheng = TB_ZhiCheng.SelectedValue;

            string Telephone = TB_Telephone.Text.ToString().Trim();
            string InOffice = DropDL_Job.SelectedIndex.ToString();//...
            string Email = TB_Email.Text.ToString().Trim();

            if (users.UpdateGeRenXinXi(UserName, Sex, Unit, Education, ZhiCheng, Telephone, InOffice, Email, UserID))
            {
                Response.Write("<script>alert('信息更新成功')</script>");
                users.UpdateLogins(UserID);             //更新登录次数
            }
            else
            {
                Response.Write("<script>alert('信息更新失败')</script>");
                return;
            }

            Session["UserName"] = users.GetUserName(Session["UserID"].ToString()); //完善完信息后再将UserName保存到session
            string Role = Session["Role"].ToString();      //完善完信息后再根据角色跳到不通的页面。
            Session["Unit"] = users.GetUserUnit(Session["UserID"].ToString());
            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;
            }
        }
 protected void Button1_Click(object sender, EventArgs e)
 {
     sr_User users = new sr_User();
     string UserID=Session["UserID"].ToString();
     string Password = users.GetPassword(UserID);
     try
     {
         string strPwd = TB_OldPassword.Text;
         string oldPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(strPwd, "MD5");
         if (Password != oldPwd)
         {
             Response.Write("<script>alert('旧密码输入有误')</script>");
             TB_OldPassword.Text = "";
             TB_OldPassword.Focus();
             return;
         }
         else if(TB_NewPassword1.Text!=TB_NewPassword2.Text)
         {
             Response.Write("<script>alert('两次输入的新密码不一致,请重新输入')</script>");
             TB_OldPassword.Text = "";
             TB_NewPassword1.Text = "";
             TB_NewPassword2.Text = "";
             TB_OldPassword.Focus();
             return;
         }
         string strPassword = TB_NewPassword1.Text.ToString();
         string newPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(strPassword, "MD5");
         if (users.UpdatePassword(newPwd, UserID))
         {
             Response.Write("<script>alert('密码更改成功')</script>");
             TB_OldPassword.Text = "";
             TB_NewPassword1.Text = "";
             TB_NewPassword2.Text = "";
             TB_OldPassword.Focus();
         }
         else
             Response.Write("<script>alert('密码更改失败')</script>");
     }
     catch (Exception ee)
     {
         Console.WriteLine(ee.Message);
     }
 }
Esempio n. 4
0
        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 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 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();
        }