76 lines
1.8 KiB
C#
76 lines
1.8 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using TaskTrackerContracts.BindingModels;
|
|
using TaskTrackerContracts.BusinessLogicsContracts;
|
|
using TaskTrackerContracts.SearchModels;
|
|
|
|
namespace TaskTrackerView
|
|
{
|
|
public partial class FormProject : Form
|
|
{
|
|
|
|
private readonly IProjectLogic _logic;
|
|
|
|
private int? _id;
|
|
public int Id { set { _id = value; } }
|
|
public FormProject(IProjectLogic logic)
|
|
{
|
|
InitializeComponent();
|
|
_logic = logic;
|
|
}
|
|
private void FormComponent_Load(object sender, EventArgs e)
|
|
{
|
|
if (_id.HasValue)
|
|
{
|
|
try
|
|
{
|
|
var view = _logic.ReadElement(new ProjectSearchModel { Id = _id.Value });
|
|
if (view != null)
|
|
{
|
|
textBoxName.Text = view.ProjectName;
|
|
|
|
}
|
|
}
|
|
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 ProjectBindingModel
|
|
{
|
|
Id = _id ?? 0,
|
|
ProjectName = textBoxName.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();
|
|
}
|
|
}
|
|
}
|