88 lines
3.4 KiB
C#
88 lines
3.4 KiB
C#
|
using AircraftPlantContracts.BusinessLogicsContracts;
|
|||
|
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 AircraftPlantView
|
|||
|
{
|
|||
|
public partial class FormSell : Form
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IPlaneLogic _logicP;
|
|||
|
private readonly IShopLogic _logicS;
|
|||
|
public FormSell(ILogger<FormSell> logger, IPlaneLogic planeLogic, IShopLogic shopLogic)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_logger = logger;
|
|||
|
_logicP = planeLogic;
|
|||
|
_logicS = shopLogic;
|
|||
|
}
|
|||
|
private void FormSell_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
_logger.LogInformation("Загрузка изделий для продажи");
|
|||
|
try
|
|||
|
{
|
|||
|
var list = _logicP.ReadList(null);
|
|||
|
if (list != null)
|
|||
|
{
|
|||
|
comboBoxPlane.DisplayMember = "PlaneName";
|
|||
|
comboBoxPlane.ValueMember = "Id";
|
|||
|
comboBoxPlane.DataSource = list;
|
|||
|
comboBoxPlane.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(textBoxCount.Text))
|
|||
|
{
|
|||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
if (comboBoxPlane.SelectedValue == null)
|
|||
|
{
|
|||
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
_logger.LogInformation("Продажа изделий");
|
|||
|
_logger.LogInformation("Создание заказа");
|
|||
|
try
|
|||
|
{
|
|||
|
var operationResult = _logicS.SellPlanes(
|
|||
|
_logicP.ReadElement(new() { Id = Convert.ToInt32(comboBoxPlane.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();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|