private void deleteASimpleItem(object sender, EventArgs e) { //Verify the user wants to remove the item DialogResult = MessageBox.Show("Are you sure you wish to delete this item?", "Delete item:", MessageBoxButtons.YesNo); if (DialogResult == DialogResult.Yes) { var item = ((Button)sender).Parent; //Remove item from lists then destroy it from memory. ((Button)sender).Parent.Parent.Controls.Remove(item); //Set the item count back to 0, then go through all panels in the list and renumber them. //Reason for resetting itemCount is because otherwise if you have 1,2,3 and delete #2 you do not end up with 1,3,3. itemCount = 0; foreach (Panel c in pnlQuestionDetails.Controls) { if (c.Name != "questionEdit") { c.Controls.Find("itemNum", true)[0].Text = "#" + (itemCount + 1); c.Name = itemCount.ToString(); itemCount++; } } questionObjectSimple question = game[(int)lastSelected.Tag - 1] as questionObjectSimple; question.questionItems.RemoveAt(int.Parse(item.Name) - 1); item.Dispose(); } }
//Insert information entered in the pnlQuestionDetails into the question array when it is a questionObjectSimple private void applyChangesToQuesitonSimple(questionObjectSimple question) { question.questionText = pnlQuestionDetails.Controls.Find("questionEdit", true)[0].Controls.Find("questionText", true)[0].Text; question.questionNumber = pnlQuestionDetails.Controls.Find("questionEdit", true)[0].Name; question.weight = int.Parse(pnlQuestionDetails.Controls.Find("questionEdit", true)[0].Controls.Find("weight", true)[0].Text); for (int i = 0; i < itemCount; i++) { //Grab the item from the list of items Panel c = (Panel)pnlQuestionDetails.Controls[i + 1]; if (c.Name != "questionEdit") { question.questionItems[i].itemText = c.Controls.Find("itemText", true)[0].Text; question.questionItems[i].correct = ((CheckBox)c.Controls.Find("correct", true)[0]).Checked; question.questionItems[i].popups.popupEnabled = ((CheckBox)c.Controls.Find("popup", true)[0]).Checked; //If the popup checkbox is false the other controls do not exist if (((CheckBox)c.Controls.Find("popup", true)[0]).Checked) { question.questionItems[i].popups.popupTitle = c.Controls.Find("popupTitleTextBox", true)[0].Text; question.questionItems[i].popups.popupBody = c.Controls.Find("popupBodyTextBox", true)[0].Text; } else { question.questionItems[i].popups.popupTitle = ""; question.questionItems[i].popups.popupBody = ""; } } } //apply the changes to the question array game[(int)lastSelected.Tag - 1] = question; }
private void applyQuestionSettings() { try { var type = questionEdit.GetChildAtPoint(new Point(68, 29)); var text = questionEdit.GetChildAtPoint(new Point(68, 6)).Text; //If user has not entered a question, throw error. if (text == "" || text == null) { errorHandle("Please enter a question before continuing."); } else { //If user has not selected a type, throw error. if (type.Text == "" || type.Text == null) { errorHandle("Please select a question type before continuing."); } //Remove the apply button, disable changing the question type and store basic info into the array else { var apply = questionEdit.GetChildAtPoint(new Point(245, 79)); questionEdit.Controls.Remove(apply); type.Enabled = false; var weight = questionEdit.GetChildAtPoint(new Point(68, 53)).Text; if (type.Text == "Multiple Choice" || type.Text == "True or False") { questionObjectSimple question = new questionObjectSimple(); question.questionText = text; question.questionType = type.Text; question.questionNumber = lastSelected.Controls.Find("QuestionNumber", true)[0].Text; int.TryParse(weight, out question.weight); game[(int)lastSelected.Tag - 1] = question; } else if (type.Text == "Drag & Drop") { questionObjectComplex question = new questionObjectComplex(); question.questionText = text; question.questionType = type.Text; question.questionNumber = lastSelected.Controls.Find("QuestionNumber", true)[0].Text; int.TryParse(weight, out question.weight); game[(int)lastSelected.Tag - 1] = question; } lastSelected.Controls.Find("Question", true)[0].Text = text; lastSelected.Controls.Find("QuestionType", true)[0].Text = type.Text; itemCount = 0; pnlQuestionOptions.Controls.Find("btnAddOption", true)[0].Enabled = true; } } } catch (Exception) { errorHandle("Could not configure the question\nPlease try again."); } }
//Insert information entered in the pnlQuestionDetails into the question array when it is a questionObjectSimple private void applyChangesToQuesitonSimple(questionObjectSimple question, bool enableCorrectCheck) { question.questionText = pnlQuestionDetails.Controls[0].Controls[1].Text; question.weight = int.Parse(pnlQuestionDetails.Controls[0].Controls[5].Text); itemCount = pnlQuestionDetails.Controls.Count - 1; //make sure there is at least one correct answer bool hasCorrect = false; question.questionItems = new List <questionItemSimple>();; for (int i = 0; i < itemCount; i++) { //Grab the item from the list of items Panel c = (Panel)pnlQuestionDetails.Controls[i + 1]; question.questionItems.Add(new questionItemSimple()); if (c.Name != "questionEdit") { question.questionItems[i].itemText = c.Controls.Find("itemText", true)[0].Text; question.questionItems[i].correct = ((CheckBox)c.Controls.Find("correct", true)[0]).Checked; if (((CheckBox)c.Controls.Find("correct", true)[0]).Checked == true) { hasCorrect = true; } question.questionItems[i].popups = new popups(); question.questionItems[i].popups.popupEnabled = ((CheckBox)c.Controls.Find("popup", true)[0]).Checked; //If the popup checkbox is false the other controls do not exist if (((CheckBox)c.Controls.Find("popup", true)[0]).Checked) { question.questionItems[i].popups.popupTitle = c.Controls.Find("popupTitleTextBox", true)[0].Text; question.questionItems[i].popups.popupBody = c.Controls.Find("popupBodyTextBox", true)[0].Text; } else { question.questionItems[i].popups.popupTitle = ""; question.questionItems[i].popups.popupBody = ""; } } } if (enableCorrectCheck == true) { if (hasCorrect == false) { errorHandle("Please make sure at least one option is marked as correct."); return; } } //apply the changes to the question array game[(int)lastSelected.Tag] = question; }
//Insert information entered in the pnlQuestionDetails into the question array when it is a questionObjectSimple private void applyChangesToQuesitonSimple(questionObjectSimple question, bool enableCorrectCheck) { question.questionText = pnlQuestionDetails.Controls[0].Controls[1].Text; question.weight = int.Parse(pnlQuestionDetails.Controls[0].Controls[5].Text); itemCount = pnlQuestionDetails.Controls.Count - 1; //make sure there is at least one correct answer bool hasCorrect = false; question.questionItems = new List<questionItemSimple>(); ; for (int i = 0; i < itemCount; i++) { //Grab the item from the list of items Panel c = (Panel)pnlQuestionDetails.Controls[i + 1]; question.questionItems.Add(new questionItemSimple()); if (c.Name != "questionEdit") { question.questionItems[i].itemText = c.Controls.Find("itemText", true)[0].Text; question.questionItems[i].correct = ((CheckBox)c.Controls.Find("correct", true)[0]).Checked; if (((CheckBox)c.Controls.Find("correct", true)[0]).Checked == true) { hasCorrect = true; } question.questionItems[i].popups = new popups(); question.questionItems[i].popups.popupEnabled = ((CheckBox)c.Controls.Find("popup", true)[0]).Checked; //If the popup checkbox is false the other controls do not exist if (((CheckBox)c.Controls.Find("popup", true)[0]).Checked) { question.questionItems[i].popups.popupTitle = c.Controls.Find("popupTitleTextBox", true)[0].Text; question.questionItems[i].popups.popupBody = c.Controls.Find("popupBodyTextBox", true)[0].Text; } else { question.questionItems[i].popups.popupTitle = ""; question.questionItems[i].popups.popupBody = ""; } } } if (enableCorrectCheck == true) { if (hasCorrect == false) { errorHandle("Please make sure at least one option is marked as correct."); return; } } //apply the changes to the question array game[(int)lastSelected.Tag] = question; }
//Apply the main settings to question before adding to the question private void applyQuestionSettings() { try { var type = questionEdit.GetChildAtPoint(new Point(68, 29)); var text = questionEdit.GetChildAtPoint(new Point(68, 6)).Text; //If user has not entered a question, throw error. if (text == "" || text == null) { errorHandle("Please enter a question before continuing."); return; } else { //If user has not selected a type, throw error. if (type.Text == "" || type.Text == null) { errorHandle("Please select a question type before continuing."); return; } //Remove the apply button, disable changing the question type and store basic info into the array else { var apply = questionEdit.GetChildAtPoint(new Point(245, 79)); var weight = questionEdit.GetChildAtPoint(new Point(68, 53)).Text; if (type.Text == "Multiple Choice" || type.Text == "True or False") { questionObjectSimple question = new questionObjectSimple(); question.questionText = text; question.questionType = type.Text; question.questionNumber = lastSelected.Controls.Find("QuestionNumber", true)[0].Text; int.TryParse(weight, out question.weight); game[(int)lastSelected.Tag] = question; } else if (type.Text == "Drag & Drop") { questionObjectComplex question = new questionObjectComplex(); question.questionText = text; question.questionType = type.Text; question.questionNumber = lastSelected.Controls.Find("QuestionNumber", true)[0].Text; int.TryParse(weight, out question.weight); game[(int)lastSelected.Tag] = question; } else { } questionEdit.Controls.Remove(apply); type.Enabled = false; lastSelected.Controls.Find("Question", true)[0].Text = text; lastSelected.Controls.Find("QuestionType", true)[0].Text = type.Text; itemCount = 0; pnlQuestionOptions.Controls.Find("btnAddOption", true)[0].Enabled = true; } } } catch (Exception) { errorHandle("Could not configure the question\nPlease try again."); } }
//Multiple Choice item private void newItemSimple() { //Creates a panel that will be used to allow users to add options to a multi choice question questionObjectSimple question = game[(int)lastSelected.Tag] as questionObjectSimple; itemCount++; Panel pnlItem = new Panel(); pnlItem.Name = itemCount.ToString(); pnlItem.Size = new Size(320, 46); pnlItem.BackColor = System.Drawing.Color.DarkGray; //User can enter the items text Label itemNum = new Label(); itemNum.Location = new Point(4, 10); itemNum.Text = "#" + itemCount.ToString(); itemNum.Name = "itemNum"; itemNum.Size = new Size(29, 13); TextBox itemTextBox = new TextBox(); itemTextBox.Name = "itemText"; itemTextBox.Location = new Point(33, 7); itemTextBox.Size = new Size(253, 20); itemTextBox.MaxLength = 100; //Configure deleteItem Button deleteItem = new Button(); deleteItem.Name = "deleteItem"; deleteItem.Text = "X"; deleteItem.Location = new Point(292, 7); deleteItem.Size = new Size(20, 20); deleteItem.FlatStyle = FlatStyle.Flat; deleteItem.FlatAppearance.BorderSize = 0; deleteItem.FlatAppearance.BorderColor = System.Drawing.Color.Red; deleteItem.BackColor = System.Drawing.Color.Black; deleteItem.ForeColor = System.Drawing.Color.White; deleteItem.Click += deleteASimpleItem; CheckBox correct = new CheckBox(); correct.Name = "correct"; correct.Text = "Correct"; correct.Location = new Point(8, 27); correct.Size = new Size(60, 17); CheckBox popup = new CheckBox(); popup.Name = "popup"; popup.Text = "Popup"; popup.Location = new Point(74, 27); popup.Size = new Size(60, 17); popup.Click += popup_Click; if (question != null) { int index = itemCount - 1; question.questionItems.Add(new questionItemSimple()); if (question.questionItems[index] != null) { if (question.questionItems[index].correct == true) { correct.Checked = true; } if (question.questionItems[index].popups == null) { question.questionItems[index].popups = new popups(); } if (question.questionItems[index].popups.popupEnabled == true) { popUpGenerate(null, popup); } } else { errorHandle("Item could not be added. Please try again."); return; } } pnlItem.Controls.Add(itemNum); pnlItem.Controls.Add(itemTextBox); pnlItem.Controls.Add(deleteItem); pnlItem.Controls.Add(correct); pnlItem.Controls.Add(popup); //add the new item box to the main panel pnlQuestionDetails.Controls.Add(pnlItem); }
private void loadSimpleQuestion() { questionObjectSimple question = game[(int)lastSelected.Tag] as questionObjectSimple; //Go through the game list, recreate the item boxes and their items in the ui for editting. var tempCount = question.questionItems.Count; for (int i = 0; i < tempCount; i++) { //itemCount++; Panel pnlItem = new Panel(); pnlItem.Name = itemCount.ToString(); pnlItem.Size = new Size(320, 46); pnlItem.BackColor = System.Drawing.Color.DarkGray; //User can enter the items text Label itemNum = new Label(); itemNum.Location = new Point(4, 10); itemNum.Text = "#" + (i + 1); itemNum.Name = "itemNum"; itemNum.Size = new Size(29, 13); TextBox itemTextBox = new TextBox(); itemTextBox.Name = "itemText"; itemTextBox.Location = new Point(33, 7); itemTextBox.Size = new Size(253, 20); itemTextBox.MaxLength = 100; itemTextBox.Text = question.questionItems[i].itemText; //Configure deleteItem Button deleteItem = new Button(); deleteItem.Name = "deleteItem"; deleteItem.Text = "X"; deleteItem.Location = new Point(292, 7); deleteItem.Size = new Size(20, 20); deleteItem.FlatStyle = FlatStyle.Flat; deleteItem.FlatAppearance.BorderSize = 0; deleteItem.FlatAppearance.BorderColor = System.Drawing.Color.Red; deleteItem.BackColor = System.Drawing.Color.Black; deleteItem.ForeColor = System.Drawing.Color.White; deleteItem.Click += deleteASimpleItem; CheckBox correct = new CheckBox(); correct.Name = "correct"; correct.Text = "Correct"; correct.Location = new Point(8, 27); correct.Size = new Size(60, 17); CheckBox popup = new CheckBox(); popup.Name = "popup"; popup.Text = "Popup"; popup.Location = new Point(74, 27); popup.Size = new Size(60, 17); popup.Click += popup_Click; if (question != null) { if (question.questionItems[i] != null) { if (question.questionItems[i].correct == true) { correct.Checked = true; } if (question.questionItems[i].popups == null) { question.questionItems[i].popups = new popups(); } if (question.questionItems[i].popups.popupEnabled == true) { popup.Checked = true; pnlItem.Controls.Add(popup); popups popupObj = new popups(); popupObj.popupEnabled = true; popupObj.popupTitle = question.questionItems[i].popups.popupTitle; popupObj.popupBody = question.questionItems[i].popups.popupBody; popUpGenerate(popupObj, popup); } } else { errorHandle("Item could not be added. Please try again."); return; } } pnlItem.Controls.Add(itemNum); pnlItem.Controls.Add(itemTextBox); pnlItem.Controls.Add(deleteItem); pnlItem.Controls.Add(correct); pnlItem.Controls.Add(popup); pnlQuestionDetails.Controls.Add(pnlItem); itemCount = i; } }
//Insert information entered in the pnlQuestionDetails into the question array when it is a questionObjectSimple private void applyChangesToQuesitonSimple(questionObjectSimple question) { question.questionText = pnlQuestionDetails.Controls.Find("questionEdit", true)[0].Controls.Find("questionText", true)[0].Text; question.questionNumber = pnlQuestionDetails.Controls.Find("questionEdit", true)[0].Name; question.weight = int.Parse(pnlQuestionDetails.Controls.Find("questionEdit", true)[0].Controls.Find("weight", true)[0].Text); for (int i = 0; i < itemCount; i++) { //Grab the item from the list of items Panel c = (Panel)pnlQuestionDetails.Controls[i + 1]; if (c.Name != "questionEdit") { question.questionItems[i].itemText = c.Controls.Find("itemText", true)[0].Text; question.questionItems[i].correct = ((CheckBox)c.Controls.Find("correct", true)[0]).Checked; question.questionItems[i].popups.popupEnabled = ((CheckBox)c.Controls.Find("popup", true)[0]).Checked; //If the popup checkbox is false the other controls do not exist if (((CheckBox)c.Controls.Find("popup", true)[0]).Checked) { question.questionItems[i].popups.popupTitle = c.Controls.Find("popupTitleTextBox", true)[0].Text; question.questionItems[i].popups.popupBody = c.Controls.Find("popupBodyTextBox", true)[0].Text; } else { question.questionItems[i].popups.popupTitle = ""; question.questionItems[i].popups.popupBody = ""; } } } //apply the changes to the question array game[(int)lastSelected.Tag - 1] = question; }