protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ControlForTest NewControlForTest = Page.LoadControl(VirtualPathsToUserControls.ControlForTest) as ControlForTest; SimpleControlForEndOfTest CurrentTestControlForEndOfTest = Page.LoadControl(VirtualPathsToUserControls.SimpleControlForEndOfTest) as SimpleControlForEndOfTest; List<AnswerForQuestionWithOneCorrectAnswer> TestListOfAnswers = new List<AnswerForQuestionWithOneCorrectAnswer>(); TestListOfAnswers.Add(new AnswerForQuestionWithOneCorrectAnswer("Correct answer", true)); TestListOfAnswers.Add(new AnswerForQuestionWithOneCorrectAnswer("Wrong answer", false)); TestListOfAnswers.Add(new AnswerForQuestionWithOneCorrectAnswer("Wrong answer", false)); List<QuestionWithOneCorrectAnswer> TestListOfQuestions = new List<QuestionWithOneCorrectAnswer>(); for (uint CounterOfQuestions = 0; CounterOfQuestions < 5; ++CounterOfQuestions) { TestListOfQuestions.Add(new QuestionWithOneCorrectAnswer(CounterOfQuestions, 5, "Question_" + CounterOfQuestions.ToString(), TestListOfAnswers)); } Test CurrentTestObject = new Test(TestListOfQuestions, 0, 15 ,0); HiddenFieldForTestHours.Value = CurrentTestObject.Hours.ToString(); HiddenFieldForTestMinutes.Value = CurrentTestObject.Minutes.ToString(); HiddenFieldForTestSeconds.Value = CurrentTestObject.Seconds.ToString(); AccessorToSession CurrentAccessorToSession = new AccessorToSession(Session); CurrentAccessorToSession.CurrentTest = CurrentTestObject; NewControlForTest.SetTestForThisControl(CurrentTestObject, CurrentTestControlForEndOfTest, true); PanelForTestControl.Controls.Add(NewControlForTest); } }
public uint GetScore() { AccessorToSession CurrentAccessorToSession = new AccessorToSession(Session); QuestionWithOneCorrectAnswer FoundQuestionWithSameID = (QuestionWithOneCorrectAnswer)CurrentAccessorToSession.CurrentTest.CurrentCollectonOfQuestions. Where(CurrentQuestion => CurrentQuestion.ID == UInt32.Parse(HiddenFieldForQuestionID.Value)).FirstOrDefault(); int IndexOfAnswer = 0; RadioButton CurrentRadioButton = null; foreach (RepeaterItem CurrentItem in RepeaterForAnswers.Items) { CurrentRadioButton = (RadioButton)CurrentItem.FindControl("RadioButtonForAnswer"); if (CurrentRadioButton.Checked) { if (FoundQuestionWithSameID.CurrentCollectionOfAnswers.ElementAt(IndexOfAnswer).CorrectAnswer) { return UInt32.Parse(HiddenFieldForScore.Value); } else { return 0; } } ++IndexOfAnswer; } return 0; }
protected void Page_Init(object sender,EventArgs e) { if (IsPostBack) { ControlForTest NewControlForTest = Page.LoadControl(VirtualPathsToUserControls.ControlForTest) as ControlForTest; SimpleControlForEndOfTest CurrentTestControlForEndOfTest = Page.LoadControl(VirtualPathsToUserControls.SimpleControlForEndOfTest) as SimpleControlForEndOfTest; AccessorToSession CurrentAccessorToSession = new AccessorToSession(Session); NewControlForTest.SetTestForThisControl(CurrentAccessorToSession.CurrentTest, CurrentTestControlForEndOfTest, false); PanelForTestControl.Controls.Add(NewControlForTest); } }
private void CountUserScore() { uint BufferForUserScore = 0; AccessorToSession CurrentAccessorToSession = new AccessorToSession(Session); Dictionary<uint, uint> CurrentCollectionOfUserScore = CurrentAccessorToSession.CurrentUserScoreCollection; for (int Index = 0; Index < CurrentWizardForTest.WizardSteps.Count - 1; ++Index) { BufferForUserScore += CurrentCollectionOfUserScore[(CurrentWizardForTest.WizardSteps[Index].Controls[0] as IControlForQuestion).GetQuestionID()]; } SimpleControlForEndOfTest CurrentControlForEndOfTest = (SimpleControlForEndOfTest)CurrentWizardForTest.WizardSteps[CurrentWizardForTest.WizardSteps.Count - 1].Controls[0]; CurrentControlForEndOfTest.SetScore(BufferForUserScore, CurrentAccessorToSession.CurrentTest.MaxScore); HiddenFieldForStateOfTestWizard.Value = TestStates.Completed; }
public void SetTestForThisControl(Test NewTest, UserControl ControlForResultOfTest, bool UserScoreCollectionNeedToBeAddedToSession) { /*if (UserScoreCollectionNeedToBeAddedToSession) { string Script = "alert('Hello i am test control inside update panel!');"; ScriptManager..RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), Script, true); }*/ if (NewTest.CurrentCollectonOfQuestions.Count() == 0) { throw new ArgumentException(Texts.ExceptionMessageForTestControl_TestIsEmpty); } try { Label LabelFoScore = (Label)ControlForResultOfTest.FindControl("ScoreLabel"); } catch { throw new ArgumentException(Texts.ExceptionMessageForTestControl_LabelForScoreIsMissing); } HiddenFieldForStateOfTestWizard.Value = TestStates.InProgress; AccessorToSession CurrentAccessorToSession = new AccessorToSession(Session); foreach (Question Currentquestion in NewTest.CurrentCollectonOfQuestions) { WizardStep NewWizardStep = new WizardStep(); NewWizardStep.Controls.Add(CreateControlForQuestion(Currentquestion)); CurrentWizardForTest.WizardSteps.Add(NewWizardStep); } if (UserScoreCollectionNeedToBeAddedToSession) { Dictionary<uint, uint> CollectionOfUserScore = new Dictionary<uint, uint>(); foreach (Question Currentquestion in NewTest.CurrentCollectonOfQuestions) { CollectionOfUserScore[Currentquestion.ID] = 0; } CurrentAccessorToSession.CurrentUserScoreCollection = CollectionOfUserScore; } WizardStep LastWizardStep = new WizardStep(); LastWizardStep.Controls.Add(ControlForResultOfTest); CurrentWizardForTest.WizardSteps.Add(LastWizardStep); int IndexOfLastWizardStep = CurrentWizardForTest.WizardSteps.Count - 1; int IndexOfFinishStep = CurrentWizardForTest.WizardSteps.Count - 2; ConfigureWizardSteps(IndexOfLastWizardStep, IndexOfFinishStep); }
protected void UpdateUserScore() { IControlForQuestion CurrentControlForQuestion = CurrentWizardForTest.ActiveStep.Controls[0] as IControlForQuestion; uint CurrentQuestionID = CurrentControlForQuestion.GetQuestionID(); AccessorToSession CurrentAccessorToSession = new AccessorToSession(Session); Dictionary<uint, uint> TestDictionary = CurrentAccessorToSession.CurrentUserScoreCollection; CurrentAccessorToSession.CurrentUserScoreCollection[CurrentQuestionID] = CurrentControlForQuestion.GetScore(); }