PIbd-23-Nasyrov-A.G.-Flower.../ProjectFlowerShop/FormReportFlowerComponent.cs

89 lines
3.1 KiB
C#
Raw Normal View History

2024-03-26 18:10:51 +04:00
using FlowerShopContracts.BusinessLogicsContracts;
using FlowerShopContracts.BindingModels;
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 Microsoft.Extensions.Logging;
namespace ProjectFlowerShop
{
public partial class FormReportFlowerComponent : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportFlowerComponent(ILogger<FormReportFlowerComponent> logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void buttonSaveToExcel_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveFlowerComponentToExcelFile(new ReportBindingModel
{
FileName = dialog.FileName
});
2024-03-26 18:29:32 +04:00
_logger.LogInformation("Сохранение списка изделий по компонентам");
2024-03-26 18:10:51 +04:00
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception ex)
{
2024-03-26 18:29:32 +04:00
_logger.LogError(ex, "Ошибка сохранения списка изделий по компонентам");
2024-03-26 18:10:51 +04:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void FormReportFlowerComponent_Load(object sender, EventArgs e)
{
try
{
var dict = _logic.GetFlowerComponent();
if (dict != null)
{
dataGridView.Rows.Clear();
foreach (var elem in dict)
{
dataGridView.Rows.Add(new object[] { elem.FlowerName, "", "" });
foreach (var listElem in elem.Components)
2024-03-26 18:10:51 +04:00
{
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);
}
}
}
}