public void Init()
 {
     //SystemController sys = (SystemController)Application["systemController"];
     var cfg = new NHibernate.Cfg.Configuration().Configure("hibernate.cfg.xml");
     sessionFactory = cfg.BuildSessionFactory();
     sys = new SystemController(sessionFactory);
 }
 protected void Application_Start(object sender, EventArgs e)
 {
     var cfg = new NHibernate.Cfg.Configuration().Configure(Server.MapPath("Config\\hibernate.cfg.xml"));
     NHibernate.ISessionFactory sessionFactory = cfg.BuildSessionFactory();
     Application.Add("sessionFactory", sessionFactory);
     SystemController sys = new SystemController((NHibernate.ISessionFactory)Application["sessionFactory"]);
     Application.Add("systemController", sys);
 }
        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");
            }
        }