97 lines
3.8 KiB
C#
97 lines
3.8 KiB
C#
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;
|
|
using SecuritySystemContracts.BusinessLogicsContracts;
|
|
using SecuritySystemContracts.ViewModels;
|
|
|
|
namespace SecuritySystemView
|
|
{
|
|
public partial class FormShopSecure : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IShopLogic _shopLogic;
|
|
private readonly ISecureLogic _SecureLogic;
|
|
private readonly List<ShopViewModel>? _listShops;
|
|
private readonly List<SecureViewModel>? _listSecure;
|
|
public FormShopSecure(ILogger<FormShopSecure> logger, IShopLogic shopLogic, ISecureLogic SecureLogic)
|
|
{
|
|
InitializeComponent();
|
|
_shopLogic = shopLogic;
|
|
_SecureLogic = SecureLogic;
|
|
_logger = logger;
|
|
_listShops = shopLogic.ReadList(null);
|
|
if (_listShops != null)
|
|
{
|
|
comboBoxShop.DisplayMember = "ShopName";
|
|
comboBoxShop.ValueMember = "Id";
|
|
comboBoxShop.DataSource = _listShops;
|
|
comboBoxShop.SelectedItem = null;
|
|
}
|
|
|
|
_listSecure = SecureLogic.ReadList(null);
|
|
if (_listSecure != null)
|
|
{
|
|
comboBoxSecure.DisplayMember = "SecureName";
|
|
comboBoxSecure.ValueMember = "Id";
|
|
comboBoxSecure.DataSource = _listSecure;
|
|
comboBoxSecure.SelectedItem = null;
|
|
}
|
|
}
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxShop.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (comboBoxSecure.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
_logger.LogInformation("Добавление изделия в магазин");
|
|
try
|
|
{
|
|
var Secure = _SecureLogic.ReadElement(new()
|
|
{
|
|
Id = (int)comboBoxSecure.SelectedValue
|
|
});
|
|
if (Secure == null)
|
|
{
|
|
throw new Exception("Изделие не найдено. Дополнительная информация в логах.");
|
|
}
|
|
var resultOperation = _shopLogic.AddSecureInShop(
|
|
model: new() { Id = (int)comboBoxShop.SelectedValue },
|
|
secure: Secure,
|
|
count: (int)numericUpDownCount.Value
|
|
);
|
|
if (!resultOperation)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|