Exemplo n.º 1
0
 private QLTTNDataContext.MyDeThi getDeThiDuocChon()
 {
     QLTTNDataContext.MyDeThi dt = null;
     foreach (DataGridViewRow row in dgvDT.Rows)
     {
         var cell = row.Cells["Chon"] as DataGridViewCheckBoxCell;
         if (cell.Value == cell.TrueValue)
         {
             dt = new QLTTNDataContext.MyDeThi
             {
                 maDT           = int.Parse(row.Cells["maDT"].Value.ToString()),
                 TenDT          = row.Cells["TenDT"].Value.ToString(),
                 maGV           = row.Cells["maGV"].Value.ToString(),
                 maKhoi         = row.Cells["maKhoi"].Value.ToString(),
                 maMH           = row.Cells["maMH"].Value.ToString(),
                 ThoiGianLamBai = TimeSpan.Parse(row.Cells["ThoiGianLamBai"].Value.ToString())
             };
             break;
         }
     }
     return(dt);
 }
Exemplo n.º 2
0
        public frmSuaKT(frmGiaoVien frmgv, GiaoVien GV, int makt, string maKhoi, BindingSource bsKyThi)
        {
            frmgv.Enabled = false;
            this.GV       = GV;
            this.maKhoi   = maKhoi;
            this.makt     = makt;

            KTCCN = QLTTN.KyThis.Where(kt => kt.maKT == makt).FirstOrDefault();
            BT    = QLTTN.BuoiThis.Where(BT => BT.maKT == makt && BT.DeThi.maMH == GV.maMH).FirstOrDefault();
            if (BT != null)
            {
                DSHS = QLTTN.BaiLams.Where(bl => bl.maKT == BT.maKT && bl.maDT == BT.maDT).
                       Select(hs => new QLTTNDataContext.MyHocSinh
                {
                    maHS     = hs.maHS,
                    HoTen    = hs.HocSinh.HoTen,
                    maKhoi   = hs.HocSinh.maKhoi,
                    maLop    = hs.HocSinh.maLop,
                    NgaySinh = (DateTime)hs.HocSinh.NgaySinh
                }).
                       ToList();
                DT = QLTTN.KyThis.Where(kt => kt.maKT == this.makt).FirstOrDefault()
                     .BuoiThis.Where(BT => BT.DeThi.maMH == GV.maMH)
                     .Select(BT => new QLTTNDataContext.MyDeThi
                {
                    maDT           = BT.maDT,
                    maGV           = BT.DeThi.maGV,
                    maKhoi         = BT.DeThi.maKhoi,
                    maMH           = BT.DeThi.maMH,
                    TenDT          = BT.DeThi.TenDT,
                    ThoiGianLamBai = (TimeSpan)BT.DeThi.ThoiGianLamBai
                }).FirstOrDefault();
            }


            InitializeComponent();

            Load += (s, e) =>
            {
                SetQLKT();
                LoadQLKTDgvDeThi();
                LoadQLKTDgvHocSinh();
                txtTenKT.DataBindings.Add("Text", bsKyThi, "TenKT", true, DataSourceUpdateMode.Never);
                lblLoaiKT.DataBindings.Add("Text", bsKyThi, "LoaiKT", true, DataSourceUpdateMode.Never);
                lblMaKhoi.Text = maKhoi;
            };

            this.FormClosing += (s, e) =>
            {
                frmgv.Enabled = true;
            };
            btnSuaKT.Click += (s, e) =>
            {
                if (string.IsNullOrWhiteSpace(txtTenKT.Text))
                {
                    MessageBox.Show("Không được để trống tên kỳ thi", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (dtpNgayThi.Value < DateTime.Now)
                {
                    MessageBox.Show("Ngày giờ thi phải lớn hơn ngày giờ hiện tại", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                foreach (DataGridViewRow row in dgvHS.Rows)
                {
                    var cell = row.Cells["Chon"] as DataGridViewCheckBoxCell;
                    if (cell.Value == cell.TrueValue)
                    {
                        DSMaHSDuocChon.Add(row.Cells["maHS"].Value.ToString());
                    }
                }
                if (DSMaHSDuocChon.Count == 0)
                {
                    MessageBox.Show($"Mời bạn chọn các thí sinh (lưu ý chọn các thí sinh không bận thi vào thời gian {dtpNgayThi.Value}", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                List <int> dsMaDT = new List <int>();
                foreach (DataGridViewRow row in dgvDT.Rows)
                {
                    var cell = row.Cells["Chon"] as DataGridViewCheckBoxCell;
                    if (cell.Value == cell.TrueValue && row.Cells["maMH"].Value.ToString() == GV.maMH)
                    {
                        dsMaDT.Add(int.Parse(row.Cells["maDT"].Value.ToString()));
                    }
                }
                if (dsMaDT.Count == 0)
                {
                    MessageBox.Show("Hãy chọn một đề thi của bộ môn mà bạn đang phụ trách cho kỳ thi", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                try
                {
                    var KTCCN = QLTTN.KyThis.Where(kythi => kythi.maKT == makt).FirstOrDefault();
                    KTCCN.TenKT = txtTenKT.Text;

                    if (KTCCN.LoaiKT == "ThiThiet")
                    {
                        if (BT != null)
                        {
                            QLTTN.BaiLams.DeleteAllOnSubmit(BT.BaiLams);
                            QLTTN.BuoiThis.DeleteOnSubmit(BT);
                            QLTTN.SubmitChanges();
                        }
                        BT = new BuoiThi
                        {
                            maKT       = KTCCN.maKT,
                            maDT       = dsMaDT[0],
                            NgayGioThi = dtpNgayThi.Value
                        };

                        if (dsMaDT.Count > 0)
                        {
                            // tạo buổi thi mới
                            QLTTN.BuoiThis.InsertOnSubmit(BT);

                            // thêm các thí sinh vào buổi thi mới này
                            foreach (var mahs in DSMaHSDuocChon)
                            {
                                QLTTN.BaiLams.InsertOnSubmit(new BaiLam
                                {
                                    maKT   = KTCCN.maKT,
                                    maDT   = dsMaDT[0],
                                    maHS   = mahs,
                                    DiemSo = -1
                                });
                            }
                        }
                    }
                    else if (KTCCN.LoaiKT == "ThiThu")
                    {
                        foreach (var BT in KTCCN.BuoiThis)
                        {
                            QLTTN.BaiLams.DeleteAllOnSubmit(BT.BaiLams);
                            QLTTN.BuoiThis.DeleteOnSubmit(BT);
                            QLTTN.SubmitChanges();
                        }

                        foreach (var madt in dsMaDT)
                        {
                            BuoiThi BT = new BuoiThi()
                            {
                                maKT       = KTCCN.maKT,
                                maDT       = madt,
                                NgayGioThi = dtpNgayThi.Value
                            };
                            QLTTN.BuoiThis.InsertOnSubmit(BT);
                            QLTTN.SubmitChanges();

                            foreach (var hs in DSHS)
                            {
                                QLTTN.BaiLams.InsertOnSubmit(new BaiLam
                                {
                                    maHS   = hs.maHS,
                                    maDT   = BT.maDT,
                                    maKT   = KTCCN.maKT,
                                    DiemSo = -1
                                });
                            }
                        }
                    }

                    QLTTN.SubmitChanges();
                    frmgv.LoadQLKTOTDgvKyThi();
                    MessageBox.Show("Cập nhật thành công", "Thông báo");
                    this.Close();
                }
                catch (Exception exc)
                {
                    MessageBox.Show($"KHÔNG THỂ CẬP NHẬT KỲ THI ĐÃ DIỄN RA {Environment.NewLine}{exc.Message}", "Thông báo từ btnCapNhatKT", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            };
        }