private void cbMonHoc_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (cbMonHoc.SelectedValue != null) { db = new MyDbContext(); listSV = new List <SinhVienVMM>(); MonHoc monhoc = db.MonHoc.Find(cbMonHoc.SelectedValue); List <Lop> lops = db.Lop.Where(x => x.MaMonHoc == monhoc.MaMonHoc).ToList(); if (lops.Count != 0) { foreach (Lop lop in lops) { List <ThamGia> thamGias = db.ThamGia.Where(x => x.MaLop == lop.MaLop).ToList(); foreach (ThamGia thamGia in thamGias) { SinhVien sv = db.SinhVien.Find(thamGia.MaSinhVien); SinhVienVMM svvmm = new SinhVienVMM(sv, monhoc.TenMon, lop.TenLop, thamGia.Diem); listSV.Add(svvmm); } } dataGridDanhSachSV.ItemsSource = listSV; } else { dataGridDanhSachSV.ItemsSource = null; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void cbLop_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { List <ThamGia> thamGias = db.ThamGia.Where(x => x.MaLop == cbLop.SelectedValue.ToString()).ToList(); if (thamGias.Count != 0) { listSV = new List <SinhVienVMM>(); db = new MyDbContext(); foreach (ThamGia thamgia in thamGias) { string tenMon = db.MonHoc.Find(cbMon.SelectedValue).TenMon; string tenLop = db.Lop.Find(cbLop.SelectedValue).TenLop; SinhVien sv = db.SinhVien.Find(thamgia.MaSinhVien); SinhVienVMM svvmm = new SinhVienVMM(sv, tenMon, tenLop, thamgia.Diem); listSV.Add(svvmm); } dataGridDanhSachSV.ItemsSource = listSV; } }catch (Exception ex) {} }
void Load() { cbLuaChon.SelectedIndex = 0; if (listSV == null) { listSV = new List <SinhVienVMM>(); db = new MyDbContext(); List <SinhVien> tmpSV = db.SinhVien.OrderBy(x => x.TenSinhVien).ToList(); foreach (SinhVien sinhVien in tmpSV) { List <ThamGia> thamGias = db.ThamGia.Where(x => x.MaSinhVien == sinhVien.MaSinhVien).ToList(); if (thamGias.Count != 0) { foreach (ThamGia thamGia in thamGias) { Lop lop = db.Lop.FirstOrDefault(x => x.MaLop == thamGia.MaLop); MonHoc monHoc = db.MonHoc.FirstOrDefault(x => x.MaMonHoc == lop.MaMonHoc); SinhVienVMM sinhVienVMM = new SinhVienVMM(sinhVien, monHoc.TenMon, lop.TenLop, thamGia.Diem); listSV.Add(sinhVienVMM); } } else { SinhVienVMM sinhVienVMM = new SinhVienVMM(sinhVien); listSV.Add(sinhVienVMM); } } dataGridKetQua.ItemsSource = null; dataGridKetQua.ItemsSource = listSV.OrderBy(x => x.TenLop); dataGridKetQua.Items.Refresh(); } else { dataGridKetQua.ItemsSource = listSV; } }
private void btnTimKiem_Click(object sender, RoutedEventArgs e) { try { if (cbLuaChon.SelectedItem != null) { //Ten Sv if (cbLuaChon.SelectedIndex == 0) { db = new MyDbContext(); List <SinhVienVMM> tmp = new List <SinhVienVMM>(); if (!String.IsNullOrEmpty(txtTenSV.Text)) { List <SinhVien> tmpSV = db.SinhVien.Where(x => x.TenSinhVien.ToLower().Contains(txtTenSV.Text.ToLower())).OrderByDescending(x => x.TenSinhVien).ToList(); foreach (SinhVien sinhVien in tmpSV) { List <ThamGia> thamGias = db.ThamGia.Where(x => x.MaSinhVien == sinhVien.MaSinhVien).ToList(); if (thamGias.Count != 0) { foreach (ThamGia thamGia in thamGias) { Lop lop = db.Lop.FirstOrDefault(x => x.MaLop == thamGia.MaLop); MonHoc monHoc = db.MonHoc.FirstOrDefault(x => x.MaMonHoc == lop.MaMonHoc); SinhVienVMM sinhVienVMM = new SinhVienVMM(sinhVien, monHoc.TenMon, lop.TenLop, thamGia.Diem); tmp.Add(sinhVienVMM); } } else { SinhVienVMM sinhVienVMM = new SinhVienVMM(sinhVien); tmp.Add(sinhVienVMM); } } dataGridKetQua.ItemsSource = null; dataGridKetQua.ItemsSource = tmp.OrderBy(x => x.TenLop); dataGridKetQua.Items.Refresh(); } else { List <SinhVien> tmpSV = db.SinhVien.OrderBy(x => x.TenSinhVien).ToList(); foreach (SinhVien sinhVien in tmpSV) { List <ThamGia> thamGias = db.ThamGia.Where(x => x.MaSinhVien == sinhVien.MaSinhVien).ToList(); if (thamGias.Count != 0) { foreach (ThamGia thamGia in thamGias) { Lop lop = db.Lop.FirstOrDefault(x => x.MaLop == thamGia.MaLop); MonHoc monHoc = db.MonHoc.FirstOrDefault(x => x.MaMonHoc == lop.MaMonHoc); SinhVienVMM sinhVienVMM = new SinhVienVMM(sinhVien, monHoc.TenMon, lop.TenLop, thamGia.Diem); tmp.Add(sinhVienVMM); } } else { SinhVienVMM sinhVienVMM = new SinhVienVMM(sinhVien); tmp.Add(sinhVienVMM); } } dataGridKetQua.ItemsSource = null; dataGridKetQua.ItemsSource = tmp.OrderBy(x => x.TenLop); dataGridKetQua.Items.Refresh(); } } //Diem else if (cbLuaChon.SelectedIndex == 1) { if (!String.IsNullOrEmpty(txtTenSV.Text)) { List <SinhVienVMM> tmp = listSV.Where(x => x.TenSinhVien.ToLower().Contains(txtTenSV.Text.ToLower())).ToList(); if (!String.IsNullOrEmpty(txtNoiDungTimKiem.Text)) { double diem; if (Double.TryParse(txtNoiDungTimKiem.Text, out diem)) { tmp = tmp.Where(x => x.Diem == diem - 1 || x.Diem == diem || x.Diem == diem + 1).ToList(); dataGridKetQua.ItemsSource = null; dataGridKetQua.ItemsSource = tmp.OrderBy(x => x.Diem); dataGridKetQua.Items.Refresh(); } else { MessageBox.Show("Vui lòng xem lại điểm đã nhập"); } } else { //dataGridKetQua.ItemsSource = null; //dataGridKetQua.ItemsSource = listSV.OrderBy(x => x.TenLop); //dataGridKetQua.Items.Refresh(); MessageBox.Show("Vui lòng nhập điểm hợp lệ"); } } else { if (!String.IsNullOrEmpty(txtNoiDungTimKiem.Text)) { double diem; if (Double.TryParse(txtNoiDungTimKiem.Text, out diem)) { List <SinhVienVMM> tmp = listSV.Where(x => x.Diem == diem - 1 || x.Diem == diem || x.Diem == diem + 1).ToList(); dataGridKetQua.ItemsSource = null; dataGridKetQua.ItemsSource = tmp.OrderBy(x => x.Diem); dataGridKetQua.Items.Refresh(); } else { MessageBox.Show("Vui lòng xem lại điểm đã nhập"); } } } } //Môn học else if (cbLuaChon.SelectedIndex == 2) { List <SinhVienVMM> tmp = listSV; if (!String.IsNullOrEmpty(txtTenSV.Text)) { tmp = tmp.Where(x => x.TenSinhVien.ToLower().Contains(txtTenSV.Text.ToLower())).OrderByDescending(x => x.TenSinhVien).ToList(); if (!String.IsNullOrEmpty(txtNoiDungTimKiem.Text)) { tmp = tmp.Where(x => x.TenMonHoc.ToLower().Contains(txtNoiDungTimKiem.Text.ToLower())).OrderBy(x => x.TenMonHoc).ToList(); dataGridKetQua.ItemsSource = null; dataGridKetQua.ItemsSource = tmp; dataGridKetQua.Items.Refresh(); } else { dataGridKetQua.ItemsSource = null; dataGridKetQua.ItemsSource = tmp; dataGridKetQua.Items.Refresh(); } } else { tmp = tmp.Where(x => x.TenMonHoc.ToLower().Contains(txtNoiDungTimKiem.Text.ToLower())).OrderBy(x => x.TenMonHoc).ToList(); dataGridKetQua.ItemsSource = null; dataGridKetQua.ItemsSource = tmp; dataGridKetQua.Items.Refresh(); } } } else { MessageBox.Show("Vui lòng chọn mục tìm kiếm"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }