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);
        }
        public static DataSet GetExportableData(QuestionBank qb, string filePath)
        {
            //Creating DataTable for header
            DataTable dtHeader = new DataTable("Practice Test");

            dtHeader.Columns.Add("Header", typeof(String));
            dtHeader.Columns.Add("Value", typeof(String));

            DataRow hr1 = dtHeader.NewRow();

            hr1[0] = "Name";
            hr1[1] = qb.Name;
            dtHeader.Rows.Add(hr1);
            DataRow hr2 = dtHeader.NewRow();

            hr2[0] = "Description";
            hr2[1] = qb.Description;
            dtHeader.Rows.Add(hr2);
            DataRow hr3 = dtHeader.NewRow();

            hr3[0] = "Time Allocated";
            hr3[1] = qb.TimeAllocated.ToString();
            dtHeader.Rows.Add(hr3);
            DataRow hr4 = dtHeader.NewRow();

            hr4[0] = "Country";
            hr4[1] = "IN";
            dtHeader.Rows.Add(hr4);
            DataRow hr5 = dtHeader.NewRow();

            hr5[0] = "Examination";
            hr5[1] = qb.ExamGrade;
            dtHeader.Rows.Add(hr5);

            DataRow hr6 = dtHeader.NewRow();

            hr6[0] = "Positive Marks";
            hr6[1] = qb.PositiveMarks;
            dtHeader.Rows.Add(hr6);

            DataRow hr7 = dtHeader.NewRow();

            hr7[0] = "Negative Marks";
            hr7[1] = qb.NegativeMarks;
            dtHeader.Rows.Add(hr7);

            DataTable dtQuestions = new DataTable("Questions");

            dtQuestions.Columns.Add("Examination", typeof(String));
            dtQuestions.Columns.Add("Subject", typeof(String));
            dtQuestions.Columns.Add("Topic", typeof(String));
            dtQuestions.Columns.Add("Complexity", typeof(String));

            dtQuestions.Columns.Add("Instuction", typeof(String));
            dtQuestions.Columns.Add("Positive Marks", typeof(String));
            dtQuestions.Columns.Add("Negative Marks", typeof(String));

            dtQuestions.Columns.Add("Question", typeof(String));
            dtQuestions.Columns.Add("Option 1", typeof(String));
            dtQuestions.Columns.Add("Option 2", typeof(String));
            dtQuestions.Columns.Add("Option 3", typeof(String));
            dtQuestions.Columns.Add("Option 4", typeof(String));
            dtQuestions.Columns.Add("Option 5", typeof(String));
            dtQuestions.Columns.Add("Answers", typeof(String));
            dtQuestions.Columns.Add("Explanation", typeof(String));

            DataSet ds = new DataSet();

            ds.Tables.Add(dtHeader);

            ImageProcessor _processor = new ImageProcessor(filePath);

            foreach (Question q in qb.Questions)
            {
                //Remove style attribute
                QBProcessor.CleanseQuestionBankData(q);

                DataRow drow = dtQuestions.NewRow();
                drow[0] = qb.ExamGrade;
                drow[1] = q.Subject;
                drow[2] = q.Topic;

                if (q.Complexity == 1)
                {
                    drow[3] = "Easy";
                }
                else if (q.Complexity == 3)
                {
                    drow[3] = "Hard";
                }
                else
                {
                    drow[3] = "Moderate";
                }

                drow[4] = _processor.ExtractImage(q.Instruction);
                drow[5] = q.PositiveMarks;
                drow[6] = q.NegativeMarks;

                //Extract images from Question
                drow[7] = _processor.ExtractImage(q.QuestionText);

                //Initialize Option texts
                drow[8]  = "";
                drow[9]  = "";
                drow[10] = "";
                drow[11] = "";
                drow[12] = "";
                drow[13] = "";

                //Extract images from answer explanation
                drow[14] = _processor.ExtractImage(q.AnswerExplanation);

                int i = 8;
                foreach (Answer a in q.OptionTexts)
                {
                    drow[i] = _processor.ExtractImage(a.OptionText);
                    if (a.IsCorrect)
                    {
                        if (drow[13].ToString() == "")
                        {
                            drow[13] = (i - 7).ToString();
                        }
                        else
                        {
                            drow[13] = drow[13] + ", " + (i - 7).ToString();
                        }
                    }
                    i++;
                }
                dtQuestions.Rows.Add(drow);
            }

            ds.Tables.Add(dtQuestions);

            return(ds);
        }