Exemple #1
0
        private void FormTest_Load(object sender, EventArgs e)
        {
            status.Text             = "bình thường";
            metroLabelStat.Visible  = false;
            metroButtonExit.Visible = false;
            metroLabelStat.Visible  = false;
            LoadInfo();
            listQuestion = DataUlti.DSCauHoi(MaDeThi);
            listAnswer   = DataUlti.DSDapAn(MaDeThi);

            timer1.Tick += Timer1_Tick;
            timer1.Start();

            answerCount = listAnswer.Count / 4;
            for (int i = 0; i < answerCount; i++)
            {
                metroComboBoxQuestion.Items.Add((i + 1).ToString());
            }

            metroLabelProgress.Text             = string.Format("Đã hoàn thành: {0}/{1}", 0, answerCount);
            metroComboBoxQuestion.SelectedIndex = 0;

            metroLabelHint.Visible  = false;
            metroLabelHint2.Visible = false;

            Reload(test);
            showSpoil = true;
        }
Exemple #2
0
        private void BtnXuatFileCauHoi_Click(object sender, EventArgs e)
        {
            try
            {
                saveFileDialog.Filter = "Excel files (*.xls)|*.xls";
                DialogResult result = saveFileDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    if (File.Exists(saveFileDialog.FileName))
                    {
                        File.Delete(saveFileDialog.FileName);
                    }

                    var DSCauHoi = DataUlti.DSCauHoi();

                    using (DataTable dt = new DataTable())
                    {
                        dt.Columns.Add("MaCauHoi", typeof(string));
                        dt.Columns.Add("Mon", typeof(string));
                        dt.Columns.Add("DoKho", typeof(int));
                        dt.Columns.Add("Khoi", typeof(int));
                        dt.Columns.Add("NoiDung", typeof(string));
                        dt.Columns.Add("GoiY", typeof(string));

                        foreach (var ch in DSCauHoi)
                        {
                            dt.Rows.Add(ch.MaCauHoi, ch.Mon, ch.DoKho, ch.Khoi, ch.NoiDung, ch.GoiY);
                        }

                        if (!DataUlti.WriteExcelFile(saveFileDialog.FileName, dt, 2))
                        {
                            MessageBox.Show("Không thể xuất ra file excel");
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Xuất file thành công");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Exemple #3
0
        public FormTest()
        {
            InitializeComponent();
            MHS     = "1612030009";
            MaDeThi = "MH01120001";
            MaKyThi = "CK201801MH01";

            metroLabelStat.Visible  = false;
            metroButtonExit.Visible = false;
            metroLabelStat.Visible  = false;

            listQuestion = DataUlti.DSCauHoi(MaDeThi);
            listAnswer   = DataUlti.DSDapAn(MaDeThi);

            answerCount = listAnswer.Count / 4;
            for (int i = 0; i < answerCount; i++)
            {
                metroComboBoxQuestion.Items.Add((i + 1).ToString());
            }

            metroLabelProgress.Text             = string.Format("Đã hoàn thành: {0}/{1}", 0, answerCount);
            metroComboBoxQuestion.SelectedIndex = 0;
            Reload(test);
        }
Exemple #4
0
        private void BtnNhapFileCauHoi_Click(object sender, EventArgs e)
        {
            try
            {
                fileDialogImportExcel.Filter = "Excel files (*.xlsx)|*.xlsx|Excel files (*.xls)|*.xls";
                DialogResult dialog = fileDialogImportExcel.ShowDialog();

                if (dialog == DialogResult.OK)
                {
                    var notExistList = new List <DataRow>();
                    var existList    = new List <DataRow>();

                    // Lấy dữ liệu từ file excel
                    //DataGridView tmpDGV = new DataGridView();
                    //tmpDGV.Columns.Clear();
                    var dt = DataUlti.ReadExcelFile(fileDialogImportExcel.FileName);
                    //tmpDGV.DataSource = dt;

                    // Lấy danh sách câu hỏi
                    var chList = DataUlti.DSCauHoi();

                    //Lấy ra danh sách các câu hỏi chưa có trong database
                    IEnumerable <string> list = chList.Select(ch => ch.MaCauHoi);
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        var MaCH = dt.Rows[i]["MaCauHoi"].ToString();
                        if (!list.Contains(MaCH))
                        {
                            notExistList.Add(dt.Rows[i]);
                        }
                        else
                        {
                            existList.Add(dt.Rows[i]);
                        }
                    }

                    // add vào database
                    // tạo đối tương CauHoi
                    if (notExistList.Count > 0)
                    {
                        int flag = 0;
                        foreach (var item in notExistList)
                        {
                            var ch = new CauHoi()
                            {
                                MaCauHoi = item["MaCauHoi"].ToString(),
                                Mon      = item["Mon"].ToString(),
                                DoKho    = int.Parse(item["DoKho"].ToString()),
                                Khoi     = int.Parse(item["Khoi"].ToString()),
                                NoiDung  = item["NoiDung"].ToString(),
                                GoiY     = item["GoiY"].ToString()
                            };

                            if (!DataUlti.ThemCauHoi(ch))
                            {
                                flag = 1;
                                break;
                            }
                        }

                        if (flag == 0)
                        {
                            dt.Columns.Clear();
                            dt.Rows.Clear();
                            MessageBox.Show("Đã thêm vào CSDL");
                            LoadCauHoi();
                        }
                        else
                        {
                            MessageBox.Show("Có lỗi xãy ra");
                        }
                    }
                    else
                    {
                        if (existList.Count > 0)
                        {
                            string str = "";
                            if (existList.Count < 5)
                            {
                                foreach (var item in existList)
                                {
                                    str += item["MaCauHoi"].ToString() + "\n";
                                }
                                MessageBox.Show(string.Format("Các câu hỏi bị trùng:\n{0}", str));
                            }
                            else
                            {
                                MessageBox.Show(string.Format("Số lượng câu hỏi đã tồn tại quá nhiều: {0}", existList.Count));
                            }
                        }
                    }
                    notExistList.Clear();
                    existList.Clear();
                    dt.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }