82 lines
2.8 KiB
C#
82 lines
2.8 KiB
C#
using ConstructionFirmBusinessLogic.BusinessLogics;
|
|
using Subd_4.BindingModels;
|
|
using Subd_4.BusinessLogicContracts;
|
|
using Subd_4.SearchModels;
|
|
|
|
namespace viewmodel
|
|
{
|
|
public partial class FormTeam : Form
|
|
{
|
|
private readonly ITeamLogic _logic;
|
|
|
|
private int? _id;
|
|
public int Id { set { _id = value; } }
|
|
|
|
public FormTeam(ITeamLogic logic)
|
|
{
|
|
InitializeComponent();
|
|
_logic = logic;
|
|
}
|
|
|
|
private void FormMenu_Load(object sender, EventArgs e)
|
|
{
|
|
if (_id.HasValue)
|
|
{
|
|
try
|
|
{
|
|
var view = _logic.ReadElement(new TeamSearchModel { Id = _id.Value });
|
|
if (view != null)
|
|
{
|
|
textBoxNameTeam.Text = view.TeamName;
|
|
textBoxNameLeader.Text = view.LeaderName;
|
|
textBoxExpirience.Text = view.Experince.ToString();
|
|
textBoxType.Text = view.TeamType;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(textBoxNameTeam.Text) || string.IsNullOrEmpty(textBoxExpirience.Text))
|
|
{
|
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
var model = new TeamBindingModel
|
|
{
|
|
Id = _id ?? 0,
|
|
TeamName = textBoxNameTeam.Text,
|
|
LeaderName = textBoxNameLeader.Text,
|
|
Experince = Convert.ToInt32(textBoxExpirience.Text),
|
|
TeamType = textBoxType.Text
|
|
};
|
|
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();
|
|
}
|
|
}
|
|
}
|