private void GenerateReportButton_Click(object sender, EventArgs e) { CompletenessReportGenerator completenessReportGenerator; double level4Threshold; double level3Threshold; using (FileDialog fileDialog = new SaveFileDialog()) { fileDialog.DefaultExt = "pdf"; fileDialog.Filter = "PDF files|*.pdf|All files|*.*"; if (fileDialog.ShowDialog() == DialogResult.OK) { completenessReportGenerator = new CompletenessReportGenerator() { TitleText = TitleTextTextBox.Text, CompanyText = CompanyTextTextBox.Text, ReportDate = new DateTime(ReportDateDateTimePicker.Value.Ticks, DateTimeKind.Utc), Level4Alias = Level4AliasTextBox.Text, Level3Alias = Level3AliasTextBox.Text }; if (double.TryParse(Level4ThresholdTextBox.Text, out level4Threshold)) completenessReportGenerator.Level4Threshold = level4Threshold; if (double.TryParse(Level3ThresholdTextBox.Text, out level3Threshold)) completenessReportGenerator.Level3Threshold = level3Threshold; completenessReportGenerator.GenerateReport().Save(fileDialog.FileName); } } }
private static void GenerateCompletenessReport() { CompletenessReportGenerator completenessReportGenerator = new CompletenessReportGenerator(); Arguments args = new Arguments(Environment.CommandLine, true); string arg; string reportLocation = ""; string reportFileName = ""; DateTime reportDate = DateTime.UtcNow; double threshold; if (TryGetValue(args, "archiveLocation", out arg)) completenessReportGenerator.ArchiveLocation = arg; if (TryGetValue(args, "reportLocation", out arg)) reportLocation = arg; if (TryGetValue(args, "reportFileName", out arg)) reportFileName = arg; if (TryGetValue(args, "title", out arg)) completenessReportGenerator.TitleText = arg; if (TryGetValue(args, "company", out arg)) completenessReportGenerator.CompanyText = arg; if (TryGetValue(args, "reportDate", out arg) && DateTime.TryParse(arg, out reportDate)) { if (reportDate.Kind == DateTimeKind.Unspecified) reportDate = new DateTime(reportDate.Ticks, DateTimeKind.Utc); completenessReportGenerator.ReportDate = reportDate; } if (TryGetValue(args, "level4Threshold", out arg) && double.TryParse(arg, out threshold)) completenessReportGenerator.Level4Threshold = threshold; if (TryGetValue(args, "level3Threshold", out arg) && double.TryParse(arg, out threshold)) completenessReportGenerator.Level3Threshold = threshold; if (TryGetValue(args, "level4Alias", out arg)) completenessReportGenerator.Level4Alias = arg; if (TryGetValue(args, "level3Alias", out arg)) completenessReportGenerator.Level3Alias = arg; if (string.IsNullOrEmpty(reportFileName)) reportFileName = string.Format("{0} {1:yyyy-MM-dd}.pdf", completenessReportGenerator.TitleText, completenessReportGenerator.ReportDate); reportLocation = FilePath.GetAbsolutePath(reportLocation); if (!Directory.Exists(reportLocation)) Directory.CreateDirectory(reportLocation); string reportFilePath = Path.Combine(reportLocation, reportFileName); // Generate PDF report completenessReportGenerator.GenerateReport().Save(reportFilePath); // E-mail PDF report if parameters were provided EmailReport(args, string.Format("{0} {1} for {2:MMMM dd, yyyy}", completenessReportGenerator.CompanyText, completenessReportGenerator.TitleText, reportDate), reportFilePath); }