Ejemplo n.º 1
0
 public bool ThemDeThi(DETHI model)
 {
     db.DETHIs.Add(model);
     db.SaveChanges();
     CapNhatDeThiMoi(model.IDDETHI);
     return(true);
 }
Ejemplo n.º 2
0
        static public bool xoaDeThiVaoDB(DETHI dt)
        {
            //xóa ở chi tiết đề thi trước
            using (QLTTNDataContext qlttn = new QLTTNDataContext())
            {
                try
                {
                    //Xóa ở chi tiết đề thi
                    var chiTietDeThi = qlttn.CHITIETDETHIs.Where(ctdt => ctdt.MaDeThi.Equals(dt.MaDeThi));
                    foreach (var ctdt in chiTietDeThi)
                    {
                        qlttn.CHITIETDETHIs.DeleteOnSubmit(ctdt);
                    }


                    //Xóa ở đề thi
                    var deThi = qlttn.DETHIs.Where(dtt => dtt.MaDeThi.Equals(dt.MaDeThi));
                    foreach (var dtt in deThi)
                    {
                        qlttn.DETHIs.DeleteOnSubmit(dtt);
                        qlttn.SubmitChanges();
                    }
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
        private DETHI Save_total_score_to_db(int idDeThi, double score)
        {
            DETHI dETHI = db.DETHIs.Find(idDeThi);

            dETHI.TongDiem = (decimal?)score;
            db.SaveChanges();
            return(dETHI);
        }
Ejemplo n.º 4
0
        private DETHI CreateDeThi(string mucDo, int idTaiKhoan)
        {
            DETHI dethi = new DETHI();

            dethi.NgayThi = DateTime.Now;
            dethi.MucDo   = mucDo;
            dethi.IDUser  = idTaiKhoan;
            db.DETHIs.Add(dethi);
            db.SaveChanges();
            return(dethi);
        }
Ejemplo n.º 5
0
 public void SaveDeThi(DETHI obj)
 {
     try
     {
         db.DETHIs.InsertOnSubmit(obj);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 6
0
 private void Create_danh_sach_cau_hoi(DETHI de_thi, IEnumerable <CAUHOI> cau_hois)
 {
     for (int i = 0; i < cau_hois.Count(); i++)
     {
         var            cau_hoi_id        = cau_hois.ElementAt(i).IDCauHoi;
         DANHSACHCAUHOI danh_sach_cau_hoi = new DANHSACHCAUHOI();
         danh_sach_cau_hoi.IDDeThi  = de_thi.IDDeThi;
         danh_sach_cau_hoi.IDCauHoi = cau_hoi_id;
         db.DANHSACHCAUHOIs.Add(danh_sach_cau_hoi);
         db.SaveChanges();
     }
 }
Ejemplo n.º 7
0
        // GET: LamDeThi
        public ActionResult Index(int id)
        {
            id = 1;

            DETHI dt = new DETHI();

            dt = dt.ChiTietDeThi(id);
            ViewData["DSCHDT"] = dt.ListCauHoi;

            ViewBag.id = id;

            return(View());
        }
Ejemplo n.º 8
0
        public int SuaDeThi(DETHI model)
        {
            var de = db.DETHIs.Find(model.IDDETHI);

            de.TENDETHI   = model.TENDETHI;
            de.IDMUCDO    = model.IDMUCDO;
            de.IDMON      = model.IDMON;
            de.IDTHOIGIAN = model.IDTHOIGIAN;
            de.IDSOCAU    = model.IDSOCAU;
            de.NGAYTAODE  = DateTime.Now;
            de.DOTINCAY   = model.DOTINCAY;
            de.TRANGTHAI  = model.TRANGTHAI;
            db.SaveChanges();
            return(model.IDDETHI);
        }
Ejemplo n.º 9
0
 static public bool themDeThiVaoDB(DETHI dt)
 {
     using (QLTTNDataContext qlttn = new QLTTNDataContext())
     {
         try
         {
             qlttn.DETHIs.InsertOnSubmit(dt);
             qlttn.SubmitChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Ejemplo n.º 10
0
        public ActionResult Edit(DETHI model, FormCollection collection)
        {
            DeThiDao dao = new DeThiDao();

            var ketqua = dao.SuaDeThi(model);

            if (ketqua != 0)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "loi error");
            }
            return(View("Index"));
        }
Ejemplo n.º 11
0
        public ActionResult CreateExam(int idLinhVuc)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("LoginUser", "Login"));
            }

            string mucDo        = "1";
            int    id_tai_khoan = int.Parse(Session["ID"].ToString());
            //int id_linh_vuc = Int32.Parse(idLinhVuc);
            IEnumerable <CAUHOI> cau_hois = Get_cau_hoi_by_linh_vuc(idLinhVuc);
            // Create DETHI and danh sach cau hoi
            DETHI dethi = CreateDeThi(mucDo, id_tai_khoan);

            Create_danh_sach_cau_hoi(dethi, cau_hois);
            // Get session exam
            Create_new_session_exam(dethi.IDDeThi, cau_hois);
            return(RedirectToAction("Index", new { quiz_idx = 0 }));
        }
Ejemplo n.º 12
0
        private void AddDeThi()
        {
            var id = data.DETHIs.Where(u => u.MaDeThi == int.Parse(cb_dethi.Text)).SingleOrDefault <DETHI>();

            if (id != null)
            {
                tb_thongbao.Text = "Mã Đề thi đã tồn tại.";
                return;
            }
            else
            {
                DETHI d = new DETHI();
                d.MaKiThi = txt_id_kt.Text;
                d.MaDeThi = int.Parse(cb_dethi.Text);
                data.DETHIs.InsertOnSubmit(d);
                data.SubmitChanges();
                tb_thongbao.Text = "Thêm đề thi thành công";
            }
        }
Ejemplo n.º 13
0
 private void RemoveDeThi()
 {
     try
     {
         if (System.Windows.Forms.MessageBox.Show("Xác nhận xoá? ", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
         {
             DETHI d = data.DETHIs.Single(item => item.MaDeThi == int.Parse(cb_dethi.Text));
             data.DETHIs.DeleteOnSubmit(d);
             data.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     finally
     {
         GetData_DeThi();
     }
 }
Ejemplo n.º 14
0
        public ActionResult Create(DETHI model, FormCollection collection)
        {
            var dao = new DeThiDao();

            // TODO: Add insert logic here
            if (ModelState.IsValid)
            {
                var ketqua = dao.ThemDeThi(model);
                if (!ketqua)
                {
                    return(View("Index"));
                }
                return(RedirectToAction("ThemCauHoi", new { id = model.IDDETHI }));
            }
            else
            {
                ModelState.AddModelError("", "Loi error");
            }
            return(View("Index"));
        }
Ejemplo n.º 15
0
 private void dethi_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         int rowindex = kithi.SelectedIndex;
         if (rowindex == -1)
         {
             Clear();
         }
         else
         {
             DETHI a = (DETHI)dethi.SelectedItem;
             cb_dethi.SelectedValue = a.MaDeThi;
             GetData_Cauhoi();
             GetData_Monhoc();
         }
     }
     catch (Exception ex)
     {
     }
 }
Ejemplo n.º 16
0
        public ActionResult KetQua()
        {
            List <string> lstdapan = new List <string>();

            string id = Request.Form["id"];


            string a;

            for (int i = 1; i <= 50; i++)
            {
                a = string.Concat("CauHoi", i.ToString());
                if (Request.Form[a] == null)
                {
                    lstdapan.Add("Sai");
                }
                if (Request.Form[a] != null)
                {
                    lstdapan.Add(Request.Form[a]);
                }
            }
            DETHI dt = new DETHI();

            dt    = dt.ChiTietDeThi(int.Parse(id));
            lstCH = dt.ListCauHoi; //dung r ma sai gi dau xem nay
            int count = 0;

            for (int i = 0; i <= 49; i++)
            {
                if (lstCH[i].DapAnDung.ToString().Trim().ToLower().Equals(lstdapan[i].ToString().Trim().ToLower()))
                {
                    count++;
                }
            }
            ViewBag.made = id;
            ViewBag.a    = count;
            ViewBag.diem = count * 0.2;
            return(View());
        }
Ejemplo n.º 17
0
 static public bool capNhatDeThiVaoDB(DETHI dt)
 {
     using (QLTTNDataContext qlttn = new QLTTNDataContext())
     {
         try
         {
             var deThi = qlttn.DETHIs.Where(dtt => dtt.MaDeThi.Equals(dt.MaDeThi));
             foreach (var dtt in deThi)
             {
                 dtt.ThoiGianLamBai = dt.ThoiGianLamBai;
                 dtt.MaKhoi         = dt.MaKhoi;
                 dtt.MaMonHoc       = dt.MaMonHoc;
             }
             qlttn.SubmitChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Ejemplo n.º 18
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            KYTHI obj = new KYTHI();

            obj.TENKYTHI = txtTenKT.Text;
            obj.NGAYTHI  = (DateTime)dateNgayThi.Value;
            obj.SODETHI  = Convert.ToInt32(txtSoDT.Text);
            obj.MABODT   = Convert.ToInt32(cbBoDT.SelectedItem.Value);
            int mabodt = Convert.ToInt32(cbBoDT.SelectedItem.Value);

            try
            {
                kythiBus = new KyThiBUS();
                kythiBus.SaveKyThi(obj);
            }
            catch (Exception ex)
            {
                txtError.Text = ex.Message;
            }
            //Lấy số đề thi để tạo
            int sodethi = Convert.ToInt32(txtSoDT.Text);

            //Thành công thì tạo các đề thi tự động
            //Lấy thông tin mã các câu hỏi từ bộ đề thi
            bodtBus = new BoDeThiBUS();
            ArrayList dsch       = bodtBus.GetCauHois(mabodt);
            int       makythimoi = kythiBus.GetMaKyThiNew();

            for (int j = 0; j < sodethi; j++)
            {
                //Lấy được hoán vị xong thì bắt đầu lưu vào
                dethiBus = new DeThiBUS();
                DETHI obj2 = new DETHI();
                obj2.NGAYTAO = DateTime.Now;
                obj2.MAKYTHI = makythimoi;
                dethiBus.SaveDeThi(obj2);

                foreach (int ch in dsch)
                {
                    CHITIETDETHI obj1 = new CHITIETDETHI();
                    obj1.MACH = ch;
                    //Lấy danh sách câu trả lời
                    daBus = new DapAnBUS();
                    ArrayList dsda = daBus.GetDSDapAn(ch);
                    //Tạo ra các dãy số đảo của câu trả lời và lưu vào dữ liệu
                    int[] numbers = new int[] { 1, 2, 3, 4 };

                    Random rnd    = new Random();
                    int[]  hoanvi = numbers.OrderBy(x => rnd.Next()).ToArray();
                    //Có được hoán vị thì sẽ hoán vị ds đáp án

                    if (dsda.Count < 4)
                    {
                        continue;
                    }
                    for (int i = 0; i < hoanvi.Length; i++)
                    {
                        int index = hoanvi[i];
                        obj1.DA += dsda[index - 1].ToString() + ",";
                    }


                    dethiBus.SaveChiTietDeThi(obj1);
                }
            }


            ASPxGridView1.DataBind();
        }
Ejemplo n.º 19
0
 static public bool themDeThiVaoDB(DETHI dt)
 {
     return(DAO_Giao_Vien.themDeThiVaoDB(dt));
 }
Ejemplo n.º 20
0
 static public bool capNhatDeThiVaoDB(DETHI dt)
 {
     return(DAO_Giao_Vien.capNhatDeThiVaoDB(dt));
 }
Ejemplo n.º 21
0
 static public bool xoaDeThiVaoDB(DETHI dt)
 {
     return(DAO_Giao_Vien.xoaDeThiVaoDB(dt));
 }