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

65 lines
2.0 KiB
C#
Raw Normal View History

using ConstructionCompanyContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging;
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 ConstructionCompanyView
{
public partial class FormEmployeeOrders : Form
{
private readonly ILogger _logger;
private readonly IEmployeeOrderLogic _logic;
public FormEmployeeOrders(ILogger<FormEmployeeOrders> logger, IEmployeeOrderLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormEmployeeOrders_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["EmployeeId"].Visible = false;
dataGridView.Columns["OrderId"].Visible = false;
dataGridView.Columns["EmployeeName"].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(FormEmployeeOrder));
if (service is FormEmployeeOrder form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
}