83 lines
3.0 KiB
C#
83 lines
3.0 KiB
C#
|
using ProjectGarage.Reports;
|
|||
|
using ProjectGarage.Repositories;
|
|||
|
using ProjectGarage.Repositories.Implementations;
|
|||
|
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 ProjectGarage.Forms
|
|||
|
{
|
|||
|
public partial class FormFuelReport : Form
|
|||
|
{
|
|||
|
private readonly IUnityContainer _container;
|
|||
|
|
|||
|
public FormFuelReport(IUnityContainer container, IFuelRepository fuelRepository)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
|||
|
comboBoxFuelReport.DataSource = fuelRepository.ReadFuels();
|
|||
|
comboBoxFuelReport.DisplayMember = "FuelName";
|
|||
|
comboBoxFuelReport.ValueMember = "Id";
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonMakeReport_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (string.IsNullOrWhiteSpace(textBoxFilePath.Text))
|
|||
|
{
|
|||
|
throw new Exception("Отсутствует имя файла для отчета");
|
|||
|
}
|
|||
|
if (comboBoxFuelReport.SelectedIndex < 0)
|
|||
|
{
|
|||
|
throw new Exception("Не выбран корм");
|
|||
|
}
|
|||
|
if (dateTimePickerFinal.Value <= dateTimePickerStart.Value)
|
|||
|
{
|
|||
|
throw new Exception("Дата начала должна быть раньше даты окончания");
|
|||
|
}
|
|||
|
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text,
|
|||
|
(int)comboBoxFuelReport.SelectedValue!,
|
|||
|
dateTimePickerStart.Value, dateTimePickerFinal.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);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|