Пример #1
0
        /// <summary>
        /// Convert original data from object array to structured list
        /// </summary>
        /// <param name="path">The path of the data file</param>
        /// <returns></returns>
        public List_Question ToList(string path)
        {
            object[,] array = GetDataFromExcel(path);
            List_Question lq = new List_Question();
            Question      q;

            for (int i = 2; i <= rowCount; i = i + 5)
            {
                if (array[i, 1] != null)
                {
                    q          = new Question();
                    q.question = array[i, 2].ToString();
                    for (int j = 1; j <= 4; j++)
                    {
                        q.answers.Add(array[i + j, 2].ToString());
                        if (array[i + j, 1] != null)
                        {
                            q.correctAns = j;
                        }
                    }
                    lq.Add(q);
                }
            }
            return(lq);
        }
Пример #2
0
        /// <summary>
        /// Load entire questions from file
        /// </summary>
        void LoadQuestions()
        {
            Microsoft_Excel xls = new Microsoft_Excel();
            List_Question   lq  = new List_Question();
            string          path;

            do
            {
                path = Microsoft_Excel.OpenFile();
                if (path == null)
                {
                    MessageBox.Show(new Form()
                    {
                        WindowState = FormWindowState.Maximized, TopMost = true
                    }, "Không có thư viện câu hỏi nên chương trình sẽ tự động thoát!", "Lưu ý", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    Exit();
                }
                lq = xls.ToList(path);
                t  = lq.list.Count;
                if (t == 0)
                {
                    MessageBox.Show("Dữ liệu câu hỏi rỗng!!! Vui lòng chọn tập tin khác");
                }
            } while (t == 0);
            if (isRandom)
            {
                Shuffle(lq.list);
            }
            data = lq;
        }