private void BtnLuu_Click(object sender, RoutedEventArgs e) { if (svListCur.Count != 0) { if (txtTenLop.Text != "Nhập tên lớp" && String.IsNullOrEmpty(txtTenLop.Text) == false) { db = new MyDbContext(); ThamSo ts = db.ThamSo.Find(4); //Tạo lớp Lop lop = new Lop(); lop.MaLop = monHoc.MaMonHoc + "_L" + ts.GiaTri; lop.TenLop = txtTenLop.Text; lop.MaGiangVien = txtMaGiangVien.SelectedValue.ToString(); lop.MaMonHoc = monHoc.MaMonHoc; db.Lop.Add(lop); //Cập nhật giá trị tham sô ts.GiaTri = (int.Parse(ts.GiaTri) + 1).ToString(); for (int i = 0; i < svListCur.Count; i++) { ThamGia tg = new ThamGia(); tg.MaLop = lop.MaLop; tg.MaSinhVien = svListCur[i].MaSinhVien; db.ThamGia.Add(tg); } db.SaveChanges(); this.Close(); } } }
private void btnLuu_Click(object sender, RoutedEventArgs e) { try { List <SinhVienVMM> sinhViens = dataGridDanhSachSV.ItemsSource as List <SinhVienVMM>; if (sinhViens.Count != 0) { db = new MyDbContext(); List <ThamGia> listThamGia = db.ThamGia.Where(x => x.MaLop == cbLop.SelectedValue.ToString()).ToList(); if (listThamGia.Count != 0) { foreach (ThamGia thamGia in listThamGia) { ThamGia tg = db.ThamGia.Find(thamGia.MaLop, thamGia.MaSinhVien); if (tg != null) { tg.Diem = (float)Math.Round(sinhViens.FirstOrDefault(x => x.MaSinhVien == thamGia.MaSinhVien).Diem, 2); db.SaveChanges(); dataGridDanhSachSV.Items.Refresh(); } } } dataGridDanhSachSV.Items.Refresh(); MessageBox.Show("Đã lưu"); } }catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void bntHuyLop_Click(object sender, RoutedEventArgs e) { try { db = new MyDbContext(); var obj = dataGridDanhSachLop.SelectedItems; if (obj != null) { foreach (var lop in obj) { Lop mlop = db.Lop.Find((lop as Lop).MaLop); List <ThamGia> listThamGia = db.ThamGia.Where(x => x.MaLop == mlop.MaLop).ToList(); foreach (var tg in listThamGia) { ThamGia mtg = tg as ThamGia; if (String.IsNullOrEmpty(mtg.MaLop) == false) { db.ThamGia.Remove(db.ThamGia.Find(mtg.MaLop, mtg.MaSinhVien)); db.SaveChanges(); } } db.Lop.Remove(mlop); db.SaveChanges(); } MessageBox.Show("Đã xóa"); Reload(); } }catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void UpdateThamGia(this ThamGia thamGia, ThamGiaViewModel thamGiaVM) { thamGia.IdHangMuc = thamGiaVM.IdHangMuc; thamGia.IdNhanVien = thamGiaVM.IdNhanVien; thamGia.LoaiHangMuc = thamGiaVM.LoaiHangMuc; thamGia.HeSoThamGia = thamGiaVM.HeSoThamGia; }
public int insertThamGia(int bookID, int authorID) { ThamGia thamgia = new ThamGia() { MaSach = bookID, MaTG = authorID }; db.ThamGias.Add(thamgia); db.SaveChanges(); return(thamgia.MaTG); }
private void btnLuu_Click(object sender, RoutedEventArgs e) { if (svListCur.Count != 0) { if (!String.IsNullOrEmpty(txtTenLop.Text)) { db = new MyDbContext(); ThamSo ts = db.ThamSo.Find(4); //Cập nhật lớp Lop newLop = db.Lop.Find(lop.MaLop); newLop.TenLop = txtTenLop.Text; newLop.MaGiangVien = txtMaGiangVien.SelectedValue.ToString(); newLop.MaMonHoc = monHoc.MaMonHoc; LopDAO dao = new LopDAO(); dao.Update(newLop); //Cập nhật giá trị tham sô ts.GiaTri = (int.Parse(ts.GiaTri) + 1).ToString(); List <ThamGia> thamgias = db.ThamGia.Where(x => x.MaLop == lop.MaLop).ToList(); foreach (ThamGia item in thamgias) { db.ThamGia.Remove(item); } db.SaveChanges(); for (int i = 0; i < svListCur.Count; i++) { ThamGia tg = new ThamGia(); tg.MaLop = lop.MaLop; tg.MaSinhVien = svListCur[i].MaSinhVien; db.ThamGia.Add(tg); } db.SaveChanges(); Reload(); this.Close(); } else { MessageBox.Show("Tên lớp không được để trống"); } } else { MessageBox.Show("Vui lòng chọn sinh viên"); } }
private void btnLuu_Click(object sender, RoutedEventArgs e) { if (svListCur.Count != 0 && String.IsNullOrEmpty(txtTenLop.Text) == false) { db = new MyDbContext(); ThamSo ts = db.ThamSo.Find(4); //Cập nhật lớp lop.TenLop = txtTenLop.Text; lop.MaGiangVien = txtMaGiangVien.SelectedValue.ToString(); lop.MaMonHoc = monHoc.MaMonHoc; Lop newLop = db.Lop.Find(lop.MaLop); newLop.MaGiangVien = lop.MaGiangVien; newLop.TenLop = lop.TenLop; db.SaveChanges(); //Cập nhật giá trị tham sô ts.GiaTri = (int.Parse(ts.GiaTri) + 1).ToString(); List <ThamGia> thamgias = db.ThamGia.Where(x => x.MaLop == lop.MaLop).ToList(); foreach (ThamGia item in thamgias) { db.ThamGia.Remove(item); } db.SaveChanges(); for (int i = 0; i < svListCur.Count; i++) { ThamGia tg = new ThamGia(); tg.MaLop = lop.MaLop; tg.MaSinhVien = svListCur[i].MaSinhVien; db.ThamGia.Add(tg); } db.SaveChanges(); this.Close(); } }
private void btnLuuThamGia_Click(object sender, EventArgs e) { try { if (txtVaiTro.Text.Equals("")) { MessageBox.Show("Bạn cần điền vai trò của tác giả!", "Cảnh báo", MessageBoxButtons.OK); } else { ThamGia entity = new ThamGia(); entity.MaSach = int.Parse(cbSach.SelectedValue.ToString()); entity.MaTacGia = int.Parse(cbTacGia.SelectedValue.ToString()); entity.VaiTro = txtVaiTro.Text; client.createAttend(entity); MessageBox.Show("Thêm mới thành công!", "Chúc mừng", MessageBoxButtons.OK); resetform(); } } catch (Exception) { MessageBox.Show("Thêm mới thất bại", "Lỗi", MessageBoxButtons.OK); } }