125 lines
4.6 KiB
C#
Raw Normal View History

2024-02-27 21:03:00 +04:00
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 TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using Microsoft.Extensions.Logging;
2024-02-27 21:55:35 +04:00
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
2024-02-27 21:03:00 +04:00
namespace TypographyView
{
public partial class FormMakeShipment : Form
{
private readonly ILogger _logger;
private readonly IPrintedLogic _logicPrinted;
private readonly IShopLogic _logicShop;
public FormMakeShipment(ILogger<FormMakeShipment> logger, IPrintedLogic logicPrinted, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicPrinted = logicPrinted;
_logicShop = logicShop;
}
private void FormMakeShipment_Load(object sender, EventArgs e)
{
_logger.LogInformation("Printeds loading");
try
{
var list = _logicPrinted.ReadList(null);
if (list != null)
{
comboBoxPrinted.DisplayMember = "PrintedName";
comboBoxPrinted.ValueMember = "Id";
comboBoxPrinted.DataSource = list;
comboBoxPrinted.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Printeds loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Shops loading");
try
{
var list = _logicShop.ReadList(null);
if (list != null)
{
comboBoxShop.DisplayMember = "ShopName";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = list;
comboBoxShop.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Shops loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxShop.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxPrinted.SelectedValue == null)
{
MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Shop replenishment");
try
{
var iceCream = _logicPrinted.ReadElement(new PrintedSearchModel
{ Id = Convert.ToInt32(comboBoxPrinted.SelectedValue) });
if (iceCream == null)
{
throw new Exception("Закуска не найдено.");
}
var operationResult = _logicShop.MakeShipment(new ShopSearchModel
{
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
},
iceCream,
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, "Shop replenishment error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
2024-02-27 21:55:35 +04:00
}