Exemplo n.º 1
0
        public static bool ThemTaiKhoan(TaiKhoan tk)
        {
            bool flag = true;

            using (var qltk = new QuanLyThiTracNghiemDataContext())
            {
                var query = qltk.TaiKhoans.Where(t => t.ChuTaiKhoan == tk.ChuTaiKhoan).SingleOrDefault();

                // query != null => User có MaTK đã có tài khoản, ko thể tạo
                if (query != null)
                {
                    MessageBox.Show("Đã có tài khoản cho mã tài khoản này");
                    flag = false;
                }
                else
                {
                    qltk.TaiKhoans.InsertOnSubmit(tk);

                    try
                    {
                        qltk.SubmitChanges();
                    }
                    catch (Exception)
                    {
                        flag = false;
                    }
                }
            }
            return(flag);
        }
Exemplo n.º 2
0
        public static bool LuuDapAn(IList <LuuTru> lt)
        {
            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                foreach (var i in lt)
                {
                    //MessageBox.Show(i.MaKyThi + " | " + i.MaDeThi + " | " + i.MaHocSinh + " | " + i.MaCauHoi + " | " + i.MaDapAn);

                    var temp = ds.LuuTrus.Where(s => s.MaHocSinh == i.MaHocSinh && s.MaCauHoi == i.MaCauHoi &&
                                                s.MaDeThi == i.MaDeThi && s.MaKyThi == i.MaKyThi)
                               .SingleOrDefault();
                    if (temp == null)
                    {
                        // Thêm
                        ds.LuuTrus.InsertOnSubmit(i);
                    }
                    else
                    {
                        // Cập nhật
                        temp.MaDapAn = i.MaDapAn;
                    }
                    try
                    {
                        ds.SubmitChanges();
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        public static bool ThemCauHoi(CauHoi ch)
        {
            bool flag = true;

            using (var qlch = new QuanLyThiTracNghiemDataContext())
            {
                var query = qlch.CauHois.Where(c => c.MaCauHoi == ch.MaCauHoi).SingleOrDefault();

                if (query != null)
                {
                    flag = false;
                }
                else
                {
                    qlch.CauHois.InsertOnSubmit(ch);

                    try
                    {
                        qlch.SubmitChanges();
                    }
                    catch (Exception)
                    {
                        flag = false;
                    }
                }
            }
            return(flag);
        }
Exemplo n.º 4
0
 public static bool KetThucBaiThi(string id, string MKT)
 {
     using (var ds = new QuanLyThiTracNghiemDataContext())
     {
         try
         {
             var q = ds.DSDUTHIs
                     .Where(d => d.MaHocSinh == id && d.MaKyThi == MKT)
                     .SingleOrDefault();
             if (q != null)
             {
                 q.DaThi  = true;
                 q.KetQua = (from l in ds.LuuTrus
                             join d in ds.DapAns
                             on new { l.MaCauHoi, l.MaDapAn }
                             equals new { d.MaCauHoi, d.MaDapAn }
                             where d.Dung == true && l.MaKyThi == MKT && l.MaHocSinh == id
                             select l).Count() * 0.1666;
                 ds.SubmitChanges();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 5
0
 private void LoadInfo()
 {
     using (var ds = new QuanLyThiTracNghiemDataContext())
     {
         try
         {
             if (offi)
             {
                 var q = ds.KyThis.Where(k => k.MaKyThi == MaKyThi).SingleOrDefault();
                 lblExamName.Text = q.TenKyThi;
                 lblTestId.Text   = string.Format("Mã đề: {0}", MaDeThi);
                 lblDate.Text     = string.Format("Ngày thi: {0}", q.NgayThi.Value.ToShortDateString());
                 lblTime.Text     = string.Format("Thời gian làm bài: {0} phút", q.ThoiGianLamBai);
             }
             else
             {
                 lblExamName.Text = "Luyện tập";
                 lblTestId.Text   = string.Format("Mã đề: {0}", MaDeThi);
                 lblDate.Visible  = false;
                 lblTime.Visible  = false;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Exemplo n.º 6
0
 public static HocSinh TimHocSinh(string MHS)
 {
     using (var ds = new QuanLyThiTracNghiemDataContext())
     {
         HocSinh temp = ds.HocSinhs.Where(sv => sv.MaHocSinh == MHS).SingleOrDefault();
         return(temp);
     }
 }
Exemplo n.º 7
0
 private void LoadCbBoxKT()
 {
     using (var ds = new QuanLyThiTracNghiemDataContext())
     {
         cbExam.DataSource    = ds.KyThis.ToList();
         cbExam.DisplayMember = "TenKyThi";
         cbExam.ValueMember   = "MaKyThi";
     }
 }
Exemplo n.º 8
0
        public static IList <DeThi> DSDeThiLuyenTap(string MMH)
        {
            IList <DeThi> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = ds.DeThis.Where(d => d.MonThi == MMH).ToList();
            }
            return(rt);
        }
Exemplo n.º 9
0
        public static IList <DSDUTHI> DSThi(string mkt)
        {
            IList <DSDUTHI> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = ds.DSDUTHIs.Where(s => s.MaKyThi == mkt).ToList();
            }
            return(rt);
        }
Exemplo n.º 10
0
        public static IList <CauHoi> DSCauHoi()
        {
            IList <CauHoi> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = ds.CauHois.ToList();
            }
            return(rt);
        }
Exemplo n.º 11
0
        public static IList <HocSinh> DSHocSinh()
        {
            IList <HocSinh> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = ds.HocSinhs.ToList();
            }
            return(rt);
        }
Exemplo n.º 12
0
        public static IList <TaiKhoan> DSTaiKhoan()
        {
            IList <TaiKhoan> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = ds.TaiKhoans.ToList();
            }
            return(rt);
        }
Exemplo n.º 13
0
        public static IList <MonHoc> DSMon()
        {
            IList <MonHoc> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = ds.MonHocs.ToList();
            }
            return(rt);
        }
Exemplo n.º 14
0
        public static IList <GiaoVien> DSGiaoVien()
        {
            IList <GiaoVien> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = ds.GiaoViens.ToList();
            }
            return(rt);
        }
Exemplo n.º 15
0
        public static IList <LuuTru> XemLichSuBaiLam(string MSSV, string MaDeThi, string MaKyThi)
        {
            IList <LuuTru> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = ds.LuuTrus.Where(s => s.MaDeThi == MaDeThi && s.MaHocSinh == MSSV &&
                                      s.MaKyThi == MaKyThi).ToList();
            }
            return(rt);
        }
Exemplo n.º 16
0
        public static IList <ChiTietKyThi> LayDeThi(string MKT)
        {
            IList <ChiTietKyThi> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = (from c in ds.ChiTietKyThis
                      where c.MaKyThi == MKT
                      select c).ToList();
            }
            return(rt);
        }
Exemplo n.º 17
0
        public static IList <KyThi> LayLichThi(string id)
        {
            IList <KyThi> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = (from c in ds.KyThis
                      join d in ds.DSDUTHIs
                      on c.MaKyThi equals d.MaKyThi
                      where d.MaHocSinh == id
                      select c).ToList();
            }
            return(rt);
        }
Exemplo n.º 18
0
        public static IList <ChiTietKyThi> DSDeThi(string MHS)
        {
            IList <ChiTietKyThi> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = (from c in ds.ChiTietKyThis
                      join d in ds.DSDUTHIs
                      on c.MaKyThi equals d.MaKyThi
                      where d.MaHocSinh == MHS
                      select c).ToList();
            }
            return(rt);
        }
Exemplo n.º 19
0
        public static IList <DapAn> DSDapAn(string MDT)
        {
            IList <DapAn> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = (from d in ds.DapAns
                      join c in ds.ChiTietDeThis
                      on d.MaCauHoi equals c.MaCauHoi
                      where c.MaDeThi == MDT
                      select d).ToList();
            }
            return(rt);
        }
Exemplo n.º 20
0
        public static bool TiepTucThi(string id, string MKT)
        {
            bool rt = true;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                var q = ds.DSDUTHIs.Where(d => d.MaHocSinh == id && d.MaKyThi == MKT).SingleOrDefault();
                if (q != null)
                {
                    rt = q.ThoiGianBD.HasValue;
                }
            }
            return(rt);
        }
Exemplo n.º 21
0
        public static IList <CauHoi> DSCauHoi(string MDT)
        {
            IList <CauHoi> rt;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                rt = (from c in ds.CauHois
                      join d in ds.ChiTietDeThis
                      on c.MaCauHoi equals d.MaCauHoi
                      where d.MaDeThi == MDT
                      select c).ToList();
            }
            return(rt);
        }
Exemplo n.º 22
0
        // Xóa đề thi
        private void btnXoa1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtMaDeThi1.Text))
            {
                return;
            }
            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                DeThi temp;
                try
                {
                    temp = ds.DeThis.Where(d => d.MaDeThi == txtMaDeThi1.Text).SingleOrDefault();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }


                if (temp != null)
                {
                    var CTDT = ds.ChiTietDeThis.Where(d => d.MaDeThi == temp.MaDeThi);
                    ds.ChiTietDeThis.DeleteAllOnSubmit(CTDT);

                    var CTKT = ds.ChiTietKyThis.Where(k => k.MaDeThi == temp.MaDeThi);
                    ds.ChiTietKyThis.DeleteAllOnSubmit(CTKT);

                    var LT = ds.LuuTrus.Where(l => l.MaDeThi == temp.MaDeThi);
                    ds.LuuTrus.DeleteAllOnSubmit(LT);

                    var DSDT = ds.DSDUTHIs.Where(d => d.MaDeThi == temp.MaDeThi);
                    ds.DSDUTHIs.DeleteAllOnSubmit(DSDT);

                    ds.DeThis.DeleteOnSubmit(temp);

                    try
                    {
                        ds.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                }
            }
            MessageBox.Show("Xóa thành công");
            LoadDeThi();
        }
Exemplo n.º 23
0
 public static bool KiemTraHopLe(TaiKhoan tk)
 {
     using (var ds = new QuanLyThiTracNghiemDataContext())
     {
         TaiKhoan temp = ds.TaiKhoans
                         .Where(t => t.TenDangNhap == tk.TenDangNhap && t.MatKhau == tk.MatKhau)
                         .SingleOrDefault();
         if (temp != null)
         {
             tk.ChuTaiKhoan = temp.ChuTaiKhoan;
             tk.PhanHe      = temp.PhanHe;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 24
0
        public static bool ThemGiaoVien(GiaoVien gv)
        {
            bool flag = true;

            using (var datacontext = new QuanLyThiTracNghiemDataContext())
            {
                datacontext.GiaoViens.InsertOnSubmit(gv);
                try
                {
                    datacontext.SubmitChanges();
                }
                catch (Exception)
                {
                    flag = false;
                }
            }
            return(flag);
        }
Exemplo n.º 25
0
        public static bool ThemHocSinh(HocSinh hs)
        {
            bool flag = true;

            using (var datacontext = new QuanLyThiTracNghiemDataContext())
            {
                datacontext.HocSinhs.InsertOnSubmit(hs);

                try
                {
                    datacontext.SubmitChanges();
                }
                catch (Exception)
                {
                    flag = false;
                }
            }
            return(flag);
        }
Exemplo n.º 26
0
        public static bool ThemChuTaiKhoan(ChuTaiKhoan ctk)
        {
            bool flag = true;

            using (var datacontext = new QuanLyThiTracNghiemDataContext())
            {
                datacontext.ChuTaiKhoans.InsertOnSubmit(ctk);

                try
                {
                    datacontext.SubmitChanges();
                }
                catch (Exception)
                {
                    flag = false;
                }
            }
            return(flag);
        }
Exemplo n.º 27
0
        private void BtnKiemTra_Click(object sender, EventArgs e)
        {
            using (var kt = new QuanLyThiTracNghiemDataContext())
            {
                //var query = kt.ChuTaiKhoans.Where(u => u.ID == txtMaTK.Text).SingleOrDefault();
                var query = kt.TaiKhoans.Where(u => u.ChuTaiKhoan == txtMaTK.Text).SingleOrDefault();

                if (query != null)
                {
                    MessageBox.Show("Người dùng đã có tài khoản");
                }
                else
                {
                    txtTenTK.Enabled   = true;
                    txtMatKhau.Enabled = true;
                    btnXacNhan.Enabled = true;
                }
            }
        }
Exemplo n.º 28
0
        // Xóa kỳ thi.
        private void BtnXoa_Click(object sender, EventArgs e)
        {
            if (dtg1.SelectedRows.Count != 1)
            {
                return;
            }
            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                var temp = ds.KyThis.Where(k => k.MaKyThi == txtMaKyThi.Text).SingleOrDefault();
                if (temp != null)
                {
                    var DSDT = ds.DSDUTHIs.Where(d => d.MaKyThi == temp.MaKyThi);
                    ds.DSDUTHIs.DeleteAllOnSubmit(DSDT);

                    var LT = ds.LuuTrus.Where(d => d.MaKyThi == temp.MaKyThi);
                    ds.LuuTrus.DeleteAllOnSubmit(LT);

                    var CTKT = ds.ChiTietKyThis.Where(d => d.MaKyThi == temp.MaKyThi);
                    ds.ChiTietKyThis.DeleteAllOnSubmit(CTKT);

                    ds.KyThis.DeleteOnSubmit(temp);

                    try
                    {
                        ds.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                }
            }

            MessageBox.Show("Xóa thành công");

            LoadKyThi();
        }
Exemplo n.º 29
0
        public static bool SuaThongTinTaiKhoan(TaiKhoan tk)
        {
            using (var qltk = new QuanLyThiTracNghiemDataContext())
            {
                var tmp = qltk.TaiKhoans.Where(t => t.ChuTaiKhoan == tk.ChuTaiKhoan).SingleOrDefault();

                if (tmp != null)
                {
                    //tmp.TenDangNhap = tk.TenDangNhap;
                    tmp.MatKhau = tk.MatKhau;
                    tmp.PhanHe  = tk.PhanHe;
                    try
                    {
                        qltk.SubmitChanges();
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 30
0
        public static bool BatDauThi(string id, string MKT, string MDT)
        {
            bool rt = true;

            using (var ds = new QuanLyThiTracNghiemDataContext())
            {
                var q = ds.DSDUTHIs.Where(d => d.MaHocSinh == id && d.MaKyThi == MKT).SingleOrDefault();
                if (q != null)
                {
                    q.ThoiGianBD = DateTime.Now.TimeOfDay;
                    q.MaDeThi    = MDT;
                    try
                    {
                        ds.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        rt = false;
                    }
                }
            }
            return(rt);
        }