PIbd-23_Starostin_I.K._Ship.../ShipyardView/FormReportShipComponents.cs

85 lines
3.2 KiB
C#
Raw Normal View History

2024-06-02 16:43:14 +04:00
using Microsoft.Extensions.Logging;
using ShipyardContracts.BindingModels;
using ShipyardContracts.BusinessLogicContracts;
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;
namespace ShipyardView
{
public partial class FormReportShipComponents : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportShipComponents(
ILogger<FormReportShipComponents> logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void SaveButton_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveShipComponentToExcelFile(
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);
}
}
}
private void FormReportShipComponents_Load(object sender, EventArgs e)
{
try
{
var dict = _logic.GetShipComponent();
if (dict != null)
{
dataGridView.Rows.Clear();
foreach (var elem in dict)
{
dataGridView.Rows.Add(new object[] { elem.ShipName, "", "" });
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);
}
}
}
}