private void btnBrowseCSV_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DisableUI();
                using (var ofd = new System.Windows.Forms.OpenFileDialog {
                    AddExtension = true, DefaultExt = ".csv", CheckFileExists = true, DereferenceLinks = true, Filter = "CSV files (*.csv)|*.csv", FilterIndex = 0, ValidateNames = true
                })
                {
                    if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        txtDataPath.Text = ofd.FileName;
                    }
                    if (string.IsNullOrWhiteSpace(txtDataPath.Text) || (File.Exists(txtDataPath.Text) == false))
                    {
                        MessageBox.Show("Please select a valid data file.", "Invalid input", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    _builder = new UScheduleBuilder();
                    ClearInfo();
                    lstSchedules.Items.Clear();
                    lstObligatorySubjects.ItemsSource = null;
                    lstObligatorySubjects.Items.Clear();
                    foreach (var classData in File.ReadAllLines(txtDataPath.Text).Select(a => a.Split(',')))
                    {
                        if (chkExcludeFullClasses.IsChecked ?? false)
                        {
                            if (classData[8] == classData[9])
                            {
                                continue;
                            }
                        }
                        TimeSpan[] times = classData[6].Split(' ').Select(a => TimeSpan.ParseExact(a, "h\\:mm", CultureInfo.InvariantCulture)).ToArray();
                        //UClass uClass = new UClass(course: new UCourse(int.Parse(classData[0]), int.Parse(classData[2]), classData[1]), instructorName: classData[4], days: DayOfWeekConverter.ToDays(classData[5].Split(' ').Select(a => a[0])), startTime: times[0], endTime: times[1], section: 0, capacity: 0, numberOfRegisteredStudents: 0, year: 2018, USemester.First);

                        //_builder.Classes.Add(uClass);
                    }
                    lstObligatorySubjects.ItemsSource = _builder.Classes.Select(a => a.Course).Distinct();
                    btnProcess.IsEnabled = true;
                }
            }
            finally
            {
                EnableUI();
            }
        }
Exemple #2
0
        private void BtnGenerate_Click(object sender, RoutedEventArgs e)
        {
            btnGenerate.IsEnabled = false;
            ClearSelectedSchedule();
            _lstSchedulesItems.Clear();
            if (ValidateConstraints() == false)
            {
                btnGenerate.IsEnabled = true;
                return;
            }
            UScheduleBuilder builder = new UScheduleBuilder();

            foreach (var cls in _classesModels.Values.Where(c => c.IsIncluded))
            {
                builder.Classes.Add(cls.Source);
            }
            foreach (var mandCls in lstMandatoryCourses.SelectedItems.OfType <UCourse>())
            {
                builder.ObligatoryCourses.Add(mandCls);
            }
            builder.Breaks.AddRange(_lstBreaksItems);
            foreach (var day in lstContraintDays.SelectedItems.OfType <DayOfWeek>())
            {
                builder.Days.Add(day);
            }
            builder.MinStartTime      = tmeConstraintMinStartTime.Value.Value.ToTimeSpan();
            builder.MaxStartTime      = tmeConstraintMaxStartTime.Value.Value.ToTimeSpan();
            builder.MinEndTime        = tmeConstraintMinEndTime.Value.Value.ToTimeSpan();
            builder.MaxEndTime        = tmeConstraintMaxEndTime.Value.Value.ToTimeSpan();
            builder.MinFinancialHours = udConstraintMinFinancialHours.Value.Value;
            builder.MaxFinancialHours = udConstraintMaxFinancialHours.Value.Value;
            foreach (var schedule in builder.Build())
            {
                _lstSchedulesItems.Add(new UScheduleListModel(schedule));
            }
            btnGenerate.IsEnabled = true;
        }