private void btn_add_option_Click(object sender, EventArgs e) { if (pan_options.Controls.Count > 0) { OptionControl oc = new OptionControl(); oc.Name = "option" + (pan_options.Controls.Count - 1); oc.OptionLetter = (char)(Convert.ToInt32(((OptionControl)pan_options.Controls[(pan_options.Controls.Count - 1)]).OptionLetter) + 1); oc.Location = new Point(2, 2 + ((pan_options.Controls.Count) * 36)); pan_options.Controls.Add(oc); } else { OptionControl oc = new OptionControl(); oc.Location = new Point(2, 2); oc.Name = "option0"; oc.OptionLetter = 'A'; pan_options.Controls.Add(oc); } }
private void addOptionToolStripMenuItem_Click(object sender, EventArgs e) { OptionControl ctrl = new OptionControl(); if (pan_options.Controls.Count != 0) { OptionControl info = (OptionControl)pan_options.Controls[pan_options.Controls.OfType<OptionControl>().Count() - 1]; ctrl.Location = new Point(info.Location.X, info.Location.Y + 35); int num = Convert.ToInt32(info.Name.Replace("optionControl", "")); ctrl.Name = "optionControl" + (num + 1); ctrl.OptionLetter = (char)(Convert.ToInt32(info.OptionLetter) + 1); } else { ctrl.Location = new Point(0, 0); ctrl.Name = "optionControl1"; ctrl.OptionLetter = 'A'; } pan_options_ControlChanged(btn_add_option, null); pan_options.Controls.Add(ctrl); }
private void PullNextQuestion(TreeNode questionNode) { Question queryResult = rawQuestionList.FirstOrDefault(s => s.SectionTitle == questionNode.Parent.Text && s.QuestionNumber == Convert.ToInt32(questionNode.Text.Replace("Question ", ""))); if (queryResult != null) { ClearControls(); int questionIndex = rawQuestionList.IndexOf(queryResult); txt_question_text.Text = rawQuestionList[questionIndex].QuestionText; txt_answer_explanation.Text = rawQuestionList[questionIndex].AnswerExplanation; if (string.IsNullOrWhiteSpace(rawQuestionList[questionIndex].QuestionImagePath)) { pct_question_picture.Image = null; pct_question_picture.ImageLocation = null; btn_clear_picture.Visible = false; btn_select_picture.Visible = false; pct_question_picture.Visible = false; } else { pct_question_picture.Image = new Bitmap(rawQuestionList[questionIndex].QuestionImagePath); pct_question_picture.ImageLocation = rawQuestionList[questionIndex].QuestionImagePath; btn_clear_picture.Visible = true; btn_select_picture.Visible = true; pct_question_picture.Visible = true; } int i = 0; foreach(var option in rawQuestionList[questionIndex].QuestionOptions) { OptionControl oc = new OptionControl(); oc.OptionLetter = option.Key; oc.OptionText = option.Value; oc.Location = new Point(2, i * 36); if (option.Key == rawQuestionList[questionIndex].QuestionAnswer) { oc.IsChecked = true; } pan_options.Controls.Add(oc); i++; } } else { ClearControls(); } }
private void trv_explorer_AfterSelect(object sender, TreeViewEventArgs e) { if (((TreeView)sender).SelectedNode.Name.Contains("ques")) { //enable relevant options addOptionToolStripMenuItem.Enabled = true; newQuestionToolStripMenuItem.Enabled = false; btn_new_question.Enabled = false; newSectionToolStripMenuItem.Enabled = false; btn_new_section.Enabled = false; splcn_main_view.Panel2.Enabled = true; editToolStripMenuItem1.Enabled = false; previousItemToolStripMenuItem.Enabled = true; nextItemToolStripMenuItem.Enabled = true; //enable printing btn_print_exam.Enabled = true; printToolStripMenuItem.Enabled = true; btn_print_preview.Enabled = true; //display question lbl_question_and_section.Text = "Section: " + ((TreeView)sender).SelectedNode.Parent.Text + ", " + ((TreeView)sender).SelectedNode.Text; //RefreshInputControls(); try { bool exists = false; Question present = new Question(); try { var temp = tempExamStore.FindAll(s => s.SectionTitle == ((TreeView)sender).SelectedNode.Parent.Text); present = temp.SingleOrDefault(c => c.QuestionNumber == Convert.ToInt32(((TreeView)sender).SelectedNode.Text.Replace("Question ", ""))); exists = tempExamStore.Contains(present); } catch (NullReferenceException ex) { Debug.Print("Error: " + ex.Message + ", Inner Exception: " + ex.InnerException); } finally { if (exists) { txt_question_text.Text = present.QuestionText; if (string.IsNullOrWhiteSpace(present.QuestionImagePath)) { pct_question_picture.Image = null; pct_question_picture.ImageLocation = null; btn_clear_picture.Visible = false; btn_select_picture.Visible = false; pct_question_picture.Visible = false; } else { pct_question_picture.Image = new Bitmap(present.QuestionImagePath); pct_question_picture.ImageLocation = present.QuestionImagePath; btn_clear_picture.Visible = true; btn_select_picture.Visible = true; pct_question_picture.Visible = true; } foreach (var item in present.QuestionOptions) { OptionControl ctrl = new OptionControl(); ctrl.OptionLetter = item.Key; ctrl.OptionText = item.Value; if (item.Key == present.QuestionAnswer) { ctrl.IsChecked = true; } if (pan_options.Controls.Count != 0) { OptionControl info = (OptionControl)pan_options.Controls[pan_options.Controls.OfType<OptionControl>().Count() - 1]; ctrl.Location = new Point(info.Location.X, info.Location.Y + 35); int num = Convert.ToInt32(info.Name.Replace("optionControl", "")); ctrl.Name = "optionControl" + (num + 1); } else { ctrl.Location = new Point(0, 0); ctrl.Name = "optionControl1"; } pan_options_ControlChanged(btn_add_option, null); pan_options.Controls.Add(ctrl); } } else { btn_select_picture.Visible = false; btn_clear_picture.Visible = false; pct_question_picture.Visible = false; } } } catch (NullReferenceException ex) { //MessageBox.Show(ex.Message + " " + ex.InnerException + Environment.NewLine + ex.Source); Debug.Print("Error: " + ex.Message + ", Inner Exception: " + ex.InnerException); } catch (ArgumentNullException ex) { //MessageBox.Show(ex.Message + " " + ex.InnerException + Environment.NewLine + ex.Source); Debug.Print("Error: " + ex.Message + ", Inner Exception: " + ex.InnerException); } } //enable add questions else if (((TreeView)sender).SelectedNode.Name.Contains("secNode")) { splcn_main_view.Panel2.Enabled = false; addOptionToolStripMenuItem.Enabled = false; newQuestionToolStripMenuItem.Enabled = true; btn_new_question.Enabled = true; newSectionToolStripMenuItem.Enabled = false; btn_new_section.Enabled = false; previousItemToolStripMenuItem.Enabled = true; nextItemToolStripMenuItem.Enabled = true; //clear status text lbl_question_and_section.Text = ""; //dislplay edit option editToolStripMenuItem1.Enabled = true; //disable printing btn_print_exam.Enabled = false; printToolStripMenuItem.Enabled = false; btn_print_preview.Enabled = false; } //enable add sections else if (((TreeView)sender).SelectedNode.Name.Contains("examNode")) { splcn_main_view.Panel2.Enabled = false; newSectionToolStripMenuItem.Enabled = true; addOptionToolStripMenuItem.Enabled = false; btn_new_section.Enabled = true; newQuestionToolStripMenuItem.Enabled = false; btn_new_question.Enabled = false; previousItemToolStripMenuItem.Enabled = false; nextItemToolStripMenuItem.Enabled = false; //display edit option editToolStripMenuItem1.Enabled = false; //disable printing btn_print_exam.Enabled = false; printToolStripMenuItem.Enabled = false; btn_print_preview.Enabled = false; } else { splcn_main_view.Panel2.Enabled = false; addOptionToolStripMenuItem.Enabled = false; newQuestionToolStripMenuItem.Enabled = false; addOptionToolStripMenuItem.Enabled = false; btn_new_question.Enabled = false; newSectionToolStripMenuItem.Enabled = false; btn_new_section.Enabled = false; //disable printing btn_print_exam.Enabled = false; printToolStripMenuItem.Enabled = false; btn_print_preview.Enabled = false; } }