2024-04-25 18:59:25 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SushiBarContracts.BindingModels;
|
|
|
|
|
using SushiBarContracts.BusinessLogicsContracts;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace SushiBarView
|
|
|
|
|
{
|
|
|
|
|
public partial class FormReportSushiComponents : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IReportLogic _logic;
|
|
|
|
|
public FormReportSushiComponents(ILogger<FormReportSushiComponents>
|
|
|
|
|
logger, IReportLogic logic)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
|
|
|
|
private void FormReportSushiComponents_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var dict = _logic.GetSushiComponent();
|
|
|
|
|
if (dict != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridViewExcel.Rows.Clear();
|
|
|
|
|
foreach (var elem in dict)
|
|
|
|
|
{
|
2024-04-25 23:32:23 +04:00
|
|
|
|
dataGridViewExcel.Rows.Add(new object[] { elem.SushiName, "", "" });
|
|
|
|
|
foreach (var listElem in elem.Components)
|
2024-04-25 18:59:25 +04:00
|
|
|
|
{
|
|
|
|
|
dataGridViewExcel.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
|
|
|
|
|
}
|
|
|
|
|
dataGridViewExcel.Rows.Add(new object[] { "Итого", "", elem.TotalCount });
|
|
|
|
|
dataGridViewExcel.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.SaveSushiComponentToExcelFile(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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|