126 lines
4.8 KiB
C#
126 lines
4.8 KiB
C#
|
using AbstractLawFirmContracts.BindingModels;
|
|||
|
using AbstractLawFirmContracts.BusinessLogicsContracts;
|
|||
|
using AbstractLawFirmContracts.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 LawFirmView
|
|||
|
{
|
|||
|
public partial class FormShopSupply : Form
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IDocumentLogic _logicD;
|
|||
|
private readonly IShopLogic _logicS;
|
|||
|
public FormShopSupply(ILogger<FormShopSupply> logger, IDocumentLogic logicD, IShopLogic logicS)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_logger = logger;
|
|||
|
_logicD = logicD;
|
|||
|
_logicS = logicS;
|
|||
|
}
|
|||
|
|
|||
|
private void FormShopSupply_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
_logger.LogInformation("Загрузка документов для пополнения");
|
|||
|
try
|
|||
|
{
|
|||
|
var list = _logicD.ReadList(null);
|
|||
|
if (list != null)
|
|||
|
{
|
|||
|
comboBoxDocument.DisplayMember = "DocumentName";
|
|||
|
comboBoxDocument.ValueMember = "Id";
|
|||
|
comboBoxDocument.DataSource = list;
|
|||
|
comboBoxDocument.SelectedItem = null;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка загрузки списка документов");
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
|
|||
|
_logger.LogInformation("Загрузка магазинов для пополнения");
|
|||
|
try
|
|||
|
{
|
|||
|
var list = _logicS.ReadList(null);
|
|||
|
if (list != null)
|
|||
|
{
|
|||
|
comboBoxShop.DisplayMember = "ShopName";
|
|||
|
comboBoxShop.ValueMember = "Id";
|
|||
|
comboBoxShop.DataSource = list;
|
|||
|
comboBoxShop.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 (comboBoxDocument.SelectedValue == null)
|
|||
|
{
|
|||
|
MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
if (comboBoxShop.SelectedValue == null)
|
|||
|
{
|
|||
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
_logger.LogInformation("Создание поставки");
|
|||
|
try
|
|||
|
{
|
|||
|
var operationResult = _logicS.SupplyDocuments(
|
|||
|
new ShopSearchModel
|
|||
|
{
|
|||
|
Id = Convert.ToInt32(comboBoxShop.SelectedValue),
|
|||
|
ShopName = comboBoxShop.Text
|
|||
|
},
|
|||
|
new DocumentBindingModel
|
|||
|
{
|
|||
|
Id = Convert.ToInt32(comboBoxDocument.SelectedValue),
|
|||
|
DocumentName = comboBoxDocument.Text
|
|||
|
},
|
|||
|
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();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|