SUBD_PIbd-21_Balberova_D.N./BeautySaloon/BeautySaloonView/FormOrderServices.cs
2023-03-29 20:00:53 +04:00

100 lines
3.0 KiB
C#

using BeautySaloonContracts.BusinessLogicsContracts;
using BeautySaloonContracts.ViewModels;
using BeautySaloonDataModels;
namespace BeautySaloonView
{
public partial class FormOrderServices : Form
{
private readonly List<ServiceViewModel>? _listS;
private readonly List<EmployeeViewModel>? _listE;
public int IdService
{
get
{
return Convert.ToInt32(comboBoxService.SelectedValue);
}
set
{
comboBoxService.SelectedValue = value;
}
}
public int IdEmployee
{
get
{
return Convert.ToInt32(comboBoxEmployee.SelectedValue);
}
set
{
comboBoxEmployee.SelectedValue = value;
}
}
public IServiceModel? ServiceModel
{
get
{
if (_listS == null)
{
return null;
}
foreach (var elem in _listS)
{
if (elem.Id == IdService)
{
return elem;
}
}
return null;
}
}
public TimeOnly Date
{
get { return TimeOnly.FromDateTime(dateTimePicker.Value); }
set { dateTimePicker.Text = value.ToString(); }
}
public FormOrderServices(IServiceLogic logicS, IEmployeeLogic logicE)
{
InitializeComponent();
_listS = logicS.ReadList(null);
_listE = logicE.ReadList(null);
if (_listS != null)
{
comboBoxService.DisplayMember = "Name";
comboBoxService.ValueMember = "Id";
comboBoxService.DataSource = _listS;
comboBoxService.SelectedItem = null;
}
if (_listE != null)
{
comboBoxEmployee.DisplayMember = "FIO";
comboBoxEmployee.ValueMember = "Id";
comboBoxEmployee.DataSource = _listE;
comboBoxEmployee.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxService.SelectedValue == null)
{
MessageBox.Show("Выберите услугу", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxEmployee.SelectedValue == null)
{
MessageBox.Show("Выберите работника", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}