public bool CapNhatPhong(Phong PhongClient) { try { using (var db = new TKBEntities()) { Phong gv = db.Phongs.First(l => l.MaPhong == PhongClient.MaPhong); gv.TenPhong = PhongClient.TenPhong; gv.TinhTrang = PhongClient.TinhTrang; gv.SucChua = PhongClient.SucChua; db.SaveChanges(); return true; } } catch { return false; } }
public bool CapNhatLop(Lop lopClient) { try { using (var db = new TKBEntities()) { Lop lop = db.Lops.First(l => l.MaLop == lopClient.MaLop); lop.TenLop = lopClient.TenLop; lop.KhoiLop = lopClient.KhoiLop; lop.CaHoc = lopClient.CaHoc; lop.SiSo = lopClient.SiSo; lop.GhiChu = lopClient.GhiChu; db.SaveChanges(); return true; } } catch { return false; } }
public bool CapNhatGiaoVien(GiaoVien GiaoVienClient) { try { using (var db = new TKBEntities()) { GiaoVien gv = db.GiaoViens.First(l => l.MaGiaoVien == GiaoVienClient.MaGiaoVien); gv.TenGiaoVien = GiaoVienClient.TenGiaoVien; gv.GioiTinh = GiaoVienClient.GioiTinh; gv.DiaChi = GiaoVienClient.DiaChi; gv.DienThoai = GiaoVienClient.DienThoai; gv.Email = GiaoVienClient.Email; db.SaveChanges(); return true; } } catch { return false; } }
private void DeleteTKB(int maLop, string namHoc) { using (var db = new TKBEntities()) { ThoiKhoaBieu tkb = db.ThoiKhoaBieux.FirstOrDefault(p => p.Lop.MaLop == maLop && (p.NamHoc == namHoc || (namHoc == null && p.NamHoc.Equals(null)))); if (tkb != null) { List<ChiTietTKB> chiTiets = db.ChiTietTKBs.Where(p => p.ThoiKhoaBieu.MaTKB == tkb.MaTKB).ToList(); if (chiTiets != null) { foreach (var ct in chiTiets) { db.DeleteObject(ct); } db.SaveChanges(); } db.DeleteObject(tkb); db.SaveChanges(); } } }
public bool XoaPhong(int maPhong) { try { using (var db = new TKBEntities()) { Phong gv = db.Phongs.First(l => l.MaPhong == maPhong); db.DeleteObject(gv); db.SaveChanges(); return true; } } catch { return false; } }
public bool XoaLop(int maLop) { try { using (var db = new TKBEntities()) { Lop lop = db.Lops.First(l => l.MaLop == maLop); db.DeleteObject(lop); db.SaveChanges(); return true; } } catch { return false; } }
public bool XoaGiaoVien(int maGiaoVien) { try { using (var db = new TKBEntities()) { GiaoVien gv = db.GiaoViens.First(l => l.MaGiaoVien == maGiaoVien); db.DeleteObject(gv); db.SaveChanges(); return true; } } catch { return false; } }
public bool UpdateTKB(int maChiTiet, int maMH, int maGV, int maPhong) { try { using (var db = new TKBEntities()) { ChiTietTKB chiTiet = db.ChiTietTKBs.FirstOrDefault(p => p.MaChiTietTKB == maChiTiet); if (chiTiet != null) { chiTiet.MonHoc = db.MonHocs.FirstOrDefault(o => o.MaMonHoc == maMH); chiTiet.GiaoVien = db.GiaoViens.FirstOrDefault(o => o.MaGiaoVien == maGV); chiTiet.Phong = db.Phongs.FirstOrDefault(o => o.MaPhong == maPhong); } db.SaveChanges(); } return true; } catch (Exception ex) { return false; } }
public bool ThemPhong(Phong gv) { try { using (var db = new TKBEntities()) { db.AddToPhongs(gv); db.SaveChanges(); } return true; } catch { return false; } }
public bool ThemLop(Lop lop) { try { using (var db = new TKBEntities()) { db.AddToLops(lop); db.SaveChanges(); } return true; } catch { return false; } }
public bool ThemGiaoVien(GiaoVien gv) { try { using (var db = new TKBEntities()) { db.AddToGiaoViens(gv); db.SaveChanges(); } return true; } catch { return false; } }
public bool SaveChiTietTKB(int maTKB, int thu, int tiet, int maMH, int maGV, int maPhong) { try { using (var db = new TKBEntities()) { ChiTietTKB chiTiet = new ChiTietTKB() { ThoiKhoaBieu = db.ThoiKhoaBieux.FirstOrDefault(p => p.MaTKB == maTKB), MonHoc = db.MonHocs.FirstOrDefault(p => p.MaMonHoc == maMH), GiaoVien = db.GiaoViens.FirstOrDefault(p => p.MaGiaoVien == maGV), Phong = db.Phongs.FirstOrDefault(p => p.MaPhong == maPhong), TietBatDau = tiet, TietKetThuc = tiet, Thu = thu }; db.AddToChiTietTKBs(chiTiet); db.SaveChanges(); } return true; } catch (Exception ex) { return false; } }
public bool NewTKB(int lop, string namHoc) { try { if (namHoc.Length > 0) { DeleteTKB(lop, namHoc); using (var db = new TKBEntities()) { ThoiKhoaBieu tkb = new ThoiKhoaBieu() { Lop = db.Lops.FirstOrDefault(p => p.MaLop == lop), NamHoc = namHoc }; db.AddToThoiKhoaBieux(tkb); db.SaveChanges(); return true; } } return false; } catch (Exception ex) { return false; } }
public bool DeleteChiTietTKB(int maChiTiet) { try { using (var db = new TKBEntities()) { ChiTietTKB chiTiet = db.ChiTietTKBs.FirstOrDefault(p => p.MaChiTietTKB == maChiTiet); if (chiTiet != null) { db.DeleteObject(chiTiet); db.SaveChanges(); } return true; } } catch (Exception ex) { return false; } }
private void SaveTKB(List<ThoiKhoaBieu> lstTKB, List<Lop> dsLop) { using (var db = new TKBEntities()) { foreach (ThoiKhoaBieu oTKB in lstTKB) { if (oTKB.MaTKB == 0) { ThoiKhoaBieu tkb = new ThoiKhoaBieu() { Lop = db.Lops.FirstOrDefault(p => p.MaLop == oTKB.Lop.MaLop), NamHoc = oTKB.NamHoc }; db.AddToThoiKhoaBieux(tkb); db.SaveChanges(); foreach (ChiTietTKB ct in oTKB.ChiTietTKBs.ToList()) { ChiTietTKB chiTiet = new ChiTietTKB() { ThoiKhoaBieu = tkb, MonHoc = db.MonHocs.FirstOrDefault(p => p.MaMonHoc == ct.MonHoc.MaMonHoc), GiaoVien = db.GiaoViens.FirstOrDefault(p => p.MaGiaoVien == ct.GiaoVien.MaGiaoVien), Phong = db.Phongs.FirstOrDefault(p => p.MaPhong == ct.Phong.MaPhong), TietBatDau = ct.TietBatDau + 1, TietKetThuc = ct.TietKetThuc + 1, Thu = ct.Thu + 2 }; db.AddToChiTietTKBs(chiTiet); db.SaveChanges(); } } } } }