Beispiel #1
0
        private void RegexClassTable()
        {
            Regex ClassTable  = new Regex("<table.+?</table>", RegexOptions.Singleline);                  //匹配表格
            Regex SingleLine  = new Regex("第\\d{1,2}节.+?</tr>", RegexOptions.Singleline);                 //第\d{1,2}节.+?</tr> 匹配单节课
            Regex SingleClass = new Regex("<td.+?>.+?</td>", RegexOptions.Singleline);                    //<td.+?>.+?</td> 匹配单课
            Regex ExtraTime   = new Regex("\\d{4}.\\d{2}.\\d{2}.+?<.+?>.[^<]+", RegexOptions.Singleline); //\d{4}.\d{2}.\d{2}.+?<.+?>.[^<]+ 某些课程出现的额外时间和教室信息
            Regex ClassRoom   = new Regex("[\u4e00-\u9fa5]-[^<]+", RegexOptions.Singleline);              //[\u4e00-\u9fa5]-[^<]+ 课程教室
            Regex TDHead      = new Regex("align=\"Center\" rowspan.+?>", RegexOptions.Singleline);       //TD信息头
            Regex Info        = new Regex(".+?<.+?>", RegexOptions.Singleline);                           //获取单行信息
            Regex InfoLabel   = new Regex("<.+?>", RegexOptions.Singleline);                              //单行信息标签
            Regex huge        = new Regex("{.+?}", RegexOptions.Singleline);                              //获取周数

            Regex nums         = new Regex("\\d,\\d{1,2},\\d{1,2}");                                      //三节课的课程
            Regex num          = new Regex("\\d,\\d");                                                    //两节课的课程
            Regex ClassPerWeek = new Regex("\\d节/周");                                                     //N节一周


            Match           CLASSTable = ClassTable.Match(WebCode);                     //获取表格
            MatchCollection SingleLINE = SingleLine.Matches(CLASSTable.Value);          //获取所有单行

            for (int i = 0; i < SingleLINE.Count; i++)                                  //行数
            {
                MatchCollection SingleCLASS = SingleClass.Matches(SingleLINE[i].Value); //列数
                for (int j = 0; j < SingleCLASS.Count; j++)
                {
                    if (SingleCLASS[j].Value.IndexOf("&nbsp") != -1)//空格
                    {
                        continue;
                    }

                    LoginInfo.ClassNode node = new LoginInfo.ClassNode();
                    if (ClassRoom.IsMatch(SingleCLASS[j].Value) == false)
                    {
                        node.Location = "课表内无教室信息";
                    }
                    else
                    {
                        node.Location = ClassRoom.Match(SingleCLASS[j].Value).Value;
                    }

                    MatchCollection ClassInfo   = Info.Matches(SingleCLASS[j].Value);
                    string[]        classstring = new string[ClassInfo.Count];
                    int             index       = 0;
                    for (int Ccnt = 0; Ccnt < ClassInfo.Count; Ccnt++)
                    {
                        string infos = ClassInfo[Ccnt].ToString().Replace(InfoLabel.Match(ClassInfo[Ccnt].Value).Value, "");//去除标签,获得信息
                        if (infos != "")
                        {
                            classstring[index++] = infos;
                        }
                        else
                        {
                            Ccnt++;
                        }
                    }
                    node.ClassName = classstring[0].Replace("<br>", "");
                    node.ClassTime = classstring[1];
                    node.Teacher   = classstring[2];

                    if (classstring.Length > 4)
                    {
                        for (int hugei = 4; hugei < classstring.Length; hugei++)
                        {
                            try
                            {
                                if (huge.IsMatch(classstring[hugei]))
                                {
                                    node.ClassTime += " " + huge.Match(classstring[hugei]).Value;
                                    break;
                                }
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }

                    LoginInfo.ClassList.Add(node);
                    LoginInfo.MaxIndex++;

                    int CntOfClass = 0;
                    if (nums.IsMatch(node.ClassTime) != false)
                    {
                        CntOfClass = 3;
                    }
                    else if (num.IsMatch(node.ClassTime) != false)
                    {
                        CntOfClass = 2;
                    }
                    else if (ClassPerWeek.IsMatch(node.ClassTime) != false)
                    {
                        Regex numbers = new Regex("\\d节/周");
                        Regex number  = new Regex("\\d");
                        CntOfClass = Convert.ToInt32(number.Match(numbers.Match(node.ClassTime).Value).Value);
                    }

                    for (int x = 0; x < CntOfClass; x++)
                    {
                        LoginInfo.ClassTable[(i + x), j] = Convert.ToString(LoginInfo.MaxIndex);
                    }
                }
            }
        }
Beispiel #2
0
        private void DeCT_Click(object sender, EventArgs e)
        {
            string c = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text, "MD5");

            if (FilePath == "")
            {
                MessageBox.Show("未选择文件,请选择后再试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (password.Text == "")
            {
                MessageBox.Show("未输入密码,请输入后再试!", "空密码提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            StreamReader sr = new StreamReader(FilePath, Encoding.UTF8);

            string content = sr.ReadToEnd();

            if (content.IndexOf(c) == -1)
            {
                MessageBox.Show("密码错误!请检查后再试!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                sr.Close();
                return;
            }

            sr.Close();

            Base64CryptFun Crypt = new Base64CryptFun();

            string NoPassContent = content.Replace("Password:"******"\r\n", "");

            NoPassContent = Crypt.Decode(NoPassContent);

            Regex Loc          = new Regex("<.+?>");
            Regex ClassName    = new Regex("ClassName:.+", RegexOptions.Multiline);
            Regex ClassTime    = new Regex("ClassTime:.+", RegexOptions.Multiline);
            Regex Teacher      = new Regex("Teacher:.+", RegexOptions.Multiline);
            Regex Location     = new Regex("Location:.+", RegexOptions.Multiline);
            Regex Num          = new Regex("\\d{1,2}", RegexOptions.Multiline);
            Regex SelectedYear = new Regex("SelectedYear:.+", RegexOptions.Multiline);
            Regex SelectedTerm = new Regex("SelectedTerm:.+", RegexOptions.Multiline);

            MatchCollection ClassMatch    = ClassName.Matches(NoPassContent);
            MatchCollection TimeMatch     = ClassTime.Matches(NoPassContent);
            MatchCollection TeaMatch      = Teacher.Matches(NoPassContent);
            MatchCollection LocationMatch = Location.Matches(NoPassContent);
            MatchCollection LocMatch      = Loc.Matches(NoPassContent);

            LoginInfo.ClassList.Clear();

            for (int i = 0; i < ClassMatch.Count; i++)
            {
                LoginInfo.ClassNode node = new LoginInfo.ClassNode();

                node.ClassName = ClassMatch[i].Value.Replace("\r", "").Replace("ClassName:", "").Replace("\n", "");
                node.ClassTime = TimeMatch[i].Value.Replace("\r", "").Replace("ClassTime:", "").Replace("\n", "");
                node.Location  = LocationMatch[i].Value.Replace("\r", "").Replace("Location:", "").Replace("\n", "");
                node.Teacher   = TeaMatch[i].Value.Replace("\r", "").Replace("Teacher:", "").Replace("\n", "");

                LoginInfo.ClassList.Add(node);
            }

            //MessageBox.Show(Convert.ToString(LoginInfo.ClassList.Count));

            for (int i = 0; i < LocMatch.Count; i++)
            {
                if (Num.IsMatch(LocMatch[i].Value) == true)
                {
                    LoginInfo.ClassTable[i / 7, i % 7] = Num.Match(LocMatch[i].Value).Value;
                }
                else
                {
                    LoginInfo.ClassTable[i / 7, i % 7] = null;
                }
            }

            string Year = SelectedYear.Match(NoPassContent).Value.Replace("SelectedYear:", "").Replace("\r\n", "");
            string Trem = SelectedTerm.Match(NoPassContent).Value.Replace("SelectedTerm:", "").Replace("\r\n", "");

            LoginInfo.SelectedYear    = Year;
            LoginInfo.SelectedTerm    = Trem;
            LoginInfo.QueryFormOnline = false;

            if (table == null || table.IsDisposed)
            {
                table = new ClassTableForm();
                table.Show();
            }
            else
            {
                table.Activate();
            }
        }