Esempio n. 1
0
        /// <summary>
        /// Write the schedule of an instructor to an Excel sheet.
        /// </summary>
        /// <param name="teacherCourseSchedule">Schedule of a teacher's courses.</param>
        /// <param name="roomRepo">The collection of rooms.</param>
        /// <param name="teacherName">The name of an instructor</param>
        public void PrintSchedule(ITeacherScheduleRepository teacherCourseSchedule, IRoomRepository roomRepo, string teacherName)
        {
            List <Course> courses = teacherCourseSchedule.Courses.ToList();

            var coursesInRoom = from course in courses
                                where (course.State == Course.CourseState.Assigned && course.MeetingDays != null) ||
                                (course.State != Course.CourseState.Assigned || course.MeetingDays == null) ||
                                (course.State != Course.CourseState.Assigned || course.MeetingDays != null)
                                group course by new { name = course.Instructor, roomNameAssignment = course.RoomAssignment };

            ISheet sheet = _workbook.CloneSheet(_workbook.GetSheetIndex(_scheduleTemplate));

            foreach (var courseGroup in coursesInRoom)
            {
                Room room       = courseGroup.Key.roomNameAssignment;
                var  sheetIndex = _workbook.GetSheetIndex(sheet);

                _workbook.SetSheetName(sheetIndex, teacherName);
                _workbook.SetSheetHidden(sheetIndex, SheetState.Visible);

                PrintCourses(sheet, courseGroup.ToList());
                printLegend(sheet);
            }

            _workbook.SortWorksheets();
            _workbook.SetActiveSheet(0);

            _workbook.WriteToFile(_outputFile);
        }
 /// <summary>
 /// Constructor for ScheduleVisualization. Sets passed parameters.
 /// </summary>
 /// <param name="courseRepo">The collection of courses.</param>
 /// <param name="roomRepo">The collection of rooms.</param>
 /// <param name="printer">Printer for the Excel schedules.</param>
 /// <param name="teacherName">Name of a teacher.</param>
 /// <param name="teacherSchedule">Collection of teachers' schedules.</param>
 public ScheduleVisualization(ICourseRepository courseRepo, IRoomRepository roomRepo, ISchedulePrinter printer, string teacherName, ITeacherScheduleRepository teacherSchedule)
 {
     CourseRepo      = courseRepo;
     RoomRepo        = roomRepo;
     Printer         = printer;
     TeacherName     = teacherName;
     TeacherSchedule = teacherSchedule;
 }
Esempio n. 3
0
        /// <summary>
        /// Create an Excel workbook of a teacher's schedule.
        /// </summary>
        /// <param name="sender">A reference to the control/object that raised the event.</param>
        /// <param name="e">State information and event data associated with a routed event.</param>
        private void Teacher_Export_Click(object sender, RoutedEventArgs e)
        {
            if (ViewModel.Conflicts.Count != 0)
            {
                string           message = "Exporting to Excel while there are conflicts may result in incorrect output. Do you wish to continue with the export?";
                string           caption = "Export to Excel";
                MessageBoxImage  icon    = MessageBoxImage.Warning;
                MessageBoxButton button  = MessageBoxButton.YesNo;
                MessageBoxResult result  = System.Windows.MessageBox.Show(message, caption, button, icon);

                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }

            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
            saveFileDialog.Filter = "Excel Worksheets|*.xls";
            if (saveFileDialog.ShowDialog() == true)
            {
                var fileName     = saveFileDialog.FileName;
                var templateFile = System.IO.Path.Combine(Environment.CurrentDirectory, "ClassroomGridTemplate.xls");
                using (var fileStream = File.OpenRead(templateFile))
                {
                    IWorkbook workbook = new HSSFWorkbook(fileStream);
                    workbook.RemoveSheetAt(workbook.GetSheetIndex("Sheet1"));

                    workbook.MissingCellPolicy = MissingCellPolicy.CREATE_NULL_AS_BLANK;
                    ExcelSchedulePrinter printer          = new ExcelSchedulePrinter(fileName, workbook);
                    ICourseRepository    courseRepository = CourseRepository.GetInstance();
                    //ITeacherScheduleRepository courseSchedule = TeacherScheduleRepository.GetInstance();
                    TeacherScheduleRepository.InitInstance(CoursesForCurrentTeacher);
                    ITeacherScheduleRepository courseSchedule = TeacherScheduleRepository.GetInstance();
                    //ICourseRepository export_courses = (ICourseRepository)CoursesForCurrentTeacher;

                    new ScheduleVisualization(courseRepository, null, printer, SuggestedTeacherlistBox.SelectedValue.ToString(), courseSchedule).PrintTeacherSchedule();
                    //new ScheduleVisualization(export_courses, null, printer).PrintSchedule();
                }
            }
        }
 /// <summary>
 /// Initilize courseRepo to courseRepository.
 /// </summary>
 /// <param name="courseRepo">The collection of courses</param>
 public AssignmentConflictDetectorSchedule(ITeacherScheduleRepository courseSchedule)
 {
     CourseSchedule = courseSchedule;
 }