PIbd-23_Abazov_A.A._Constru.../ConstructionCompany/ConstructionCompanyView/FormMaterialOrders.cs

69 lines
2.1 KiB
C#
Raw Normal View History

using ConstructionCompanyContracts.BusinessLogicContracts;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
2023-04-21 19:48:18 +04:00
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConstructionCompanyView
{
public partial class FormMaterialOrders : Form
{
private readonly ILogger _logger;
private readonly IMaterialOrderLogic _logic;
public FormMaterialOrders(ILogger<FormMaterialOrders> logger, IMaterialOrderLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormMaterialOrders_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["MaterialId"].Visible = false;
dataGridView.Columns["OrderId"].Visible = false;
dataGridView.Columns["Quantity"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка поставок");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки поставок");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMaterialOrder));
if (service is FormMaterialOrder form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
}