Esempio n. 1
0
 public static void Begin(int[,] oldAdjacencyMatrix, int beginI)
 {
     AdjacencyMatrixSize = AlgorithmRunner.AdjacencyMatrixSize;
     AdjacencyMatrix     = oldAdjacencyMatrix;
     for (i = beginI; i < AdjacencyMatrixSize; i++)
     {
         for (j = i + 1; j < AdjacencyMatrixSize; j++)
         {
             //ProgressHelper.CreateMatrixInfo = (1 + i) + "/" + (1 + j);
             //ProgressHelper.pbCreateMatrix = 100 * (i * AdjacencyMatrixSize + j) / (AdjacencyMatrixSize * AdjacencyMatrixSize);
             AlgorithmRunner.SaveOBJ("Status", "inf Đang phân tích dữ liệu (" + (1 + i) + "/" + (1 + j) + ")...");
             AdjacencyMatrix[i, j] = AdjacencyMatrix[j, i] = CheckGroups(AlgorithmRunner.Groups[i], AlgorithmRunner.Groups[j]);
         }
         if (Stop)
         {
             //AlgorithmRunner.SaveOBJ("AdjacencyMatrix", AdjacencyMatrix);
             WriteAdjacencyMatrix(AdjacencyMatrix, AlgorithmRunner.RealPath("AdjacencyMatrix"));
             AlgorithmRunner.SaveOBJ("BeginI", i + 1);
             AlgorithmRunner.Clear();
             Stoped = true;
             Environment.Exit(0);
             return;
         }
     }
     WriteAdjacencyMatrix(AdjacencyMatrix, AlgorithmRunner.RealPath("AdjacencyMatrix"));
     AlgorithmRunner.DeleteOBJ("BeginI");
 }
Esempio n. 2
0
        public static List <Shift> InitShift()
        {
            String Path = AlgorithmRunner.RealPath("Shift");

            if (File.Exists(Path))
            {
                return(JsonConvert.DeserializeObject <List <Shift> >(File.ReadAllText(Path)));
            }
            else
            {
                List <Shift> aShift = new List <Shift>();
                for (int i = 0; i < InputHelper.Options.NumDate; i++)
                {
                    for (int j = 0; j < InputHelper.Options.Times.Count; j++)
                    {
                        DateTime ShiftTime = InputHelper.Options.StartDate.AddDays(i)
                                             .AddHours(InputHelper.Options.Times[j].Hour)
                                             .AddMinutes(InputHelper.Options.Times[j].Minute);
                        aShift.Add(new Shift()
                        {
                            IsBusy = (ShiftTime.DayOfWeek == DayOfWeek.Sunday), Time = ShiftTime
                        });
                    }
                }
                return(aShift);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Lấy danh sách sinh viên thi của từng môn học
        /// </summary>
        private static void GetStudentList()
        {
            int SumStudents = 0;

            StudentByGroup = new Dictionary <String, List <String> >();
            for (int GroupIndex = 0; GroupIndex < AlgorithmRunner.Groups.Count; GroupIndex++)
            {
                String SubjectID = AlgorithmRunner.GetSubjectID(AlgorithmRunner.Groups[GroupIndex]);
                String ClassList = AlgorithmRunner.GetClassList(AlgorithmRunner.Groups[GroupIndex]);
                //String IgnoreStudents = InputHelper.IgnoreStudents.ContainsKey(SubjectID) ? JsonConvert.SerializeObject(InputHelper.IgnoreStudents[SubjectID]) : "[]";
                //IgnoreStudents = IgnoreStudents.Substring(1, IgnoreStudents.Length - 2).Replace("\"", "'");
                IEnumerable <String> Result = InputHelper.db.Database.SqlQuery <String>("select sinhvien.MaSinhVien from pdkmh, sinhvien "
                                                                                        + "where pdkmh.MaSinhVien = sinhvien.MaSinhVien "
                                                                                        + "and MaMonHoc = '" + SubjectID + "' "
                                                                                        //                  + (IgnoreStudents.Length > 0 ? "and not(sinhvien.MaSinhVien in (" + IgnoreStudents + ")) " : "")
                                                                                        + "and pdkmh.Nhom in(" + ClassList + ") "
                                                                                        + "order by (Ten + Ho)");
                StudentByGroup.Add(AlgorithmRunner.Groups[GroupIndex], Result.ToList <String>());
                SumStudents += Result.ToList <String>().Count;
            }

            if (SumStudents > SumContaint)
            {
                AlgorithmRunner.SaveOBJ("Status", "err Phòng thi không đủ");
                AlgorithmRunner.IsBusy = false;
                Thread.CurrentThread.Abort();
            }

            AlgorithmRunner.GroupsRoom         = new List <Room> [AlgorithmRunner.Groups.Count];
            AlgorithmRunner.GroupsRoomStudents = new List <String> [AlgorithmRunner.Groups.Count][];
        }
Esempio n. 4
0
        private static void DeleteOld(string dot)
        {
            try
            {
                InitRoom(dot, false);
                var MaCaQry = (from ca in InputHelper.db.This
                               where ca.Dot == dot
                               select new { MaCa = ca.MaCa }).Distinct().ToList();

                db.Database.ExecuteSqlCommand("DELETE FROM Thi WHERE Dot='" + dot + "'");
                foreach (var ca in MaCaQry)
                {
                    db.Database.ExecuteSqlCommand("DELETE FROM CaThi WHERE MaCa='" + ca.MaCa + "'");
                }

                var DbName = Regex.Match(db.Database.Connection.ConnectionString, "initial\\scatalog=([^;]+)").Groups[1].Value;
                db.Database.ExecuteSqlCommand("DBCC SHRINKFILE (" + DbName + ", 1) ");
                db.Database.ExecuteSqlCommand("DBCC SHRINKFILE (" + DbName + "_log, 1) ");
            }
            catch
            {
                AlgorithmRunner.SaveOBJ("Status", "err Lỗi Pri trong khi xoá CSDL, hãy thử chạy lại lần nữa!");
                InitRoom(dot, true);
                AlgorithmRunner.IsBusy = false;
                Thread.CurrentThread.Abort();
            }
        }
Esempio n. 5
0
        public static Options InitOptions()
        {
            String OptionsPath = AlgorithmRunner.RealPath("Options");

            if (File.Exists(OptionsPath))
            {
                return(JsonConvert.DeserializeObject <Options>(File.ReadAllText(OptionsPath)));
            }
            else
            {
                return(new Options()
                {
                    StartDate = DateTime.Now.Date,
                    NumDate = 100,
                    DateMin = 1,
                    ShiftTime = 120,
                    MinStudent = 10,
                    Times = new List <DateTime>()
                    {
                        DateTime.Now.Date.AddHours(7).AddMinutes(15),
                        DateTime.Now.Date.AddHours(9).AddMinutes(30),
                        DateTime.Now.Date.AddHours(13),
                        DateTime.Now.Date.AddHours(15).AddMinutes(15)
                    }
                });
            }
        }
Esempio n. 6
0
        public static List <RoomList> InitRooms()
        {
            String Path = AlgorithmRunner.RealPath("Rooms");

            if (File.Exists(Path))
            {
                return(JsonConvert.DeserializeObject <List <RoomList> >(File.ReadAllText(Path)));
            }
            else
            {
                List <RoomList> aRoomList = new List <RoomList>();
                List <Room>     Rooms     = db.phongs.Where(p => p.SucChua > 0).Select(m => new Room()
                {
                    RoomID    = m.MaPhong,
                    Container = (int)m.SucChua,
                    IsBusy    = false
                }).ToList();
                for (int i = 0; i < Options.NumDate; i++)
                {
                    DateTime ShiftTime = Options.StartDate.AddDays(i);
                    for (int j = 0; j < Options.Times.Count; j++)
                    {
                        aRoomList.Add(new RoomList()
                        {
                            Rooms = new List <Room>(Rooms), Time = ShiftTime + Options.Times[j].TimeOfDay
                        });
                    }
                }
                return(aRoomList);
            }
        }
Esempio n. 7
0
 public static void Delete()
 {
     AlgorithmRunner.IsBusy = true;
     AlgorithmRunner.SaveOBJ("Status", "inf Đang Xoá CSDL cũ");
     DeleteOld();
     AlgorithmRunner.SaveOBJ("Status", "inf Hoàn tất quá trình Xoá CSDL!");
     AlgorithmRunner.IsBusy = false;
 }
Esempio n. 8
0
 public static void Run()
 {
     AlgorithmRunner.IsBusy = true;
     AlgorithmRunner.SaveOBJ("Status", "inf Đang lưu dữ liệu xếp lịch thủ công");
     Save(AlgorithmRunner.HandmadeData);
     AlgorithmRunner.SaveOBJ("Status", "inf Hoàn tất lưu dữ liệu xếp lịch thủ công");
     AlgorithmRunner.IsBusy = false;
 }
Esempio n. 9
0
        private static void Save()
        {
            int GCount = AlgorithmRunner.Groups.Count;

            for (int GroupIndex = 0; GroupIndex < GCount; GroupIndex++)
            {
                Thi aRecord = new Thi();
                aRecord.MaMonHoc = AlgorithmRunner.GetSubjectID(AlgorithmRunner.Groups[GroupIndex]);
                aRecord.Nhom     = AlgorithmRunner.GetClassList(AlgorithmRunner.Groups[GroupIndex]);
                DateTime FirstShiftTime = InputHelper.Options.StartDate.AddHours(InputHelper.Options.Times[0].Hour)
                                          .AddMinutes(InputHelper.Options.Times[0].Minute);
                String ShiftID = "";// InputHelper.Options.StartDate.Year + "" + InputHelper.Options.StartDate.Month + "" + InputHelper.Options.StartDate.Day;
                ShiftID += RoomArrangement.CalcShift(FirstShiftTime, AlgorithmRunner.GroupsTime[GroupIndex]).ToString();
                if ((from ct in db.CaThis where ct.MaCa == ShiftID select ct).Count() == 0)
                {
                    var pa = new SqlParameter[]
                    {
                        new SqlParameter("@MaCa", SqlDbType.NVarChar)
                        {
                            Value = ShiftID
                        },
                        new SqlParameter("@GioThi", SqlDbType.DateTime)
                        {
                            Value = AlgorithmRunner.GroupsTime[GroupIndex]
                        },
                    };
                    db.Database.ExecuteSqlCommand("INSERT INTO CaThi (MaCa, GioThi) VALUES (@MaCa, @GioThi)", pa);
                }
                aRecord.MaCa = ShiftID;
                String SQLQuery = "";
                for (int RoomIndex = 0; RoomIndex < AlgorithmRunner.GroupsRoom[GroupIndex].Count; RoomIndex++)
                {
                    aRecord.MaPhong = AlgorithmRunner.GroupsRoom[GroupIndex][RoomIndex].RoomID;
                    for (int StudentIndex = 0; StudentIndex < AlgorithmRunner.GroupsRoomStudents[GroupIndex][RoomIndex].Count; StudentIndex++)
                    {
                        aRecord.MaSinhVien = AlgorithmRunner.GroupsRoomStudents[GroupIndex][RoomIndex][StudentIndex];
                        SQLQuery          += String.Format("INSERT INTO Thi (MaCa, MaMonHoc, Nhom, MaPhong, MaSinhVien) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')\r\n",
                                                           aRecord.MaCa,
                                                           aRecord.MaMonHoc,
                                                           aRecord.Nhom,
                                                           aRecord.MaPhong,
                                                           aRecord.MaSinhVien
                                                           );
                    } // sinh viên
                }     // phòng
                try
                {
                    AlgorithmRunner.SaveOBJ("Status", "inf Đang Lưu vào cơ sở dữ liệu (" + (GroupIndex + 1) + "/" + GCount + ")");
                    db.Database.ExecuteSqlCommand(SQLQuery);
                }
                catch
                {
                    AlgorithmRunner.SaveOBJ("Status", "err Lỗi trong khi chèn thêm nội dung vào CSDL! Hãy thử lại hoặc liên hệ với quản trị nếu vẫn lỗi!");
                    AlgorithmRunner.IsBusy = false;
                    Thread.CurrentThread.Abort();
                }
            }// môn
        }
Esempio n. 10
0
 public static void RunFixSubJect()
 {
     AlgorithmRunner.IsBusy = true;
     AlgorithmRunner.SaveOBJ("Status", "inf Đang Xoá CSDL cũ");
     Delete(AlgorithmRunner.HandmadeData);
     AlgorithmRunner.SaveOBJ("Status", "inf Đang lưu dữ liệu xếp lịch");
     Save(AlgorithmRunner.HandmadeData);
     AlgorithmRunner.SaveOBJ("Status", "inf Hoàn tất lưu dữ liệu xếp lịch");
     AlgorithmRunner.IsBusy = false;
 }
Esempio n. 11
0
 public static void Run()
 {
     AlgorithmRunner.IsBusy = true;
     AlgorithmRunner.SaveOBJ("Status", "inf Đang Xoá CSDL cũ");
     DeleteOld();
     AlgorithmRunner.SaveOBJ("Status", "inf Đang Lưu vào cơ sở dữ liệu");
     Save();
     AlgorithmRunner.SaveOBJ("Status", "inf Hoàn tất quá trình lưu!");
     AlgorithmRunner.IsBusy = false;
 }
Esempio n. 12
0
        static int CheckGroups(String Group1ID, String Group2ID)
        {
            String Subject1ID = AlgorithmRunner.GetSubjectID(Group1ID);
            String Subject2ID = AlgorithmRunner.GetSubjectID(Group2ID);
            String Group1     = AlgorithmRunner.GetClassList(Group1ID);
            String Group2     = AlgorithmRunner.GetClassList(Group2ID);

            if (Subject1ID == Subject2ID && Group1 != Group2)
            {
                return(1);
            }

            /*String StudentsList1 = "";
             * String StudentsList2 = "";
             * try
             * {
             *  foreach (String st in InputHelper.IgnoreStudents[Subject1ID])
             *  {
             *      StudentsList1 += (StudentsList1.Length > 0 ? ", " : "") + "'" + st + "'";
             *  }
             * }
             * catch { }
             *
             * try
             * {
             *  foreach (String st in InputHelper.IgnoreStudents[Subject2ID])
             *  {
             *      StudentsList2 += (StudentsList2.Length > 0 ? ", " : "") + "'" + st + "'";
             *  }
             * }
             * catch { }*/

            var pa = new SqlParameter[]
            {
                new SqlParameter("@S1ID", SqlDbType.NVarChar)
                {
                    Value = Subject1ID
                },
                new SqlParameter("@S2ID", SqlDbType.NVarChar)
                {
                    Value = Subject2ID
                }
            };
            int Result = db.Database.SqlQuery <int>("select count(s1.MaSinhVien) from pdkmh as s1 "
                                                    + "where s1.MaSinhVien in (select s2.MaSinhVien from pdkmh as s2 "
                                                    + "where s2.MaMonHoc = @S2ID "
                                                    //+ (StudentsList2.Length > 0 ? "and not(s2.MaSinhVien in (" + StudentsList2 + "))" : "")
                                                    + "and s2.Nhom in(" + Group2 + ")"
                                                    + ") "
                                                    // + (StudentsList1.Length > 0 ? "and not(s1.MaSinhVien in (" + StudentsList1 + "))" : "")
                                                    + "and s1.MaMonHoc = @S1ID "
                                                    + "and s1.Nhom in(" + Group1 + ")", pa).ElementAt(0);

            return(Result == 0 ? 0 : 1);
        }
Esempio n. 13
0
 public static void Run()
 {
     Init();
     Arrangement();
     AlgorithmRunner.SaveOBJ("GroupsTime", AlgorithmRunner.GroupsTime);
     AlgorithmRunner.SaveOBJ("GroupsRoom", AlgorithmRunner.GroupsRoom);
     AlgorithmRunner.SaveOBJ("GroupsRoomStudents", AlgorithmRunner.GroupsRoomStudents);
     //    UpdateShiftsAndRooms();
     AlgorithmRunner.SaveOBJ("AppShifts", InputHelper.Shifts);
     AlgorithmRunner.SaveOBJ("AppRooms", InputHelper.Rooms);
 }
Esempio n. 14
0
 public static void Run()
 {
     AlgorithmRunner.IsBusy = true;
     //AlgorithmRunner.SaveOBJ("Status", "inf Đang Xoá CSDL cũ");
     //DeleteOld();
     AlgorithmRunner.SaveOBJ("Status", "inf Đang Lưu vào cơ sở dữ liệu");
     Save();
     AlgorithmRunner.SaveOBJ("Status", "inf Hoàn tất quá trình lưu! lúc: " + DateTime.Now);
     AlgorithmRunner.IsBusy = false;
     //        Thread.CurrentThread.Abort();
 }
Esempio n. 15
0
 public static void Run()
 {
     AlgorithmRunner.IsBusy = true;
     AlgorithmRunner.SaveOBJ("Status", "inf Chuẩn bị phân tích cơ sở dữ liệu");
     Stop   = false;
     Stoped = false;
     Begin(AlgorithmRunner.AdjacencyMatrix, AlgorithmRunner.BeginI);
     Stoped = true;
     AlgorithmRunner.IsBusy = false;
     AlgorithmRunner.SaveOBJ("Status", "inf Phân tích xong cơ sở dữ liệu lúc: " + DateTime.Now);
     // Thread.CurrentThread.Abort();
 }
Esempio n. 16
0
        private static DateTime IncTime(DateTime Time, int Shift)
        {
            int CurrentShiftIndex = ShiftList.FindIndex(m => m.Time == Time);

            if (CurrentShiftIndex + Shift > ShiftList.Count - 1)
            {
                AlgorithmRunner.SaveOBJ("Status", "err Số ca thi không đủ, đang dừng lại ở ca thi thứ: " + CurrentShiftIndex + Shift);
                AlgorithmRunner.IsBusy = false;
                Thread.CurrentThread.Abort();
            }
            return(ShiftList[CurrentShiftIndex + Shift].Time);
        }
Esempio n. 17
0
        public static Dictionary <String, List <String> > InitIgnoreStudents()
        {
            String Path = AlgorithmRunner.RealPath("IgnoreStudents");

            if (File.Exists(Path))
            {
                return(JsonConvert.DeserializeObject <Dictionary <String, List <String> > >(File.ReadAllText(Path)));
            }
            else
            {
                return(new Dictionary <String, List <String> >());
            }
        }
Esempio n. 18
0
        public static List <Priority> InitSubjectPriority()
        {
            String Path = AlgorithmRunner.RealPath("SubjectPriority");

            if (File.Exists(Path))
            {
                return(JsonConvert.DeserializeObject <List <Priority> >(File.ReadAllText(Path)));
            }
            else
            {
                return(new List <Priority>());
            }
        }
Esempio n. 19
0
 private static void Check(String MaMH, String Class)
 {
     String[] aClass = Class.Split(',');
     for (int i = 0; i < aClass.Length; i++)
     {
         if (InputHelper.Groups.ContainsKey(MaMH + "_" + aClass[i]))
         {
             InputHelper.Groups[MaMH + "_" + aClass[i]].IsIgnored = true;
         }
     }
     // OutputHelper.SaveOBJ("Groups", InputHelper.Groups);
     AlgorithmRunner.SaveOBJ("Groups", InputHelper.Groups);
 }
Esempio n. 20
0
        public static void Delete(HandmadeData Data)
        {
            String ClassList = "";

            foreach (String cl in Data.Class)
            {
                ClassList += cl + ",";
            }

            ClassList = ClassList.Remove(ClassList.Length - 1, 1);


            var SubjectID = Data.SubjectID;

            DKMHEntities db = new DKMHEntities();

            var MaCaQry = (from thi in InputHelper.db.This
                           where thi.MaMonHoc == SubjectID && thi.Nhom == ClassList
                           select new
            {
                MaCa = thi.MaCa,
                MSMH = thi.MaMonHoc,
                Nhom = thi.Nhom
            }).FirstOrDefault();

            try
            {
                InitRooms(SubjectID, MaCaQry.MaCa, false);

                db.Database.ExecuteSqlCommand("DELETE FROM Thi WHERE MaCa='" + MaCaQry.MaCa + "' and MaMonHoc='" + MaCaQry.MSMH + "' and Nhom='" + MaCaQry.Nhom + "'");

                var MC = InputHelper.db.This.Where(m => m.MaCa == MaCaQry.MaCa).FirstOrDefault();
                if (MC == null)
                {
                    db.Database.ExecuteSqlCommand("DELETE FROM CaThi WHERE MaCa='" + MaCaQry.MaCa + "'");
                }

                var DbName = Regex.Match(db.Database.Connection.ConnectionString, "initial\\scatalog=([^;]+)").Groups[1].Value;
                db.Database.ExecuteSqlCommand("DBCC SHRINKFILE (" + DbName + ", 1) ");
                db.Database.ExecuteSqlCommand("DBCC SHRINKFILE (" + DbName + "_log, 1) ");
            }
            catch
            {
                AlgorithmRunner.SaveOBJ("Status", "err Lỗi Pri trong khi xoá CSDL, hãy thử chạy lại lần nữa!");
                InitRooms(SubjectID, MaCaQry.MaCa, true);
                AlgorithmRunner.IsBusy = false;
                Thread.CurrentThread.Abort();
            }
        }
Esempio n. 21
0
 private static void UpdateShiftsAndRooms(DateTime[] GroupsTime, List <Room>[] GroupsRoom)
 {
     for (int Index = 0; Index < GroupsTime.Length; Index++)
     {
         int ShiftIndex = InputHelper.Shifts.FindIndex(m => m.Time == GroupsTime[Index]);
         InputHelper.Shifts[ShiftIndex].IsBusy = true;
         int RoomListIndex = InputHelper.Rooms.FindIndex(m => m.Time == GroupsTime[Index]);
         foreach (Room aRoom in GroupsRoom[Index])
         {
             int RoomIndex = InputHelper.Rooms[RoomListIndex].Rooms.FindIndex(m => m.RoomID == aRoom.RoomID);
             InputHelper.Rooms[RoomListIndex].Rooms[RoomIndex].IsBusy = true;
         }
     }
     AlgorithmRunner.SaveOBJ("Rooms", InputHelper.Rooms);
 }
Esempio n. 22
0
        private static void InitRoom(bool ok)
        {
            var room = (from r in InputHelper.db.This
                        select new
            {
                r.MaPhong,
                r.CaThi.GioThi
            }).Distinct();

            foreach (var r in room)
            {
                int index = InputHelper.Rooms.Find(m => m.Time == r.GioThi).Rooms.FindIndex(m => m.RoomID == r.MaPhong);
                InputHelper.Rooms.Find(m => m.Time == r.GioThi).Rooms[index].IsBusy = ok;
            }
            AlgorithmRunner.SaveOBJ("Rooms", InputHelper.Rooms);
        }
Esempio n. 23
0
        public static void Delete(object Dot)
        {
            AlgorithmRunner.IsBusy = true;
            AlgorithmRunner.SaveOBJ("Status", "inf Đang Xoá CSDL cũ");

            if (Dot.ToString() == "")
            {
                DeleteOld();
            }
            else
            {
                DeleteOld((string)Dot);
            }
            AlgorithmRunner.SaveOBJ("Status", "inf Hoàn tất quá trình Xoá CSDL!");
            AlgorithmRunner.IsBusy = false;
        }
Esempio n. 24
0
        private static void InitRooms(string SubjectID, string MaCa, bool ok)
        {
            var room = (from r in InputHelper.db.This
                        where r.MaMonHoc == SubjectID && r.MaCa == MaCa
                        select new
            {
                r.MaPhong,
                r.CaThi.GioThi
            }).Distinct();

            foreach (var r in room)
            {
                int index = InputHelper.Rooms.Find(m => m.Time == r.GioThi).Rooms.FindIndex(m => m.RoomID == r.MaPhong);
                InputHelper.Rooms.Find(m => m.Time == r.GioThi).Rooms[index].IsBusy = ok;
            }
            AlgorithmRunner.SaveOBJ("Rooms", InputHelper.Rooms);
        }
Esempio n. 25
0
 private static void DeleteOld()
 {
     try
     {
         db.Database.ExecuteSqlCommand("DELETE FROM Thi");
         db.Database.ExecuteSqlCommand("DELETE FROM CaThi");
         var DbName = Regex.Match(db.Database.Connection.ConnectionString, "initial\\scatalog=([^;]+)").Groups[1].Value;
         db.Database.ExecuteSqlCommand("DBCC SHRINKFILE (" + DbName + ", 1) ");
         db.Database.ExecuteSqlCommand("DBCC SHRINKFILE (" + DbName + "_log, 1) ");
     }
     catch
     {
         AlgorithmRunner.SaveOBJ("Status", "err Lỗi trong khi xoá CSDL, hãy thử chạy lại lần nữa!");
         AlgorithmRunner.IsBusy = false;
         Thread.CurrentThread.Abort();
     }
 }
Esempio n. 26
0
        /// <summary>
        /// tạo danh sách phòng thi, nếu có file rồi thì đọc từ file còn ko thì tạo file
        /// </summary>
        /// <returns></returns>
        public static List <RoomList> InitRooms()
        {
            String Path = AlgorithmRunner.RealPath("Rooms");

            if (File.Exists(Path))
            {
                //List<RoomList> RoomsTemp = JsonConvert.DeserializeObject<List<RoomList>>(File.ReadAllText(Path));

                //var room = (from r in InputHelper.db.This
                //            select new
                //            {
                //                r.MaPhong,
                //                r.CaThi.GioThi
                //            }).Distinct();

                //foreach (var r in room)
                //    RoomsTemp.Find(m => m.Time == r.GioThi).Rooms.RemoveAt(RoomsTemp.Find(m => m.Time == r.GioThi).Rooms.FindIndex(p => p.RoomID == r.MaPhong));

                //return RoomsTemp;
                return(JsonConvert.DeserializeObject <List <RoomList> >(File.ReadAllText(Path)));
            }
            else
            {
                List <RoomList> aRoomList = new List <RoomList>();
                List <Room>     Rooms     = db.phongs.Where(p => p.SucChua > 0).Select(m => new Room()
                {
                    RoomID    = m.MaPhong,
                    Container = (int)m.SucChua,
                    IsBusy    = false
                }).ToList();
                for (int i = 0; i < Options.NumDate; i++)
                {
                    DateTime ShiftTime = Options.StartDate.AddDays(i);
                    for (int j = 0; j < Options.Times.Count; j++)
                    {
                        aRoomList.Add(new RoomList()
                        {
                            Rooms = new List <Room>(Rooms), Time = ShiftTime + Options.Times[j].TimeOfDay
                        });
                    }
                }
                InputHelper.Rooms = aRoomList;
                AlgorithmRunner.SaveOBJ("Rooms", InputHelper.Rooms);
                return(aRoomList);
            }
        }
Esempio n. 27
0
        /// <summary>
        /// B3: Tăng thời gian của tất cả các môn có màu khác và thi sau lên 1 khoảng sao cho > max[màu các môn vừa tăng thời gian]
        /// </summary>
        /// <param name="GroupIndex"></param>
        /// <param name="RoomList"></param>
        private static void RoomArrangementForOneGroup(int GroupIndex, List <Room> RoomList)
        {
            int StudentsNumber = StudentByGroup[AlgorithmRunner.Groups[GroupIndex]].Count;

            if (StudentsNumber > MaxContaint)
            {
                AlgorithmRunner.SaveOBJ("Status", "err Phòng thi không đủ, đang dừng lại ở nhóm thi: " + AlgorithmRunner.Groups[GroupIndex] + " với số sinh viên là:" + StudentsNumber);
                AlgorithmRunner.IsBusy = false;
                Thread.CurrentThread.Abort();
            }
            AlgorithmRunner.GroupsRoom[GroupIndex] = new List <Room>();
            int OldRoomUsedIndex = RoomUsedIndex;

            while (StudentsNumber > 0)
            {
                RoomUsedIndex++;
                if (RoomUsedIndex < RoomList.Count) // còn phòng
                {
                    AlgorithmRunner.GroupsRoom[GroupIndex].Add(RoomList[RoomUsedIndex]);
                    StudentsNumber -= RoomList[RoomUsedIndex].Container;

                    // đáng lẽ code phân trực tiếp sv vào phòng ở đây, nhưng như vậy phòng ít phòng nhiều
                    // để đó sau này truy vấn lại môn này thi mấy phòng rồi chia sau!
                }
                else // hết phòng == > cần giãn ca
                {
                    AlgorithmRunner.GroupsRoom[GroupIndex].Clear(); // xoá mấy phòng lỡ thêm vào
                    Progressed[GroupIndex] = false; // cho nó trở lại trạng thái chưa xử lý
                    RoomUsedIndex          = OldRoomUsedIndex;
                    // chuyển môn hiện tại qua ca tiếp theo
                    AlgorithmRunner.GroupsTime[GroupIndex] = IncTime(AlgorithmRunner.GroupsTime[GroupIndex], 1);
                    int CurrentColor = AlgorithmRunner.Colors[GroupIndex];
                    // Kiểm tra và tăng max
                    if (AlgorithmRunner.MaxColorTime[CurrentColor] < AlgorithmRunner.GroupsTime[GroupIndex])
                    {
                        // đổi max
                        AlgorithmRunner.MaxColorTime[CurrentColor] = AlgorithmRunner.GroupsTime[GroupIndex];
                        // chuyển các môn màu khác ở ca phía sau đi ra sau 1 ca, tránh tình trạng khác màu mà cùng ca
                        IncSubjectAfter(CurrentColor);
                    }
                    return; // thoát luôn
                }
            }
            MakeStudentList(GroupIndex);
        }
Esempio n. 28
0
        public static Dictionary <String, Group> InitGroups()
        {
            String GroupFile = AlgorithmRunner.RealPath("Groups");
            Dictionary <String, Group> aGroups = File.Exists(GroupFile) ?
                                                 JsonConvert.DeserializeObject <Dictionary <String, Group> >(File.ReadAllText(GroupFile)) :
                                                 (from m in db.monhocs
                                                  join d in db.pdkmhs on m.MaMonHoc equals d.MaMonHoc
                                                  select new Group()
            {
                MaMonHoc = m.MaMonHoc,
                TenMonHoc = m.TenMonHoc,
                TenBoMon = m.bomon.TenBoMon,
                TenKhoa = m.bomon.khoa.TenKhoa,
                Nhom = d.Nhom,
                SoLuongDK = d.nhom1.SoLuongDK,
                GroupID = 1,
                IsIgnored = false
            })
                                                 .Distinct()
                                                 .ToDictionary(k => (k.MaMonHoc + "_" + k.Nhom), k => k);

            return(aGroups);
        }
Esempio n. 29
0
        public static void Save(HandmadeData Data)
        {
            DKMHEntities db        = new DKMHEntities();
            var          ClassList = "";

            foreach (String cl in Data.Class)
            {
                ClassList += (ClassList.Length > 0 ? ", " : "") + "'" + cl + "'";
            }

            var StudentList = db.Database.SqlQuery <StudentInfo>("select pdkmh.MaSinhVien, pdkmh.Nhom from pdkmh, sinhvien " +
                                                                 "where pdkmh.MaSinhVien = sinhvien.MaSinhVien and MaMonHoc = '" + Data.SubjectID + "' and Nhom in (" + ClassList + ") "
                                                                 ).ToList();

            var DotQry = (from m in InputHelper.db.This
                          select m.Dot).Max();
            int dot = 1;

            if (DotQry != null)
            {
                dot = int.Parse(DotQry[0].ToString());
            }

            DateTime FirstShiftTime = InputHelper.Options.StartDate.AddHours(InputHelper.Options.Times[0].Hour)
                                      .AddMinutes(InputHelper.Options.Times[0].Minute);
            String ShiftID = dot.ToString();//InputHelper.Options.StartDate.Year + "" + InputHelper.Options.StartDate.Month + "" + InputHelper.Options.StartDate.Day;

            ShiftID += "_" + RoomArrangement.CalcShift(FirstShiftTime, Data.Date).ToString();
            if ((from ct in db.CaThis where ct.MaCa == ShiftID select ct).Count() == 0)
            {
                var pa = new SqlParameter[]
                {
                    new SqlParameter("@MaCa", SqlDbType.NVarChar)
                    {
                        Value = ShiftID
                    },
                    new SqlParameter("@GioThi", SqlDbType.DateTime)
                    {
                        Value = Data.Date
                    },
                };
                db.Database.ExecuteSqlCommand("INSERT INTO CaThi (MaCa, GioThi) VALUES (@MaCa, @GioThi)", pa);
            }


            Thi aRecord = new Thi();

            aRecord.MaMonHoc = Data.SubjectID;
            aRecord.MaCa     = ShiftID;
            ClassList        = "";
            foreach (String cl in Data.Class)
            {
                ClassList += cl + ",";
            }
            ClassList    = ClassList.Remove(ClassList.Length - 1, 1);
            aRecord.Nhom = ClassList;
            String SQLQuery     = "";
            int    StudentIndex = 0;

            for (int Index = 0; Index < Data.Room.Count; Index++)
            {
                aRecord.MaPhong = Data.Room[Index];
                for (int i = 0; i < Data.Num[Index]; i++)
                {
                    aRecord.MaSinhVien = StudentList[StudentIndex].MaSinhVien;
                    SQLQuery          += String.Format("INSERT INTO Thi (MaCa, MaMonHoc, Nhom, MaPhong, MaSinhVien, Dot) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}','{5}')\r\n",
                                                       aRecord.MaCa,
                                                       aRecord.MaMonHoc,
                                                       aRecord.Nhom,
                                                       aRecord.MaPhong,
                                                       aRecord.MaSinhVien,
                                                       dot
                                                       );
                    StudentIndex++;
                }
                int RoomIndex = InputHelper.Rooms.Find(m => m.Time == Data.Date).Rooms.FindIndex(m => m.RoomID == aRecord.MaPhong);
                InputHelper.Rooms.Find(m => m.Time == Data.Date).Rooms[RoomIndex].IsBusy = true;
            }
            db.Database.ExecuteSqlCommand(SQLQuery);
            AlgorithmRunner.SaveOBJ("Rooms", InputHelper.Rooms);
        }