Ejemplo n.º 1
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);
 }
Ejemplo 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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        //private void dtg2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        //{
        //    try
        //    {
        //        DataGridViewRow row = new DataGridViewRow();
        //        row = dtg2.Rows[e.RowIndex];
        //        txtMaDeThi1.Text = row.Cells[0].Value.ToString();

        //        txtMaMon1.Text=row.Cells[1].Value.ToString();
        //        txtKhoi1.Text = row.Cells[2].Value.ToString();


        //    }
        //    catch (Exception)
        //    {


        //    }
        //}

        private void btnSua_Click(object sender, EventArgs e)
        {
            WindowsFormsApp2.KyThi kt = dt.KyThis.Where(k => k.MaKyThi == txtMaKyThi.Text).SingleOrDefault();

            if (kt != null)
            {
                kt.NgayThi  = dateTimePicker1.Value;
                kt.Khoi     = int.Parse(cbKhoi.SelectedItem.ToString());
                kt.TenKyThi = txtTenKyThi.Text;

                try
                {
                    dt.SubmitChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        public static bool SuaThongTinHocSinh(HocSinh sv)
        {
            using (var qlsv = new QuanLyThiTracNghiemDataContext())
            {
                var svO = qlsv.HocSinhs.Where(s => s.MaHocSinh == sv.MaHocSinh).SingleOrDefault();

                if (svO != null)
                {
                    svO.TenHocSinh = sv.TenHocSinh;
                    svO.NgaySinh   = sv.NgaySinh;
                    svO.GioiTinh   = sv.GioiTinh;
                    svO.QueQuan    = sv.QueQuan;
                    try
                    {
                        qlsv.SubmitChanges();
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 14
0
        private void BtnXacNhan_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtMaTK.Text) && string.IsNullOrEmpty(txtTenTK.Text) && string.IsNullOrEmpty(txtMatKhau.Text))
            {
                MessageBox.Show("Xin nhập đầy đủ thông tin");
                return;
            }
            else
            {
                int flag = 1;
                using (var tk = new QuanLyThiTracNghiemDataContext())
                {
                    var isHocSinh = tk.HocSinhs.Where(u => u.MaHocSinh == txtMaTK.Text).SingleOrDefault();

                    if (isHocSinh != null)
                    {
                        // tạo đối tượng tài khoản
                        TaiKhoan t = new TaiKhoan()
                        {
                            ChuTaiKhoan = txtMaTK.Text,
                            TenDangNhap = txtTenTK.Text,
                            MatKhau     = txtMatKhau.Text,
                            PhanHe      = 1
                        };

                        //ChuTaiKhoan ctk = new ChuTaiKhoan()
                        //{
                        //    ID = txtMaTK.Text
                        //};

                        tk.TaiKhoans.InsertOnSubmit(t);
                        //tk.ChuTaiKhoans.InsertOnSubmit(ctk);
                        try
                        {
                            tk.SubmitChanges();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            return;
                        }
                    }
                    else
                    {
                        var isGiaoVien = tk.GiaoViens.Where(u => u.MaGiaoVien == txtMaTK.Text).SingleOrDefault();

                        if (isGiaoVien != null)
                        {
                            TaiKhoan t = new TaiKhoan()
                            {
                                ChuTaiKhoan = txtMaTK.Text,
                                TenDangNhap = txtTenTK.Text,
                                MatKhau     = txtMatKhau.Text,
                                PhanHe      = 2
                            };

                            //ChuTaiKhoan ctk = new ChuTaiKhoan()
                            //{
                            //    ID = txtMaTK.Text
                            //};

                            tk.TaiKhoans.InsertOnSubmit(t);
                            //tk.ChuTaiKhoans.InsertOnSubmit(ctk);
                            try
                            {
                                tk.SubmitChanges();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                return;
                            }
                        }
                        else
                        {
                            flag = 0;
                        }
                    }
                }

                if (flag == 1)
                {
                    MessageBox.Show("Đăng ký thành công");
                    return;
                }
                else
                {
                    MessageBox.Show("Mã tài khoản không tồn tại");
                }
            }
        }