Пример #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
        //student插入判断
        //插入判断
        protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            StudentManager stu = new StudentManager();

               if (e.Values["username"] == null || e.Values["passwd"] == null || e.Values["name"] == null || e.Values["major"] == null)
            {
                System.Web.UI.ScriptManager.RegisterClientScriptBlock(UpdatePanel1,this.GetType(), "msg1", "alert('插入失败!user表中字段不能为空');", true);
                e.Cancel = true;
                return;
            }
               if (stu.GetStudent(e.Values["username"].ToString()) != null)
            {
              ScriptManager.RegisterClientScriptBlock (UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!user表中usrname字段已存在');", true);
                e.Cancel = true;
                return;
            }
        }
Пример #3
0
 //answer表插入判断
 protected void DetailsView7_ItemInserting(object sender, DetailsViewInsertEventArgs e)
 {
     StudentManager stu = new StudentManager();
     ProblemManager p = new ProblemManager();
     if (e.Values["student"] == null || e.Values["problem"] == null)
     {
         ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!answer表中Student,prob字段不能为空');", true);
         e.Cancel = true;
         return;
     }
     if (stu.GetStudent(e.Values["student"].ToString()) == null)
     {
         ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!answer表中外键student字段不存在');", true);
         e.Cancel = true;
         return;
     }
     if(p.GetProblemById(int.Parse(e.Values["problem"].ToString()))==null)
     {
         ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!answer表中外键problem字段不存在');", 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);
            }
        }