private Task <string> GetTableAsync(ClassTableGoal goal) { return(Task.Run <string>(() => { return GetClassTable(goal); })); }
private async void TestView_Click(object sender, EventArgs e) { ClassTableGoal goal = new ClassTableGoal(); goal.Year = Year.Text; goal.Trem = Time.Text; await GetTableAsync(goal); await GetTableTask(); MessageBox.Show(ClassTable[0, 0]); }
private async void Query_Click(object sender, EventArgs e) { if (TermIndex.Text == "" || TermYear.Text == "") { MessageBox.Show("有未选择部分,请选择后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string Year = ""; string TermDate = ""; Regex YearRegex = new Regex("\\d{4}"); Year = YearRegex.Match(TermYear.Text).Value; if (TermIndex.Text.IndexOf('1') != -1) { TermDate = "1"; } else { TermDate = "2"; } ClassTableGoal classgoal = new ClassTableGoal(); classgoal.Year = Year; classgoal.Trem = TermDate; await GetTableAsync(classgoal); await GetTableTask(); Regex times = new Regex("\\d{4}-\\d{4}", RegexOptions.Singleline); string timesstring = times.Match(TermYear.Text).Value; if (PageCode.IndexOf("<option selected=\"selected\" value=\"" + timesstring) == -1) { MessageBox.Show("当前学期暂无课程,请检查查询时间后再试!", "无课程提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (classform == null || classform.IsDisposed) { classform = new ClassForm(TermYear.Text, TermIndex.Text, ClassTable); classform.Show(); } else { classform.Activate(); } }
private string GetClassTable(ClassTableGoal classtable) { #region 创建变量并初始化正则表达式 string postvalue = ""; PageCode = Send_Get(SetUrl(ModeList[0])); string url = SetUrl(ModeList[0]); Regex input = new Regex("input type=\"hidden\" name=\".*?\" value=\".*?\""); Regex inputname = new Regex("name=\".*?\""); Regex inputvalue = new Regex("value=\".*?\""); Regex SelectYear = new Regex("<option selected=\"selected\" value=\"\\d+-\\d+\">"); Regex SelectTerm = new Regex("<option selected=\"selected\" value=\"\\d\">"); #endregion #region 检查请求的学期是否为当前学期 如是当前学期则直接返回数据 Match YearMatch = SelectYear.Match(PageCode); Match TermMatch = SelectTerm.Match(PageCode); String Year = YearMatch.ToString(); String Term = TermMatch.ToString(); if (Year.IndexOf(classtable.Year) != -1 && Term.IndexOf(classtable.Trem) != -1) { return(PageCode); } #endregion #region 构造发送的字符串 MatchCollection inputmatch = input.Matches(PageCode); postvalue = inputname.Match(inputmatch[0].Value).ToString().Replace("name=\"", "").Replace("\"", "") + "=xnd&" + inputname.Match(inputmatch[1].Value).ToString().Replace("name=\"", "").Replace("\"", "") + "=&" + inputname.Match(inputmatch[2].Value).ToString().Replace("name=\"", "").Replace("\"", "") + "=" + inputvalue.Match(inputmatch[2].Value).ToString().Replace("name=\"", "").Replace("\"", "").Replace("+", "%2b") + "&xnd="; postvalue += classtable.Year + "-" + Convert.ToString(Convert.ToInt32(classtable.Year) + 1) + "&xqd=" + classtable.Trem; postvalue = postvalue.Replace("value=", ""); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(postvalue); #endregion #region 构造参数结构 SendPostLoginParameter send = new SendPostLoginParameter(); send.Bytesarray = bytes; send.PostUrl = url; send.ReferUrl = url; send.NeedRedirect = false; #endregion PageCode = Send_Post(send); return(PageCode); }