Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["name"]) && !string.IsNullOrEmpty(Request.Form["password"]))//获取form中的参数
                {
                    string UserName = Request.Form["name"].ToString();
                    string UserPassword = Request.Form["password"].ToString();
                    string Identity = Request["status"];
                    string Major = Request["account"];

                    if (Identity == student.ID)
                    {
                        StudentManager StudentMan = new StudentManager();
                        Student stu = new Student();

                        stu.username = UserName;
                        stu.passwd = UserPassword;
                        stu.name = UserName;
                        if (Major == null)
                        {
                            Major = string.Empty;
                        }
                        stu.major = Major;
                        //stu.grade = string.Empty;
                        StudentMan.AddStudent(stu);
                        Session["student"] = stu;
                        Session["UserRole"] = "Student";
                        Response.Redirect("StudentMainForm.aspx");
                    }

                    else if (Identity == teacher.ID)
                    {
                        TeacherManager TeacherMan = new TeacherManager();
                        Teacher tea = new Teacher();
                        tea.username = UserName;
                        tea.passwd = UserPassword;
                        tea.name = UserName;

                        TeacherMan.AddTeacher(tea);
                        Session["teacher"] = tea;
                        Session["UserRole"] = "Teacher";
                        Response.Redirect("AddCourse.aspx");
                    }

                }

            }
            catch (Exception ex)
            {
                Response.Write("<Script Language=JavaScript>alert('用户名已存在!');</Script>");
            }
        }
Пример #2
0
        //course 插入判断
        protected void DetailsView3_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            CourseManager course = new CourseManager();
            TeacherManager t = new TeacherManager();
            if (e.Values["num"] == null || e.Values["teacher"] == null || e.Values["name"] == null)
            {
                ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!course表中num,teacher,name字段都不能为空');", true);
                e.Cancel = true;
                return;
            }
            if (course.GetCourseByNum(e.Values["num"].ToString()) != null)
            {
                ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!course表中num已存在');", true);
                e.Cancel = true;
                return;
            }

            if (t.GetTeacher(e.Values["teacher"].ToString())==null)
            {
                ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!course表中外键teacher不存在');", true);
                e.Cancel = true;
                return;
            }
        }
Пример #3
0
 //teacher 插入判断
 protected void DetailsView2_ItemInserting(object sender, DetailsViewInsertEventArgs e)
 {
     TeacherManager teacher = new TeacherManager();
     if (e.Values["username"] == null || e.Values["passwd"] == null || e.Values["name"] == null )
     {
         ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!teacher表中字段都不能为空');", true);
         e.Cancel = true;
         return;
     }
     else if (teacher.GetTeacher(e.Values["username"].ToString()) != null)
     {
         ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!teacher表中该usrname已存在');", true);
         e.Cancel = true;
         return;
     }
 }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["Action"]))//获取form的Action中的参数
                {
                    Action = Request.QueryString["Action"].Trim().ToLower();//去掉空格并变小写
                }
                switch (Action)
                {
                    case "login":
                        if (!string.IsNullOrEmpty(Request.Form["TxtUserName"]) && !string.IsNullOrEmpty(Request.Form["TxtPassword"]))//获取form中的参数
                        {
                            string UserName = Request.Form["TxtUserName"].ToString();
                            string UserPassword = Request.Form["TxtPassword"].ToString();
                            string Identity = Request.Form["DropExpiration"].ToString();
                            StudentManager StudentMan = new StudentManager();
                            TeacherManager TeacherMan = new TeacherManager();
                            AdminManager AdminMan = new AdminManager();

                            try
                            {
                                if (Identity.Equals("student"))
                                {
                                    if (UserPassword != StudentMan.GetStudent(UserName).passwd)
                                    {
                                        Response.Write("<Script Language=JavaScript>alert('密码或用户名错误,请重试!');</Script>");
                                    }
                                    else
                                    {
                                        Session["UserRole"] = "Student";
                                        Session["student"] = StudentMan.GetStudent(UserName);
                                        Response.Redirect("StudentMainForm.aspx");
                                    }
                                }

                                else if (Identity.Equals("teacher"))
                                {
                                    if (UserPassword != TeacherMan.GetTeacher(UserName).passwd)
                                    {
                                        Response.Write("<Script Language=JavaScript>alert('密码或用户名错误,请重试!');</Script>");
                                    }
                                    else
                                    {
                                        Session["UserRole"] = "Teacher";
                                        Session["teacher"] = TeacherMan.GetTeacher(UserName);
                                        Response.Redirect("AddCourse.aspx");
                                    }
                                }

                                else if (Identity.Equals("admin"))
                                {
                                    if (UserPassword != AdminMan.GetAdmin(UserName).passwd)
                                    {
                                        Response.Write("<Script Language=JavaScript>alert('密码或用户名错误,请重试!');</Script>");
                                    }
                                    else
                                    {
                                        Session["UserRole"] = "Admin";
                                        Session["admin"] = AdminMan.GetAdmin(UserName);
                                        Response.Redirect("admin.aspx?user="******"<Script Language=JavaScript>alert('错误的身份选择!');</Script>");
                            }

                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }