81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
using SushiBarBusinessLogic;
|
|
using SushiBarContracts.BindingModels;
|
|
using SushiBarContracts.SearchModels;
|
|
|
|
namespace SushiBarView.Forms
|
|
{
|
|
public partial class FormCustomer : Form
|
|
{
|
|
private readonly CustomerLogic _logic;
|
|
|
|
private int? _id;
|
|
public int Id { set { _id = value; } }
|
|
|
|
public FormCustomer(CustomerLogic Logic)
|
|
{
|
|
InitializeComponent();
|
|
_logic = Logic;
|
|
}
|
|
|
|
private void FormCustomer_Load(object sender, EventArgs e)
|
|
{
|
|
if (_id.HasValue)
|
|
{
|
|
try
|
|
{
|
|
var View = _logic.ReadElement(new CustomerSearchModel
|
|
{
|
|
Id = _id.Value
|
|
});
|
|
|
|
if (View != null)
|
|
{
|
|
FioTextBox.Text = View.Fio;
|
|
EmploymentDateTimePicker.Value = View.BirthdayDate ?? new DateTime();
|
|
SumOfAllOrdersTextBox.Text = View.SumOfAllOrders.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(FioTextBox.Text))
|
|
{
|
|
MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var Model = new CustomerBindingModel
|
|
{
|
|
Id = _id ?? 0,
|
|
Fio = FioTextBox.Text,
|
|
BirthdayDate = EmploymentDateTimePicker.Value,
|
|
SumOfAllOrders = 0,
|
|
};
|
|
|
|
var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model);
|
|
|
|
if (!OperationResult)
|
|
{
|
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
|
}
|
|
|
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка сохранения повара", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|