Ejemplo n.º 1
0
        /// <summary>
        /// Gets the selected file exporter.
        /// </summary>
        /// <returns>The file exporter.</returns>
        private IBooksFileExport GetSelectedFileExporter()
        {
            Type             exporterType = SelectedExportType.GetGeneratorClass();
            object           instance     = Activator.CreateInstance(exporterType);
            IBooksFileExport exporter     = (IBooksFileExport)instance;

            return(exporter);
        }
        private void ExportReports(object parameter)
        {
            Console.WriteLine($"Selected Report Type : {SelectedReportType}, Export : {SelectedExportType}");
            string         fileformats    = SelectedExportType.ToLower() == "pdf" ? "PDF (*.pdf) | *.pdf" : "Excel (*.xlsx) | *.xlsx; *.xls";
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = fileformats;
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            saveFileDialog.Title            = $"Export as {SelectedExportType}";
            if (saveFileDialog.ShowDialog() == true)
            {
                var fileInfo = new FileInfo(saveFileDialog.FileName);
                Console.WriteLine($"Filename : {saveFileDialog.FileName}, {fileInfo.Name}, {fileInfo.Directory.FullName}");
                switch (SelectedReportType.ToLower())
                {
                case "training report":
                    if (SelectedExportType.ToLower() == "excel")
                    {
                        Utility.ExportExcelReports.TrainingReport(Drivers.Where(x => x.IsSelected).ToList(), saveFileDialog.FileName);
                    }
                    else
                    {
                        ExportTrainingReportAsPDF(Drivers.Where(x => x.IsSelected).ToList(), saveFileDialog.FileName);
                    }
                    break;

                case "individual report":
                    if (SelectedExportType.ToLower() == "excel")
                    {
                        Utility.ExportExcelReports.IndividualDriversReport(Drivers.Where(x => x.IsSelected).ToList(), saveFileDialog.FileName);
                    }
                    else
                    {
                        ExportIndividualReportsAsPDF(Drivers.Where(x => x.IsSelected).ToList(), fileInfo.Name, fileInfo.Directory.FullName);
                    }
                    break;

                case "detailed lesson report":
                    if (SelectedExportType.ToLower() == "excel")
                    {
                        Utility.ExportExcelReports.DetailedLessonReport(Drivers.Where(x => x.IsSelected).ToList(), saveFileDialog.FileName);
                    }
                    else
                    {
                        ExportDetailedLessonReportsAsPDF(Drivers.Where(x => x.IsSelected).ToList(), fileInfo.Name, fileInfo.Directory.FullName);
                    }
                    break;
                }
            }
        }