private void btn_LoadFile_Click(object sender, EventArgs e)
{
QuestionBL questionBL = new QuestionBL();
OpenFileDialog OpenFile = new OpenFileDialog();
DialogResult Result = OpenFile.ShowDialog();
if (Result == DialogResult.OK)
{
if (Path.GetExtension(OpenFile.FileName) == ".txt" || Path.GetExtension(OpenFile.FileName) == ".xml" || Path.GetExtension(OpenFile.FileName) == ".jqz")
{
if (Path.GetExtension(OpenFile.FileName) == ".txt")
{
dataGridView1.Columns.Clear();
QuestionBL QuestionBL = new QuestionBL();
List<DO.Question> QuestionList;
QuestionList = QuestionBL.GetFileTXT(OpenFile.FileName);
txt_FilePath.Text = OpenFile.FileName;
if (QuestionList != null)
{
dataGridView1.DataSource = QuestionList;
Showcolumns();
CheckQuestion();
if (WrongQuestion > 0)
{
MessageBox.Show("Tập tin nhập vào có " + WrongQuestion + " câu hỏi không hợp lệ (câu hỏi bị bôi đỏ). "
+"Hệ thống không cho phép chọn các câu hỏi đó. "
+"Vui lòng kiểm tra lại nội dung, loại câu hỏi và Phải chọn đáp án cho câu hỏi.", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
dataGridView1.Columns.Clear();
txt_FilePath.Text = "";
MessageBox.Show("Tải file không thành công. Bạn định dạng file không hợp lý.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
//xml
if (Path.GetExtension(OpenFile.FileName) == ".xml")
{
dataGridView1.Columns.Clear();
QuestionBL QuestionBL = new QuestionBL();
List<DO.Question> QuestionList;
QuestionList = QuestionBL.GetFileXML(OpenFile.FileName);
txt_FilePath.Text = OpenFile.FileName;
if (QuestionList != null)
{
dataGridView1.DataSource = QuestionList;
Showcolumns();
CheckQuestion();
if (WrongQuestion > 0)
{
MessageBox.Show("Tập tin nhập vào có " + WrongQuestion + " câu hỏi không hợp lệ (câu hỏi bị bôi đỏ). "
+ "Hệ thống không cho phép chọn các câu hỏi đó. "
+ "Vui lòng kiểm tra lại nội dung, loại câu hỏi và Phải chọn đáp án cho câu hỏi.", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
dataGridView1.Columns.Clear();
txt_FilePath.Text = "";
MessageBox.Show("Tải file không thành công. Bạn định dạng file không hợp lý.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
//hot potatoes
dataGridView1.Columns.Clear();
QuestionBL QuestionBL = new QuestionBL();
List<DO.Question> QuestionList;
QuestionList = QuestionBL.GetFileHotPotato(OpenFile.FileName);
txt_FilePath.Text = OpenFile.FileName;
if (QuestionList != null)
{
dataGridView1.DataSource = QuestionList;
Showcolumns();
CheckQuestion();
if (WrongQuestion > 0)
{
MessageBox.Show("Tập tin nhập vào có " + WrongQuestion + " câu hỏi không hợp lệ (câu hỏi bị bôi đỏ). "
+ "Hệ thống không cho phép chọn các câu hỏi đó. "
+ "Vui lòng kiểm tra lại nội dung, loại câu hỏi và Phải chọn đáp án cho câu hỏi.", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
dataGridView1.Columns.Clear();
txt_FilePath.Text = "";
MessageBox.Show("Tải file không thành công. Bạn định dạng file không hợp lý.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
else
{
dataGridView1.Columns.Clear();
txt_FilePath.Text = "";
MessageBox.Show("Tải file không thành công. Bạn phải chọn File .XML hoặc .TXT.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
chk_CheckAll.Checked = false;
}
}