/// <summary> /// Shows a specific group box depends on selected question's type. /// </summary> /// <param name="type">The type.</param> private void ShowGroupBox(string type) //this method show a specific Groupbox depends on type of question then save old data (before editing ) in variables { switch (type) //switch type of question { case "Slider": q = new Slider(question_table.Rows[0].ItemArray[0].ToString(), (int)question_table.Rows[0].ItemArray[1], (int)(question_table.Rows[0].ItemArray[3]), (int)(Type_table.Rows[0].ItemArray[1]), (int)(Type_table.Rows[0].ItemArray[2]), Type_table.Rows[0].ItemArray[3].ToString(), Type_table.Rows[0].ItemArray[4].ToString()); //create object from slider class and fill it with saved values retrived from database (old values) Start_textBox.Text = q.Current_values().ElementAt(0).ToString(); //show stored value of Start value End_textBox.Text = q.Current_values().ElementAt(1).ToString(); //show stored value of End value Start_caption_textBox.Text = q.Current_values().ElementAt(2).ToString(); //show stored value of Start_caption End_caption_textBox.Text = q.Current_values().ElementAt(3).ToString(); //show stored value of End_caption Next_Number_UpDown(QuestionOrderUpDown1); Slider_GroupBox.Visible = true; //show groupbox that hold text boxes to display and editing question's values break; case "Smiley": q = new Smiley(question_table.Rows[0].ItemArray[0].ToString(), (int)question_table.Rows[0].ItemArray[1], (int)(question_table.Rows[0].ItemArray[3]), (int)(Type_table.Rows[0].ItemArray[1])); //create object from Smiley and fill it with stored values retrived from database (old value) Smile_textBox.Text = q.Current_values().ElementAt(0).ToString(); //show stored value of Faces Next_Number_UpDown(QuestionOrderUpDown3); Smiley_GroupBox.Visible = true; //show groupbox that hold text boxes to display and editing question's values break; case "Stars": q = new Stars(question_table.Rows[0].ItemArray[0].ToString(), (int)question_table.Rows[0].ItemArray[1], (int)(question_table.Rows[0].ItemArray[3]), (int)(Type_table.Rows[0].ItemArray[1])); //create object from Stars and fill it with stored values retrived from database (old value) Stars_textbox.Text = q.Current_values().ElementAt(0).ToString(); //show stored value of Stars Next_Number_UpDown(QuestionOrderUpDown2); Stars_GroupBox.Visible = true; //show groupbox that hold text boxes to display and editing question's values break; } }
/// <summary> /// Handles the Click event of the Radio control, create question object and fill controls with default values of that question. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void Radio_Click(object sender, EventArgs e) { Relese(q); //call method release that release q object if refere to another object if (ReferenceEquals(sender, Slider_Radio)) //if slider radio button { q = new Slider(Next_ID) //create slider object { ID = Next_ID, }; Slider_Radio.Checked = true;//set check property of Slider radio button to true Next_Number_UpDown(QuestionOrderUpDown1); Show_controls(); } else if (ReferenceEquals(sender, Smiley_Radio)) //if Smiley radio button { q = new Smiley(Next_ID) //create smiley object { Question_order = Next_ID //sign qustion_order property to next_order field }; Smiley_Radio.Checked = true; //set check property of Smiley radio button to true Next_Number_UpDown(QuestionOrderUpDown3); Show_controls(); } else if (ReferenceEquals(sender, Stars_Radio)) //if Stars radio button { q = new Stars(Next_ID) //create star object { Question_order = Next_ID //sign qustion_order property to next_order field }; Stars_Radio.Checked = true; //set check property of Stars radio button to true Next_Number_UpDown(QuestionOrderUpDown2); Show_controls(); } }
/// <summary> /// Show related controls depending on question type. /// </summary> private void Show_controls() { question_box.Text = IsEdit == true ? question.Question_text : question_box.Text; Shared_numeric.Visible = true; int index = QuestionType_ComboBox.SelectedIndex; switch (index) { case 0: Slider slider = (Slider)question; Shared_label.Text = "Start :"; Shared_label.Visible = true; QuestionTip.SetToolTip(Shared_numeric, "Enter start value"); Shared_numeric.Value = Int32.Parse(slider.Slider_default[0]); //fill textbox with default value of start End_numeric.Value = Int32.Parse(slider.Slider_default[1]); //fill textbox with default value of end Start_caption_textBox.Text = slider.Slider_default[2]; //fill textbox with default value of start caption End_caption_textBox.Text = slider.Slider_default[3]; //fill textbox with default value of end caption Slider_panel.Visible = true; break; case 1: Smiley smiley = (Smiley)question; Shared_label.Text = "Smiles :"; Shared_label.Visible = true; QuestionTip.SetToolTip(Shared_numeric, "Enter number of smiles"); Shared_numeric.Value = smiley.Smiles_default; //fill textbox with default value of faces Slider_panel.Visible = false; break; case 2: Stars stars = (Stars)question; Shared_label.Text = "Stars :"; Shared_label.Visible = true; QuestionTip.SetToolTip(Shared_numeric, "Enter number of stars"); Shared_numeric.Value = stars.Stars_default; //fill textbox with default value of stars Slider_panel.Visible = false; break; } }
/// <summary> /// change question values if they are correct. /// </summary> /// <param name="Values">The values.</param> /// <returns></returns> /// <exception cref="FormatException"> /// </exception> private bool Change_Values()//check if values are changed or not { try { question.Question_order = Q_order; if (!IsEmpty(question_box)) { question.Question_text = question_box.Text;//validate user input } else { MessageBox.Show("Please write a question", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Print_Errors("Please write a question"); return(false); } } catch (FormatException ex) { MessageBox.Show("Question should not contain a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Print_Errors("Question should not contain a number", ex); return(false); } if (question.Question_type == "Slider") { Slider slider = (Slider)question; try { if (!IsEmpty(Shared_numeric)) { slider.Start = Int32.Parse(Shared_numeric.Text); } } catch (ArgumentOutOfRangeException ex) { MessageBox.Show("Start values should be between 0-100", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Print_Errors("Start values should be between 0-100", ex); return(false); } try { if (!IsEmpty(End_numeric)) { slider.End = Int32.Parse(End_numeric.Text); } if (!IsEmpty(End_caption_textBox)) { slider.End_Caption = End_caption_textBox.Text; } if (!IsEmpty(Start_caption_textBox)) { slider.Start_Caption = Start_caption_textBox.Text; } } catch (ArgumentOutOfRangeException ex) { MessageBox.Show("End value should be between 0-100", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Print_Errors("End value should be between 0-100", ex); return(false); } try { return(slider.Validate()); } catch (ArgumentOutOfRangeException ex) { MessageBox.Show("Start value should be lower than End value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Print_Errors("Start value should be lower than End value", ex); return(false); } } else if (question.Question_type == "Smiley") { Smiley smiley = (Smiley)question; try { if (!IsEmpty(Shared_numeric)) { smiley.Smiles = Int32.Parse(Shared_numeric.Text); } } catch (ArgumentOutOfRangeException ex) { MessageBox.Show("Number of faces should be between 2-5", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Print_Errors("Number of faces should be between 2-5", ex); return(false); } } else if (question.Question_type == "Stars") { Stars stars = (Stars)question; try { if (!IsEmpty(Shared_numeric)) { stars.Star = Int32.Parse(Shared_numeric.Text); } } catch (ArgumentOutOfRangeException ex) { MessageBox.Show("Number of stars should be between 0-10", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Print_Errors("Number of stars should be between 0-10", ex); return(false); } } return(true); }
/// <summary> /// Determines whether the specified box is empty. /// </summary> /// <param name="box">The box.</param> /// <returns> /// <c>true</c> if the specified box is empty; otherwise, <c>false</c>. /// </returns> private bool IsEmpty(object box) { if (ReferenceEquals(box, question_box)) { if (question_box.Text == "") { return(true); } else { return(false); } } else if (ReferenceEquals(box, Shared_numeric)) { switch (question.Question_type) { case "Slider": Slider slider = (Slider)question; if (Shared_numeric.Value == Int32.Parse(slider.Slider_default[0])) { return(true); } else { return(false); } case "Smiley": Smiley smiley = (Smiley)question; if (Shared_numeric.Value == smiley.Smiles_default) { return(true); } else { return(false); } case "Stars": Stars stars = (Stars)question; if (Shared_numeric.Value == stars.Stars_default) { return(true); } else { return(false); } default: return(false); } } else if (ReferenceEquals(box, End_numeric)) { Slider slider = (Slider)question; if (End_numeric.Value == Int32.Parse(slider.Slider_default[1])) { return(true); } else { return(false); } } else if (ReferenceEquals(box, Start_caption_textBox) || Start_caption_textBox.Text == "") { Slider slider = (Slider)question; if (Start_caption_textBox.Text == slider.Slider_default[2]) { return(true); } else { return(false); } } else if (ReferenceEquals(box, End_caption_textBox) || End_caption_textBox.Text == "") { Slider slider = (Slider)question; if (End_caption_textBox.Text == slider.Slider_default[3]) { return(true); } else { return(false); } } else { return(false); } }