2024-02-24 21:32:11 +04:00
|
|
|
|
using DinerContracts.BindingModels;
|
|
|
|
|
using DinerContracts.BusinessLogicsContacts;
|
2024-05-13 21:06:39 +04:00
|
|
|
|
using DinerContracts.BusinessLogicsContracts;
|
2024-02-24 21:32:11 +04:00
|
|
|
|
using DinerContracts.SearchModels;
|
2024-02-25 16:50:29 +04:00
|
|
|
|
using DinerDataModels.Enums;
|
2024-02-24 21:32:11 +04:00
|
|
|
|
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 DinerView
|
|
|
|
|
{
|
|
|
|
|
public partial class FormCreateOrder : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ISnackLogic _logicSnack;
|
|
|
|
|
private readonly IOrderLogic _logicOrder;
|
2024-05-13 21:06:39 +04:00
|
|
|
|
private readonly IClientLogic _clientLogic;
|
2024-02-24 21:32:11 +04:00
|
|
|
|
|
2024-05-13 21:06:39 +04:00
|
|
|
|
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISnackLogic logicSnack, IOrderLogic logicOrder, IClientLogic clientLogic)
|
2024-02-24 21:32:11 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logicSnack = logicSnack;
|
|
|
|
|
_logicOrder = logicOrder;
|
2024-05-13 21:06:39 +04:00
|
|
|
|
_clientLogic = clientLogic;
|
2024-02-24 21:32:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CalcSum()
|
|
|
|
|
{
|
|
|
|
|
if (comboBoxProduct.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(comboBoxProduct.SelectedValue);
|
|
|
|
|
var product = _logicSnack.ReadElement(new SnackSearchModel { ID = id });
|
|
|
|
|
int count = Convert.ToInt32(textBoxCount.Text);
|
2024-02-25 16:50:29 +04:00
|
|
|
|
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
|
2024-02-24 21:32:11 +04:00
|
|
|
|
_logger.LogInformation("Расчет суммы заказа");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void textBoxCount_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CalcSum();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void comboBoxProduct_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CalcSum();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Заполните поле количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxProduct.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-13 21:06:39 +04:00
|
|
|
|
if (comboBoxClient.SelectedValue == null) {
|
|
|
|
|
MessageBox.Show("Выбирите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Создание заказа");
|
2024-02-24 21:32:11 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _logicOrder.CreateOrder(new OrderBindingModel
|
|
|
|
|
{
|
2024-05-05 18:00:10 +04:00
|
|
|
|
SnackID = Convert.ToInt32(comboBoxProduct.SelectedValue),
|
2024-02-24 21:32:11 +04:00
|
|
|
|
Count = Convert.ToInt32(textBoxCount.Text),
|
2024-05-15 16:26:13 +04:00
|
|
|
|
ProductName = comboBoxProduct.SelectedValue.ToString(),
|
|
|
|
|
Sum = Convert.ToDouble(textBoxSum.Text),
|
2024-05-13 21:06:39 +04:00
|
|
|
|
ClientID = Convert.ToInt32(comboBoxClient.SelectedValue)
|
2024-02-25 16:50:29 +04:00
|
|
|
|
|
2024-02-24 21:32:11 +04:00
|
|
|
|
});
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormCreateOrder_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Загрузка Снэков");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logicSnack.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
2024-02-25 16:50:29 +04:00
|
|
|
|
comboBoxProduct.DisplayMember = "ProductName";
|
2024-02-24 21:32:11 +04:00
|
|
|
|
comboBoxProduct.ValueMember = "ID";
|
|
|
|
|
comboBoxProduct.DataSource = list;
|
|
|
|
|
comboBoxProduct.SelectedItem = null;
|
|
|
|
|
}
|
2024-05-13 21:06:39 +04:00
|
|
|
|
|
|
|
|
|
var listClient = _clientLogic.ReadList(null);
|
|
|
|
|
if (listClient != null) {
|
|
|
|
|
comboBoxClient.DisplayMember = "ClientFIO";
|
|
|
|
|
comboBoxClient.ValueMember = "ID";
|
|
|
|
|
comboBoxClient.DataSource = listClient;
|
|
|
|
|
comboBoxClient.SelectedItem = null;
|
|
|
|
|
}
|
2024-02-24 21:32:11 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
2024-05-13 21:06:39 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки списка снэков или клиентов");
|
2024-02-24 21:32:11 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|