/// <summary>
        /// 删除指定学生在教务系统数据库中的所有信息
        /// </summary>
        /// <param name="StuID">学号</param>
        public static void DeleteStu(string StuID)
        {
            using (var context = new jwContext())
            {
                var stu = context.Students.FirstOrDefault(s => s.StuID == StuID);
                if (stu != null)
                {
                    context.Students.Remove(stu);
                    context.SaveChanges();
                }

                var scores = context.Scores.Where(s => s.StuID == StuID);
                foreach (var s in scores)
                {
                    context.Scores.Remove(s);
                    context.SaveChanges();
                }

                var course = context.Courses.Where(c => c.StuID == StuID);
                foreach (var c in course)
                {
                    context.Courses.Remove(c);
                    context.SaveChanges();
                }
            }
        }
Exemple #2
0
        public void ProcessCourse()
        {
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(course_result);
            HtmlNode           table      = htmlDoc.DocumentNode.SelectSingleNode("//table[@class='table listTable']");
            HtmlNodeCollection tableNodes = table.ChildNodes;
            HtmlNodeCollection trNodes    = new HtmlNodeCollection(table);

            foreach (var n in tableNodes)
            {
                if (n.Name == "tr")
                {
                    trNodes.Add(n);
                }
            }
            trNodes.RemoveAt(0);    //第一个tr节点非课程项,故去除

            foreach (var n in trNodes)
            {
                HtmlNodeCollection tdNodes = n.ChildNodes;
                var itemlist = new List <String>();
                foreach (var td in tdNodes)     //每个tdNodes中含27个td
                {
                    var a = td.InnerText.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "");
                    itemlist.Add(a);
                }

                using (var context = new jwContext())
                {
                    var thisLessonNum = itemlist[1]; //直接将itemlist[1]放入Linq表达式将报错
                    var course        = context.Courses.SingleOrDefault(c => c.StuID == stuid && c.LessonNum == thisLessonNum);
                    if (course == null)              //确保表中不存在此项记录
                    {
                        var newcourse = new Course
                        {
                            StuID           = stuid,
                            LessonNum       = itemlist[1],
                            LessonName      = itemlist[3],
                            LessonType      = itemlist[5],
                            LearninType     = itemlist[7],
                            TeachingCollege = itemlist[9],
                            Teacher         = itemlist[11],
                            Specialty       = itemlist[13],
                            Credit          = itemlist[15],
                            LessonHours     = itemlist[17],
                            Time            = itemlist[19],
                            Note            = itemlist[21]
                        };
                        context.Courses.Add(newcourse);
                        context.SaveChanges();
                    }
                }
            }
        }
        public void ProcessScore()
        {
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(score_result);
            HtmlNode           table      = htmlDoc.DocumentNode.SelectSingleNode("//table[@class='table listTable']");
            HtmlNodeCollection tableNodes = table.ChildNodes;
            HtmlNodeCollection trNodes    = new HtmlNodeCollection(table);

            foreach (var n in tableNodes)
            {
                if (n.Name == "tr")
                {
                    trNodes.Add(n);
                }
            }
            trNodes.RemoveAt(0);    //第一个tr节点非课程项,故去除

            foreach (var n in trNodes)
            {
                HtmlNodeCollection tdNodes = new HtmlNodeCollection(n);
                foreach (var d in n.ChildNodes)
                {
                    if (d.Name == "td")
                    {
                        tdNodes.Add(d);
                    }
                }

                var itemlist = new List <String>();
                foreach (var td in tdNodes)
                {
                    var a = td.InnerText.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "");
                    itemlist.Add(a);
                }

                using (var context = new jwContext())
                {
                    var thisLessonName = itemlist[0]; //直接将itemlist[1]放入Linq表达式将报错
                    var score          = context.Scores.SingleOrDefault(s => s.StuID == stuid && s.LessonName == thisLessonName);
                    if (score == null)                //确保表中不存在此项记录
                    {
                        if (itemlist[10] != "")       //只存储已出成绩的课
                        {
                            var newscore = new Score
                            {
                                StuID             = stuid,
                                LessonName        = itemlist[0],
                                LessonType        = itemlist[1],
                                GeneralLessonType = itemlist[2],
                                LessonAttribute   = itemlist[3],
                                Credit            = itemlist[4],
                                TeacherName       = itemlist[5],
                                TeachingCollege   = itemlist[6],
                                LearningType      = itemlist[7],
                                Year = itemlist[8],
                                Term = itemlist[9],
                                Mark = itemlist[10],
                            };
                            context.Scores.Add(newscore);
                            context.SaveChanges();
                        }
                    }
                }
            }
        }
Exemple #4
0
        public void LoginSys()
        {
            urls.GetURLs();
            var client  = new RestClient(urls.login_url);
            var request = new RestRequest(Method.POST);

            request.AddHeader("Host", "bkjw.whu.edu.cn");
            request.AddHeader("Connection", "keep-alive");
            request.AddHeader("Origin", "http://bkjw.whu.edu.cn/");
            request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36");
            request.AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
            request.AddHeader("Accept-Language", "zh-CN,zh;q=0.9");
            request.AddHeader("Referer", "http://bkjw.whu.edu.cn/");

            request.AddParameter("timestamp", GetTimeStamp(false));
            request.AddParameter("jwb", "%E6%AD%A6%E5%A4%A7%E6%9C%AC%E7%A7%91%E6%95%99%E5%8A%A1%E7%B3%BB%E7%BB%9F");
            request.AddParameter("id", StuID);
            request.AddParameter("pwd", MD5Encrypt32(Password));
            request.AddParameter("xdvfb", GetCaptchaStr());

            request.AddCookie(urls.Cookie.Name, urls.Cookie.Value);

            var response = client.Execute(request);

            var ResponseContent = Encoding.GetEncoding("GB2312").GetString(response.RawBytes);

            if (response.ResponseUri.ToString() == "http://bkjw.whu.edu.cn/stu/stu_index.jsp")   //url成功重定向,登录成功
            {
                Console.WriteLine("登录成功。");
                //Console.WriteLine(ResponseContent);
                Setcsrftoken(ResponseContent);
                SetCourseUrl();
                SetScoreUrl();
                StuName = GetStuName(ResponseContent);
                College = GetCollege(ResponseContent);

                using (var context = new jwContext())
                {
                    var stu = context.Students.SingleOrDefault(s => s.StuID == StuID);
                    if (stu == null)
                    {
                        var newstu = new Student {
                            QQ = QQ, StuID = StuID, StuName = StuName, College = College, BotQQ = BotQQ
                        };
                        context.Students.Add(newstu);
                        context.SaveChanges();
                    }
                }
            }
            else if (ResponseContent.Contains("验证码错误"))
            {
                Dc.ReportError("***REMOVED***", CaptchaID);
                throw new CaptchaErrorException("验证码错误");
            }
            else if (ResponseContent.Contains("密码错误"))
            {
                throw new PasswordErrorException("用户名/密码错误");
            }
            else
            {
                throw new Exception("未知错误");
            }
        }