Exemple #1
0
        private void ProcessMultiQuestion(MultiQuestion question, DefaultConfigModel model)
        {
            WriteContent(question.Content);
            WriteDefaultAnswer(question.DefaultAnswer);
            WriteDescription(question.Descriptions);
            var multiAnswer = question as MultiAnswerQuestion;

            if (multiAnswer != null)
            {
                var           line    = Console.ReadLine();
                List <string> answers = new List <string>();
                while (!string.IsNullOrEmpty(line))
                {
                    answers.Add(line);
                    line = Console.ReadLine();
                }

                if (answers.Count > 0)
                {
                    question.Setter(answers.ToArray(), model);
                }
                else
                {
                    question.SetDefault(model);
                }
            }
        }
Exemple #2
0
 // Start is called before the first frame update
 void Start()
 {
     Score        = 0;
     hantei_maru  = GameObject.Find("hantei_maru");
     hantei_batsu = GameObject.Find("hantei_batsu");
     hantei_maru.SetActive(false);
     hantei_batsu.SetActive(false);
     MQ = GameObject.Find("QuizText").GetComponent <MultiQuestion>();
     AT = GameObject.Find("AnswerText").GetComponent <AnswerText>();
 }
Exemple #3
0
        private void dgvMultiQuestion_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string question = "";

            if (e.RowIndex < 0)
            {
                return;
            }
            MultiQuestion mq = lstMulti.ElementAt(e.RowIndex);

            question += mq.content;
            question += "================================================" + "\r\n";
            MessageBox.Show("MList question=" + lstSimple.Count);
            foreach (SimpleQuestion sq in mq.lstQuestion)
            {
                question += sq.question + "\r\n";
                for (int i = 0; i < sq.answer.Count; ++i)
                {
                    question += (char)(65 + i) + ". " + sq.answer.ElementAt(i) + "\r\n";
                }
                question += "=> Correct: " + (char)(65 + sq.correctAnswer) + "\r\n\r\n";
            }
            txtView.Text = question;
        }
Exemple #4
0
        private void GetData(object path)
        {
            //numOfAnswer++
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            SimpleQuestion qItem = null;
            // Define an object to pass to the API for missing parameters
            object miss     = System.Reflection.Missing.Value;
            object readOnly = true;

            Microsoft.Office.Interop.Word.Document docs =
                word.Documents.Open(ref path, ref miss, ref readOnly,
                                    ref miss, ref miss, ref miss, ref miss, ref miss, ref miss,
                                    ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);

            int flag = 0;

            for (int i = 1; i <= docs.Paragraphs.Count; i++)
            {
                string temp = docs.Paragraphs[i].Range.Text.Trim();
                if (temp.Trim().ToLower().Equals("<multi>"))// multi question
                {
                    MultiQuestion qMul = new MultiQuestion();
                    //int no_multi_ques = 0;
                    do
                    {
                        temp = docs.Paragraphs[++i].Range.Text;
                        if (temp.Trim() == "")
                        {
                            break;
                        }

                        qMul.content += temp + "\r\n";
                        //lọc công thức toán

                        /*
                         *   temp = docs.Paragraphs[++i].Range.Text;
                         *   if (LocCongThucToan(temp, i, no_multi_ques))
                         *   {
                         *      MessageBox.Show("Chen anh answ " + i);
                         *   }
                         */
                    } while (temp != string.Empty);

                    if (temp.Trim() != "")
                    {
                        MessageBox.Show("Lỗi cú pháp tại \"" + qMul.content + "\"...");
                        lstSimple.Clear();
                        lstMulti.Clear();
                        return;
                    }

                    while (!temp.Trim().ToLower().Equals("</multi>"))
                    {
                        temp = docs.Paragraphs[++i].Range.Text.Trim();
                        if (temp != "")
                        {
                            qItem               = new SimpleQuestion();
                            qItem.question      = temp;
                            qItem.correctAnswer = -1;
                            List <string> answer = new List <string>();
                            do
                            {
                                temp = docs.Paragraphs[++i].Range.Text.Trim();
                                if (temp == string.Empty || temp.ToLower().Equals("</multi>"))
                                {
                                    break;
                                }
                                temp = Regex.Replace(temp, "[a-z1-4](\\.|\\))[ \t]+", "", RegexOptions.IgnoreCase);
                                if (temp.EndsWith("*"))
                                {
                                    qItem.correctAnswer = answer.Count;
                                    temp = temp.Substring(0, temp.Length - 1).Trim();
                                    answer.Add(temp);
                                }
                                else
                                {
                                    answer.Add(temp);
                                }
                            } while (temp != string.Empty);

                            qItem.answer = answer;

                            if (qItem.correctAnswer != -1)
                            {
                                qMul.lstQuestion.Add(qItem);
                            }
                            else
                            {
                                MessageBox.Show("Câu hỏi \"" + qItem.question + "\" không có câu trả lời đúng");
                                lstSimple.Clear();
                                lstMulti.Clear();
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Lỗi cú pháp tại " + qMul.content + "\"...");
                            lstSimple.Clear();
                            lstMulti.Clear();
                            return;
                        }
                    }

                    lstMulti.Add(qMul);

                    //hiển thị list câu hỏi lên rtxtFileNoiDung
                    string question = "";
                    question += qMul.content;
                    question += "\n================================================" + "\r\n";
                    foreach (SimpleQuestion sq in qMul.lstQuestion)
                    {
                        question += sq.question + "\r\n";
                        for (int idx = 0; idx < sq.answer.Count; ++idx)
                        {
                            question += (char)(65 + idx) + ". " + sq.answer.ElementAt(idx) + "\r\n";
                        }
                        question += "=> Correct: " + (char)(65 + sq.correctAnswer) + "\r\n\r\n\n";
                    }
                    rtxtFileNoiDung.Text += question;

                    //Ignore blank paragraph
                    i++;
                }
                else if (temp != string.Empty) //simple question
                {
                    if (flag % 2 == 0)
                    {
                        //remove question number like Câu 1, Câu 2,...
                        temp  = Regex.Replace(temp, "^[0-9]+\\.[ ]*|^Câu [0-9]+:[ ]*|^Question [0-9]+:[ ]*", "", RegexOptions.IgnoreCase);
                        qItem = new SimpleQuestion();
                        //lọc công thức toán học

                        /*  if(LocCongThucToan(temp,i))
                         * {
                         *    MessageBox.Show("Chen anh ");
                         * }*/
                        qItem.question = temp;
                    }
                    else
                    {
                        List <string> answer = new List <string>();
                        qItem.correctAnswer = -1;
                        // int no_ans = 0;
                        while (temp != string.Empty)
                        {
                            //lọc công thức toán học

                            /* no_ans++;
                             *
                             * if (LocCongThucToan(temp, i, no_ans))
                             * {
                             *   MessageBox.Show("Chen anh answ "+i);
                             * }*/
                            //remove answer key, like A,B,C,D
                            temp = Regex.Replace(temp, "[a-z1-4](\\.|\\))[ \t]+", "", RegexOptions.IgnoreCase);
                            if (temp.EndsWith("*"))
                            {
                                qItem.correctAnswer = answer.Count;
                                temp = temp.Substring(0, temp.Length - 1).Trim();
                                answer.Add(temp);
                            }
                            else
                            {
                                answer.Add(temp);
                            }
                            temp = docs.Paragraphs[++i].Range.Text.Trim();
                        }

                        qItem.answer = answer;

                        if (qItem.correctAnswer != -1)
                        {
                            lstSimple.Add(qItem);

                            //hiển thị lstSimple lên txtFileNoiDung
                            string question = "Question: ";
                            question += qItem.question + "\r\n";
                            for (int idx = 0; idx < qItem.answer.Count; ++idx)
                            {
                                question += (char)(65 + idx) + ". " + qItem.answer.ElementAt(idx) + "\r\n";
                            }
                            question             += "=> Correct: " + (char)(65 + qItem.correctAnswer) + "\r\n\n";
                            rtxtFileNoiDung.Text += question;
                        }
                        else
                        {
                            MessageBox.Show("Câu hỏi \"" + qItem.question + "\" không có câu trả lời đúng");
                            lstSimple.Clear();
                            lstMulti.Clear();
                            return;
                        }
                    }
                    flag++;
                }
                else
                {
                    MessageBox.Show("Lỗi cú pháp tại " + lstSimple.ElementAt(lstSimple.Count - 1).question);
                    lstSimple.Clear(); lstMulti.Clear();
                    return;
                }
            }
            docs.Close();
            word.Quit();
        }
Exemple #5
0
        private void GetData(object path)
        {
            //numOfAnswer++
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            SimpleQuestion qItem = null;
            // Define an object to pass to the API for missing parameters
            object miss     = System.Reflection.Missing.Value;
            object readOnly = true;

            Microsoft.Office.Interop.Word.Document docs =
                word.Documents.Open(ref path, ref miss, ref readOnly,
                                    ref miss, ref miss, ref miss, ref miss, ref miss, ref miss,
                                    ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);

            int flag = 0;

            for (int i = 1; i <= docs.Paragraphs.Count; i++)
            {
                string temp = docs.Paragraphs[i].Range.Text.Trim();
                if (temp.Trim().ToLower().Equals("<multi>"))
                {
                    MultiQuestion qMul = new MultiQuestion();
                    do
                    {
                        temp = docs.Paragraphs[++i].Range.Text;
                        if (temp.Trim() == "")
                        {
                            break;
                        }
                        qMul.content += temp + "\r\n";
                    } while (temp != string.Empty);
                    if (temp.Trim() != "")
                    {
                        MessageBox.Show("Syntax error at \"" + qMul.content + "\"...");
                        lstSimple.Clear(); lstMulti.Clear();
                        return;
                    }
                    while (!temp.Trim().ToLower().Equals("</multi>"))
                    {
                        temp = docs.Paragraphs[++i].Range.Text.Trim();
                        if (temp != "")
                        {
                            qItem               = new SimpleQuestion();
                            qItem.question      = temp;
                            qItem.correctAnswer = -1;
                            List <string> answer = new List <string>();
                            do
                            {
                                temp = docs.Paragraphs[++i].Range.Text.Trim();
                                if (temp == string.Empty || temp.ToLower().Equals("</multi>"))
                                {
                                    break;
                                }
                                temp = Regex.Replace(temp, "[a-z1-4](\\.|\\))[ \t]+", "", RegexOptions.IgnoreCase);
                                if (temp.EndsWith("*"))
                                {
                                    qItem.correctAnswer = answer.Count;
                                    temp = temp.Substring(0, temp.Length - 1).Trim();
                                    answer.Add(temp);
                                }
                                else
                                {
                                    answer.Add(temp);
                                }
                            } while (temp != string.Empty);
                            qItem.answer = answer;
                            if (qItem.correctAnswer != -1)
                            {
                                qMul.lstQuestion.Add(qItem);
                            }
                            else
                            {
                                MessageBox.Show("Question \"" + qItem.question + "\" have no correct answer");
                                lstSimple.Clear(); lstMulti.Clear();
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Syntax error at " + qMul.content + "\"...");
                            lstSimple.Clear(); lstMulti.Clear();
                            return;
                        }
                    }
                    lstMulti.Add(qMul);
                    //Ignore blank paragraph
                    i++;
                }
                else if (temp != string.Empty)
                {
                    if (flag % 2 == 0)
                    {
                        //remove question number like Câu 1, Câu 2,...
                        temp           = Regex.Replace(temp, "^[0-9]+\\.[ ]*|^Câu [0-9]+:[ ]*|^Question [0-9]+:[ ]*", "", RegexOptions.IgnoreCase);
                        qItem          = new SimpleQuestion();
                        qItem.question = temp;
                    }
                    else
                    {
                        List <string> answer = new List <string>();
                        qItem.correctAnswer = -1;
                        while (temp != string.Empty)
                        {
                            //remove answer key, like A,B,C,D
                            temp = Regex.Replace(temp, "[a-z1-4](\\.|\\))[ \t]+", "", RegexOptions.IgnoreCase);
                            if (temp.EndsWith("*"))
                            {
                                qItem.correctAnswer = answer.Count;
                                temp = temp.Substring(0, temp.Length - 1).Trim();
                                answer.Add(temp);
                            }
                            else
                            {
                                answer.Add(temp);
                            }
                            temp = docs.Paragraphs[++i].Range.Text.Trim();
                        }
                        qItem.answer = answer;
                        if (qItem.correctAnswer != -1)
                        {
                            lstSimple.Add(qItem);
                        }
                        else
                        {
                            MessageBox.Show("Question \"" + qItem.question + "\" have no correct answer");
                            lstSimple.Clear(); lstMulti.Clear();
                            return;
                        }
                    }
                    flag++;
                }
                else
                {
                    MessageBox.Show("Syntax error at " + lstSimple.ElementAt(lstSimple.Count - 1).question);
                    lstSimple.Clear(); lstMulti.Clear();
                    return;
                }
            }
            docs.Close();
            word.Quit();
            BindSimpleQuestion(lstSimple);
            BindMultiQuestion(lstMulti);
        }