private void delete_Click(object sender, EventArgs e) { if (this.ID == null) { MessageBox.Show("No selected question to be deleted", "OK", MessageBoxButton.OK, MessageBoxImage.Warning); } MessageBoxResult dr = MessageBox.Show("Are you sure to delete this question?", "Confirmation", MessageBoxButton.YesNo); if (dr == MessageBoxResult.Yes) { Question q = QBManager.QBank.Questions.Where(qt => qt.ID == this.ID).FirstOrDefault(); if (q.MasterCode != null) { q.IsDeleted = true; //Logically delete } else { QBManager.QBank.Questions.Remove(q); //physically delete because this questions is not yet synced with server } QBManager.Save(); //frmParent.RefreshGrid(QBManager.QBank.Questions); removeQuestion(q); //this.Close(); } }
public static void SetDefaultTopic(QuestionBank qb) { foreach (Question q in qb.Questions) { if (!MasterUtil.IsTopicValid(q.Topic, q.Subject, qb.ExamGrade)) { q.Topic = "Others"; } } QBManager.Save(); }
private void btnDelete_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { MessageBoxResult dr = MessageBox.Show("Are you sure to delete this question?", "Confirmation", MessageBoxButton.YesNo); if (dr == MessageBoxResult.Yes) { Question q = (Question)((System.Windows.FrameworkElement)(sender)).DataContext; if (q.MasterCode != null) { q.IsDeleted = true; //Logically delete } else { QBManager.QBank.Questions.Remove(q); //physically delete because this questions is not yet synced with server } QBManager.Save(); //frmParent.RefreshGrid(QBManager.QBank.Questions); removeQuestion(q); //this.Close(); } }
private bool ValidateAndSaveQuestion() { if (comboSubject.SelectedIndex == -1) { MessageBox.Show("Please select a subject.", "Qrator", MessageBoxButton.OK, MessageBoxImage.Warning); comboSubject.Focus(); return(false); } //if (htmlwysiwyg1.getPlainText() == null && htmlwysiwyg1.getHTML() == null) if (txtQuestion.Text == null) { MessageBox.Show("Please enter question text.", "Qrator", MessageBoxButton.OK, MessageBoxImage.Warning); txtQuestion.Focus(); return(false); } //if (htmlwysiwyg2.getPlainText() == null && htmlwysiwyg2.getHTML() == null) if (txtOp1.Text == null) { MessageBox.Show("Please enter text for 1st. option.", "Qrator", MessageBoxButton.OK, MessageBoxImage.Warning); txtOp1.Focus(); return(false); } //if (htmlwysiwyg3.getPlainText() == null && htmlwysiwyg3.getHTML() == null) if (txtOp2.Text == null) { MessageBox.Show("Please enter text for 2nd. option.", "Qrator", MessageBoxButton.OK, MessageBoxImage.Warning); txtOp2.Focus(); return(false); } if (chkOp1.IsChecked == false && chkOp2.IsChecked == false && chkOp3.IsChecked == false && chkOp4.IsChecked == false && chkOp5.IsChecked == false) { MessageBox.Show("At least one option must be checked.", "Qrator", MessageBoxButton.OK, MessageBoxImage.Warning); txtOp1.Focus(); return(false); } if (chkOp3.IsChecked == true && (txtOp3.Text == null)) //(htmlwysiwyg4.getPlainText() == null && htmlwysiwyg4.getHTML() == null)) { MessageBox.Show("Please enter text for 3rd. option since you have selected it as correct answer.", "Qrator", MessageBoxButton.OK, MessageBoxImage.Warning); txtOp3.Focus(); return(false); } if (chkOp4.IsChecked == true && (txtOp4.Text == null)) //(htmlwysiwyg5.getPlainText() == null && htmlwysiwyg5.getHTML() == null)) { MessageBox.Show("Please enter text for 4th. option since you have selected it as correct answer.", "Qrator", MessageBoxButton.OK, MessageBoxImage.Warning); txtOp4.Focus(); return(false); } if (chkOp5.IsChecked == true && (txtOp5.Text == null))//(htmlwysiwyg6.getPlainText() == null && htmlwysiwyg6.getHTML() == null)) { MessageBox.Show("Please enter text for 5th. option since you have selected it as correct answer.", "Qrator", MessageBoxButton.OK, MessageBoxImage.Warning); txtOp5.Focus(); return(false); } short complexity = 0; if (radEasy.IsChecked == true) { complexity = 1; } else if (radMod.IsChecked == true) { complexity = 2; } else if (radHard.IsChecked == true) { complexity = 3; } List <Answer> answers = new List <Answer>(); Answer a1 = new Answer { IsCorrect = (bool)chkOp1.IsChecked, OptionText = txtOp1.Text }; answers.Add(a1); Answer a2 = new Answer { IsCorrect = (bool)chkOp2.IsChecked, OptionText = txtOp2.Text }; answers.Add(a2); Answer a3 = new Answer { IsCorrect = (bool)chkOp3.IsChecked, OptionText = txtOp3.Text }; answers.Add(a3); Answer a4 = new Answer { IsCorrect = (bool)chkOp4.IsChecked, OptionText = txtOp4.Text }; answers.Add(a4); //if (htmlwysiwyg6.getPlainText() != null && htmlwysiwyg6.getPlainText().Trim() != "") if (txtOp5.Text == null) { Answer a5 = new Answer { IsCorrect = (bool)chkOp5.IsChecked, OptionText = txtOp5.Text }; answers.Add(a5); } timeSpent.Stop(); TimeSpan ts = timeSpent.Elapsed; if (this.ID == null) { Question q = new Question { AnswerExplanation = txtExplination.Text, //htmlwysiwyg7.getHTML(), Instruction = txtDirection.Text, // htmlwysiwyg8.getHTML(), Complexity = complexity, CreatedDate = DateTime.Now, LastModifiedDate = DateTime.Now, QuestionText = txtQuestion.Text, //htmlwysiwyg1.getHTML(), Subject = comboSubject.Text, Topic = comboTopic.Text, OptionTexts = answers, ID = Guid.NewGuid().ToString(), TotalTimeSpent = ts.TotalMinutes }; this.ID = q.ID; QBProcessor.CleanseQuestionBankData(q); QBManager.QBank.Questions.Add(q); addQuestion(q); clearFields(); } else { Question quest = QBManager.QBank.Questions.Find(q => q.ID == this.ID); quest.AnswerExplanation = txtExplination.Text; // htmlwysiwyg7.getHTML(); quest.Instruction = txtDirection.Text; // htmlwysiwyg8.getHTML(); quest.Complexity = complexity; quest.LastModifiedDate = DateTime.Now; quest.QuestionText = txtQuestion.Text; // htmlwysiwyg1.getHTML(); quest.Subject = comboSubject.Text; quest.Topic = comboTopic.Text; //Update option texts quest.OptionTexts[0].IsCorrect = answers[0].IsCorrect; quest.OptionTexts[0].ModifiedDate = DateTime.Now; quest.OptionTexts[0].OptionText = answers[0].OptionText; quest.OptionTexts[1].IsCorrect = answers[1].IsCorrect; quest.OptionTexts[1].ModifiedDate = DateTime.Now; quest.OptionTexts[1].OptionText = answers[1].OptionText; quest.OptionTexts[2].IsCorrect = answers[2].IsCorrect; quest.OptionTexts[2].ModifiedDate = DateTime.Now; quest.OptionTexts[2].OptionText = answers[2].OptionText; quest.OptionTexts[3].IsCorrect = answers[3].IsCorrect; quest.OptionTexts[3].ModifiedDate = DateTime.Now; quest.OptionTexts[3].OptionText = answers[3].OptionText; //An option has been removed if (quest.OptionTexts.Count > answers.Count) { quest.OptionTexts[4].IsDeleted = true; } else if (quest.OptionTexts.Count < answers.Count) //An option has been added { Answer a = new Answer(); a.IsCorrect = answers[4].IsCorrect; a.ModifiedDate = DateTime.Now; a.OptionText = answers[4].OptionText; quest.OptionTexts.Add(a); } else if (answers.Count > 4) { quest.OptionTexts[4].IsCorrect = answers[4].IsCorrect; quest.OptionTexts[4].ModifiedDate = DateTime.Now; quest.OptionTexts[4].OptionText = answers[4].OptionText; } if (quest.TotalTimeSpent != 0.00) { quest.TotalTimeSpent = quest.TotalTimeSpent + ts.TotalMinutes; } else { quest.TotalTimeSpent = ts.TotalMinutes; } QBProcessor.CleanseQuestionBankData(quest); int index = 0; foreach (Question q in itmsQuestions.Items) { if (q.ID == this.ID) { itmsQuestions.Items.Remove(q); itmsQuestions.Items.Insert(index, quest); break; } index++; } clearFields(); } QBManager.Save(); return(true); }
private void savebtn_Click(object sender, RoutedEventArgs e) { //Validate if (txtName.Text.Trim() == "" || txtName.Text == string.Empty) { MessageBox.Show("Please enter question bank name.", "QBank", MessageBoxButton.OK, MessageBoxImage.Warning); txtName.Focus(); return; } if (comboGrade.SelectedIndex == -1) { MessageBox.Show("Please select an entrance examination.", "QBank", MessageBoxButton.OK, MessageBoxImage.Warning); comboGrade.Focus(); return; } if (txtDescr.Text.Trim() == "" || txtDescr.Text == string.Empty) { MessageBox.Show("Please provide a description of the question bank.", "QBank", MessageBoxButton.OK, MessageBoxImage.Warning); txtDescr.Focus(); return; } //Save Information if (this.IsNew) { QuestionBank qb = new QuestionBank { Description = txtDescr.Text, Name = txtName.Text, TimeAllocated = Int16.Parse(txtTime.Text), Questions = new List <Question>(), ExamGrade = comboGrade.Text }; System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); System.Windows.Forms.DialogResult dr = saveFileDialog1.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { QBManager.FileName = saveFileDialog1.FileName; qb.CreatedDate = DateTime.Now; qb.CreatedBy = Environment.UserName; qb.LastModifiedDate = DateTime.Now; qb.Mode = "Operator"; QBManager.QBank = qb; QBManager.Save(); MessageBox.Show("Question bank created successfully. Please add questions.", "Success", MessageBoxButton.OK, MessageBoxImage.Information); //frmParent.RefreshGrid(qb.Questions); this.Close(); } } else { QBManager.QBank.Description = txtDescr.Text; QBManager.QBank.LastModifiedDate = DateTime.Now; QBManager.QBank.Name = txtName.Text; QBManager.QBank.TimeAllocated = Int16.Parse(txtTime.Text); QBManager.QBank.ExamGrade = comboGrade.Text; QBManager.Save(); MessageBox.Show("Question bank updated successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } }