private void ResultForm_Load(object sender, EventArgs e)
        {
            rooms         = roomReader.GetRooms();
            courses       = courseReader.GetCourses();
            prelectors    = prelectorReader.GetPrelectors();
            studentGroups = studentGroupReader.GetStudentGroups();

            courseClassReader.ResetData();
            if (_isExamProblem)
            {
                courseClasses = courseClassReader.GetCourseClasses();
            }
            else
            {
                courseClasses = courseClassReader.GetCourseClassesWithoutRoomSplit();
            }

            prelectors    = prelectorReader.UpdateCourseClasses(courseClasses);
            studentGroups = studentGroupReader.UpdateCourseClasses(courseClasses);

            Configuration.GetInstance.InitializeDate(prelectors, studentGroups, courses, rooms, courseClasses);

            btnPause.Enabled = false;
            btnStop.Enabled  = false;

            if (Algorithm.Configuration.GetInstance.GetNumberOfRooms() > 0)
            {
                _createGridView = new CreateDataGridViews(Configuration.GetInstance.Rooms, this);
                Schedule prototype = new Schedule(int.Parse(PARAMETER_NUMBER_OF_CROSSOVER_POINTS), int.Parse(PARAMETER_MUTAITION_SIZE),
                                                  int.Parse(PARAMETER_CROSSOVER_PROBABILITY), int.Parse(PARAMETER_MUTAITION_PROBABILITY), _isExamProblem);
                Schedule.ScheduleObserver sso = new Schedule.ScheduleObserver();
                sso.SetWindow(_createGridView);

                _algorithm = new Algorithm.Algorithm(int.Parse(PARAMETER_NUMBER_OF_CHROMOSOMES), int.Parse(PARAMETER_REPLACE_BY_GENERATION),
                                                     int.Parse(PARAMETER_TRACK_BEST), prototype, sso, _isExamProblem);

                _state = ThreadState.Unstarted;
                timerWorkingSet.Start();
            }
            else
            {
                MessageBox.Show("Not found any room!", "Number of Rooms Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                timerWorkingSet.Stop();
                _algorithm = null;
                Dispose();
                return;
            }

            if (Configuration.GetInstance.GetNumberOfCourseClasses() <= 0)
            {
                btnStart.Enabled = false;
            }
        }
Example #2
0
        private void CollectData()
        {
            _roomReader.ResetData();
            _courseReader.ResetData();
            _prelectorReader.ResetData();
            _courseClassReader.ResetData();
            _studentGroupReader.ResetData();

            try
            {
                _rooms = _roomReader.GetRooms();
            } catch (Exception _ex)
            {
                MessageBox.Show("Sınıf verileri okunurken hata oluştu!", "Veri Okuma Hatası", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            try
            {
                _courses = _courseReader.GetCourses();
            }
            catch (Exception _ex)
            {
                MessageBox.Show("Ders verileri okunurken hata oluştu!", "Veri Okuma Hatası", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            try
            {
                _prelectors = _prelectorReader.GetPrelectors();
            }
            catch (Exception _ex)
            {
                MessageBox.Show("Öğretim görevlisi verileri okunurken hata oluştu!", "Veri Okuma Hatası", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            try
            {
                _courseClasses = _courseClassReader.GetCourseClasses();
            }
            catch (Exception _ex)
            {
                MessageBox.Show("Ders oturumu verileri okunurken hata oluştu!", "Veri Okuma Hatası", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            try
            {
                _studentGroups = _studentGroupReader.GetStudentGroups();
            }
            catch (Exception _ex)
            {
                MessageBox.Show("Öğrenci grubu verileri okunurken hata oluştu!", "Veri Okuma Hatası", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            UpdateDashboard();
        }
        private void SaveGroupsSchedule(Schedule schedule, List <KeyValuePair <CourseClass, int> > courseClasses)
        {
            List <StudentGroup> _allGroups = _studentGroupReader.GetStudentGroups();
            int _sheetCount = ((int)_allGroups.Count / 10) + 1;

            int _groupsPosition = 0;

            for (int i = 1; i <= _sheetCount; i++)
            {
                int _groupCountInThisSheet = Math.Min(10, _allGroups.Count - _groupsPosition);
                if (_groupCountInThisSheet == 0)
                {
                    break;
                }

                string              _sheetName = SHEET_NAME_GROUPS + (i > 1 ? $" {i}" : "");
                ExcelWorksheet      _ws        = CreateWorksheet(_sheetName);
                List <StudentGroup> _groups    = _allGroups.GetRange(_groupsPosition, _groupCountInThisSheet);
                _groupsPosition += _groupCountInThisSheet;

                int _startRow = 0;
                _groups.ForEach(r =>
                {
                    CreateTable(_ws, r.Name, _startRow);
                    _startRow += TIME_SPANS.Length + 1 + TABLE_ROW_SPACING;
                });

                int _numberOfRooms = Algorithm.Configuration.GetInstance.GetNumberOfRooms();
                int _daySize       = schedule.day_Hours * _numberOfRooms;

                _groups.ForEach(group =>
                {
                    foreach (KeyValuePair <CourseClass, int> it in courseClasses.Where(cc => cc.Key.StudentGroups.Contains(group)).ToList())
                    {
                        int _pos    = it.Value;
                        int _day    = _pos / _daySize;
                        int _time   = _pos % _daySize;
                        int _roomId = _time / schedule.day_Hours;
                        _startRow   = _groups.IndexOf(group) * (TABLE_ROW_SPACING + 1 + TIME_SPANS.Length);
                        _time       = (_time % schedule.day_Hours) + _startRow;
                        int _dur    = it.Key.Duration;

                        CourseClass _cc = it.Key;
                        Room _room      = Algorithm.Configuration.GetInstance.GetRoomById(_roomId);

                        string groups_Name = "";
                        foreach (var gs in _cc.StudentGroups)
                        {
                            groups_Name += gs.Name + "  ";
                        }
                        groups_Name = groups_Name.Trim();

                        _ws.Cells[_time + 1, _day + 1].Value = $"{_cc.Course.Name}\n{_cc.Prelector.Name}\n{_room.Name}";
                        _ws.Cells[_time + 1, _day + 1].Style = _anyCellStyle;

                        // Merge Cells
                        try
                        {
                            if (_cc.Duration > 1)
                            {
                                _ws.Cells.GetSubrangeAbsolute(_time + 1, _day + 1, _time + _dur, _day + 1).Merged = true;
                            }
                            _ws.Cells[_time + 1, _day + 1].Style = _anyCellStyle;
                        }
                        catch
                        {
                            _ws.Cells[_time + 1, _day + 1].Style.Font.Color = Color.DarkRed;
                        }
                    }
                });
            }
        }