2024-11-29 19:46:50 +04:00
|
|
|
|
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)
|
|
|
|
|
{
|
2024-12-01 16:33:11 +04:00
|
|
|
|
throw new Exception("Не выбран доход или расход");
|
2024-11-29 19:46:50 +04:00
|
|
|
|
}
|
|
|
|
|
if (dateTimePickerEnd.Value <= dateTimePickerStart.Value)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Дата начала должна быть раньше даты окончания");
|
|
|
|
|
}
|
2024-12-01 16:33:11 +04:00
|
|
|
|
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxSelectIncome.SelectedValue!,
|
|
|
|
|
(int)comboBoxSelectExpense.SelectedValue!, dateTimePickerStart.Value, dateTimePickerEnd.Value))
|
2024-11-29 19:46:50 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Документ сформирован",
|
|
|
|
|
"Формирование документа",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах",
|
|
|
|
|
"Формирование документа",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при создании очета",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|