private void btnXepLop_Click(object sender, EventArgs e) { if (lvDSHSChuaCoLop_XepLop.SelectedItems.Count > 0) { // kiem tra lop chuyen den da dat si so toi da chua ThayDoiQuyDinhBLL quydinhbll = new ThayDoiQuyDinhBLL(); List <ThamSo> DanhSachThamSo = quydinhbll.GetListThamSo(); int siSoToiDa = 100; foreach (ThamSo thamso in DanhSachThamSo) { if (thamso.MaThamSo == "SiSoToiDa") { siSoToiDa = (int)thamso.GiaTri; } } string[] Listtemp = cbLop_XL.Text.Split(' '); Lop lop = lopBLL.GetLop(Listtemp[0]); if (lop.SiSo == siSoToiDa) { MessageBox.Show("Lớp này đã đầy, bạn vui lòng xếp vào lớp khác!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool Error = true; QuaTrinhHocTapBLL qthbll = new QuaTrinhHocTapBLL(); foreach (ListViewItem lvi in lvDSHSChuaCoLop_XepLop.SelectedItems) { string maQTHMax = qthbll.GetMaQTHMax(); string maQTH = "" + (Int32.Parse(maQTHMax) + 1); string maHocSinh = lvi.SubItems[1].Text; string[] listTemp; listTemp = cbLop_XL.Text.Split(' '); string maLop = listTemp[0]; // MessageBox.Show(maQTH + " " + maLop); bool er = qthbll.ThemQuatrinhhoctap(maQTH, maLop, cbHocKy_XL.Text, cbNamHoc_XL.Text, maHocSinh, 0); if (!er) { Error = true; break; } } if (Error) { int soLuongHocSinhVuaXep = lvDSHSChuaCoLop_XepLop.SelectedItems.Count; MessageBox.Show("Bạn vừa xếp thành công " + soLuongHocSinhVuaXep + " học sinh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDanhSachHocSinhChuaXepLop(); LoadDanhSachHocSinhLopDuocXep_MHXL(); } else { MessageBox.Show("Lỗi, vui lòng xem lại chuỗi kết nối CSDL !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Bạn cần chọn ít nhất 1 học sinh để xếp lớp", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnLuu_Click(object sender, EventArgs e) { if (lvDSHS.SelectedItems.Count > 0) { #region KiemTraRangBuocTuNhien if (string.IsNullOrEmpty(tbDiem.Text)) { MessageBox.Show("Bạn phải điền điểm vào ô điểm!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { float diem = float.Parse(tbDiem.Text); ThayDoiQuyDinhBLL quydinhbll = new ThayDoiQuyDinhBLL(); List <ThamSo> dsThamSo = quydinhbll.GetListThamSo(); float diemToiThieu = 0, diemToiDa = 10; foreach (ThamSo ts in dsThamSo) { if (ts.MaThamSo == "DiemToiThieu") { diemToiThieu = ts.GiaTri; } if (ts.MaThamSo == "DiemToiDa") { diemToiDa = ts.GiaTri; } } if (diem < diemToiThieu || diem > diemToiDa) { MessageBox.Show("Điểm phải lớn hơn " + diemToiThieu + " và nhỏ hơn " + diemToiDa, "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch { MessageBox.Show("Điểm phải là dạng số!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endregion QuaTrinhHocTapBLL qthocbll = new QuaTrinhHocTapBLL(); QuaTrinhHocTap qthoctap = qthocbll.GetQuaTrinhHocTapCo(tbMaHS.Text, cbDSHocKy.Text, cbDSNH.Text); BangDiemMonBLL bdbll = new BangDiemMonBLL(); BangDiemMon bdm = bdbll.GetBangDiemMon(qthoctap.MaQTH, cbDanhSachMonHoc.Text); if (bdm == null) { //neu chua ton tai bd thi them bd vao string mabdm = bdbll.GetMaBDMMax(); mabdm = (Int32.Parse(mabdm) + 1).ToString(); // MessageBox.Show(mabdm + ""); bdbll.ThemBDM(mabdm, qthoctap.MaQTH, cbDanhSachMonHoc.Text); bdm = bdbll.GetBangDiemMon(qthoctap.MaQTH, cbDanhSachMonHoc.Text); } //lay ra ma ma bang diem dang can nhap string mabd = bdm.MaBangDiemMon; //lay ra chi tiet bang diem mon, neu chua co thi insert| nhieu khi da them diem truoc do nen da co CTBangDiemMonBLL ctbdbll = new CTBangDiemMonBLL(); ChiTietBangDiemMon ctbdm = ctbdbll.GetCTBangDiemMon(mabd, cbDSHTKT.Text); ErrorType result; if (ctbdm == null) { #region Nếu chưa tồn tại bảng điểm chi tiết tức là đang insert //tao ma chi tiet bang diem mon moi de insert string mactbd = ctbdbll.GetMaCTBDMMax(); mactbd = (Int32.Parse(mactbd) + 1).ToString(); // MessageBox.Show(mactbd); result = ctbdbll.ThemCTBDM(mactbd, mabd, cbDSHTKT.Text, tbDiem.Text); #endregion } else { #region Đã tồn tại tức là mình đang update. result = ctbdbll.SuaCTBDM(ctbdm.MaCTBangDiemMon, mabd, cbDSHTKT.Text, tbDiem.Text); // MessageBox.Show("sua bang diem"); #endregion } if (result == ErrorType.THANH_CONG) { MessageBox.Show("Thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tbDiem.Text = ""; } else { MessageBox.Show("Không thể thêm", "Lỗi kết nối", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Bạn phải chọn 1 học sinh để vào điểm", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }