diff --git a/ProjectFamilyBudget/Forms/FormMoneyReport.Designer.cs b/ProjectFamilyBudget/Forms/FormMoneyReport.Designer.cs
new file mode 100644
index 0000000..97249c3
--- /dev/null
+++ b/ProjectFamilyBudget/Forms/FormMoneyReport.Designer.cs
@@ -0,0 +1,186 @@
+namespace ProjectFamilyBudget.Forms
+{
+ partial class FormMoneyReport
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ label1 = new Label();
+ label2 = new Label();
+ label3 = new Label();
+ label4 = new Label();
+ label5 = new Label();
+ textBoxFilePath = new TextBox();
+ buttonSelectFilePath = new Button();
+ comboBoxSelectIncome = new ComboBox();
+ comboBoxSelectExpense = new ComboBox();
+ dateTimePickerStart = new DateTimePicker();
+ dateTimePickerEnd = new DateTimePicker();
+ buttonMakeReport = new Button();
+ SuspendLayout();
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(21, 19);
+ label1.Name = "label1";
+ label1.Size = new Size(87, 15);
+ label1.TabIndex = 0;
+ label1.Text = "Путь до файла";
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(21, 64);
+ label2.Name = "label2";
+ label2.Size = new Size(41, 15);
+ label2.TabIndex = 1;
+ label2.Text = "Доход";
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(21, 111);
+ label3.Name = "label3";
+ label3.Size = new Size(45, 15);
+ label3.TabIndex = 2;
+ label3.Text = "Расход";
+ //
+ // label4
+ //
+ label4.AutoSize = true;
+ label4.Location = new Point(21, 164);
+ label4.Name = "label4";
+ label4.Size = new Size(74, 15);
+ label4.TabIndex = 3;
+ label4.Text = "Дата начала";
+ //
+ // label5
+ //
+ label5.AutoSize = true;
+ label5.Location = new Point(21, 205);
+ label5.Name = "label5";
+ label5.Size = new Size(68, 15);
+ label5.TabIndex = 4;
+ label5.Text = "Дата конца";
+ //
+ // textBoxFilePath
+ //
+ textBoxFilePath.Location = new Point(137, 16);
+ textBoxFilePath.Name = "textBoxFilePath";
+ textBoxFilePath.Size = new Size(152, 23);
+ textBoxFilePath.TabIndex = 5;
+ //
+ // buttonSelectFilePath
+ //
+ buttonSelectFilePath.Location = new Point(295, 16);
+ buttonSelectFilePath.Name = "buttonSelectFilePath";
+ buttonSelectFilePath.Size = new Size(25, 23);
+ buttonSelectFilePath.TabIndex = 6;
+ buttonSelectFilePath.Text = "..";
+ buttonSelectFilePath.UseVisualStyleBackColor = true;
+ buttonSelectFilePath.Click += buttonSelectFilePath_Click;
+ //
+ // comboBoxSelectIncome
+ //
+ comboBoxSelectIncome.FormattingEnabled = true;
+ comboBoxSelectIncome.Location = new Point(137, 61);
+ comboBoxSelectIncome.Name = "comboBoxSelectIncome";
+ comboBoxSelectIncome.Size = new Size(183, 23);
+ comboBoxSelectIncome.TabIndex = 7;
+ //
+ // comboBoxSelectExpense
+ //
+ comboBoxSelectExpense.FormattingEnabled = true;
+ comboBoxSelectExpense.Location = new Point(137, 108);
+ comboBoxSelectExpense.Name = "comboBoxSelectExpense";
+ comboBoxSelectExpense.Size = new Size(183, 23);
+ comboBoxSelectExpense.TabIndex = 8;
+ //
+ // dateTimePickerStart
+ //
+ dateTimePickerStart.Location = new Point(137, 158);
+ dateTimePickerStart.Name = "dateTimePickerStart";
+ dateTimePickerStart.Size = new Size(183, 23);
+ dateTimePickerStart.TabIndex = 9;
+ //
+ // dateTimePickerEnd
+ //
+ dateTimePickerEnd.Location = new Point(137, 199);
+ dateTimePickerEnd.Name = "dateTimePickerEnd";
+ dateTimePickerEnd.Size = new Size(183, 23);
+ dateTimePickerEnd.TabIndex = 10;
+ //
+ // buttonMakeReport
+ //
+ buttonMakeReport.Location = new Point(103, 237);
+ buttonMakeReport.Name = "buttonMakeReport";
+ buttonMakeReport.Size = new Size(138, 23);
+ buttonMakeReport.TabIndex = 11;
+ buttonMakeReport.Text = "Сформировать";
+ buttonMakeReport.UseVisualStyleBackColor = true;
+ buttonMakeReport.Click += buttonMakeReport_Click;
+ //
+ // FormMoneyReport
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(343, 282);
+ Controls.Add(buttonMakeReport);
+ Controls.Add(dateTimePickerEnd);
+ Controls.Add(dateTimePickerStart);
+ Controls.Add(comboBoxSelectExpense);
+ Controls.Add(comboBoxSelectIncome);
+ Controls.Add(buttonSelectFilePath);
+ Controls.Add(textBoxFilePath);
+ Controls.Add(label5);
+ Controls.Add(label4);
+ Controls.Add(label3);
+ Controls.Add(label2);
+ Controls.Add(label1);
+ Name = "FormMoneyReport";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "Отчет по движению денег";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label label1;
+ private Label label2;
+ private Label label3;
+ private Label label4;
+ private Label label5;
+ private TextBox textBoxFilePath;
+ private Button buttonSelectFilePath;
+ private ComboBox comboBoxSelectIncome;
+ private ComboBox comboBoxSelectExpense;
+ private DateTimePicker dateTimePickerStart;
+ private DateTimePicker dateTimePickerEnd;
+ private Button buttonMakeReport;
+ }
+}
\ No newline at end of file
diff --git a/ProjectFamilyBudget/Forms/FormMoneyReport.cs b/ProjectFamilyBudget/Forms/FormMoneyReport.cs
new file mode 100644
index 0000000..4fffe71
--- /dev/null
+++ b/ProjectFamilyBudget/Forms/FormMoneyReport.cs
@@ -0,0 +1,83 @@
+using ProjectFamilyBudget.Reports;
+using ProjectFamilyBudget.Repositories;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Unity;
+
+namespace ProjectFamilyBudget.Forms
+{
+ public partial class FormMoneyReport : Form
+ {
+ private readonly IUnityContainer _container;
+ public FormMoneyReport(IUnityContainer container, IIncome income, IExpense expense)
+ {
+ InitializeComponent();
+ _container = container ?? throw new ArgumentNullException(nameof(container));
+
+ comboBoxSelectIncome.DataSource = income.ReadIncome();
+ comboBoxSelectIncome.DisplayMember = "Name";
+ comboBoxSelectIncome.ValueMember = "Id";
+
+ comboBoxSelectExpense.DataSource = expense.ReadExpense();
+ comboBoxSelectExpense.DisplayMember = "Name";
+ comboBoxSelectExpense.ValueMember = "Id";
+ }
+
+ private void buttonSelectFilePath_Click(object sender, EventArgs e)
+ {
+ var sfd = new SaveFileDialog()
+ {
+ Filter = "Excel Files | *.xlsx"
+ };
+ if (sfd.ShowDialog() != DialogResult.OK)
+ {
+ return;
+ }
+ textBoxFilePath.Text = sfd.FileName;
+ }
+
+ private void buttonMakeReport_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(textBoxFilePath.Text))
+ {
+ throw new Exception("Отсутствует имя файла для отчета");
+ }
+ if (comboBoxSelectIncome.SelectedIndex < 0 || comboBoxSelectExpense.SelectedIndex < 0)
+ {
+ throw new Exception("Не выбран корм");
+ }
+ if (dateTimePickerEnd.Value <= dateTimePickerStart.Value)
+ {
+ throw new Exception("Дата начала должна быть раньше даты окончания");
+ }
+ if (_container.Resolve().CreateTable(textBoxFilePath.Text, (int)comboBoxSelectIncome.SelectedValue!, (int)comboBoxSelectExpense.SelectedValue!, dateTimePickerStart.Value, dateTimePickerEnd.Value))
+ {
+ MessageBox.Show("Документ сформирован",
+ "Формирование документа",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах",
+ "Формирование документа",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при создании очета",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+}
diff --git a/ProjectFamilyBudget/Forms/FormMoneyReport.resx b/ProjectFamilyBudget/Forms/FormMoneyReport.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectFamilyBudget/Forms/FormMoneyReport.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectFamilyBudget/Reports/TableReport.cs b/ProjectFamilyBudget/Reports/TableReport.cs
index 4e138d6..5092fd3 100644
--- a/ProjectFamilyBudget/Reports/TableReport.cs
+++ b/ProjectFamilyBudget/Reports/TableReport.cs
@@ -13,21 +13,21 @@ public class TableReport
private readonly IPeopleIncome _peopleIncomeRepository;
private readonly IPeopleExpense _peopleExpenseRepository;
private readonly ILogger _logger;
- internal static readonly string[] item = ["Человек", "Дата", "Заработано", "Потрачено"];
+ internal static readonly string[] item = ["Название операции", "Дата", "Заработано", "Потрачено"];
public TableReport(IPeopleIncome peopleIncomeRepository, IPeopleExpense peopleExpenseRepository, ILogger logger)
{
_peopleIncomeRepository = peopleIncomeRepository ?? throw new ArgumentNullException(nameof(peopleIncomeRepository));
_peopleExpenseRepository = peopleExpenseRepository ?? throw new ArgumentNullException(nameof(peopleExpenseRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
- public bool CreateTable(string filePath, int peopleIncomeId, DateTime startDate, DateTime endDate)
+ public bool CreateTable(string filePath, int incomeId, int expenseId, DateTime startDate, DateTime endDate)
{
try
{
new ExcelBuilder(filePath)
.AddHeader("Сводка по движению денег", 0, 3)
.AddParagraph("за период", 0)
- .AddTable([10, 15, 15], GetData(sumId, startDate, endDate))
+ .AddTable([15, 10, 15, 15], GetData(incomeId, expenseId, startDate, endDate))
.Build();
return true;
}
@@ -37,36 +37,24 @@ public class TableReport
return false;
}
}
- private List GetData(int peopleIncomeId, DateTime startDate, DateTime endDate)
+ private List GetData(int incomeId,int expenseId, DateTime startDate, DateTime endDate)
{
var data = _peopleIncomeRepository
- .ReadPeopleIncome()
- .Where(x => x.DataReciept >= startDate && x.DataReciept <= endDate && x.IncomePeopleIncomes.Any(y => y.PeopleIncomeId == peopleIncomeId))
- .Select(x => new { x.PeopleId, Date = x.DataReciept, CountIn = x.IncomePeopleIncomes.FirstOrDefault(y => y.PeopleIncomeId == peopleIncomeId)?.Count, CountOut = (int?)null })
- .Union(
- _peopleExpenseRepository
- .ReadPeopleExpense()
- .Where(x => x.DataReciept >= startDate && x.DataReciept <= endDate && x.ExpensePeopleExpenses.Any(y => y.PeopleExpenseId == fuelId))
- .Select(x => new { Date = x.SaleDate, CountIn = (int?)null, CountOut = x.FuelFuelSale.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity })
- )
- .OrderBy(x => x.Date);
-
- var groupedData = data
- .GroupBy(x => x.Date)
- .Select(g => new
- {
- Date = g.Key,
- TotalIn = g.Sum(x => x.CountIn),
- TotalOut = g.Sum(x => x.CountOut)
- })
+ .ReadPeopleIncome()
+ .Where(x => x.DataReciept >= startDate && x.DataReciept <= endDate && x.IncomePeopleIncomes.Any(y => y.IncomeId == incomeId))
+ .Select(x => new { x.PeopleId, Date = x.DataReciept, CountIn = x.IncomePeopleIncomes.FirstOrDefault(y => y.IncomeId == incomeId)?.Sum, CountOut = (int?)null })
+ .Union(
+ _peopleExpenseRepository
+ .ReadPeopleExpense()
+ .Where(x => x.DataReciept >= startDate && x.DataReciept <= endDate && x.ExpensePeopleExpenses.Any(y => y.ExpenseId == expenseId))
+ .Select(x => new { x.PeopleId, Date = x.DataReciept, CountIn = (int?)null, CountOut = x.ExpensePeopleExpenses.FirstOrDefault(predicate: y => y.ExpenseId == expenseId)?.Sum }))
.OrderBy(x => x.Date);
return
new List() { item }
- .Union(groupedData
- .Select(x => new string[] { x.Date.ToString("dd.MM.yyyy"), x.TotalIn.ToString()!, x.TotalOut.ToString()! }))
+ .Union(data.Select(x => new string[] {x.PeopleId.ToString(), x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty,x.CountOut?.ToString() ?? string.Empty }))
.Union(
- new[] { new string[] { "Всего", groupedData.Sum(x => x.TotalIn).ToString()!, groupedData.Sum(x => x.TotalOut).ToString()! } }
+ [[ "Всего", "", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString() ]]
)
.ToList();
}