139 lines
5.3 KiB
C#
139 lines
5.3 KiB
C#
|
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;
|
|||
|
private readonly IVisitLogic _logicV;
|
|||
|
public FormCreateVisit(ILogger<FormCreateVisit> logger, IVisitLogic logicV, IServiceLogic logicS)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_logger = logger;
|
|||
|
_logicS = logicS;
|
|||
|
_logicV = logicV;
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
|
|||
|
private void LoadData()
|
|||
|
{
|
|||
|
_logger.LogInformation("Загрузка услуг для посещения");
|
|||
|
try
|
|||
|
{
|
|||
|
var list = _logicS.ReadList(null);
|
|||
|
if (list != null)
|
|||
|
{
|
|||
|
comboBoxMaster.DisplayMember = "ServiceName";
|
|||
|
comboBoxMaster.ValueMember = "Id";
|
|||
|
comboBoxMaster.DataSource = list;
|
|||
|
comboBoxMaster.SelectedItem = null;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка загрузки списка услуг");
|
|||
|
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)
|
|||
|
{
|
|||
|
CalcSum();
|
|||
|
}
|
|||
|
|
|||
|
private void ComboBoxMaster_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
CalcSum();
|
|||
|
}
|
|||
|
|
|||
|
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();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|