87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using LawFirmContracts.BusinessLogicsContracts;
|
|
using LawFirmContracts.ViewModels;
|
|
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 LawFirmView
|
|
{
|
|
public partial class FormSellDocuments : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IShopLogic _shopLogic;
|
|
private readonly IDocumentLogic _documentLogic;
|
|
private readonly List<DocumentViewModel>? _listDocument;
|
|
public FormSellDocuments(ILogger<FormSellDocuments> logger, IShopLogic shopLogic, IDocumentLogic documentLogic)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_shopLogic = shopLogic;
|
|
_documentLogic = documentLogic;
|
|
_listDocument = documentLogic.ReadList(null);
|
|
if (_listDocument != null)
|
|
{
|
|
comboBoxDocuments.DisplayMember = "DocumentName";
|
|
comboBoxDocuments.ValueMember = "Id";
|
|
comboBoxDocuments.DataSource=_listDocument;
|
|
comboBoxDocuments.SelectedItem = null;
|
|
}
|
|
}
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxDocuments.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(numericUpDownCount.Text))
|
|
{
|
|
MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
_logger.LogInformation("Продажа документов");
|
|
try
|
|
{
|
|
var document = _documentLogic.ReadElement(new()
|
|
{
|
|
Id = (int)comboBoxDocuments.SelectedValue
|
|
});
|
|
if (document == null)
|
|
{
|
|
throw new Exception("Документ не найден. Дополнительная информация в логах.");
|
|
}
|
|
var operationResult = _shopLogic.SellDocuments(
|
|
model: document,
|
|
count: (int)numericUpDownCount.Value
|
|
);
|
|
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();
|
|
}
|
|
}
|
|
}
|