2023-05-13 19:29:18 +04:00
|
|
|
|
using BeautySalonContracts.BindingModels;
|
|
|
|
|
using BeautySalonContracts.BusinessLogicsContracts;
|
|
|
|
|
using BeautySalonContracts.SearchModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace BeautySalon
|
|
|
|
|
{
|
|
|
|
|
public partial class FormCreateVisit : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IServiceLogic _logicS;
|
2023-05-13 23:36:15 +04:00
|
|
|
|
private readonly IClientLogic _logicC;
|
2023-05-13 19:29:18 +04:00
|
|
|
|
private readonly IVisitLogic _logicV;
|
2023-05-17 02:04:30 +04:00
|
|
|
|
public FormCreateVisit(ILogger<FormCreateVisit> logger, IVisitLogic logicV, IServiceLogic logicS, IClientLogic logicC)
|
2023-05-13 19:29:18 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logicS = logicS;
|
|
|
|
|
_logicV = logicV;
|
2023-05-13 23:36:15 +04:00
|
|
|
|
_logicC = logicC;
|
2023-05-13 19:29:18 +04:00
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Загрузка услуг для посещения");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logicS.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
2023-05-13 23:36:15 +04:00
|
|
|
|
comboBoxService.DisplayMember = "ServiceName";
|
|
|
|
|
comboBoxService.ValueMember = "Id";
|
|
|
|
|
comboBoxService.DataSource = list;
|
|
|
|
|
comboBoxService.SelectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки списка услуг");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Загрузка клиентов для заказа");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logicC.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxClient.DisplayMember = "ClientFIO";
|
|
|
|
|
comboBoxClient.ValueMember = "Id";
|
|
|
|
|
comboBoxClient.DataSource = list;
|
|
|
|
|
comboBoxClient.SelectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки списка клиентов");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2023-05-17 02:04:30 +04:00
|
|
|
|
}
|
2023-05-13 19:29:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormCreateVisit_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Загрузка мастеров для посещения");
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CalcSum()
|
|
|
|
|
{
|
2023-05-17 02:04:30 +04:00
|
|
|
|
if (comboBoxService.SelectedValue != null && comboBoxClient.SelectedValue != null)
|
2023-05-13 19:29:18 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(comboBoxService.SelectedValue);
|
|
|
|
|
var service = _logicS.ReadElement(new ServiceSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
textBoxSum.Text = Math.Round((service?.Cost ?? 0), 2).ToString();
|
|
|
|
|
_logger.LogInformation("Расчет суммы посещения");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка расчета суммы посещения");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ComboBoxClient_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ComboBoxMaster_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-05-17 02:04:30 +04:00
|
|
|
|
_logger.LogInformation("Загрузка услуг для мастера");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logicS.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxService.DisplayMember = "ServiceName";
|
|
|
|
|
comboBoxService.ValueMember = "Id";
|
|
|
|
|
comboBoxService.DataSource = list;
|
|
|
|
|
comboBoxService.SelectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки списка мастеров");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
2023-05-13 19:29:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ComboBoxService_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CalcSum();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (comboBoxClient.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxService.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите услугу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
2023-05-17 02:04:30 +04:00
|
|
|
|
}
|
2023-05-13 19:29:18 +04:00
|
|
|
|
_logger.LogInformation("Создание посещения");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _logicV.Create(new VisitBindingModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
|
|
|
|
|
ClientFIO = comboBoxClient.Text,
|
|
|
|
|
ServiceId = Convert.ToInt32(comboBoxService.SelectedValue),
|
|
|
|
|
ServiceName = comboBoxService.Text,
|
2023-05-17 02:04:30 +04:00
|
|
|
|
DateOfVisit = dateTimePicker.Value.ToUniversalTime(),
|
2023-05-13 19:29:18 +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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|