97 lines
3.5 KiB
C#
97 lines
3.5 KiB
C#
using ComputerShopContracts.BindingModels;
|
|
using ComputerShopContracts.BusinessLogicsContracts;
|
|
using ComputerShopContracts.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 ComputersShop
|
|
{
|
|
public partial class FormShopSell : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IComputerLogic _logicC;
|
|
private readonly IShopLogic _logicS;
|
|
|
|
public FormShopSell(ILogger<FormShopSell> logger, IComputerLogic logicC, IShopLogic logicS)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_logicC = logicC;
|
|
_logicS = logicS;
|
|
}
|
|
|
|
private void FormShopSell_Load(object sender, EventArgs e)
|
|
{
|
|
_logger.LogInformation("Загрузка компьютеров для продажи");
|
|
try
|
|
{
|
|
var list = _logicC.ReadList(null);
|
|
if (list != null)
|
|
{
|
|
comboBoxComputer.DisplayMember = "ComputerName";
|
|
comboBoxComputer.ValueMember = "Id";
|
|
comboBoxComputer.DataSource = list;
|
|
comboBoxComputer.SelectedItem = null;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка загрузки списка компьютеров");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void buttonSell_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|
{
|
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (comboBoxComputer.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
_logger.LogInformation("Создание продажи");
|
|
try
|
|
{
|
|
var operationResult = _logicS.SellComputer(
|
|
new ComputerBindingModel
|
|
{
|
|
Id = Convert.ToInt32(comboBoxComputer.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();
|
|
}
|
|
}
|
|
}
|