private void Save(Schedule schedule) { int numberOfRooms = Configuration.GetInstance.GetNumberOfRooms(); int daySize = schedule.day_Hours * numberOfRooms; var db = new LINQDataContext(); db.Classroom_TimeDeleteAll(); foreach (KeyValuePair<CourseClass, int> it in schedule.GetClasses().ToList()) { // coordinate of time-space slot int pos = it.Value; // int pos of _slot array int day = pos / daySize; int time = pos % daySize; // this is not time now! int room = time / schedule.day_Hours; time = time % schedule.day_Hours; // this is a time now! int dur = it.Key.GetDuration; CourseClass cc = it.Key; Algorithm.Room r = Configuration.GetInstance.GetRoomById(room); // // Save Classroom_Time // db.Classroom_TimeSave(r.Origin_ID_inDB, cc.Class_ID, cc.GetProfessor.GetId, time, dur, day); // // Save New_GroupsPerClassroom // foreach (var gs in cc.GetGroups) { db.New_GroupsPerClassSave(r.Origin_ID_inDB, cc.Class_ID, time, day, gs.GetId); } } }
public void SetSchedule(Schedule schedule, bool showGraphical) { _schedule = schedule.MakeCopy(false); if (Monitor.TryEnter(Locker, 500)) { //_resultWindow.Controls["lblFitness"].Text = schedule.GetFitness().ToString(); SetText("Fitness: " + schedule.GetFitness().ToString()); Monitor.Exit(Locker); } else return; if (showGraphical) { // // ReSet to New DataGridView // foreach (KeyValuePair<int, DataGridView> it in dgvList) { ClearDataGridView(it.Value); } // int numberOfRooms = Configuration.GetInstance.GetNumberOfRooms(); int daySize = schedule.day_Hours * numberOfRooms; Random rand = new Random(); foreach (KeyValuePair<CourseClass, int> it in schedule.GetClasses().ToList()) { // coordinate of time-space slot int pos = it.Value; // int pos of _slot array int day = pos / daySize; int time = pos % daySize; // this is not time now! int room = time / schedule.day_Hours; time = time % schedule.day_Hours; // this is a time now! int dur = it.Key.GetDuration; CourseClass cc = it.Key; Room r = Configuration.GetInstance.GetRoomById(room); string groups_Name = ""; foreach (var gs in cc.GetGroups) { groups_Name += gs.GetName + "\r\n"; } groups_Name = groups_Name.Trim(); ((DataGridViewTextBoxCellEx)dgvList[r.GetId][day + 1, time]).RowSpan = cc.GetDuration; dgvList[r.GetId][day + 1, time].Style.BackColor = Color.FromArgb(rand.Next(70, 250), rand.Next(70, 250), rand.Next(70, 250)); dgvList[r.GetId][day + 1, time].Value = string.Format(CultureInfo.CurrentCulture, "{0}\r\n{1}\r\n{2}\r\n{3}", cc.GetCourse.GetName, cc.GetProfessor.GetName, groups_Name, cc.Lab); //(cc.GetCourse.GetName + Environment.NewLine + // cc.GetProfessor.GetName + Environment.NewLine + // groups_Name + Environment.NewLine + cc.Lab); } } }