protected void Page_Load(object sender, EventArgs e) { using (MooDB db = new MooDB()) { if (Request["id"] != null) { CollectEntityByID(db, int.Parse(Request["id"])); } if (testCase == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } if (testCase.Problem.TestCaseHidden) { if (!Permission.Check("testcase.hidden.read", false)) return; } else { if (!Permission.Check("testcase.read", true)) return; } if (testCase is TranditionalTestCase) { asTranditional = testCase as TranditionalTestCase; multiView.SetActiveView(viewTranditional); } else if (testCase is SpecialJudgedTestCase) { asSpecialJudged = testCase as SpecialJudgedTestCase; multiView.SetActiveView(viewSpecialJudged); } else if (testCase is InteractiveTestCase) { asInteractive = testCase as InteractiveTestCase; multiView.SetActiveView(viewInteractive); } else if (testCase is AnswerOnlyTestCase) { asAnswerOnly = testCase as AnswerOnlyTestCase; multiView.SetActiveView(viewAnswerOnly); } else { PageUtil.Redirect("未知的测试数据类型", "~/"); return; } multiView.GetActiveView().DataBind(); linkbar.DataBind(); Header.DataBind(); } }
/// <summary> /// 创建新的 InteractiveTestCase 对象。 /// </summary> /// <param name="id">ID 属性的初始值。</param> /// <param name="testData">TestData 属性的初始值。</param> /// <param name="timeLimit">TimeLimit 属性的初始值。</param> /// <param name="memoryLimit">MemoryLimit 属性的初始值。</param> public static InteractiveTestCase CreateInteractiveTestCase(global::System.Int32 id, global::System.Byte[] testData, global::System.Int32 timeLimit, global::System.Int32 memoryLimit) { InteractiveTestCase interactiveTestCase = new InteractiveTestCase(); interactiveTestCase.ID = id; interactiveTestCase.TestData = testData; interactiveTestCase.TimeLimit = timeLimit; interactiveTestCase.MemoryLimit = memoryLimit; return interactiveTestCase; }
protected void btnSubmit_Click(object sender, EventArgs e) { if (!Page.IsValid) return; int problemID = (int)ViewState["problemID"]; int testCaseID; using (MooDB db = new MooDB()) { problem = (from p in db.Problems where p.ID == problemID select p).Single<Problem>(); if (problem.LockTestCase) { if (!Permission.Check("testcase.locked.create", false)) return; } else { if (!Permission.Check("testcase.create", false)) return; } User currentUser = ((SiteUser)User.Identity).GetDBUser(db); TestCase testCase; if (problem.Type == "Tranditional") { testCase = new TranditionalTestCase() { Score = int.Parse(txtScore.Text), TimeLimit = int.Parse(txtTimeLimit.Text), MemoryLimit = int.Parse(txtMemoryLimit.Text), Input = fileInput.FileBytes, Answer = fileAnswer.FileBytes, Problem = problem, CreatedBy = currentUser }; } else if (problem.Type == "SpecialJudged") { int judgerID = int.Parse(txtJudger.Text); UploadedFile judger = (from f in db.UploadedFiles where f.ID == judgerID select f).Single<UploadedFile>(); testCase = new SpecialJudgedTestCase() { TimeLimit = int.Parse(txtTimeLimit.Text), MemoryLimit = int.Parse(txtMemoryLimit.Text), Input = fileInput.FileBytes, Answer = fileAnswer.FileBytes, Judger = judger, Problem = problem, CreatedBy = currentUser }; } else if (problem.Type == "Interactive") { int invokerID = int.Parse(txtInvoker.Text); UploadedFile invoker = (from f in db.UploadedFiles where f.ID == invokerID select f).Single<UploadedFile>(); testCase = new InteractiveTestCase() { Invoker = invoker, MemoryLimit = int.Parse(txtMemoryLimit.Text), TimeLimit = int.Parse(txtTimeLimit.Text), Problem = problem, TestData = fileTestData.FileBytes, CreatedBy = currentUser }; } else if (problem.Type == "AnswerOnly") { int judgerID = int.Parse(txtJudger.Text); UploadedFile judger = (from f in db.UploadedFiles where f.ID == judgerID select f).Single<UploadedFile>(); testCase = new AnswerOnlyTestCase() { Judger = judger, Problem = problem, TestData = fileTestData.FileBytes, CreatedBy = currentUser }; } else { PageUtil.Redirect("未知的题目类型", "~/"); return; } db.TestCases.AddObject(testCase); db.SaveChanges(); testCaseID = testCase.ID; Logger.Info(db, "创建测试数据#" + testCaseID); } PageUtil.Redirect("创建成功", "~/TestCase/?id=" + testCaseID); }