78 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 FormExpenseReport : Form
{
private string _fileName = string.Empty;
private readonly IUnityContainer _container;
public FormExpenseReport(IUnityContainer container, IExpense expense)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
comboBoxSelectExpense.DataSource = expense.ReadExpense();
comboBoxSelectExpense.DisplayMember = "Name";
comboBoxSelectExpense.ValueMember = "Id";
}
private void buttonSelectFile_Click(object sender, EventArgs e)
{
var sfd = new SaveFileDialog()
{
Filter = "Pdf Files | *.pdf"
};
if (sfd.ShowDialog() == DialogResult.OK)
{
_fileName = sfd.FileName;
labelFile.Text = Path.GetFileName(_fileName);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(_fileName))
{
throw new Exception("Отсутствует имя файла для отчета");
}
if (comboBoxSelectExpense.SelectedIndex < 0)
{
throw new Exception("Не выбран расход");
}
if
(_container.Resolve<ChartReport>().CreateChart(_fileName, (int)comboBoxSelectExpense.SelectedValue!,dateTimePicker.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);
}
}
}
}