126 lines
4.5 KiB
C#
126 lines
4.5 KiB
C#
using CarRepairShopContracts.BusinessLogicsContracts;
|
|
using CarRepairShopContracts.SearchModels;
|
|
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 CarRepairShopView
|
|
{
|
|
public partial class FormRepairShop : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IRepairLogic _logicR;
|
|
private readonly IShopLogic _logicS;
|
|
public FormRepairShop(ILogger<FormRepairShop> logger, IRepairLogic logicR, IShopLogic logicS)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_logicR = logicR;
|
|
_logicS = logicS;
|
|
}
|
|
|
|
private void FormRepairShop_Load(object sender, EventArgs e)
|
|
{
|
|
_logger.LogInformation("Загрузка магазинов");
|
|
try
|
|
{
|
|
var list = _logicS.ReadList(null);
|
|
if (list != null)
|
|
{
|
|
comboBoxShop.DisplayMember = "ShopName";
|
|
comboBoxShop.ValueMember = "Id";
|
|
comboBoxShop.DataSource = list;
|
|
comboBoxShop.SelectedItem = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка загрузки списка магазинов");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
|
|
_logger.LogInformation("Загрузка ремонтов");
|
|
try
|
|
{
|
|
var list = _logicR.ReadList(null);
|
|
if (list != null)
|
|
{
|
|
comboBoxRepair.DisplayMember = "RepairName";
|
|
comboBoxRepair.ValueMember = "Id";
|
|
comboBoxRepair.DataSource = list;
|
|
comboBoxRepair.SelectedItem = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка загрузки списка ремонтов");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(comboBoxShop.Text))
|
|
{
|
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(comboBoxRepair.Text))
|
|
{
|
|
MessageBox.Show("Выберите ремонт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|
{
|
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
_logger.LogInformation("Пополнение магазина");
|
|
|
|
try
|
|
{
|
|
var operationResult = _logicS.AddRepair(new ShopSearchModel
|
|
{
|
|
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
|
|
},
|
|
|
|
_logicR.ReadElement(new RepairSearchModel()
|
|
{
|
|
Id = Convert.ToInt32(comboBoxRepair.SelectedValue)
|
|
})!,
|
|
|
|
Convert.ToInt32(textBoxCount.Text));
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
}
|
|
}
|