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;
|
|
|
|
|
private readonly IMasterLogic _logicM;
|
2023-05-13 19:29:18 +04:00
|
|
|
|
private readonly IVisitLogic _logicV;
|
2023-05-13 23:36:15 +04:00
|
|
|
|
public FormCreateVisit(ILogger<FormCreateVisit> logger, IVisitLogic logicV, IServiceLogic logicS, IClientLogic logicC, IMasterLogic logicM)
|
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;
|
|
|
|
|
_logicM = logicM;
|
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);
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Загрузка мастеров для заказа");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logicM.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxMaster.DisplayMember = "MasterFIO";
|
2023-05-13 19:29:18 +04:00
|
|
|
|
comboBoxMaster.ValueMember = "Id";
|
|
|
|
|
comboBoxMaster.DataSource = list;
|
|
|
|
|
comboBoxMaster.SelectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-05-13 23:36:15 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки списка мастеров");
|
2023-05-13 19:29:18 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormCreateVisit_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Загрузка мастеров для посещения");
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CalcSum()
|
|
|
|
|
{
|
|
|
|
|
if (comboBoxService.SelectedValue != null)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxMaster.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите мастера", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Создание посещения");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _logicV.Create(new VisitBindingModel
|
|
|
|
|
{
|
|
|
|
|
MasterId = Convert.ToInt32(comboBoxMaster.SelectedValue),
|
|
|
|
|
MasterFIO = comboBoxMaster.Text,
|
|
|
|
|
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
|
|
|
|
|
ClientFIO = comboBoxClient.Text,
|
|
|
|
|
ServiceId = Convert.ToInt32(comboBoxService.SelectedValue),
|
|
|
|
|
ServiceName = comboBoxService.Text,
|
|
|
|
|
DateOfVisit = dateTimePicker.Value,
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|