예제 #1
0
 /// <summary>
 /// Xoa cau hoi trong listview & database
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (txtNoiDungCauHoi.Text == "" ||
         txtDapAnA.Text == "" ||
         txtDapAnB.Text == "" ||
         txtDapAnC.Text == "" ||
         txtDapAnD.Text == "")
     {
         DialogResult r = MessageBox.Show("Vui lòng nhập đầy đủ nội dung câu hỏi và đáp án! ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     if (rbA.Checked == false && rbB.Checked == false && rbC.Checked == false && rbD.Checked == false)
     {
         DialogResult r = MessageBox.Show("Bạn chưa chọn đáp án đúng cho câu hỏi. ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     if (cbbChuDe.SelectedIndex < 0)
     {
         DialogResult r = MessageBox.Show("Vui lòng chọn chủ đề cho câu hỏi.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         if (lvHienThiCauHoi.SelectedItems.Count > 0)
         {
             int ma_CauHoi = (int)lvHienThiCauHoi.SelectedItems[0].Tag;
             _0864186_TracNghiemDataContext db = new _0864186_TracNghiemDataContext();
             CauHoi cauHoi = db.CauHois.Single(ch => ch.maCauHoi == ma_CauHoi);
             db.CauHois.DeleteOnSubmit(cauHoi);
             db.SubmitChanges();
             LoadDuLieu_SoanCauHoi();
             XoaTruongDuLieu();
         }
     }
 }
예제 #2
0
        private void HienDapAnDung()
        {
            int ma_CauHoi = (int)lvHienThiCauHoi.SelectedItems[0].Tag;
            _0864186_TracNghiemDataContext db = new _0864186_TracNghiemDataContext();
            CauHoi cauHoi = db.CauHois.Single(ch => ch.maCauHoi == ma_CauHoi);
            int    dapAn  = (int)cauHoi.dapAnDung;

            switch (dapAn)
            {
            case 1:
                rbA.Checked = true;
                break;

            case 2:
                rbB.Checked = true;
                break;

            case 3:
                rbC.Checked = true;
                break;

            case 4:
                rbD.Checked = true;
                break;
            }
        }
예제 #3
0
        /// <summary>
        /// Them cau hoi
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtNoiDungCauHoi.Text == "" ||
                txtDapAnA.Text == "" ||
                txtDapAnB.Text == "" ||
                txtDapAnC.Text == "" ||
                txtDapAnD.Text == "")
            {
                DialogResult r = MessageBox.Show("Vui lòng nhập đầy đủ nội dung câu hỏi và đáp án! ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (rbA.Checked == false && rbB.Checked == false && rbC.Checked == false && rbD.Checked == false)
            {
                DialogResult r = MessageBox.Show("Bạn chưa chọn đáp án đúng cho câu hỏi. ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (cbbChuDe.SelectedIndex < 0)
            {
                DialogResult r = MessageBox.Show("Vui lòng chọn chủ đề cho câu hỏi.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                _0864186_TracNghiemDataContext db = new _0864186_TracNghiemDataContext();
                CauHoi cauHoi = new CauHoi();

                int ma_ChuDe = cbbChuDe.SelectedIndex;
                //cauHoi.maChuDe = ma_ChuDe + 1;
                cauHoi.maChuDe = listChuDe[ma_ChuDe];
                cauHoi.noiDung = txtNoiDungCauHoi.Text;
                cauHoi.dapAnA  = txtDapAnA.Text;
                cauHoi.dapAnB  = txtDapAnB.Text;
                cauHoi.dapAnC  = txtDapAnC.Text;
                cauHoi.dapAnD  = txtDapAnD.Text;
                if (rbA.Checked == true)
                {
                    cauHoi.dapAnDung = 1;
                }
                else if (rbB.Checked == true)
                {
                    cauHoi.dapAnDung = 2;
                }
                else if (rbC.Checked == true)
                {
                    cauHoi.dapAnDung = 3;
                }
                else
                {
                    cauHoi.dapAnDung = 4;
                }
                db.CauHois.InsertOnSubmit(cauHoi);
                db.SubmitChanges();
                LoadDuLieu_SoanCauHoi();
                XoaTruongDuLieu();
            }
        }
예제 #4
0
        private void btnTaodeThi_Click(object sender, EventArgs e)
        {
            _0864186_TracNghiemDataContext db = new _0864186_TracNghiemDataContext();
            SaveFileDialog d = new SaveFileDialog();

            d.Filter = "Luu file xml|*.xml";
            if (d.ShowDialog() == DialogResult.OK)
            {
                XmlDocument doc  = new XmlDocument();
                XmlElement  root = doc.CreateElement("DeThi");
                doc.AppendChild(root);

                foreach (ListViewItem lvi in lvChonCauHoi.Items)
                {
                    if (lvi.Checked == true)
                    {
                        int    ma_CauHoi = (int)lvi.Tag;
                        CauHoi cauhoi    = db.CauHois.Single(c => c.maCauHoi == ma_CauHoi);

                        XmlElement noodCau = doc.CreateElement("CauHoi");
                        root.AppendChild(noodCau);

                        XmlElement nodeNoiDung = doc.CreateElement("NoiDung");
                        noodCau.AppendChild(nodeNoiDung);
                        nodeNoiDung.InnerText = cauhoi.noiDung;

                        XmlElement nodeDapAnA = doc.CreateElement("DapAnA");
                        noodCau.AppendChild(nodeDapAnA);
                        nodeDapAnA.InnerText = cauhoi.dapAnA;

                        XmlElement nodeDapAnB = doc.CreateElement("DapAnB");
                        noodCau.AppendChild(nodeDapAnB);
                        nodeDapAnB.InnerText = cauhoi.dapAnB;

                        XmlElement nodeDapAnC = doc.CreateElement("DapAnC");
                        noodCau.AppendChild(nodeDapAnC);
                        nodeDapAnC.InnerText = cauhoi.dapAnC;

                        XmlElement nodeDapAnD = doc.CreateElement("DapAnD");
                        noodCau.AppendChild(nodeDapAnD);
                        nodeDapAnD.InnerText = cauhoi.dapAnD;

                        XmlElement nodeDapAnDung = doc.CreateElement("DapAnDung");
                        noodCau.AppendChild(nodeDapAnDung);
                        nodeDapAnDung.InnerText = cauhoi.dapAnDung.ToString();
                    }
                }
                doc.Save(d.FileName);
            }
        }
예제 #5
0
 /// <summary>
 /// Hien thi du lieu khi chon trong listview
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void lvHienThiCauHoi_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
 {
     if (lvHienThiCauHoi.SelectedItems.Count > 0)
     {
         btnThem.Enabled = false;
         int ma_CauHoi = (int)lvHienThiCauHoi.SelectedItems[0].Tag;
         _0864186_TracNghiemDataContext db = new _0864186_TracNghiemDataContext();
         CauHoi cauHoi = db.CauHois.Single(ch => ch.maCauHoi == ma_CauHoi);
         txtNoiDungCauHoi.Text = cauHoi.noiDung;
         txtDapAnA.Text        = cauHoi.dapAnA;
         txtDapAnB.Text        = cauHoi.dapAnB;
         txtDapAnC.Text        = cauHoi.dapAnC;
         txtDapAnD.Text        = cauHoi.dapAnD;
         HienDapAnDung();
         int   temp  = (int)cauHoi.maChuDe;
         ChuDe chuDe = db.ChuDes.Single(cd => cd.maChuDe == cauHoi.maChuDe);
         cbbChuDe.Text = chuDe.tenChuDe;
         //cbbChuDe.Items[temp - 1];
     }
 }
예제 #6
0
 /// <summary>
 /// Cap nhat cau hoi
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnCapNhat_Click(object sender, EventArgs e)
 {
     if (lvHienThiCauHoi.SelectedItems.Count > 0)
     {
         int ma_CauHoi = (int)lvHienThiCauHoi.SelectedItems[0].Tag;
         _0864186_TracNghiemDataContext db = new _0864186_TracNghiemDataContext();
         CauHoi cauHoi = db.CauHois.Single(ch => ch.maCauHoi == ma_CauHoi);
         txtNoiDungCauHoi.Focus();
         int ma_ChuDe = cbbChuDe.SelectedIndex;
         //cauHoi.maChuDe = ma_ChuDe + 1;
         cauHoi.maChuDe = listChuDe[ma_ChuDe];
         cauHoi.noiDung = txtNoiDungCauHoi.Text;
         cauHoi.dapAnA  = txtDapAnA.Text;
         cauHoi.dapAnB  = txtDapAnB.Text;
         cauHoi.dapAnC  = txtDapAnC.Text;
         cauHoi.dapAnD  = txtDapAnD.Text;
         if (rbA.Checked == true)
         {
             cauHoi.dapAnDung = 1;
         }
         else if (rbB.Checked == true)
         {
             cauHoi.dapAnDung = 2;
         }
         else if (rbC.Checked == true)
         {
             cauHoi.dapAnDung = 3;
         }
         else
         {
             cauHoi.dapAnDung = 4;
         }
         db.SubmitChanges();
         LoadDuLieu_SoanCauHoi();
         XoaTruongDuLieu();
     }
 }
 private void detach_CauHois(CauHoi entity)
 {
     this.SendPropertyChanging();
     entity.ChuDe = null;
 }
 private void attach_CauHois(CauHoi entity)
 {
     this.SendPropertyChanging();
     entity.ChuDe = this;
 }
 partial void DeleteCauHoi(CauHoi instance);
 partial void UpdateCauHoi(CauHoi instance);
 partial void InsertCauHoi(CauHoi instance);