Пример #1
0
        private void Save_Click(object sender, EventArgs e)
        {
            if (password.Text == "")
            {
                MessageBox.Show("请输入密码后再试!", "密码为空提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (LoginInfo.ClassList.Count == 0 || LoginInfo.QueryFormOnline == false)
            {
                MessageBox.Show("请查询课表后再试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DateTime date     = DateTime.Now;
            string   FileName = Convert.ToString(date.Year) + "_" + Convert.ToString(date.Month) + "_" + Convert.ToString(date.Day) + "_" + Convert.ToString(date.Hour) + Convert.ToString(date.Minute) + Convert.ToString(date.Second) + Convert.ToString(date.Millisecond) + ".txt";

            //FileStream fs = new FileStream(FileName + ".dat", FileMode.Create);
            StreamWriter sW1 = new StreamWriter(FileName, true, Encoding.UTF8);
            //StreamWriter sw = new StreamWriter(fs);

            string TransPsw = "Password:"******"MD5") + "\r\n";//写入加密后密码

            string Output = "";

            for (int i = 0; i < LoginInfo.ClassList.Count; i++)//写入节点信息
            {
                Output += "ClassName:" + LoginInfo.ClassList[i].ClassName + "\r\n";
                Output += "ClassTime:" + LoginInfo.ClassList[i].ClassTime + "\r\n";
                Output += "Teacher:" + LoginInfo.ClassList[i].Teacher + "\r\n";
                Output += "Location:" + LoginInfo.ClassList[i].Location + "\r\n";
                Output += "\r\n";
            }

            Output += "Locations\r\n";

            for (int i = 0; i < 12; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    Output += LoginInfo.ClassTable[i, j] == null ? "<.>" : "<" + Convert.ToString(LoginInfo.ClassTable[i, j]) + ">";
                }
                Output += "\r\n";
            }

            Output += "EndLocation\r\n";

            Output += "SelectedYear:" + LoginInfo.SelectedYear + "\r\n";
            Output += "SelectedTerm:" + LoginInfo.SelectedTerm + "\r\n";

            Base64CryptFun Crypt = new Base64CryptFun();

            Output = Crypt.Encode(Output);

            Output = TransPsw + Output;

            sW1.Write(Output);

            sW1.Close();

            MessageBox.Show("课程表导出成功,文件名为:" + FileName + ",使用当前密码可以再次读取!", "导出成功", MessageBoxButtons.OK, MessageBoxIcon.Information);

            System.Diagnostics.ProcessStartInfo pi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
            pi.Arguments = "/e,/select," + FileName;
            System.Diagnostics.Process.Start(pi);
        }
Пример #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();
            }
        }