using ConstructionCompanyContracts.BindingModels; using ConstructionCompanyContracts.BusinessLogicContracts; using ConstructionCompanyContracts.SearchModels; using ConstructionCompanyContracts.ViewModels; using ConstructionCompanyPsqlImplement.Models; using Microsoft.Extensions.Logging; using System; using System.Collections; 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 FormEmployeeOrder : Form { private readonly ILogger _logger; private readonly IOrderLogic _order; private readonly IEmployeeLogic _employee; private readonly IEmployeeOrderLogic _employeeOrder; private List? _listE; private List? _listO; public FormEmployeeOrder(ILogger logger, IOrderLogic order, IEmployeeLogic employee, IEmployeeOrderLogic employeeOrder) { InitializeComponent(); _logger = logger; _order = order; _employee = employee; _employeeOrder = employeeOrder; } private void FormEmployeeOrder_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка материалов для заказа"); _listE = _employee.ReadList(null); if (_listE != null) { comboBoxEmployee.DisplayMember = "EmployeeName"; comboBoxEmployee.ValueMember = "Id"; comboBoxEmployee.DataSource = _listE; comboBoxEmployee.SelectedItem = null; } _listO = _order.ReadList(null); if (_listO != null) { comboBoxOrder.DisplayMember = "Adress"; comboBoxOrder.ValueMember = "Id"; comboBoxOrder.DataSource = _listO; comboBoxOrder.SelectedItem = null; } } private void buttonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } private void buttonCreate_Click(object sender, EventArgs e) { if (comboBoxOrder.SelectedValue == null) { MessageBox.Show("Выберите заказ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxEmployee.SelectedValue == null) { MessageBox.Show("Выберите материал", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var model = new EmployeeOrderBindingModel { EmployeeId = Convert.ToInt32(comboBoxEmployee.SelectedValue), OrderId = Convert.ToInt32(comboBoxOrder.SelectedValue), }; var operationResult = _employeeOrder.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { _logger.LogError(ex, "Ошибка сохранения компонента"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }