87 lines
2.7 KiB
C#
87 lines
2.7 KiB
C#
|
using SushiBarContracts.BindingModels;
|
|||
|
using SushiBarContracts.BusinessLogicContracts;
|
|||
|
using SushiBarContracts.SearchModels;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace SushiBarView
|
|||
|
{
|
|||
|
public partial class FormBuyer : Form
|
|||
|
{
|
|||
|
|
|||
|
private readonly IBuyerLogic _logic;
|
|||
|
private int? _id;
|
|||
|
|
|||
|
public int Id { set { _id = value; } }
|
|||
|
|
|||
|
public FormBuyer(IBuyerLogic logic)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_logic = logic;
|
|||
|
}
|
|||
|
|
|||
|
private void FormBuyer_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_id.HasValue)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var view = _logic.ReadElement(new BuyerSearchModel { Id = _id.Value });
|
|||
|
if (view != null)
|
|||
|
{
|
|||
|
textBoxName.Text = view.BuyerName;
|
|||
|
dateTimePicker.Value = (DateTime)view.BuyerBirthDate;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void buttonSave_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if(string.IsNullOrEmpty(textBoxName.Text))
|
|||
|
{
|
|||
|
MessageBox.Show("Заполните Имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
|
|||
|
return;
|
|||
|
}
|
|||
|
try
|
|||
|
{
|
|||
|
var model = new BuyerBindingModel
|
|||
|
{
|
|||
|
Id = _id ?? 0,
|
|||
|
BuyerName = textBoxName.Text,
|
|||
|
BuyerBirthDate = dateTimePicker.Value
|
|||
|
};
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
DialogResult = DialogResult.Cancel;
|
|||
|
Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|