示例#1
0
 public ActionResult Edit(CAUHOI model, FormCollection collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var dao = new CauHoiDao().SuaCauHoi(model);
             if (dao == 1)
             {
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError("", "Loi khong sua duoc du lieu");
                 return(RedirectToAction("Edit", new { id = model.IDCAUHOI }));
             }
         }
         else
         {
             ModelState.AddModelError("", "Dien day du thong tin");
             return(RedirectToAction("Edit", new { id = model.IDCAUHOI }));
         }
     }
     catch
     {
         return(View("Error_404"));
     }
     return(View("Index"));
 }
示例#2
0
        private void gvCauHoi_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            pnLuaChon.Controls.Clear();
            if (flag)
            {
                rtbNoiDungCH.Text = string.Empty;
                int maCH = Int32.Parse(((DataRowView)cAUHOIBindingSource.Current)[0].ToString().Trim());
                if (maCH == 0)
                {
                    return;
                }

                CAUHOI         chRow = CauHoi.GetCauHoiByMaCH(maCH);
                List <LUACHON> lstLC = CauHoi.GetLuaChonByMaCH(maCH);

                rtbNoiDungCH.AppendText(chRow.NOIDUNG);
                lstLC.OrderBy(x => x.MALC);
                foreach (LUACHON lc in lstLC)
                {
                    RichTextBox rtb = new RichTextBox();

                    rtb.Multiline = true;
                    rtb.Text      = "Câu " + lc.MALC + " : " + lc.NOIDUNG;
                    rtb.Dock      = DockStyle.Top;
                    if (chRow.DAPAN.Equals(lc.MALC))
                    {
                        rtb.BackColor = Color.Green;
                    }

                    pnLuaChon.Controls.Add(rtb);
                    pnLuaChon.AutoScroll = true;
                    pnLuaChon.FireScrollEventOnMouseWheel = true;
                }
            }
        }
示例#3
0
 public ActionResult Create(CAUHOI model, FormCollection collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var dao = new CauHoiDao().ThemCauHoi(model);
             if (dao == 1)
             {
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError("", "không thể thêm dữ liệu");
                 return(View("Create"));
             }
         }
         else
         {
             ModelState.AddModelError("", "Điền thông tin đầy đủ");
             return(View("Create"));
         }
     }
     catch
     {
         return(View("Error_404"));
     }
     //return View("Index");
 }
示例#4
0
        public static void deleteQuestion(string mach)
        {
            using (QLTTNDataContext db = new QLTTNDataContext())
            {
                CAUHOI query = (from ch in db.CAUHOIs
                                join kh in db.KHOIs on ch.MaKhoi equals kh.MaKhoi
                                join mh in db.MONHOCs on ch.MaMonHoc equals mh.MaMonHoc
                                join cd in db.CAPDOCAUHOIs on ch.MaCapDo equals cd.MaCapDo
                                join lch in db.LOAICAUHOIs on ch.MaLoaiCauHoi equals lch.MaLoaiCauHoi
                                where ch.MaCauHoi == mach &&
                                ch.MaMonHoc == mh.MaMonHoc &&
                                ch.MaLoaiCauHoi == lch.MaLoaiCauHoi &&
                                ch.MaCapDo == cd.MaCapDo
                                select ch).SingleOrDefault();

                var ctdt = db.CHITIETDETHIs.Where(ct => ct.MaCauHoi.Equals(mach)).Select(ct => ct);

                foreach (var i in ctdt)
                {
                    CHITIETDETHI ch = i;
                    db.CHITIETDETHIs.DeleteOnSubmit(i);
                }
                try
                {
                    db.CAUHOIs.DeleteOnSubmit(query);
                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
 [HttpPut]      //Dịch vụ PUT
 public bool UpdateCH(int id, string nd, string a, string b, string c, string d, string idLoai)
 {
     try
     {
         DBGameDataContext db = new DBGameDataContext();
         //lấy user trong database ra
         CAUHOI ch = db.CAUHOIs.FirstOrDefault(x => x.IDCH == id);
         if (ch == null)
         {
             return(false);           //không tồn tại false
         }
         ch.NoiDung = nd;
         ch.CauA    = a;
         ch.CauB    = b;
         ch.CauC    = c;
         ch.CauD    = d;
         ch.IDLoai  = idLoai;
         db.SubmitChanges();//xác nhận chỉnh sửa
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        //Lấy thông tin theo id
        public CAUHOI GetCH(DIEM diemClient)
        {
            DBGameDataContext db = new DBGameDataContext();
            int id;

            while (true)
            {
                if (diemClient.IDLoai.Trim().Equals("1"))
                {
                    id = rand(minDe, maxDe);
                }
                else if (diemClient.IDLoai.Trim().Equals("2"))
                {
                    id = rand(minVua, maxVua);
                }
                else
                {
                    id = rand(minKho, maxKho);
                }
                if (hash.Any(x => x.Key == (diemClient.IDUser + id)))
                {
                    continue;
                }
                hash.Add(diemClient.IDUser + id, diemClient.IDUser);
                break;
            }
            CAUHOI ch = db.CAUHOIs.FirstOrDefault(x => x.IDCH == id && x.IDLoai == diemClient.IDLoai);

            return(ch);
        }
示例#7
0
        public static void InsertQuestionWithExcel(Microsoft.Office.Interop.Excel.Range xlRange, int row)
        {
            using (QLTTNDataContext dataContext = new QLTTNDataContext())
            {
                int    column  = 1;
                CAUHOI newUser = new CAUHOI()
                {
                    MaCauHoi     = xlRange.Cells[row, column].Text,
                    MaKhoi       = xlRange.Cells[row, column + 1].Text,
                    MaMonHoc     = xlRange.Cells[row, column + 2].Text,
                    MaLoaiCauHoi = xlRange.Cells[row, column + 3].Text,
                    MaCapDo      = xlRange.Cells[row, column + 4].Text,
                    CauHoi1      = xlRange.Cells[row, column + 5].Text,
                    CauA         = xlRange.Cells[row, column + 6].Text,
                    CauB         = xlRange.Cells[row, column + 7].Text,
                    CauC         = xlRange.Cells[row, column + 8].Text,
                    CauD         = xlRange.Cells[row, column + 9].Text,
                    DapAn        = xlRange.Cells[row, column + 10].Text,
                    GoiY         = xlRange.Cells[row, column + 11].Text
                };

                dataContext.CAUHOIs.InsertOnSubmit(newUser);
                dataContext.SubmitChanges();
            }
        }
示例#8
0
        public static CAUHOI GetCauHoiByMaCH(int maCH)
        {
            if (Program.KetNoi() == 0)
            {
                return(null);
            }
            SqlDataReader myReader;

            myReader = Program.ExecSqlDataReader(string.Format(KeyConst.Lenh.GetCauHoiByMaCH, maCH));
            if (myReader == null)
            {
                return(null);
            }
            myReader.Read();

            CAUHOI ch = new CAUHOI
            {
                MACH    = myReader.GetInt32(0),
                NOIDUNG = myReader.GetString(1),
                DAPAN   = myReader.GetString(2),
                TRINHDO = myReader.GetString(3),
                MAMH    = myReader.GetString(4),
                MAGV    = myReader.GetString(5)
            };

            myReader.Close();
            return(ch);
        }
    static void Main(string[] args)
    {
        CAUHOI[] DeThi = XuLyCauHoi.Doc("DeThiTracNghiem.txt");
        String   Chuoi = "Du lieu khong hop le";

        if (DeThi != null)
        {
            Random t = new Random();
            do
            {
                CAUHOI cauhoi = DeThi[t.Next() % DeThi.Length];
                Chuoi = XuLyCauHoi.XuatChuoi(cauhoi);
                XuLyChuoi.Xuat(Chuoi);
                long ChonLua = XuLySoNguyen.Nhap("\nBan chon cau tra loi nao?(1.." + cauhoi.TraLoi.Length + ")"
                                                 , 1, cauhoi.TraLoi.Length);
                long tl = XuLyCauHoi.TraLoiCauHoi(cauhoi);
                Chuoi = "Cau tra loi dung la cau so " + tl + "\n\t ==> ";
                if (tl == ChonLua)
                {
                    Chuoi = Chuoi + "Ban da tra loi dung";
                }
                else
                {
                    Chuoi = Chuoi + "Ban da tra loi sai";
                }
                XuLyChuoi.Xuat(Chuoi);
            } while (XuLySoNguyen.Nhap("\n\nBan co muon lam tiep khong? (1. Tiep; 0. Thoat)") == 1);
        }
        else
        {
            XuLyChuoi.Xuat(Chuoi);
        }
    }
示例#10
0
        public ActionResult ThemCauHoi(FormCollection fc)
        {
            var m = new CAUHOI();

            m.SetData(fc);
            m.ThemCauHoi(m);
            return(RedirectToAction("ThemTC"));
        }
        public ActionResult ManageDapAn(int idCauHoi)
        {
            if (Session["Quyen"] != "Admin")
            {
                return(RedirectToAction("Index", "HomePage"));
            }
            //List<CAUHOI> cAUHOIs = db.CAUHOIs.Where(p => p.IDLinhVuc == idLinhVuc).ToList();
            CAUHOI cAUHOI = db.CAUHOIs.Find(idCauHoi);

            return(View(cAUHOI));
        }
示例#12
0
    public static String XuatChuoi(CAUHOI P)
    {
        String kq = P.NoiDung + " = \r\n";

        for (int i = 0; i < n_traloi; i++)
        {
            kq = kq + "(" + (i + 1) + ") " + XuLyTraLoi.XuatChuoi(P.TraLoi[i]);
            if (i < n_traloi - 1)
            {
                kq = kq + "\t\t";
            }
        }
        return(kq);
    }
        [HttpDelete]    //Dịch vụ DELETE

        //Xóa 1 user
        public bool DeleteCH(int id)
        {
            DBGameDataContext db = new DBGameDataContext();
            //lấy user tồn tại ra
            CAUHOI ch = db.CAUHOIs.FirstOrDefault(x => x.IDCH == id);

            if (ch == null)
            {
                return(false);
            }
            db.CAUHOIs.DeleteOnSubmit(ch);
            db.SubmitChanges();
            return(true);
        }
示例#14
0
    public static long TraLoiCauHoi(CAUHOI P)
    {
        Boolean  flag = true;
        BIEUTHUC Q    = XuLyBieuThuc.KhoiTao(P.NoiDung);
        long     t    = XuLyBieuThuc.TinhToan(Q);

        for (int i = 0; i < P.TraLoi.Length; i++)
        {
            if (t == long.Parse(P.TraLoi[i].NoiDung))
            {
                return(i + 1);
            }
        }
        return(-1);
    }
示例#15
0
 public int SuaCauHoi(CAUHOI model)
 {
     object[] parameter =
     {
         new SqlParameter("@IDCAUHOI",      model.IDCAUHOI),
         new SqlParameter("@NOIDUNGCAUHOI", model.NOIDUNGCAUHOI.Trim()),
         new SqlParameter("@DAPAN_A",       model.DAPAN_A.Trim()),
         new SqlParameter("@DAPAN_B",       model.DAPAN_B.Trim()),
         new SqlParameter("@DAPAN_C",       model.DAPAN_C.Trim()),
         new SqlParameter("@DAPAN_D",       model.DAPAN_D.Trim()),
         new SqlParameter("@DAPAN_DUNG",    model.DAPAN_DUNG.Trim()),
         new SqlParameter("@TRANGTHAI",     model.TRANGTHAI),
         new SqlParameter("@IDMON",         model.IDMON),
     };
     return(db.Database.ExecuteSqlCommand("CAUHOI_SuaCauHoi @IDCAUHOI, @NOIDUNGCAUHOI, @DAPAN_A, @DAPAN_B, @DAPAN_C, @DAPAN_D, @DAPAN_DUNG, @TRANGTHAI, @IDMON", parameter));
 }
示例#16
0
    public static void btnExport_Question_Click(DataParameter _inputParameter, BackgroundWorker bgWorker_Export, DataGridView dtgv_ListQuestion, ProgressBar pgBar)
    {
        if (bgWorker_Export.IsBusy)
        {
            return;
        }
        using (SaveFileDialog s_File = new SaveFileDialog()
        {
            Filter = "Excel Workbook|*.xls"
        })
        {
            if (s_File.ShowDialog() == DialogResult.OK)
            {
                _inputParameter.FileName = s_File.FileName;
                List <CAUHOI> listQuestion = new List <CAUHOI>();
                for (int i = 0; i < dtgv_ListQuestion.Rows.Count - 1; i++)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    row = dtgv_ListQuestion.Rows[i];
                    CAUHOI user = new CAUHOI()
                    {
                        MaCauHoi     = row.Cells[0].Value.ToString(),
                        MaKhoi       = row.Cells[1].Value.ToString(),
                        MaMonHoc     = row.Cells[2].Value.ToString(),
                        MaLoaiCauHoi = row.Cells[3].Value.ToString(),
                        MaCapDo      = row.Cells[4].Value.ToString(),
                        CauHoi1      = row.Cells[5].Value.ToString(),
                        CauA         = row.Cells[6].Value.ToString(),
                        CauB         = row.Cells[7].Value.ToString(),
                        CauC         = row.Cells[8].Value.ToString(),
                        CauD         = row.Cells[9].Value.ToString(),
                        DapAn        = row.Cells[10].Value.ToString(),
                        GoiY         = row.Cells[11].Value.ToString()
                    };
                    listQuestion.Add(user);
                }

                _inputParameter.listQuestion = listQuestion;

                pgBar.Minimum = 0;
                pgBar.Value   = 0;
                bgWorker_Export.RunWorkerAsync(_inputParameter);
            }
        }
    }
        private CAUHOI Add_quiz_to_db(int idLinhVuc,
                                      int idLoaiCauHoi,
                                      string noiDungCauHoi,
                                      List <string> noiDungDapAns,
                                      List <bool> tinhChats)
        {
            CAUHOI cauhoi = new CAUHOI();

            cauhoi = cauhoi.Add_cau_hoi(noiDungCauHoi, idLinhVuc, idLoaiCauHoi);
            for (int idx = 0; idx < noiDungDapAns.Count; idx++)
            {
                string noiDungDapAn = noiDungDapAns[idx];
                bool   tinhChat     = tinhChats[idx];
                int    idCauHoi     = cauhoi.IDCauHoi;
                DAPAN  dapan        = new DAPAN();
                dapan.Add_dap_an(noiDungDapAn, idCauHoi, tinhChat, null);
            }
            return(cauhoi);
        }
        public void SetData()
        {
            if (LISTMACH.Count == 0)
            {
                return;
            }
            lblTenMonHoc.Text = "XE TRƯỚC BỘ ĐỀ MÔN : " + TTENMH;
            KHOA kh = Khoa.GetKhoaByMaKhoa(MAKHOA);

            lblTenKhoa.Text    = "KHOA : " + kh.TENKH;
            lblTrinhDo.Text    = TrinhDo.GetTDByMaTD(MATRINHDO).TENTD;
            lblThongTinBD.Text = "Thời gian : " + THOIGIANTHI.ToString() + " phút";

            RichTextBox    rtbCau = new RichTextBox();
            CAUHOI         ch     = null;
            List <LUACHON> lc     = null;

            for (int i = 0; i < LISTMACH.Count; i++)
            {
                ch = CauHoi.GetCauHoiByMaCH(LISTMACH[i]);
                if (rtbCau.Text.Trim() == string.Empty)
                {
                    rtbCau.Text = "Câu " + (i + 1).ToString() + " : ";
                    rtbCau.AppendText(Environment.NewLine + "    " + ch.NOIDUNG);
                }
                else
                {
                    rtbCau.AppendText(Environment.NewLine + "Câu " + (i + 1).ToString() + " : " + ch.NOIDUNG);
                }
                lc = CauHoi.GetLuaChonByMaCH(LISTMACH[i]);
                for (int j = 0; j < lc.Count; j++)
                {
                    rtbCau.AppendText(Environment.NewLine + "     Câu " + KeyConst.LUACHON[j] + " : " + lc[j].NOIDUNG);
                }
            }
            rtbCau.Dock = DockStyle.Fill;
            FontStyle newFontStyle = (FontStyle)(FontStyle.Bold);

            rtbCau.Font           = new Font("Times New Rowman", 25, newFontStyle);
            pnBaiThi.AutoScroll   = true;
            rtbCau.SelectionStart = 0;
            pnBaiThi.Controls.Add(rtbCau);
        }
示例#19
0
 public static CAUHOI[] KhoiTao(String Chuoi)
 {
     CAUHOI[] kq;
     kq = null;
     if (KiemTra(Chuoi))
     {
         String[] M = Chuoi.Split(new String[] { ChuoiPhanCach },
                                  StringSplitOptions.None);
         kq = new CAUHOI[M.Length / 2];
         String S;
         for (int i = 0, j = 0; i < M.Length; i += 2, j++)
         {
             S             = M[i].Replace("=", "");
             kq[j].NoiDung = S.Trim();
             kq[j].TraLoi  = XuLyTraLoi.KhoiTao(M[i + 1]);
         }
     }
     return(kq);
 }
    static void Main(string[] args)
    {
        BIEUTHUC[] NoiDung;
        CAUHOI[]   De;
        NoiDung = XuLyBieuThuc.Nhap("Nhap vao noi dung cac cau hoi:\n");
        De      = new CAUHOI[NoiDung.Length];
        String Chuoi = "";
        Random t     = new Random();

        for (int i = 0; i < NoiDung.Length; i++)
        {
            De[i] = XuLyCauHoi.KhoiTao(NoiDung[i], t);
            Chuoi = Chuoi + XuLyCauHoi.XuatChuoi(De[i]);
            if (i < NoiDung.Length - 1)
            {
                Chuoi += "\r\n";
            }
        }
        XuLyTapTin.Ghi("DeThiTracNghiem.txt", Chuoi);
        XuLyChuoi.Xuat(Chuoi);
    }
 // Thêm 1 cauhoi mới
 public bool InsertNewCH(string nd, string a, string b, string c, string d, string idLoai)
 {
     try
     {
         DBGameDataContext db = new DBGameDataContext();
         CAUHOI            ch = new CAUHOI();
         //us.ID = id;
         ch.NoiDung = nd;
         ch.CauA    = a;
         ch.CauB    = b;
         ch.CauC    = c;
         ch.CauD    = d;
         ch.IDLoai  = idLoai;
         db.CAUHOIs.InsertOnSubmit(ch);
         db.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public ActionResult AddQuiz(int idLinhVuc, int idLoaiCauHoi)
        {
            if (Session["Quyen"] != "Admin")
            {
                return(RedirectToAction("Index", "HomePage"));
            }
            List <string> noiDungDapAns = new List <string>();
            List <bool>   tinhChats     = new List <bool>();

            if (idLoaiCauHoi == Constant.ID_CAU_HOI_1_DAP_AN)
            {
                string noiDungCauHoi        = Request["one-correct-quiz-content"];
                int    num_of_dap_an        = Int32.Parse(Request["one-correct-quiz-num-of-dap-an"]);
                int    true_answer_position = Int32.Parse(Request["one-correct-quiz-radio"]);

                for (int idx = 0; idx < num_of_dap_an; idx++)
                {
                    int    order = idx + 1;
                    string dapan_content_name = "one-correct-quiz-noi-dung-" + order;
                    noiDungDapAns.Add(Request[dapan_content_name]);
                    tinhChats.Add(order == true_answer_position ? true : false);
                }
                Add_quiz_to_db(idLinhVuc, idLoaiCauHoi, noiDungCauHoi, noiDungDapAns, tinhChats);
            }
            else if (idLoaiCauHoi == Constant.ID_CAU_HOI_NHIEU_DAP_AN)
            {
                string noiDungCauHoi = Request["multi-correct-quiz-content"];
                int    num_of_dap_an = Int32.Parse(Request["multi-correct-quiz-num-of-dap-an"]);
                for (int idx = 0; idx < num_of_dap_an; idx++)
                {
                    int    order              = idx + 1;
                    string checkbox_name      = "multi-correct-quiz-checkbox-" + order;
                    string dapan_content_name = "multi-correct-quiz-noi-dung-" + order;
                    noiDungDapAns.Add(Request[dapan_content_name]);
                    tinhChats.Add(Request[checkbox_name] != null ? true : false);
                }
                Add_quiz_to_db(idLinhVuc, idLoaiCauHoi, noiDungCauHoi, noiDungDapAns, tinhChats);
            }
            else if (idLoaiCauHoi == Constant.ID_CAU_HOI_SAP_XEP_THEO_THU_TU)
            {
                string     noiDungCauHoi = Request["sorted-quiz-content"];
                int        num_of_dap_an = Int32.Parse(Request["sorted-quiz-num-of-dap-an"]);
                List <int> thuTus        = new List <int>();
                for (int idx = 0; idx < num_of_dap_an; idx++)
                {
                    int    order = idx + 1;
                    string dapan_content_name = "sorted-quiz-noidung-" + order;
                    noiDungDapAns.Add(Request[dapan_content_name]);
                    tinhChats.Add(true);
                    thuTus.Add(order);
                }
                Add_quiz_to_db(idLinhVuc, idLoaiCauHoi, noiDungCauHoi, noiDungDapAns, tinhChats, thuTus);
            }
            else if (idLoaiCauHoi == Constant.ID_CAU_HOI_DIEN_VAO_CHO_TRONG)
            {
                string     noiDungCauHoi        = Request["fill-in-blank-quiz-content"];
                int        num_of_blanks        = Int32.Parse(Request["fill-in-blank-quiz-num-of-blank"]);
                int        num_of_wrong_answers = Int32.Parse(Request["fill-in-blank-quiz-num-of-wrong-answer"]);
                List <int> thuTus = new List <int>();
                // Add blank answer
                for (int idx = 0; idx < num_of_blanks; idx++)
                {
                    int    order             = idx + 1;
                    string blank_answer_name = "blank-answer-content-" + order;
                    noiDungDapAns.Add(Request[blank_answer_name]);
                    tinhChats.Add(true);
                    thuTus.Add(order);
                }
                CAUHOI cauhoi = Add_quiz_to_db(idLinhVuc, idLoaiCauHoi, noiDungCauHoi, noiDungDapAns, tinhChats, thuTus);
                // Add wrong answer
                noiDungDapAns.Clear();
                for (int idx = 0; idx < num_of_wrong_answers; idx++)
                {
                    int    order             = idx + 1;
                    string wrong_answer_name = "wrong-answer-content-" + order;
                    noiDungDapAns.Add(Request[wrong_answer_name]);
                }
                Add_wrong_answer_of_fill_in_blank_quiz_to_db(cauhoi.IDCauHoi, noiDungDapAns);
            }
            return(RedirectToAction("ManageQuiz", "Admin", new { idLinhVuc = idLinhVuc }));
        }
示例#23
0
        public static void AddNewQuestion(Cau_Hoi ch1)
        {
            using (QLTTNDataContext db = new QLTTNDataContext())
            {
                var query = (from ch in db.CAUHOIs
                             join kh in db.KHOIs on ch.MaKhoi equals kh.MaKhoi
                             join mh in db.MONHOCs on ch.MaMonHoc equals mh.MaMonHoc
                             join cd in db.CAPDOCAUHOIs on ch.MaCapDo equals cd.MaCapDo
                             join lch in db.LOAICAUHOIs on ch.MaLoaiCauHoi equals lch.MaLoaiCauHoi

                             where ch.MaCauHoi == ch1.ma_CH
                             select new
                {
                    ch
                }).SingleOrDefault();
                if (query == null)
                {
                    try
                    {
                        CAUHOI c = new CAUHOI();
                        c.MaCauHoi     = ch1.ma_CH;
                        c.MaKhoi       = ch1.Ten_Khoi;
                        c.MaMonHoc     = ch1.Ten_Mon;
                        c.MaLoaiCauHoi = ch1.Ten_LoaiCH;
                        c.MaCapDo      = ch1.Ten_CD;
                        c.CauHoi1      = ch1.noi_dung;
                        c.CauA         = ch1.Cau_A;
                        c.CauB         = ch1.Cau_B;
                        c.CauC         = ch1.Cau_C;
                        c.CauD         = ch1.Cau_D;
                        c.DapAn        = ch1.Dap_An;
                        c.GoiY         = ch1.goi_Y;
                        db.CAUHOIs.InsertOnSubmit(c);
                        db.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    try
                    {
                        query.ch.MaCauHoi     = ch1.ma_CH;
                        query.ch.MaKhoi       = ch1.Ten_Khoi;
                        query.ch.MaMonHoc     = ch1.Ten_Mon;
                        query.ch.MaLoaiCauHoi = ch1.Ten_LoaiCH;
                        query.ch.MaCapDo      = ch1.Ten_CD;
                        query.ch.CauHoi1      = ch1.noi_dung;
                        query.ch.CauA         = ch1.Cau_A;
                        query.ch.CauB         = ch1.Cau_B;
                        query.ch.CauC         = ch1.Cau_C;
                        query.ch.CauD         = ch1.Cau_D;
                        query.ch.DapAn        = ch1.Dap_An;
                        query.ch.GoiY         = ch1.goi_Y;

                        db.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
示例#24
0
        private void FormThi_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dtsTTN.CT_BAITHI' table. You can move, or remove it, as needed.
            this.cT_BAITHITableAdapter.Fill(this.dtsTTN.CT_BAITHI);
            bANGDIEMTableAdapter.Fill(this.dtsTTN.BANGDIEM);
            MyTimer.Interval = (1000); // 1 mins
            MyTimer.Tick    += new EventHandler(t_Tick);
            MyTimer.Start();

            if (MaBD != -1)
            {
                BDThiTam = BoDe.LayBDThi(MaBD);
                if (BDThi == null)
                {
                    return;
                }
                CAUHOITHI = new List <HoTroLayCauHoiThi>();
                HoTroLayCauHoiThi htCHThi  = null;
                Panel             pnCauHoi = null;
                int i = BDThiTam.Count;
                while (BDThiTam.Count != 0)
                {
                    htCHThi = new HoTroLayCauHoiThi();
                    int           r  = rnd.Next(BDThiTam.Count);
                    HoTroLayBDThi ht = BDThiTam[r];
                    BDThi.Add(ht);
                    CAUHOI         cauHoi  = CauHoi.GetCauHoiByMaCH(ht.MaCauHoi);
                    List <LUACHON> luachon = CauHoi.GetLuaChonByMaCH(ht.MaCauHoi);

                    pnCauHoi          = new Panel();
                    pnCauHoi.AutoSize = true;
                    pnCauHoi.Dock     = DockStyle.Top;

                    Label lb = new Label();
                    lb.AutoSize = true;
                    FontStyle newFontStyle = (FontStyle)(FontStyle.Bold);
                    lb.Font = new Font("Times New Rowman", 25, newFontStyle);
                    lb.Text = "Câu " + i + " : " + cauHoi.NOIDUNG;

                    RadioButton rGLuaChon = null;

                    foreach (LUACHON lc in luachon)
                    {
                        rGLuaChon          = new RadioButton();
                        rGLuaChon.AutoSize = true;
                        rGLuaChon.Name     = lc.MALC.Trim() + "-" + cauHoi.MACH.ToString().Trim();
                        rGLuaChon.Font     = new Font("Times New Rowman", 25, newFontStyle);
                        // update dap an neu thay doi lua chon
                        rGLuaChon.CheckedChanged += new EventHandler(LuaChon_Click);
                        //rGLuaChon.Add(new RadioGroupItem(lc.MALC.ToString(), "Câu " + lc.MALC.ToString() + " : " + lc.NOIDUNG));
                        rGLuaChon.Text = "Câu " + lc.MALC.ToString() + " : " + lc.NOIDUNG;
                        rGLuaChon.Dock = DockStyle.Bottom;
                        rGLuaChon.Focus();
                        pnCauHoi.Controls.Add(rGLuaChon);
                    }

                    lb.Dock = DockStyle.Top;
                    pnCauHoi.Controls.Add(lb);
                    pnThi.Controls.Add(pnCauHoi);

                    htCHThi.MaCH      = cauHoi.MACH;
                    htCHThi.STT       = ht.SoTT;
                    htCHThi.DapAn     = cauHoi.DAPAN;
                    htCHThi.STTKhiThi = i - 1;

                    CAUHOITHI.Add(htCHThi);
                    BDThiTam.RemoveAt(r);
                    i--;
                }
            }
            pnThi.AllowDrop  = true;
            pnThi.AutoScroll = true;
        }
示例#25
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["name"] == null)
                {
                    string url;
                    url = "~/DangNhap.aspx?";
                    Response.Redirect(url);
                }
                Session["diem"] = 0;
                lblHoTenSV.Text = Request.QueryString["name"];
                lblTenKT.Text   = Request.QueryString["tenkt"];
                //Load câu hỏi cho thí sinh
                //Lấy mã thí sinh

                //Lấy mã đề thi
                int mats = svBus.GetMats(lblHoTenSV.Text);
                int madt = dtBus.GetMadt(mats);
                //Lấy danh sách câu hỏi
                dsch             = chBus.GetDSCauHoiDT(madt);
                Session["dsch"]  = dsch;
                Session["no_ch"] = 0;
                //Load câu hỏi đầu tiên vào bảng câu hỏi
                CAUHOI ch1 = (CAUHOI)dsch[(int)Session["no_ch"]];

                txtCauHoi.Text     = "Câu hỏi " + ((int)Session["no_ch"] + 1).ToString() + ": " + ch1.NOIDUNG;
                imgCauHoi.ImageUrl = "~/image/" + ch1.HINHANH;
                //Lấy danh sách đáp án
                ArrayList dsda = new ArrayList();
                dsda = chBus.getDapAn(ch1.MACH);

                int index = 1;
                foreach (DAPAN item in dsda)
                {
                    if (index == 1)
                    {
                        radListDA.Items.Add("A. " + item.NOIDUNGDA, index);
                    }
                    if (index == 2)
                    {
                        radListDA.Items.Add("B. " + item.NOIDUNGDA, index);
                    }
                    if (index == 3)
                    {
                        radListDA.Items.Add("C. " + item.NOIDUNGDA, index);
                    }
                    if (index == 4)
                    {
                        radListDA.Items.Add("D. " + item.NOIDUNGDA, index);
                    }

                    if ((bool)item.DADUNG)
                    {
                        Session["dad"] = index;
                    }
                    index++;
                }
                Session["no_ch"] = (int)Session["no_ch"] + 1;
                if (!SM1.IsInAsyncPostBack)
                {
                    Session["timeout"] = DateTime.Now.AddMinutes(90).ToString();
                }
            }
        }
示例#26
0
        protected void btnTiepTheo_Click(object sender, EventArgs e)
        {
            //Lựa chọn đáp án, tính điểm, chuyển câu tiêp theo
            ASPxRadioButtonList rbl   = (ASPxRadioButtonList)this.FindControl("radListDA");
            ListEditItem        item1 = rbl.SelectedItem;

            if (item1 != null)
            {
                int dadung    = (int)Session["dad"];
                int dapanchon = Convert.ToInt32(item1.Value);
                if (dapanchon == (int)Session["dad"])
                {
                    //Tăng tổng điểm
                    int diemtong = (int)Session["diem"];
                    Session["diem"] = diemtong + 1;
                }
            }
            //Chuyển qua câu tiếp theo

            //Load câu hỏi tiếp theo vào bảng câu hỏi
            int soch = (int)Session["no_ch"];

            if (((ArrayList)Session["dsch"]).Count > soch)
            {
                CAUHOI ch1 = (CAUHOI)((ArrayList)Session["dsch"])[(int)Session["no_ch"]];
                txtCauHoi.Text     = "Câu hỏi " + ((int)Session["no_ch"] + 1).ToString() + ": " + ch1.NOIDUNG;
                imgCauHoi.ImageUrl = "~/image/" + ch1.HINHANH;
                //Lấy danh sách đáp án
                ArrayList dsda = new ArrayList();
                dsda = chBus.getDapAn(ch1.MACH);
                radListDA.Items.Clear();
                int index = 1;
                foreach (DAPAN item in dsda)
                {
                    if (index == 1)
                    {
                        radListDA.Items.Add("A. " + item.NOIDUNGDA, index);
                    }
                    if (index == 2)
                    {
                        radListDA.Items.Add("B. " + item.NOIDUNGDA, index);
                    }
                    if (index == 3)
                    {
                        radListDA.Items.Add("C. " + item.NOIDUNGDA, index);
                    }
                    if (index == 4)
                    {
                        radListDA.Items.Add("D. " + item.NOIDUNGDA, index);
                    }

                    if ((bool)item.DADUNG)
                    {
                        Session["dad"] = index;
                    }
                    index++;
                }
                Session["no_ch"] = (int)Session["no_ch"] + 1;
            }
            else
            {
                lblNotify.Text      = "Kết thúc bài thi, mời bạn Nộp bài thi";
                btnTiepTheo.Enabled = false;
            }
        }