public List <ChiTietBangDiemMon> GetAllBangDiemMon() { OpenConnection(); List <ChiTietBangDiemMon> listCTBD = new List <ChiTietBangDiemMon>(); SqlCommand com = new SqlCommand(); com.CommandType = CommandType.Text; com.CommandText = "Select * from CT_BangDiemMon"; com.Connection = conn; SqlDataReader reader = com.ExecuteReader(); while (reader.Read()) { string maCTBD = reader.GetInt32(0) + ""; string maBD = reader.GetInt32(1) + ""; string maHTKT = reader.GetString(2); float diemTB = float.Parse(reader.GetDouble(3).ToString()); ChiTietBangDiemMon bd = new ChiTietBangDiemMon(maCTBD, maBD, maHTKT, diemTB); listCTBD.Add(bd); } reader.Close(); CloseConnection(); return(listCTBD); }
public ChiTietBangDiemMon GetCTBangDiemMon(string maBD, string maHTKT) { OpenConnection(); SqlCommand com = new SqlCommand(); com.CommandType = CommandType.Text; com.CommandText = "Select * from CT_BangDiemMon where MaBangDiemMon=@maBD and maHTKT=@maHTKT"; com.Parameters.Add("@maBD", SqlDbType.Int).Value = Int32.Parse(maBD); com.Parameters.Add("@maHTKT", SqlDbType.VarChar).Value = maHTKT; com.Connection = conn; SqlDataReader reader = com.ExecuteReader(); ChiTietBangDiemMon bd = null; while (reader.Read()) { string maCTBD = reader.GetInt32(0) + ""; string maBDM = reader.GetInt32(1) + ""; string mahtkt = reader.GetString(2); float diemTB = float.Parse(reader.GetDouble(3).ToString()); bd = new ChiTietBangDiemMon(maCTBD, maBDM, mahtkt, diemTB); } reader.Close(); CloseConnection(); return(bd); }
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); } }