public void SchoolCardBalanceTest()
        {
            string  workingDirectory = Path;
            Process p = new Process();

            p.StartInfo.FileName = Path + "myBalance.exe";
            p.StartInfo.RedirectStandardInput  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.WorkingDirectory       = workingDirectory;
            p.StartInfo.UseShellExecute        = false;
            p.Start();

            p.StandardInput.WriteLine("2016050215");
            p.StandardInput.WriteLine("123310");
            string         picname      = Path + "pic.png";
            ValidateWindow vw           = new ValidateWindow(picname);
            String         validatecode = "";

            if (vw.ShowDialog() == DialogResult.OK)
            {
                validatecode = vw.vcode;
            }
            vw.Close();
            p.StandardInput.WriteLine(validatecode);
            p.WaitForExit();
            string res = null;

            while (p.StandardOutput.Peek() > -1)
            {
                res += (p.StandardOutput.ReadLine());
            }
            Assert.IsFalse(res.Equals(""));
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            LogHelper.WriteLog(typeof(CourseSelectionMainPage), "用户点击更新按钮");
            Process p = new Process();

            p.StartInfo.FileName               = Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Get_CourseInfo\\getCourseInfo.exe";
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardInput  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.WorkingDirectory       = Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Get_CourseInfo\\";
            p.Start();
            p.StandardInput.WriteLine(this.stuId);
            p.StandardInput.WriteLine(this.password);
            string filename     = Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Get_CourseInfo\\vcode.png";
            String validatecode = "";

            try
            {
                ValidateWindow vw = new ValidateWindow(filename);

                if (vw.ShowDialog() == DialogResult.OK)
                {
                    validatecode = vw.vcode;
                }
                vw.Close();
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(CourseSelectionMainPage), ex);
            }
            p.StandardInput.WriteLine(validatecode);
            File.Delete(p.StartInfo.WorkingDirectory + "vcode.png");
            string res = null;

            while (p.StandardOutput.Peek() > -1)
            {
                res += (p.StandardOutput.ReadLine());
            }
            p.WaitForExit();
            LogHelper.WriteLog(typeof(CourseSelectionMainPage), "后台进程运行结束");
            try
            {
                getMainPager();
                setMainPager();
            }
            catch (Exception ex)
            {
                MessageBox.Show("更新失败,用户信息错误");
                LogHelper.WriteLog(typeof(CourseSelectionMainPage), ex);
            }
        }
        private void updateBalance(string Path)
        {
            //初始化用户信息
            this.textBox1.Text = "姓名:" + GlobalData.user.StudentId + "";
            this.textBox2.Text = "学号:" + GlobalData.user.Name + "";
            this.textBox3.Text = "院系专业:" + GlobalData.user.School + " " + GlobalData.user.Major;
            LogHelper.WriteLog(typeof(CourseInfo), "用户点击更新按钮");

            string workingDirectory = Path;

            try
            {
                Process p = new Process();
                p.StartInfo.FileName = Path + "myBalance.exe";
                p.StartInfo.RedirectStandardInput  = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError  = true;
                p.StartInfo.CreateNoWindow         = true;
                p.StartInfo.WorkingDirectory       = workingDirectory;
                p.StartInfo.UseShellExecute        = false;
                p.Start();

                p.StandardInput.WriteLine(GlobalData.user.StudentId + "");
                p.StandardInput.WriteLine(GlobalData.user.Password);
                //MessageBox.Show(GlobalData.user.StudentId + "" + GlobalData.user.Password);
                string         picname      = Path + "pic.png";
                ValidateWindow vw           = new ValidateWindow(picname);
                String         validatecode = "";
                if (vw.ShowDialog() == DialogResult.OK)
                {
                    validatecode = vw.vcode;
                }
                vw.Close();
                p.StandardInput.WriteLine(validatecode);
                string res = null;
                while (p.StandardOutput.Peek() > -1)
                {
                    res += (p.StandardOutput.ReadLine());
                }
                p.WaitForExit();
                LogHelper.WriteLog(typeof(CourseInfo), "后台进程运行结束");
                loadFile(Path);
                File.Delete(Path + "pic.png");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                MessageBox.Show("获取余额失败");
                LogHelper.WriteLog(typeof(CourseInfo), e);
                return;
            }
        }