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 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; } }
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 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 KiemTraDangNhap(string user, string password) { TKBEntities db = new TKBEntities(); var list = db.TaiKhoans .Where(tk => tk.TenTaiKhoan == user) .Where(tk => tk.MatKhau == password) .Count(); if (list == 1) return true; return false; }
public GiaoVien GetGiaoVien(int maGiaoVien) { using (var db = new TKBEntities()) { GiaoVien gv = db.GiaoViens.FirstOrDefault(l => l.MaGiaoVien == maGiaoVien); return gv; } }
public string CheckSaveTKB(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), Thu = thu, TietBatDau = tiet, TietKetThuc = tiet, MonHoc = db.MonHocs.FirstOrDefault(p => p.MaMonHoc == maMH), GiaoVien = db.GiaoViens.FirstOrDefault(p => p.MaGiaoVien == maGV), Phong = db.Phongs.FirstOrDefault(p => p.MaPhong == maPhong) }; if (chiTiet != null) { ThoiKhoaBieu tkb = db.ThoiKhoaBieux.FirstOrDefault(p => p.MaTKB == maTKB); List<ThoiKhoaBieu> lstTKB = GetTKB(tkb.NamHoc); List<ChiTietTKB> lstChiTiet = GetDanhSachChiTietTKB(tkb.MaTKB); List<List<ChiTietTKB>> arrTKB = new List<List<ChiTietTKB>>(); for (int i = 2; i <= 8; i++) // 7days: from Monday to Sunday { List<ChiTietTKB> dsTKB = new List<ChiTietTKB>(); for (int j = 1; j <= Int32.Parse(ConfigurationManager.AppSettings["TongSoTietSang"]) + Int32.Parse(ConfigurationManager.AppSettings["TongSoTietChieu"]); j++) { ChiTietTKB ct = new ChiTietTKB(); dsTKB.Add(ct); } arrTKB.Add(dsTKB); } foreach (ChiTietTKB ct in lstChiTiet) { int maMonHoc = (int)ct.MonHocReference.EntityKey.EntityKeyValues[0].Value; int maGiaoVien = (int)ct.GiaoVienReference.EntityKey.EntityKeyValues[0].Value; arrTKB[(int)ct.Thu - 2][(int)ct.TietBatDau - 1].MonHoc = db.MonHocs.FirstOrDefault(p => p.MaMonHoc == maMonHoc); arrTKB[(int)ct.Thu - 2][(int)ct.TietBatDau - 1].GiaoVien = db.GiaoViens.FirstOrDefault(p => p.MaGiaoVien == maGiaoVien); } MonHoc mh = db.MonHocs.FirstOrDefault(o => o.MaMonHoc == maMH); if (KiemTraMonHoc(arrTKB, mh, (int)chiTiet.Thu, (int)chiTiet.TietBatDau)) { GiaoVien gv = db.GiaoViens.FirstOrDefault(p => p.MaGiaoVien == maGV); if (KiemTraGiaoVien(lstTKB, arrTKB, gv, mh.MaMonHoc, (int)chiTiet.Thu, (int)chiTiet.TietBatDau)) { // Kiểm tra phòng (từ từ làm, đuối òi) return "true"; } else return "Giáo viên này bận rồi."; } else return "Môn học này không xếp vào đây được"; } else return "Có lỗi xảy ra ở hệ thống"; } } catch (Exception ex) { return ex.ToString(); } }
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 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 List<PermissionUser> getListPermissionByRole(int idRole) { try{ TKBEntities db = new TKBEntities(); foreach( var cur in db.LoaiTaiKhoans) { if (cur.MaLoaiTK == idRole) { cur.PermissionUsers.Load(); var result = cur.PermissionUsers; return result.ToList(); } } return null; } catch { return null; } }
public bool TestCreateTKB() { List<List<ChiTietTKB>> arrTKB = new List<List<ChiTietTKB>>(); for (int i = 2; i <= 8; i++) // 7days: from Monday to Sunday { List<ChiTietTKB> dsTKB = new List<ChiTietTKB>(); for (int j = 1; j <= Int32.Parse(ConfigurationManager.AppSettings["TongSoTietSang"]) + Int32.Parse(ConfigurationManager.AppSettings["TongSoTietChieu"]); j++) { ChiTietTKB ct = new ChiTietTKB(); ct.Thu = i; ct.TietBatDau = j; ct.TietKetThuc = j; dsTKB.Add(ct); } arrTKB.Add(dsTKB); } using (var db = new TKBEntities()) { //List<Lop> dsLop = db.Lops.ToList(); List<Lop> dsLop = new List<Lop>(); dsLop.Add(new Lop() { MaLop = 7, SiSo = 20, CaHoc = "Sáng" }); dsLop.Add(new Lop() { MaLop = 8, SiSo = 20, CaHoc = "Sáng" }); List<MonHoc> dsMonHoc = db.MonHocs.ToList(); List<Phong> dsPhong = db.Phongs.ToList(); List<GiaoVien> dsGiaoVien = db.GiaoViens.ToList(); return GenerateTKB("2012", arrTKB, dsMonHoc, dsLop, dsPhong, dsGiaoVien); } }
public MonHoc GetMonHocFromTKB(int maChiTiet) { using (var db = new TKBEntities()) { ChiTietTKB temp = db.ChiTietTKBs.FirstOrDefault(p => p.MaChiTietTKB == maChiTiet); if (temp.MonHocReference.EntityKey != null) { int maMonHoc = (int)temp.MonHocReference.EntityKey.EntityKeyValues[0].Value; MonHoc monHoc = db.MonHocs.FirstOrDefault(p => p.MaMonHoc == maMonHoc); return monHoc; } return new MonHoc(); } }
public Lop GetLopFromTKB(int maTKB) { using (var db = new TKBEntities()) { ThoiKhoaBieu tkb = db.ThoiKhoaBieux.FirstOrDefault(p => p.MaTKB == maTKB); if (tkb.LopReference.EntityKey != null) { int maLop = (int)tkb.LopReference.EntityKey.EntityKeyValues[0].Value; Lop lop = db.Lops.FirstOrDefault(p => p.MaLop == maLop); return lop; } return new Lop(); } }
public Lop getLopByMaChiTietTKB(int maCT) { try { TKBEntities db = new TKBEntities(); var cttkb = db.ChiTietTKBs.Where(ct => ct.MaChiTietTKB == maCT).FirstOrDefault(); cttkb.ThoiKhoaBieuReference.Load(); cttkb.ThoiKhoaBieu.LopReference.Load(); var result = cttkb.ThoiKhoaBieu.Lop; return result; } catch { return null; } }
public Lop GetLop(int maLop) { using (var db = new TKBEntities()) { Lop lop = db.Lops.FirstOrDefault(l => l.MaLop == maLop); return lop; } }
public List<ChiTietTKB> getListTKBByGiaoVien(string tenTaiKhoan) { try { TKBEntities db = new TKBEntities(); foreach (var cur in db.ChiTietTKBs) { cur.GiaoVienReference.Load(); } var result = db.ChiTietTKBs.Where(ct => ct.GiaoVien.TenTK == tenTaiKhoan).ToList(); return result; } catch { return null; } }
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 ThemLop(Lop lop) { try { using (var db = new TKBEntities()) { db.AddToLops(lop); db.SaveChanges(); } return true; } catch { return false; } }
public Phong GetPhong(int maPhong) { using (var db = new TKBEntities()) { Phong gv = db.Phongs.FirstOrDefault(l => l.MaPhong == maPhong); return gv; } }
public GiaoVien GetGiaoVienFromTKB(int maChiTiet) { using (var db = new TKBEntities()) { ChiTietTKB temp = db.ChiTietTKBs.FirstOrDefault(p => p.MaChiTietTKB == maChiTiet); if (temp.GiaoVienReference.EntityKey != null) { int maGV = (int)temp.GiaoVienReference.EntityKey.EntityKeyValues[0].Value; GiaoVien gv = db.GiaoViens.FirstOrDefault(p => p.MaGiaoVien == maGV); return gv; } return new GiaoVien(); } }
public bool ThemGiaoVien(GiaoVien gv) { try { using (var db = new TKBEntities()) { db.AddToGiaoViens(gv); db.SaveChanges(); } return true; } catch { return false; } }
public Phong getPhongByMaChiTietTKB(int maCT) { try { TKBEntities db = new TKBEntities(); var cttkb = db.ChiTietTKBs.Where(ct => ct.MaChiTietTKB == maCT).FirstOrDefault(); cttkb.PhongReference.Load(); return cttkb.Phong; } catch { return null; } }
public bool ThemPhong(Phong gv) { try { using (var db = new TKBEntities()) { db.AddToPhongs(gv); db.SaveChanges(); } return true; } catch { return false; } }
public Phong GetPhongFromTKB(int maChiTiet) { using (var db = new TKBEntities()) { ChiTietTKB temp = db.ChiTietTKBs.FirstOrDefault(p => p.MaChiTietTKB == maChiTiet); if (temp.PhongReference.EntityKey != null) { int maPhong = (int)temp.PhongReference.EntityKey.EntityKeyValues[0].Value; Phong phong = db.Phongs.FirstOrDefault(p => p.MaPhong == maPhong); return phong; } return new Phong(); } }
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 TaiKhoan getTaiKhoanByUserName(String userName) { try { TKBEntities db = new TKBEntities(); var result = db.TaiKhoans.Where(us => us.TenTaiKhoan == userName).FirstOrDefault(); return result; } catch { return null; } }
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 List<ThoiKhoaBieu> GetTKB(string namHoc) { List<ThoiKhoaBieu> temp; using (var db = new TKBEntities()) { temp = db.ThoiKhoaBieux.Where(p => p.NamHoc == namHoc).ToList(); List<ThoiKhoaBieu> listTKB = new List<ThoiKhoaBieu>(); foreach (ThoiKhoaBieu t in temp) { ThoiKhoaBieu tkb = t; Lop lop = GetLop((int)t.LopReference.EntityKey.EntityKeyValues[0].Value); tkb.Lop = new Lop() { MaLop = lop.MaLop }; listTKB.Add(tkb); } listTKB.Sort((x, y) => string.Compare(x.Lop.MaLop.ToString(), y.Lop.MaLop.ToString())); return listTKB; } }
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 ThoiKhoaBieu GetTKBFromLop(int maLop, string namHoc) { using (var db = new TKBEntities()) { ThoiKhoaBieu tkb = db.ThoiKhoaBieux.FirstOrDefault(p => p.Lop.MaLop == maLop && p.NamHoc == namHoc); return tkb; } }