SUBD_Labs/BeautySalon/FormMasterService.cs

81 lines
2.3 KiB
C#
Raw Normal View History

2023-05-13 19:29:18 +04:00
using BeautySalonContracts.BusinessLogicsContracts;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
namespace BeautySalon
{
public partial class FormMasterService : Form
{
private readonly List<ServiceViewModel>? _list;
public int Id
{
get
{
return Convert.ToInt32(comboBoxService.SelectedValue);
}
set
{
comboBoxService.SelectedValue = value;
}
}
public IServiceModel? ServiceModel
{
get
{
if (_list == null)
{
return null;
}
foreach (var elem in _list)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
public int Time
{
get { return Convert.ToInt32(textBoxTime.Text); }
set
{ textBoxTime.Text = value.ToString(); }
}
public FormMasterService(IServiceLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxService.DisplayMember = "ServiceName";
comboBoxService.ValueMember = "Id";
comboBoxService.DataSource = _list;
comboBoxService.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxTime.Text))
{
MessageBox.Show("Заполните поле время", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxService.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();
}
}
}