94 lines
3.5 KiB
C#
94 lines
3.5 KiB
C#
|
using AbstractLawFirmContracts.BindingModels;
|
|||
|
using AbstractLawFirmContracts.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 LawFirmView
|
|||
|
{
|
|||
|
public partial class FormSellDocuments : Form
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IDocumentLogic _logicDocument;
|
|||
|
private readonly IShopLogic _logicShop;
|
|||
|
public FormSellDocuments(ILogger<FormSellDocuments> logger, IDocumentLogic logicDocument, IShopLogic logicShop)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_logger = logger;
|
|||
|
_logicDocument = logicDocument;
|
|||
|
_logicShop = logicShop;
|
|||
|
}
|
|||
|
|
|||
|
private void FormSellDocuments_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
_logger.LogInformation("Загрузка документов для продажи");
|
|||
|
try
|
|||
|
{
|
|||
|
var list = _logicDocument.ReadList(null);
|
|||
|
if (list != null)
|
|||
|
{
|
|||
|
comboBoxDoc.DisplayMember = "DocumentName";
|
|||
|
comboBoxDoc.ValueMember = "Id";
|
|||
|
comboBoxDoc.DataSource = list;
|
|||
|
comboBoxDoc.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 (comboBoxDoc.SelectedValue == null)
|
|||
|
{
|
|||
|
MessageBox.Show("Выберите пакет документов", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
_logger.LogInformation("Создание продажи");
|
|||
|
try
|
|||
|
{
|
|||
|
var operationResult = _logicShop.SellDocument(
|
|||
|
new DocumentBindingModel
|
|||
|
{
|
|||
|
Id = Convert.ToInt32(comboBoxDoc.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();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|