83 lines
3.1 KiB
C#
83 lines
3.1 KiB
C#
using ConstructionCompanyContracts.BindingModels;
|
|
using ConstructionCompanyContracts.BusinessLogicContracts;
|
|
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 ConstructionCompanyView
|
|
{
|
|
public partial class FormOrder : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IOrderLogic _logic;
|
|
public FormOrder(ILogger<FormOrder> logger, IOrderLogic logic)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_logic = logic;
|
|
}
|
|
|
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(textBoxDescription.Text))
|
|
{
|
|
MessageBox.Show("Заполните описание", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(textBoxAdress.Text))
|
|
{
|
|
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(textBoxPrice.Text))
|
|
{
|
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(textBoxNumber.Text))
|
|
{
|
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
_logger.LogInformation("Сохранение материала");
|
|
try
|
|
{
|
|
var model = new OrderBindingModel
|
|
{
|
|
Id = 0,
|
|
Description = textBoxDescription.Text,
|
|
Adress = textBoxAdress.Text,
|
|
Price = Convert.ToInt32(textBoxPrice.Text),
|
|
CustomerNumber = textBoxNumber.Text
|
|
};
|
|
var operationResult = _logic.CreateOrder(model);
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|