2024-05-05 10:58:53 +04:00
|
|
|
|
using AbstractLawFirmContracts.BindingModels;
|
|
|
|
|
using AbstractLawFirmContracts.BusinessLogicsContracts;
|
|
|
|
|
using AbstractLawFirmContracts.SearchModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
2024-05-04 20:44:03 +04:00
|
|
|
|
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 LawFirmView
|
|
|
|
|
{
|
2024-05-05 15:38:08 +04:00
|
|
|
|
public partial class Исполнитель : Form
|
2024-05-04 20:44:03 +04:00
|
|
|
|
{
|
2024-05-05 10:58:53 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IImplementerLogic _logic;
|
|
|
|
|
private int? _id;
|
|
|
|
|
public int Id { set { _id = value; } }
|
2024-05-05 15:38:08 +04:00
|
|
|
|
public Исполнитель(ILogger<Исполнитель> logger, IImplementerLogic logic)
|
2024-05-04 20:44:03 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-05 10:58:53 +04:00
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormImplementer_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Получение информации исполнителя");
|
|
|
|
|
var view = _logic.ReadElement(new ImplementerSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = _id.Value
|
|
|
|
|
});
|
|
|
|
|
if (view != null)
|
|
|
|
|
{
|
|
|
|
|
textBoxFIO.Text = view.ImplementerFIO;
|
|
|
|
|
textBoxPasswd.Text = view.Password;
|
|
|
|
|
numericUpDownQualif.Value = view.Qualification;
|
|
|
|
|
numericUpDownWorkExp.Value = view.WorkExperience;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения исполнителя");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxPasswd.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxFIO.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Сохранение исполнителя");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var model = new ImplementerBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = _id ?? 0,
|
|
|
|
|
ImplementerFIO = textBoxFIO.Text,
|
|
|
|
|
Password = textBoxPasswd.Text,
|
|
|
|
|
Qualification = (int)numericUpDownQualif.Value,
|
|
|
|
|
WorkExperience = (int)numericUpDownWorkExp.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)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка сохранения исполнителя");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
Close();
|
2024-05-04 20:44:03 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|