예제 #1
0
 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;
     }
 }
예제 #2
0
 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;
     }
 }
예제 #3
0
 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;
     }
 }
예제 #4
0
 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;
     }
 }
예제 #5
0
 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;
 }
예제 #6
0
 public GiaoVien GetGiaoVien(int maGiaoVien)
 {
     using (var db = new TKBEntities())
     {
         GiaoVien gv = db.GiaoViens.FirstOrDefault(l => l.MaGiaoVien == maGiaoVien);
         return gv;
     }
 }
예제 #7
0
 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();
     }
 }
예제 #8
0
 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;
     }
 }
예제 #9
0
 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;
     }
 }
예제 #10
0
 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;
     }
 }
예제 #11
0
        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);

            }
        }
예제 #12
0
 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();
     }
 }
예제 #13
0
 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();
     }
 }
예제 #14
0
 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;
     }
 }
예제 #15
0
 public Lop GetLop(int maLop)
 {
     using (var db = new TKBEntities())
     {
         Lop lop = db.Lops.FirstOrDefault(l => l.MaLop == maLop);
         return lop;
     }
 }
예제 #16
0
 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;
     }
 }
예제 #17
0
 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;
     }
 }
예제 #18
0
 public bool ThemLop(Lop lop)
 {
     try
     {
         using (var db = new TKBEntities())
         {
             db.AddToLops(lop);
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #19
0
 public Phong GetPhong(int maPhong)
 {
     using (var db = new TKBEntities())
     {
         Phong gv = db.Phongs.FirstOrDefault(l => l.MaPhong == maPhong);
         return gv;
     }
 }
예제 #20
0
 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();
     }
 }
예제 #21
0
 public bool ThemGiaoVien(GiaoVien gv)
 {
     try
     {
         using (var db = new TKBEntities())
         {
             db.AddToGiaoViens(gv);
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #22
0
 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;
     }
 }
예제 #23
0
 public bool ThemPhong(Phong gv)
 {
     try
     {
         using (var db = new TKBEntities())
         {
             db.AddToPhongs(gv);
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #24
0
 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();
     }
 }
예제 #25
0
 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;
     }
 }
예제 #26
0
 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;
     }
 }
예제 #27
0
 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;
     }
 }
예제 #28
0
 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;
     }
 }
예제 #29
0
 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();
         }
     }
 }
예제 #30
0
 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;
     }
 }