private void btThem_MonHoc_Click(object sender, EventArgs e) { if (dgSearchResult.Rows.Count == 0) { return; } int count_Check = 0; List <EC_MonHoc> listChecked = new List <EC_MonHoc>(); foreach (DataGridViewRow row in dgSearchResult.Rows) { if (row.Cells[3].Value != null) { if (Convert.ToBoolean(row.Cells[3].Value.ToString()) == true) { count_Check++; EC_MonHoc MonHoc = new BUS_MonHoc().Select_ByPrimaryKey(row.Cells[0].Value.ToString()); listChecked.Add(MonHoc); } } } if (count_Check == 0) { MessageBox.Show("Chọn môn học để thêm!", "Thông báo"); return; } List <EC_PhanCong_Day> listPhanCong_Day = new BUS_PhanCong_Day().SelectByFields("Ma_GiaoVien", Ma_GiaoVien); int count_Success = 0; foreach (EC_MonHoc i in listChecked) { bool check = true; foreach (EC_PhanCong_Day ec in listPhanCong_Day) { if (ec.Ma_MonHoc == i.Ma_MonHoc) { check = false; } } if (check == true) { new BUS_PhanCong_Day().ThemDuLieu(new EC_PhanCong_Day(Ma_GiaoVien, i.Ma_MonHoc)); count_Success++; } } MessageBox.Show("Thêm thành công " + count_Success.ToString() + " môn học", "Thông báo"); dgPhanCong_Day.Rows.Clear(); List <EC_PhanCong_Day> list = new BUS_PhanCong_Day().SelectByFields("Ma_GiaoVien", Ma_GiaoVien); BUS_MonHoc busMonHoc = new BUS_MonHoc(); int index = 1; foreach (EC_PhanCong_Day ec in listPhanCong_Day) { EC_MonHoc MonHoc = busMonHoc.Select_ByPrimaryKey(ec.Ma_MonHoc); dgPhanCong_Day.Rows.Add(index.ToString(), MonHoc.Ma_MonHoc, MonHoc.Ten_MonHoc, MonHoc.Lop.ToString()); index++; } }
private void btXemGiaoVien_Click(object sender, EventArgs e) { if (txbMa_MonHoc.Text == "") { return; } List <EC_PhanCong_Day> listPC_Day = new BUS_PhanCong_Day().SelectByFields("Ma_MonHoc", txbMa_MonHoc.Text); foreach (EC_PhanCong_Day ec in listPC_Day) { EC_GiaoVien GiaoVien = new BUS_GiaoVien().Select_ByPrimaryKey(ec.Ma_GiaoVien); string GioiTinh = GiaoVien.GioiTinh == true ? "Nam" : "Nữ"; dgGiaoVien.Rows.Add(GiaoVien.Ma_GiaoVien, GiaoVien.Ten_GiaoVien, GiaoVien.NgaySinh.ToShortDateString(), GioiTinh, null); } }
void Load() { EC_GiaoVien GiaoVien = new BUS_GiaoVien().Select_ByPrimaryKey(Ma_GiaoVien); if (GiaoVien.Anh != null) { picAvt.Image = HinhAnh.ByteToImage(GiaoVien.Anh); } txbMa_GiaoVien.Text = GiaoVien.Ma_GiaoVien; txbTen_GiaoVien.Text = GiaoVien.Ten_GiaoVien; txbDiaChi.Text = GiaoVien.DiaChi; txbEmail.Text = GiaoVien.Email; txbSDT.Text = GiaoVien.SDT; dtNgaySinh.Value = GiaoVien.NgaySinh; cbGioiTinh.SelectedItem = GiaoVien.GioiTinh == true ? "Nam" : "Nữ"; cbTrinhDo.SelectedItem = GiaoVien.TrinhDo; List <EC_PhanCong_Day> listPhanCong_Day = new BUS_PhanCong_Day().SelectByFields("Ma_GiaoVien", Ma_GiaoVien); BUS_MonHoc busMonHoc = new BUS_MonHoc(); int index = 1; foreach (EC_PhanCong_Day ec in listPhanCong_Day) { EC_MonHoc MonHoc = busMonHoc.Select_ByPrimaryKey(ec.Ma_MonHoc); dgPhanCong_Day.Rows.Add(index.ToString(), MonHoc.Ma_MonHoc, MonHoc.Ten_MonHoc, MonHoc.Lop.ToString()); index++; } index = 1; List <EC_LopHoc> listLopHoc = new BUS_LopHoc().SelectByFields("Ma_GiaoVien", Ma_GiaoVien); foreach (EC_LopHoc ec in listLopHoc) { List <EC_LichHoc> listBuoiHoc = new BUS_LichHoc().SelectByFields("Ma_LopHoc", ec.Ma_LopHoc); if (listBuoiHoc.Count == 0) { continue; } List <EC_BuoiHoc_HocSinh> listBHHS = new BUS_BuoiHoc_HocSinh().SelectByFields("Ma_BuoiHoc", listBuoiHoc[0].Ma_BuoiHoc); EC_MonHoc MonHoc = busMonHoc.Select_ByPrimaryKey(ec.Ma_MonHoc); dgLopDay.Rows.Add(index.ToString(), ec.Ma_LopHoc, MonHoc.Ten_MonHoc, MonHoc.Lop, ec.SoBuoi, listBHHS.Count); index++; } }
private void dgDanhsach_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } txbMa_GiaoVien.Text = txbTen_GiaoVien.Text = txbSDT.Text = txbDiaChi.Text = txbEmail.Text = txbSDT.Text = txbTenDangNhap.Text = txbID.Text = ""; dtNgaySinh.Value = DateTime.Now; cbGioiTinh.Text = cbTrinhDo.Text = ""; DataGridViewRow row = dgDanhsach.Rows[e.RowIndex]; txbMa_GiaoVien.Text = row.Cells["Ma_GiaoVien"].Value.ToString(); txbTen_GiaoVien.Text = row.Cells["Ten_GiaoVien"].Value.ToString(); txbDiaChi.Text = row.Cells["DiaChi"].Value.ToString(); txbEmail.Text = row.Cells["Email"].Value.ToString(); txbSDT.Text = row.Cells["SDT"].Value.ToString(); cbGioiTinh.SelectedIndex = row.Cells["GioiTinh"].Value.ToString() == "Nam" ? 0 : 1; dtNgaySinh.Value = Convert.ToDateTime(row.Cells["NgaySinh"].Value.ToString()); foreach (string i in cbTrinhDo.Items) { if (i == row.Cells["TrinhDo"].Value.ToString()) { cbTrinhDo.SelectedItem = i; } } string Ma_GiaoVien = row.Cells["Ma_GiaoVien"].Value.ToString(); dgDayHoc.Rows.Clear(); List <EC_PhanCong_Day> listPhanCongDay = new BUS_PhanCong_Day().SelectByFields("Ma_GiaoVien", Ma_GiaoVien); int j = 1; foreach (EC_PhanCong_Day i in listPhanCongDay) { EC_MonHoc MonHoc = new BUS_MonHoc().Select_ByPrimaryKey(i.Ma_MonHoc); dgDayHoc.Rows.Add(j.ToString(), MonHoc.Ten_MonHoc, MonHoc.Lop.ToString()); } string ID = new BUS_GiaoVien().Select_ByPrimaryKey(Ma_GiaoVien).ID; if (ID == "") { txbID.Enabled = txbTenDangNhap.Enabled = true; txbMatKhau.Visible = true; } else { EC_TaiKhoan TaiKhoan = new BUS_TaiKhoan().SelectByMa(ID); txbID.Text = ID; if (TaiKhoan == null) { txbID.Enabled = false; txbTenDangNhap.Enabled = true; txbMatKhau.Visible = true; } else { txbID.Enabled = txbTenDangNhap.Enabled = false; txbMatKhau.Visible = false; txbTenDangNhap.Text = TaiKhoan.TenDangNhap; } } }