2024-03-23 22:01:27 +04:00
|
|
|
|
using PlumbingRepairContracts.BindingModels;
|
|
|
|
|
using PlumbingRepairContracts.BusinessLogicsContracts;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
2024-04-19 19:10:14 +04:00
|
|
|
|
namespace PlumbingRepairView
|
2024-03-23 22:01:27 +04:00
|
|
|
|
{
|
|
|
|
|
public partial class FormReportWorkComponents : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IReportLogic _logic;
|
|
|
|
|
|
|
|
|
|
public FormReportWorkComponents(ILogger<FormReportWorkComponents> logger, IReportLogic logic)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormReportWorkComponents_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var dict = _logic.GetWorkComponent();
|
|
|
|
|
if (dict != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.Rows.Clear();
|
|
|
|
|
foreach (var elem in dict)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.Rows.Add(new object[] { elem.WorkName, "", "" });
|
|
|
|
|
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.SaveWorkComponentToExcelFile(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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|