2024-04-17 09:22:08 +04:00
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using RenovationWorkContracts.BindingModels;
|
|
|
|
|
using RenovationWorkContracts.BusinessLogicsContracts;
|
|
|
|
|
using RenovationWorkContracts.SearchModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using RenovationWorkListImplement.Models;
|
|
|
|
|
|
|
|
|
|
namespace RenovationWorkView
|
|
|
|
|
{
|
|
|
|
|
public partial class FormCreateOrder : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
2024-05-25 21:23:11 +04:00
|
|
|
|
private readonly IRepairLogic _logicI;
|
2024-04-17 09:22:08 +04:00
|
|
|
|
private readonly IOrderLogic _logicO;
|
2024-05-25 21:23:11 +04:00
|
|
|
|
private readonly IClientLogic _logicC;
|
|
|
|
|
public FormCreateOrder(ILogger<FormCreateOrder> logger, IRepairLogic logicI, IOrderLogic logicO, IClientLogic logicC)
|
2024-04-17 09:22:08 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
2024-05-25 21:23:11 +04:00
|
|
|
|
_logicI = logicI;
|
2024-04-17 09:22:08 +04:00
|
|
|
|
_logicO = logicO;
|
2024-05-25 21:23:11 +04:00
|
|
|
|
_logicC = logicC;
|
2024-04-17 09:22:08 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormCreateOrder_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Загрузка изделий для заказа");
|
2024-05-25 21:23:11 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logicI.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxRepair.DisplayMember = "RepairName";
|
|
|
|
|
comboBoxRepair.ValueMember = "Id";
|
|
|
|
|
comboBoxRepair.DataSource = list;
|
|
|
|
|
comboBoxRepair.SelectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Ремонтные изделия загружены");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки ремонтных изделий");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Загрузка клиентов для заказа");
|
|
|
|
|
try
|
2024-04-17 09:22:08 +04:00
|
|
|
|
{
|
2024-05-25 21:23:11 +04:00
|
|
|
|
var list = _logicC.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
ComboBoxClient.DisplayMember = "ClientFIO";
|
|
|
|
|
ComboBoxClient.ValueMember = "Id";
|
|
|
|
|
ComboBoxClient.DataSource = list;
|
|
|
|
|
ComboBoxClient.SelectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Клиенты загружены");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки клиентов");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-04-17 09:22:08 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-25 21:23:11 +04:00
|
|
|
|
|
2024-04-17 09:22:08 +04:00
|
|
|
|
private void CalcSum()
|
|
|
|
|
{
|
|
|
|
|
if (comboBoxRepair.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(comboBoxRepair.SelectedValue);
|
2024-05-25 21:23:11 +04:00
|
|
|
|
var repair = _logicI.ReadElement(new RepairSearchModel { Id = id });
|
2024-04-17 09:22:08 +04:00
|
|
|
|
int count = Convert.ToInt32(textBoxCount.Text);
|
|
|
|
|
textBoxSum.Text = Math.Round(count * (repair?.Price ?? 0), 2).ToString();
|
|
|
|
|
_logger.LogInformation("Расчет суммы заказа");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void comboBoxRepair_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CalcSum();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void textBoxCount_TextChanged(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 (comboBoxRepair.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-25 21:23:11 +04:00
|
|
|
|
if (ComboBoxClient.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-17 09:22:08 +04:00
|
|
|
|
_logger.LogInformation("Создание заказа");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(comboBoxRepair.SelectedValue);
|
2024-05-25 21:23:11 +04:00
|
|
|
|
int count = Convert.ToInt32(textBoxCount.Text);
|
2024-04-17 09:22:08 +04:00
|
|
|
|
double sum = Convert.ToDouble(textBoxSum.Text);
|
|
|
|
|
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
|
|
|
|
{
|
|
|
|
|
RepairId = Convert.ToInt32(comboBoxRepair.SelectedValue),
|
|
|
|
|
Count = Convert.ToInt32(textBoxCount.Text),
|
2024-05-25 21:23:11 +04:00
|
|
|
|
ClientId = Convert.ToInt32(ComboBoxClient.SelectedValue),
|
2024-04-17 09:22:08 +04:00
|
|
|
|
Sum = Convert.ToDouble(textBoxSum.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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|