private void btn_Run_Code_Click(object sender, EventArgs e) { if (selectedProblem == null) { MessageBox.Show("当前未选择题目"); return; } PHPRunner runner = new PHPRunner(); //selectedProblem.InputSample = "1 2"; //selectedProblem.Problemcode = "<?php echo $_GET['a']; echo $_GET['b'];"; if (this.problemcode.Text == "") { MessageBox.Show("请输入解答代码!"); return; } runner.Code = this.problemcode.Text; if (selectedProblem.InputSample != "" || selectedProblem.InputSample != null) { string[] parameters = selectedProblem.InputSample.Split(' '); for (int i = 0; i < parameters.Length; i++) { runner.QueryString += "parameter" + i + "=" + parameters[i] + "&"; //runner.Code = runner.Code.Replace(Regex.Match(runner.Code,"\\$_GET\\[\\S*\\]$").Value, "$_GET['parameter"+i+"']"); } MatchCollection mc = Regex.Matches(runner.Code, "\\$_GET\\[\\S*\\]"); int j = 0; foreach (Match m in mc) { //MessageBox.Show(m.Value); runner.Code = runner.Code.Replace(m.Value, "$_GET['parameter" + j + "']"); j++; } //runner.Code = runner.Code.Replace("$_GET['a']", "$_GET['parameter0']"); // runner.Code = runner.Code.Replace("$_GET['b']", "$_GET['parameter1']"); runner.QueryString = runner.QueryString.Substring(0, runner.QueryString.Length - 1); } String res = runner.run(); Browser_output.Text = res; Answer_tabControl.SelectedTab = Browse_Output; if (res == selectedProblem.OutputSample) { this.Main_TreeView.SelectedNode.ImageIndex = 1; selectedProblem.Status = 1; MessageBox.Show("Accept"); ProblemList.UpdateStatus(selectedProblem); } else { this.Main_TreeView.SelectedNode.ImageIndex = 2; selectedProblem.Status = -1; MessageBox.Show("WrongAnswer"); ProblemList.UpdateStatus(selectedProblem); } this.Browser_output.Text = res; this.Main_TreeView.Invalidate(); }
private void btn_Save_Click(object sender, EventArgs e) { StructureOfProblem pro = null; foreach (int key in problems.Keys) { if (this.Main_TreeView.SelectedNode.Text == ProblemList.GetProblem(key).QuestionName) { ProblemList.GetProblem(key).QuestionName = this.Main_TreeView.SelectedNode.Text; ProblemList.GetProblem(key).QuestionDescription = this.ProDescTextBox.Text; ProblemList.GetProblem(key).OutputSample = this.OutputsampleText.Text; ProblemList.GetProblem(key).Problemcode = this.StdAnswerTextBox.Text; ProblemList.GetProblem(key).InputSample = this.InputSampleText.Text; pro = ProblemList.GetProblem(key); } if (ProblemList.GetProblem(key).QuestionName == "新练习") { ProblemList.GetProblem(key).QuestionName = this.Main_TreeView.SelectedNode.Text; ProblemList.GetProblem(key).QuestionDescription = this.ProDescTextBox.Text; } } if (pro != null) { ProblemList.UpdateStatus(pro); } }