70 lines
2.8 KiB
C#
70 lines
2.8 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using PizzeriaContracts.BindingModels;
|
|
using PizzeriaContracts.BusinessLogicsContracts;
|
|
|
|
namespace PizzeriaView
|
|
{
|
|
public partial class FormReportPizzaComponents : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IReportLogic _logic;
|
|
|
|
public FormReportPizzaComponents(ILogger<FormReportPizzaComponents> logger, IReportLogic logic)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_logic = logic;
|
|
}
|
|
|
|
private void FormReportPizzaComponents_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var dict = _logic.GetPizzaComponents();
|
|
if (dict != null)
|
|
{
|
|
dataGridView.Rows.Clear();
|
|
foreach (var elem in dict)
|
|
{
|
|
dataGridView.Rows.Add(new object[] { elem.PizzaName, "", "" });
|
|
foreach (var listElem in elem.Components)
|
|
{
|
|
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
|
|
}
|
|
dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount });
|
|
dataGridView.Rows.Add(Array.Empty<object>());
|
|
}
|
|
}
|
|
_logger.LogInformation("Загрузка списка пиццы по компонентам");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка загрузки списка пицц по компонентам");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonSaveToExcel_Click(object sender, EventArgs e)
|
|
{
|
|
using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" };
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
try
|
|
{
|
|
_logic.SavePizzaComponentToExcelFile(new ReportBindingModel
|
|
{
|
|
FileName = dialog.FileName
|
|
});
|
|
_logger.LogInformation("Сохранение списка пиццы по компонентам");
|
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка сохранения списка пиццы по компонентам");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|