private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { ChangeVis(this.SelectedYear.Value != null ? Visibility.Visible : Visibility.Hidden); if (this.Grid.Visibility == Visibility.Hidden) return; this.ReportData = new FinancialReport(PurchaseAndSales.GroupedData, (int) this.SelectedYear.Value); this.FinancialGrid.ItemsSource = this.ReportData.PurchasesAndSales; this.Minus.Text = this.ReportData.Purchases + ""; this.Plus.Text = this.ReportData.Sales + ""; this.Equals.Text = this.ReportData.Result + ""; }
public IDataExportService ExportFinancialReport(FinancialReport report) { this.loggingService.WriteLine("Beginning export of financial report..."); var dialog = new SaveFileDialog { Filter = this.GenerateFilter(), InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), FileName = report.Year + "-scrooge-financial-report", DefaultExt = ".xlsx", CheckPathExists = true }; this.loggingService.WriteLine("Activating SaveFileDialog..."); var result = dialog.ShowDialog(); if (result.GetValueOrDefault(false)) { this.loggingService.WriteLine("User confirmed"); var ext = Path.GetExtension(dialog.FileName)?.Substring(1); var serializer = ext == null ? null : (this.serializers.ContainsKey(ext) ? this.serializers[ext] : null); if (serializer == null) { this.loggingService.WriteLine("No file type specified - uh oh..."); MessageBox.Show("You have to specify a file type!", "Error"); // No styling, shouldn't happen anyway return this; } this.loggingService.WriteLine("Using serializer: " + ext); serializer.SerializeFinancialReport(report, dialog.FileName); this.loggingService.WriteLine("Exporting done."); } else { this.loggingService.WriteLine("Exporting aborted."); } return this; }
public DataCell[][] FinancialReportToCellData(FinancialReport report) { var data = new List<DataCell[]> { new[] { new DataCell("Financial report - " + report.Year, DataCellType.HeadingBig), DataCell.Empty, DataCell.Empty }, new[] {DataCell.Empty, DataCell.Empty, DataCell.Empty}, new[] { new DataCell("Name", DataCellType.Heading, DataCellOutline.Bottom), new DataCell("Income", DataCellType.Heading, DataCellOutline.Bottom), new DataCell("Expenses", DataCellType.Heading, DataCellOutline.Bottom) } }; data.AddRange( report.PurchasesAndSales.Where(x => x.Type == EntryType.Sale).Select(groupedPurchaseAndSales => new[] { new DataCell(groupedPurchaseAndSales.GroupName, DataCellType.Text), new DataCell(groupedPurchaseAndSales.PurchaseAndSales.Sum(x => x.Value).ToString(), DataCellType.Number), DataCell.Empty })); data.AddRange( report.PurchasesAndSales.Where(x => x.Type == EntryType.Purchase) .Select(groupedPurchaseAndSales => new[] { new DataCell(groupedPurchaseAndSales.GroupName, DataCellType.Text), DataCell.Empty, new DataCell(groupedPurchaseAndSales.PurchaseAndSales.Sum(x => x.Value).ToString(), DataCellType.Number) })); data.Add(new[] { new DataCell("Sum", DataCellType.Heading, DataCellOutline.Top), new DataCell(report.Sales.ToString(), DataCellType.ResultGood, DataCellOutline.Top), new DataCell(report.Purchases.ToString(), DataCellType.ResultBad, DataCellOutline.Top) }); if (report.Result >= 0) { data.Add(new[] { new DataCell("Profit", DataCellType.Heading, DataCellOutline.Top), new DataCell(report.Result.ToString(), DataCellType.ResultGood, DataCellOutline.Top), new DataCell("", DataCellType.Text, DataCellOutline.Top) }); } else { data.Add(new[] { new DataCell("Loss", DataCellType.Heading, DataCellOutline.Top), new DataCell("", DataCellType.Text, DataCellOutline.Top), new DataCell((-report.Result).ToString(), DataCellType.ResultBad, DataCellOutline.Top) }); } return data.ToArray(); }
public void SerializeFinancialReport(FinancialReport report, string filename) { var cellData = Singleton<DataSerializationHelper>.Instance.FinancialReportToCellData(report); PDFDataSerializer.WriteToPDF(cellData, filename); }