/// <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();
                }
            }
        }
 /// <summary>
 /// 获取指定学生的课程信息
 /// </summary>
 /// <param name="StuID">学号</param>
 /// <returns>返回课程列表</returns>
 public static List <Course> GetCourses(string StuID)
 {
     using (var context = new jwContext())
     {
         var Courses = context.Courses.Where(s => s.StuID == StuID);
         return(Courses.ToList());
     }
 }
 /// <summary>
 /// 获取指定学生的成绩信息
 /// </summary>
 /// <param name="StuID">学号</param>
 /// <returns>返回成绩列表</returns>
 public static List <Score> GetScores(string StuID)
 {
     using (var context = new jwContext())
     {
         var Scores = context.Scores.Where(s => s.StuID == StuID);
         return(Scores.ToList());
     }
 }
Exemple #4
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();
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// 初始化教务系统数据库信息
        /// </summary>
        public static void Init()
        {
            jwContext.CurrentDirectory = System.Environment.CurrentDirectory + @"\data\app\cc.wnapp.whuHelper";

            using (var dbcontext = new jwContext())
            {
                var objectContext     = ((IObjectContextAdapter)dbcontext).ObjectContext;
                var mappingCollection = (StorageMappingItemCollection)objectContext.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
                mappingCollection.GenerateViews(new List <EdmSchemaError>());
            }
        }
        /// <summary>
        /// 获取绑定在指定机器人账号下的所有教务系统学生信息
        /// </summary>
        /// <param name="BotQQ">机器人账号</param>
        /// <returns></returns>
        public static List <Student> GetAll(string BotQQ)
        {
            List <Student> re = new List <Student>();

            using (var context = new jwContext())
            {
                var stu = context.Students.Where(s => s.BotQQ == BotQQ);
                foreach (var s in stu)
                {
                    re.Add(s);
                }
                return(re);
            }
        }
 /// <summary>
 /// 获取指定学生的绑定的QQ号
 /// </summary>
 /// <param name="StuID">学号</param>
 /// <returns>成功返回QQ,失败返回空</returns>
 public static string GetStuQQ(string StuID)
 {
     using (var context = new jwContext())
     {
         var stu = context.Students.SingleOrDefault(s => s.StuID == StuID);
         if (stu != null)
         {
             return(stu.QQ);
         }
         else
         {
             return("");
         }
     }
 }
 /// <summary>
 /// 确认系统中不存在该学生
 /// </summary>
 /// <param name="StuID">学号</param>
 /// <returns>存在返回true,不存在返回false</returns>
 public static bool StuExist(string StuID)
 {
     using (var context = new jwContext())
     {
         var stu = context.Students.SingleOrDefault(s => s.StuID == StuID);
         if (stu != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
        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 #10
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("未知错误");
            }
        }