コード例 #1
0
        public ActionResult IPAjaxList()
        {
            int start  = 0;
            int length = 0;

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

            var strSql = "";

            BLL.IPTable          ip   = new BLL.IPTable();
            List <Model.IPTable> list = ip.DataTableToList(ip.GetListByPage(strSql, "", start + 1, start + length).Tables[0]);
            int filterTotal           = ip.GetRecordCount(strSql);
            int total = ip.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,
                        Username = o.Username,
                        IP = o.IP,
                    })
                }
            }));
        }
コード例 #2
0
 public ActionResult Remove(int id)
 {
     BLL.IPTable ip = new BLL.IPTable();
     if (ip.Delete(id))
     {
         return(this.Json(new { result = 1, data = "" }));
     }
     else
     {
         return(this.Json(new { result = 0, msg = "没有这条数据" }));
     }
 }
コード例 #3
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 = "" }));
            }
        }
コード例 #4
0
        public ActionResult Clear(int id)
        {
            bool result = false;

            BLL.ExamTable          exam      = new BLL.ExamTable();
            string                 strSql    = "select * from ExamTable where Id = '" + id + "'";
            List <Model.ExamTable> tableList = new BLL.ExamTable().DataTableToList(DbHelperSQL.Query(strSql).Tables[0]);

            if (tableList.Count != 0)
            {
                foreach (Model.ExamTable tableModel in tableList)
                {
                    string path = Server.MapPath(tableModel.Filepath);
                    bool   exi  = System.IO.File.Exists(path);
                    if (exi)
                    {
                        System.IO.File.Delete(path);
                    }
                }
            }

            exam.Delete(id);

            BLL.AnswerTable          answer     = new BLL.AnswerTable();
            string                   strSql1    = "select * from AnswerTable where Exam = '" + id + "'";
            List <Model.AnswerTable> tableList1 = new BLL.AnswerTable().DataTableToList(DbHelperSQL.Query(strSql1).Tables[0]);

            if (tableList1.Count != 0)
            {
                foreach (Model.AnswerTable tableModel in tableList1)
                {
                    string path = Server.MapPath(tableModel.Filepath);
                    bool   exi  = System.IO.File.Exists(path);
                    if (exi)
                    {
                        System.IO.File.Delete(path);
                    }

                    answer.Delete(tableModel.ID);
                }
            }

            BLL.IPTable          IP         = new BLL.IPTable();
            string               strSql2    = "select * from IPTable";
            List <Model.IPTable> tableList2 = new BLL.IPTable().DataTableToList(DbHelperSQL.Query(strSql2).Tables[0]);

            if (tableList2.Count != 0)
            {
                foreach (Model.IPTable tableModel in tableList2)
                {
                    IP.Delete(tableModel.ID);
                }
            }

            result = true;

            if (result)
            {
                return(this.Json(new { result = 1, data = "" }));
            }
            else
            {
                return(this.Json(new { result = 0, msg = "没有这条数据" }));
            }
        }