99 lines
3.3 KiB
C#
99 lines
3.3 KiB
C#
using HotelContracts.BindingModels;
|
|
using HotelContracts.BusinessLogicsContracts;
|
|
using HotelContracts.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 HotelView
|
|
{
|
|
public partial class FormWorker : Form
|
|
{
|
|
|
|
private readonly IWorkerLogic _logicW;
|
|
private readonly IPostLogic _logicP;
|
|
private int? _id;
|
|
|
|
public int Id { set { _id = value; } }
|
|
|
|
public FormWorker(IWorkerLogic logicW, IPostLogic logicP)
|
|
{
|
|
InitializeComponent();
|
|
_logicW = logicW;
|
|
_logicP = logicP;
|
|
}
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(textBoxFIO.Text))
|
|
{
|
|
MessageBox.Show("Заполните Имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
return;
|
|
}
|
|
if (comboBoxPost.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите изделие", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
var model = new WorkerBindingModel
|
|
{
|
|
Id = _id ?? 0,
|
|
FIO = textBoxFIO.Text,
|
|
DateOfBirth = dateTimePicker.Value,
|
|
WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text),
|
|
Salary = Convert.ToInt32(textBoxSalary.Text),
|
|
Phone = textBoxPhone.Text,
|
|
PostId = Convert.ToInt32(comboBoxPost.SelectedValue),
|
|
};
|
|
var operationResult = _id.HasValue ? _logicW.Update(model) : _logicW.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();
|
|
}
|
|
|
|
private void FormWorker_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var postList = _logicP.ReadList(null);
|
|
if (postList != null)
|
|
{
|
|
comboBoxPost.DisplayMember = "PostName";
|
|
comboBoxPost.ValueMember = "Id";
|
|
comboBoxPost.DataSource = postList;
|
|
comboBoxPost.SelectedItem = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|