public void Login()
 {
     string id="admin";
     string password="******";
     SystemUser newUser=sys.Login(id, password);
     string successMessage;
     Object Session=null;
     Object SessionUser = null;
     if (newUser != null)
     {
         //设置用户的Session
         SessionUser = newUser;
         //不同用户创建不同的Controller,放入Session
         switch(newUser.systemUserType){
             case 1:
                 StudentController studentController=new StudentController(sessionFactory);
                 Session=studentController;
                 break;
             case 2:
                 TeacherController teacherController=new TeacherController(sessionFactory);
                 Session=teacherController;
                 break;
             case 3:
                 AdminController adminController=new AdminController(sessionFactory);
                 Session=adminController;
                 break;
             default:
                 break;
         }
         successMessage = "登陆成功,设置newUserSession[],跳转各自用户的主页";
     }
     else {
         successMessage = "用户名或密码错误";
     }
     Assert.AreNotEqual(null, SessionUser);
     Assert.AreNotEqual(null,Session);
     Assert.AreEqual("登陆成功,设置newUserSession[],跳转各自用户的主页", successMessage);
 }
 public void Init()
 {
     //SystemController sys = (SystemController)Application["systemController"];
     var cfg = new NHibernate.Cfg.Configuration().Configure("hibernate.cfg.xml");
     sessionFactory = cfg.BuildSessionFactory();
     teacherController = new TeacherController(sessionFactory);
 }
        protected void LogIn(object sender, EventArgs e)
        {
            //学号就是UserName的值取得
            string userID = systemUserID.Text;
            string password = systemUserPassword.Text;
            SystemController sys = new SystemController((NHibernate.ISessionFactory)Application["sessionFactory"]);
            SystemUser systemUser = sys.Login(userID, password);

            if(null!=systemUser){
                    Session.Add("logined", "Y");
                    Session.Add("userID", systemUser.systemUserID);
                    Session.Add("password",systemUser.systemUserPassword);
                    Session.Add("userType",systemUser.systemUserType);
                    //一周是10080分钟
                    if (rememberMeOneWeekCheckBox.Checked)
                    {
                        Session.Timeout = 10080;
                    }
                    if (Session["userType"].Equals(3))
                    {
                        //登陆生成一个老师控制器
                        AdminController adminController = new AdminController((NHibernate.ISessionFactory)Application["sessionFactory"]);
                        Session.Add("adminController", adminController);
                        string adminName="管理员";
                        Session.Add("username",adminName);
                       //登陆完跳转管理员首页
                       string skipPageUrl = "Views/AdminView/Admin.aspx";
                       Response.Redirect(skipPageUrl);
                    }
                    if (Session["userType"].Equals(2))
                    {
                        //登陆生成一个老师控制器
                        TeacherController teacherController = new TeacherController((NHibernate.ISessionFactory)Application["sessionFactory"]);
                        Session.Add("teacherController", teacherController);
                        Teacher teacher= sys.GetTeacherByID(systemUser.systemUserID);
                        string teacherName=teacher.teacherName+"老师";
                        Session.Add("teacherDepart", teacher.teacherDepart);
                        Session.Add("username",teacherName);
                       //登陆完跳转老师首页
                        string skipPageUrl = "Views/TeacherView/Teacher.aspx";
                       Response.Redirect(skipPageUrl);
                    }

                    if (Session["userType"].Equals(1))
                    {

                        StudentController studentController = new StudentController((NHibernate.ISessionFactory)Application["sessionFactory"]);
                        Session.Add("studentController", studentController);
                        Student student = sys.GetStuentByID(systemUser.systemUserID);
                        string studentName=student.studentName+"同学";
                        Session.Add("username", studentName);
                       //学生的专业,年级信息在选课时很重要
                        Session.Add("studentClassName",student.studentClassName);
                        Session.Add("studentGrade",student.studentGrade);
                        //登陆完跳转学生首页
                        string skipPageUrl = "Views/StudentView/Student.aspx";
                       Response.Redirect(skipPageUrl);
                    }

            }else{
                    failTextField.Text = "用户密码不正确,请重新输入";
                    Session.Add("logined", "N");
            }
        }