コード例 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         MySQLDatabase db  = new MySQLDatabase();
         var           res = new TeacherTable(db).GetAllTeacher();
         foreach (var item in res)
         {
             ddlTo.Items.Add(new ListItem(item.FirstName + " " + item.LastName, item.ID.ToString()));
         }
         divSuccess.Visible = false;
     }
 }
コード例 #2
0
 public ActionResult CreateTeacher(TeacherTable teacher)
 {
     try
     {
         // TODO: Add insert logic here
         teacher.TeacherPassword = getHash(teacher.TeacherPassword);
         db.Teachers.Add(teacher);
         db.SaveChanges();
         return(RedirectToAction("TeacherIndex"));
     }
     catch
     {
         return(View());
     }
 }
コード例 #3
0
 public ActionResult Edit(TeacherTable teacher)
 {
     try
     {
         // TODO: Add update logic here
         if (teacher.TeacherPassword.Length < 20)
         {
             teacher.TeacherPassword = getHash(teacher.TeacherPassword);
         }
         db.Entry(teacher).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("HomePage", new { id = teacher.TeacherId }));
     }
     catch
     {
         return(View());
     }
 }
コード例 #4
0
        public Representations GetRepresentations()
        {
            Representations     representations = new Representations();
            List <TeacherTable> teacherTables   = new List <TeacherTable>();

            representations.teacherTables = teacherTables;

            int demoTeacherCount = 4;
            int demoHourCount    = 3;

            for (int i = 0; i < demoTeacherCount; i++)
            {
                int          teacherCounter = i + 1;
                TeacherTable teacherTable   = new TeacherTable();
                teacherTables.Add(teacherTable);
                List <TeacherHour> teacherHours = new List <TeacherHour>();
                teacherTable.hours = teacherHours;
                teacherTable.name  = "Lehrer " + teacherCounter;
                for (int j = 0; j < demoHourCount; j++)
                {
                    int    hourCounter = j + 1;
                    Random rnd         = new Random();
                    teacherHours.Add(
                        new TeacherHour()
                    {
                        hour                  = hourCounter,
                        className             = "KURS" + hourCounter,
                        substituteTeacherName = "/",
                        room                  = "A" + rnd.Next(1, 3) + "." + rnd.Next(0, 3) + rnd.Next(1, 3),
                        note                  = "EVA"
                    }
                        );
                }
            }

            return(representations);
        }
コード例 #5
0
        public ActionResult Login(string Username, string Password)
        {
            BLL.AdminTable   bllAdmin   = new BLL.AdminTable();
            BLL.TeacherTable bllTeacher = new BLL.TeacherTable();
            BLL.StudentTable bllStudent = new BLL.StudentTable();

            if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password))
            {
                return(this.Json(new { result = 0, data = "" }));
            }

            Password = encryptPwd(Password);

            string strSql = "Username='******' and Password='******'";

            List <AdminTable>   adminList   = bllAdmin.DataTableToList(bllAdmin.GetList(strSql).Tables[0]);
            List <TeacherTable> teacherList = bllTeacher.DataTableToList(bllTeacher.GetList(strSql).Tables[0]);
            List <StudentTable> studentList = bllStudent.DataTableToList(bllStudent.GetList(strSql).Tables[0]);

            if (adminList.Count > 0)
            {
                AdminTable adminModel = adminList[0];
                strSql = "select * from AccessTable where ID = 1 or ID = 2 or ID = 3 or ID = 4 or ID = 5 or ID = 6";

                List <AccessTable> tableList = new BLL.AccessTable().DataTableToList(DbHelperSQL.Query(strSql).Tables[0]);

                string sessionString = "";
                if (tableList.Count != 0)
                {
                    sessionString += "[";
                    foreach (AccessTable tableModel in tableList)
                    {
                        sessionString += new JavaScriptSerializer().Serialize(tableModel) + ",";
                    }
                    sessionString  = sessionString.Remove(sessionString.Length - 1);
                    sessionString += "]";
                }

                Session.Timeout     = 30;
                Session["username"] = adminModel.Username;
                Session["access"]   = sessionString;
                Session["name"]     = adminModel.Name;
                Session["type"]     = "管理员";

                return(this.Json(new { result = 1, data = "" }));
            }
            else if (teacherList.Count > 0)
            {
                TeacherTable teacherModel = teacherList[0];
                strSql = "select * from AccessTable where ID = 3 or ID = 4 or ID = 5 or ID = 6";

                List <AccessTable> tableList = new BLL.AccessTable().DataTableToList(DbHelperSQL.Query(strSql).Tables[0]);

                string sessionString = "";
                if (tableList.Count != 0)
                {
                    sessionString += "[";
                    foreach (AccessTable tableModel in tableList)
                    {
                        sessionString += new JavaScriptSerializer().Serialize(tableModel) + ",";
                    }
                    sessionString  = sessionString.Remove(sessionString.Length - 1);
                    sessionString += "]";
                }

                Session.Timeout     = 30;
                Session["username"] = teacherModel.Username;
                Session["access"]   = sessionString;
                Session["name"]     = teacherModel.Name;
                Session["type"]     = "教师";

                return(this.Json(new { result = 1, data = "" }));
            }
            else if (studentList.Count > 0)
            {
                BLL.IPTable bllIP = new BLL.IPTable();
                string      ipv4  = GetIPv4.GetClientIPv4Address();

                string         strIP   = "IP='" + ipv4 + "'";
                List <IPTable> ipList1 = bllIP.DataTableToList(bllIP.GetList(strIP).Tables[0]);

                if (ipList1.Count > 0)
                {
                    IPTable IPModel = ipList1[0];
                    if (IPModel.Username.Equals(Username))
                    {
                        StudentTable studentModel = studentList[0];
                        strSql = "select * from AccessTable where ID = 7 or ID = 8";

                        List <AccessTable> tableList = new BLL.AccessTable().DataTableToList(DbHelperSQL.Query(strSql).Tables[0]);

                        string sessionString = "";
                        if (tableList.Count != 0)
                        {
                            sessionString += "[";
                            foreach (AccessTable tableModel in tableList)
                            {
                                sessionString += new JavaScriptSerializer().Serialize(tableModel) + ",";
                            }
                            sessionString  = sessionString.Remove(sessionString.Length - 1);
                            sessionString += "]";
                        }

                        Session.Timeout     = 30;
                        Session["username"] = studentModel.Username;
                        Session["access"]   = sessionString;
                        Session["name"]     = studentModel.Name;
                        Session["type"]     = "学生";

                        return(this.Json(new { result = 1, data = "" }));
                    }
                    else
                    {
                        return(this.Json(new { result = 2, data = "" }));
                    }
                }
                else
                {
                    strIP = "Username = '******'";
                    List <IPTable> ipList2 = bllIP.DataTableToList(bllIP.GetList(strIP).Tables[0]);

                    if (ipList2.Count > 0)
                    {
                        return(this.Json(new { result = 2, data = "" }));
                    }
                    else
                    {
                        IPTable model = new IPTable();
                        model.Username = Username;
                        model.IP       = ipv4;

                        bllIP.Add(model);

                        StudentTable studentModel = studentList[0];
                        strSql = "select * from AccessTable where ID = 7 or ID = 8";

                        List <AccessTable> tableList = new BLL.AccessTable().DataTableToList(DbHelperSQL.Query(strSql).Tables[0]);

                        string sessionString = "";
                        if (tableList.Count != 0)
                        {
                            sessionString += "[";
                            foreach (AccessTable tableModel in tableList)
                            {
                                sessionString += new JavaScriptSerializer().Serialize(tableModel) + ",";
                            }
                            sessionString  = sessionString.Remove(sessionString.Length - 1);
                            sessionString += "]";
                        }

                        Session.Timeout     = 30;
                        Session["username"] = studentModel.Username;
                        Session["access"]   = sessionString;
                        Session["name"]     = studentModel.Name;
                        Session["type"]     = "学生";

                        return(this.Json(new { result = 1, data = "" }));
                    }
                }
            }
            else
            {
                return(this.Json(new { result = 0, data = "" }));
            }
        }