Ejemplo n.º 1
0
        public override ActionResult AjaxList()
        {
            int start  = 0;
            int length = 0;

            start  = Convert.ToInt32(Request.Params["start"]);
            length = Convert.ToInt32(Request.Params["length"]);

            var strSql = "Username = '******'";

            BLL.StudentTable          bllStudent  = new BLL.StudentTable();
            List <Model.StudentTable> studentList = bllStudent.DataTableToList(bllStudent.GetList(strSql).Tables[0]);

            if (studentList.Count > 0)
            {
                Model.StudentTable studentModel = studentList[0];

                strSql = "Major = N'" + studentList[0].Major + "' and Nowstate = N'已开启'";
            }

            List <Model.ExamTable> list = exam.DataTableToList(exam.GetListByPage(strSql, "", start + 1, start + length).Tables[0]);
            int filterTotal             = exam.GetRecordCount(strSql);
            int total = exam.GetRecordCount("");

            return(this.Json(new
            {
                result = 1,
                data = new
                {
                    draw = Request.Params["draw"],
                    recordsTotal = total,
                    recordsFiltered = filterTotal,
                    data = list.Select(o => new
                    {
                        ID = o.ID,
                        Teacher = o.Teacher,
                        Major = o.Major,
                        Start = o.Start,
                        Last = o.Last,
                        Filepath = o.Filepath,
                    })
                }
            }));
        }
Ejemplo n.º 2
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 = "" }));
            }
        }