Exemplo n.º 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;
     }
 }
Exemplo n.º 2
0
 private Phong GetPhong(ref List<Phong> dsPhong, int siSo)
 {
     Phong phong = new Phong();
     for (int i = 0; i < dsPhong.Count; i++)
     {
         if (dsPhong[i].TinhTrang.ToLower().Equals("trống") && dsPhong[i].SucChua >= siSo)
         {
             phong = dsPhong[i];
             break;
         }
     }
     dsPhong.Remove(phong);
     return phong;
 }
Exemplo n.º 3
0
 private ThoiKhoaBieu BuildTKB(string namHoc, int buoi, List<MonHoc> dsMonHoc, List<Lop> dsLop, ref List<Phong> dsPhong, List<GiaoVien> dsGiaoVien, List<ThoiKhoaBieu> lstTKB, int l, List<List<ChiTietTKB>> arrTKB, Phong phong)
 {
     ThoiKhoaBieu tkb = new ThoiKhoaBieu();
     tkb.Lop = dsLop[l];
     tkb.NamHoc = namHoc;
     int tietDau = buoi == 1 ? 0 : Int32.Parse(ConfigurationManager.AppSettings["TongSoTietSang"]);
     int tietCuoi = buoi == 1 ? (tietDau + Int32.Parse(ConfigurationManager.AppSettings["TongSoTietSang"])) : (tietDau + Int32.Parse(ConfigurationManager.AppSettings["TongSoTietChieu"]));
     for (int k = 0; k < dsMonHoc.Count; k++)
     {
         MonHoc mh = dsMonHoc[k];
         GiaoVien giaoVien = null;
         List<GiaoVien> dsGV_MH = GetDSGiaoVienTheoMonHoc(mh.MaMonHoc, dsGiaoVien);
         for (int i = 0; i < 7; i++) // 7days: from Monday to Sunday
         {
             for (int j = tietDau; j < tietCuoi; j++)
             {
                 if (arrTKB[i][j].MonHoc == null) // Còn trống
                 {
                     if (KiemTraMonHoc(arrTKB, mh, i, j))
                     {
                         ChiTietTKB ctTKB = new ChiTietTKB();
                         // Xếp giáo viên vào môn học ở ngày i tiết j
                         if ((giaoVien != null && KiemTraGiaoVien(lstTKB, arrTKB, giaoVien, mh.MaMonHoc, i, j)) || GetGiaoVien(lstTKB, arrTKB, dsGV_MH, mh.MaMonHoc, i, j, out giaoVien))
                         {
                             ctTKB.ThoiKhoaBieu = tkb;
                             ctTKB.MonHoc = mh;
                             ctTKB.GiaoVien = giaoVien;
                             ctTKB.Phong = phong;
                             ctTKB.TietBatDau = j;
                             ctTKB.TietKetThuc = j;
                             ctTKB.Thu = i;
                             tkb.ChiTietTKBs.Add(ctTKB);
                             arrTKB[i][j].MonHoc = mh;
                             arrTKB[i][j].GiaoVien = giaoVien;
                             arrTKB[i][j].Phong = phong;
                             arrTKB[i][j].TietBatDau = j;
                             arrTKB[i][j].TietKetThuc = j;
                             arrTKB[i][j].Thu = i;
                         }
                     }
                 }
             }
         }
     }
     return tkb;
 }
Exemplo n.º 4
0
 public bool ThemPhong(Phong gv)
 {
     try
     {
         using (var db = new TKBEntities())
         {
             db.AddToPhongs(gv);
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 5
0
        public bool GenerateTKB(string namHoc, List<List<ChiTietTKB>> arrTKB1, List<MonHoc> dsMonHoc, List<Lop> dsLop, List<Phong> dsPhong, List<GiaoVien> dsGiaoVien)
        {
            try
            {
                // Xóa thông tin TKB cũ sẽ sắp mới
                foreach (Lop l in dsLop)
                {
                    DeleteTKB(l.MaLop, namHoc);
                }
                // Lấy danh sách TKB cũ
                List<ThoiKhoaBieu> lstTKB = GetTKB(namHoc);
                List<List<List<ChiTietTKB>>> listTKBs = new List<List<List<ChiTietTKB>>>();
                for (int l = 0; l < dsLop.Count; l++)
                {
                    List<List<ChiTietTKB>> arrTKB = new List<List<ChiTietTKB>>();
                    for (int i = 0; i < arrTKB1.Count; i++)
                    {
                        List<ChiTietTKB> temp = new List<ChiTietTKB>();
                        for (int j = 0; j < arrTKB1[i].Count; j++)
                        {
                            ChiTietTKB ct = new ChiTietTKB();
                            AddChiTietTKB(ref ct, arrTKB1[i][j]);
                            temp.Add(ct);
                        }
                        arrTKB.Add(temp);
                    }

                    // Tìm phòng trống
                    Phong phong = new Phong();
                    int caHoc = dsLop[l].CaHoc == null ? 1 : (dsLop[l].CaHoc.Equals("Sáng") ? 1 : 2);
                    phong = GetPhong(ref dsPhong, (int)dsLop[l].SiSo);
                    ThoiKhoaBieu tkb = BuildTKB(namHoc, caHoc, dsMonHoc, dsLop, ref dsPhong, dsGiaoVien, lstTKB, l, arrTKB, phong);
                    lstTKB.Add(tkb);
                    //Tối ưu TKB
                    listTKBs.Add(OptimizeTKB(arrTKB));
                }

                // Save TKB;
                SaveTKB(lstTKB, dsLop);
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }