Рефакторинг, добавил ServiceName
This commit is contained in:
parent
39fc7769eb
commit
08ad5292f5
@ -6,14 +6,16 @@ public class Service
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public ServiceType ServiceType { get; private set; }
|
public ServiceType ServiceType { get; private set; }
|
||||||
|
public string ServiceName { get; private set; } = string.Empty;
|
||||||
public string Description { get; private set; } = string.Empty;
|
public string Description { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static Service CreateEntity(int id, ServiceType type, string description)
|
public static Service CreateEntity(int id, ServiceType type, string name, string description)
|
||||||
{
|
{
|
||||||
return new Service
|
return new Service
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
ServiceType = type,
|
ServiceType = type,
|
||||||
|
ServiceName = name,
|
||||||
Description = description
|
Description = description
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,86 +1,75 @@
|
|||||||
using ITServiceManager.Entities;
|
using ITServiceManager.Entities;
|
||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
using ITServiceManager.Repositories.Implementations;
|
|
||||||
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 ITServiceManager.Forms
|
namespace ITServiceManager.Forms;
|
||||||
|
|
||||||
|
public partial class FormAppointment : Form
|
||||||
{
|
{
|
||||||
public partial class FormAppointment : Form
|
private readonly IAppointmentRepository _appointmentRepository;
|
||||||
|
private int? _appointmentId;
|
||||||
|
public int Id
|
||||||
{
|
{
|
||||||
private readonly IAppointmentRepository _appointmentRepository;
|
set
|
||||||
private int? _appointmentId;
|
|
||||||
public int Id
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var appointment =
|
|
||||||
_appointmentRepository.ReadAppointmentById(value);
|
|
||||||
if (appointment == null)
|
|
||||||
{
|
|
||||||
throw new
|
|
||||||
InvalidDataException(nameof(appointment));
|
|
||||||
}
|
|
||||||
comboBoxEmployee.SelectedIndex = appointment.EmployeeId;
|
|
||||||
comboBoxOrder.SelectedIndex = appointment.OrderId;
|
|
||||||
_appointmentId = value;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public FormAppointment(IAppointmentRepository appointmentRepository, IEmployeeRepository employeeRepository, IOrderRepository orderRepository)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_appointmentRepository = appointmentRepository ??
|
|
||||||
throw new ArgumentNullException(nameof(appointmentRepository));
|
|
||||||
|
|
||||||
comboBoxOrder.DataSource = orderRepository.ReadOrders();
|
|
||||||
comboBoxOrder.DisplayMember = "Name";
|
|
||||||
comboBoxOrder.ValueMember = "Id";
|
|
||||||
|
|
||||||
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
|
|
||||||
comboBoxEmployee.DisplayMember = "Name";
|
|
||||||
comboBoxEmployee.ValueMember = "Id";
|
|
||||||
}
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0 || dateTimePickerStart.CustomFormat != " ")
|
var appointment =
|
||||||
|
_appointmentRepository.ReadAppointmentById(value);
|
||||||
|
if (appointment == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new
|
||||||
|
InvalidDataException(nameof(appointment));
|
||||||
}
|
}
|
||||||
if (_appointmentId.HasValue)
|
comboBoxEmployee.SelectedIndex = appointment.EmployeeId;
|
||||||
{
|
comboBoxOrder.SelectedIndex = appointment.OrderId;
|
||||||
_appointmentRepository.UpdateAppointment(CreateAppointment(_appointmentId.Value));
|
_appointmentId = value;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_appointmentRepository.CreateAppointment(CreateAppointment(0));
|
|
||||||
}
|
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
|
||||||
private Appointment CreateAppointment(int id) => Appointment.CreateOperation(id, comboBoxOrder.SelectedIndex, comboBoxEmployee.SelectedIndex, Convert.ToDateTime(dateTimePickerStart) ,
|
|
||||||
Convert.ToDateTime(dateTimePickerEnd));
|
|
||||||
}
|
}
|
||||||
|
public FormAppointment(IAppointmentRepository appointmentRepository, IEmployeeRepository employeeRepository, IOrderRepository orderRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_appointmentRepository = appointmentRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(appointmentRepository));
|
||||||
|
|
||||||
|
comboBoxOrder.DataSource = orderRepository.ReadOrders();
|
||||||
|
comboBoxOrder.DisplayMember = "Name";
|
||||||
|
comboBoxOrder.ValueMember = "Id";
|
||||||
|
|
||||||
|
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
|
||||||
|
comboBoxEmployee.DisplayMember = "Name";
|
||||||
|
comboBoxEmployee.ValueMember = "Id";
|
||||||
|
}
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0 || dateTimePickerStart.CustomFormat != " ")
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
if (_appointmentId.HasValue)
|
||||||
|
{
|
||||||
|
_appointmentRepository.UpdateAppointment(CreateAppointment(_appointmentId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_appointmentRepository.CreateAppointment(CreateAppointment(0));
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
private Appointment CreateAppointment(int id) => Appointment.CreateOperation(id, comboBoxOrder.SelectedIndex, comboBoxEmployee.SelectedIndex, Convert.ToDateTime(dateTimePickerStart) ,
|
||||||
|
Convert.ToDateTime(dateTimePickerEnd));
|
||||||
}
|
}
|
||||||
|
@ -1,81 +1,71 @@
|
|||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
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;
|
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ITServiceManager.Forms
|
namespace ITServiceManager.Forms;
|
||||||
|
|
||||||
|
public partial class FormAppointments : Form
|
||||||
{
|
{
|
||||||
public partial class FormAppointments : Form
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IAppointmentRepository _appointmentRepository;
|
||||||
|
public FormAppointments(IUnityContainer container, IAppointmentRepository appointmentRepository)
|
||||||
{
|
{
|
||||||
private readonly IUnityContainer _container;
|
InitializeComponent();
|
||||||
private readonly IAppointmentRepository _appointmentRepository;
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
public FormAppointments(IUnityContainer container, IAppointmentRepository appointmentRepository)
|
_appointmentRepository = appointmentRepository ?? throw new ArgumentNullException(nameof(appointmentRepository));
|
||||||
|
}
|
||||||
|
private void FormAppointments_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
LoadList();
|
||||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
|
||||||
_appointmentRepository = appointmentRepository ?? throw new ArgumentNullException(nameof(appointmentRepository));
|
|
||||||
}
|
}
|
||||||
private void FormAppointments_Load(object sender, EventArgs e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
try
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
{
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
}
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
_container.Resolve<FormAppointment>().ShowDialog();
|
||||||
{
|
LoadList();
|
||||||
_container.Resolve<FormAppointment>().ShowDialog();
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var form = _container.Resolve<FormAppointment>();
|
|
||||||
form.Id = findId;
|
|
||||||
form.ShowDialog();
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridView.DataSource = _appointmentRepository.ReadAppointments();
|
}
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
{
|
{
|
||||||
id = 0;
|
return;
|
||||||
if (dataGridView.SelectedRows.Count < 1)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<FormAppointment>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadList() => dataGridView.DataSource = _appointmentRepository.ReadAppointments();
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,106 +1,96 @@
|
|||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
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;
|
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ITServiceManager.Forms
|
namespace ITServiceManager.Forms;
|
||||||
|
|
||||||
|
public partial class FormCompanies : Form
|
||||||
{
|
{
|
||||||
public partial class FormCompanies : Form
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly ICompanyRepository _companyRepository;
|
||||||
|
|
||||||
|
public FormCompanies(IUnityContainer container, ICompanyRepository companyRepository)
|
||||||
{
|
{
|
||||||
private readonly IUnityContainer _container;
|
InitializeComponent();
|
||||||
private readonly ICompanyRepository _companyRepository;
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
|
_companyRepository = companyRepository ?? throw new ArgumentNullException(nameof(companyRepository));
|
||||||
public FormCompanies(IUnityContainer container, ICompanyRepository companyRepository)
|
}
|
||||||
|
private void FormCompanies_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
LoadList();
|
||||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
|
||||||
_companyRepository = companyRepository ?? throw new ArgumentNullException(nameof(companyRepository));
|
|
||||||
}
|
}
|
||||||
private void FormCompanies_Load(object sender, EventArgs e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
try
|
MessageBox.Show(ex.Message, "Ошибка при загрузке",
|
||||||
{
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при загрузке",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_container.Resolve<FormCompany>().ShowDialog();
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonRemove_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_companyRepository.DeleteCompany(findId);
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var form = _container.Resolve<FormCompany>();
|
|
||||||
form.Id = findId;
|
|
||||||
form.ShowDialog();
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void LoadList() => dataGridView.DataSource = _companyRepository.ReadCompanies();
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
|
||||||
{
|
|
||||||
id = 0;
|
|
||||||
if (dataGridView.SelectedRows.Count < 1)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormCompany>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRemove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_companyRepository.DeleteCompany(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<FormCompany>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadList() => dataGridView.DataSource = _companyRepository.ReadCompanies();
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,6 @@
|
|||||||
textBoxName.Name = "textBoxName";
|
textBoxName.Name = "textBoxName";
|
||||||
textBoxName.Size = new Size(200, 23);
|
textBoxName.Size = new Size(200, 23);
|
||||||
textBoxName.TabIndex = 1;
|
textBoxName.TabIndex = 1;
|
||||||
textBoxName.TextChanged += textBoxName_TextChanged;
|
|
||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
|
@ -1,79 +1,64 @@
|
|||||||
using ITServiceManager.Entities;
|
using ITServiceManager.Entities;
|
||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
using ITServiceManager.Repositories.Implementations;
|
|
||||||
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 ITServiceManager.Forms
|
namespace ITServiceManager.Forms;
|
||||||
|
|
||||||
|
public partial class FormCompany : Form
|
||||||
{
|
{
|
||||||
public partial class FormCompany : Form
|
private readonly ICompanyRepository _companyRepository;
|
||||||
|
private int? _companyId;
|
||||||
|
public int Id
|
||||||
{
|
{
|
||||||
private readonly ICompanyRepository _companyRepository;
|
set
|
||||||
private int? _companyId;
|
|
||||||
public int Id
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var company = _companyRepository.ReadCompanyById(value);
|
|
||||||
if (company == null)
|
|
||||||
{
|
|
||||||
throw new InvalidDataException(nameof(company));
|
|
||||||
}
|
|
||||||
textBoxName.Text = company.Name;
|
|
||||||
textBoxAddress.Text = company.Address;
|
|
||||||
_companyId = value;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public FormCompany(ICompanyRepository companyRepository)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_companyRepository = companyRepository ?? throw new ArgumentNullException(nameof(companyRepository));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxAddress.Text))
|
var company = _companyRepository.ReadCompanyById(value);
|
||||||
|
if (company == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new InvalidDataException(nameof(company));
|
||||||
}
|
}
|
||||||
if (_companyId.HasValue)
|
textBoxName.Text = company.Name;
|
||||||
{
|
textBoxAddress.Text = company.Address;
|
||||||
_companyRepository.UpdateCompany(CreateCompany(_companyId.Value));
|
_companyId = value;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_companyRepository.CreateCompany(CreateCompany(0));
|
|
||||||
}
|
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
}
|
||||||
private Company CreateCompany(int id) => Company.CreateEntity(id, textBoxName.Text, textBoxAddress.Text);
|
public FormCompany(ICompanyRepository companyRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_companyRepository = companyRepository ?? throw new ArgumentNullException(nameof(companyRepository));
|
||||||
|
}
|
||||||
|
|
||||||
private void textBoxName_TextChanged(object sender, EventArgs e)
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxAddress.Text))
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
if (_companyId.HasValue)
|
||||||
|
{
|
||||||
|
_companyRepository.UpdateCompany(CreateCompany(_companyId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_companyRepository.CreateCompany(CreateCompany(0));
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
private Company CreateCompany(int id) => Company.CreateEntity(id, textBoxName.Text, textBoxAddress.Text);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
|
|
||||||
Version 2.0
|
Version 2.0
|
||||||
|
|
||||||
@ -48,7 +48,7 @@
|
|||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
@ -1,117 +1,105 @@
|
|||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
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;
|
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ITServiceManager.Forms
|
namespace ITServiceManager.Forms;
|
||||||
|
|
||||||
|
public partial class FormEmployees : Form
|
||||||
{
|
{
|
||||||
public partial class FormEmployees : Form
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IEmployeeRepository _employeeRepository;
|
||||||
|
public FormEmployees(IUnityContainer container, IEmployeeRepository
|
||||||
|
employeeRepository)
|
||||||
{
|
{
|
||||||
private readonly IUnityContainer _container;
|
InitializeComponent();
|
||||||
private readonly IEmployeeRepository _employeeRepository;
|
_container = container ??
|
||||||
public FormEmployees(IUnityContainer container, IEmployeeRepository
|
throw new ArgumentNullException(nameof(container));
|
||||||
employeeRepository)
|
_employeeRepository = employeeRepository ??
|
||||||
{
|
throw new
|
||||||
InitializeComponent();
|
ArgumentNullException(nameof(employeeRepository));
|
||||||
_container = container ??
|
|
||||||
throw new ArgumentNullException(nameof(container));
|
|
||||||
_employeeRepository = employeeRepository ??
|
|
||||||
throw new
|
|
||||||
ArgumentNullException(nameof(employeeRepository));
|
|
||||||
}
|
|
||||||
private void FormEmployees_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при загрузке",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_container.Resolve<FormEmployee>().ShowDialog();
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при добавлении",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var form = _container.Resolve<FormEmployee>();
|
|
||||||
form.Id = findId;
|
|
||||||
form.ShowDialog();
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonDel_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show("Удалить запись?", "Удаление",
|
|
||||||
MessageBoxButtons.YesNo) != DialogResult.Yes)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_employeeRepository.DeleteEmployee(findId);
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при удалении",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void LoadList() => dataGridView.DataSource =
|
|
||||||
_employeeRepository.ReadEmployees();
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
|
||||||
{
|
|
||||||
id = 0;
|
|
||||||
if (dataGridView.SelectedRows.Count < 1)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
id =
|
|
||||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private void FormEmployees_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormEmployee>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<FormEmployee>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_employeeRepository.DeleteEmployee(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadList() => dataGridView.DataSource =
|
||||||
|
_employeeRepository.ReadEmployees();
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id =
|
||||||
|
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,64 +1,53 @@
|
|||||||
using ITServiceManager.Entities;
|
using ITServiceManager.Entities;
|
||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
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;
|
|
||||||
using System.Windows.Forms.VisualStyles;
|
|
||||||
|
|
||||||
namespace ITServiceManager.Forms
|
namespace ITServiceManager.Forms;
|
||||||
|
|
||||||
|
public partial class FormOrder : Form
|
||||||
{
|
{
|
||||||
public partial class FormOrder : Form
|
private readonly IOrderRepository _orderRepository;
|
||||||
|
public FormOrder(IOrderRepository orderRepository, IServiceRepository serviceRepository, ICompanyRepository companyRepository)
|
||||||
{
|
{
|
||||||
private readonly IOrderRepository _orderRepository;
|
InitializeComponent();
|
||||||
public FormOrder(IOrderRepository orderRepository, IServiceRepository serviceRepository, ICompanyRepository companyRepository)
|
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
|
||||||
|
|
||||||
comboBoxCompany.DataSource = companyRepository.ReadCompanies();
|
comboBoxCompany.DataSource = companyRepository.ReadCompanies();
|
||||||
comboBoxCompany.DisplayMember = "Name";
|
comboBoxCompany.DisplayMember = "Name";
|
||||||
comboBoxCompany.ValueMember = "Id";
|
comboBoxCompany.ValueMember = "Id";
|
||||||
|
|
||||||
ColumnService.DataSource = serviceRepository.ReadServices();
|
ColumnService.DataSource = serviceRepository.ReadServices();
|
||||||
ColumnService.DisplayMember = "ServiceType";
|
ColumnService.DisplayMember = "ServiceName";
|
||||||
ColumnService.ValueMember = "Id";
|
ColumnService.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.RowCount < 1 || comboBoxCompany.SelectedIndex < 0 || numericUpDownPrice.Value <= 0)
|
||||||
{
|
{
|
||||||
if (dataGridView.RowCount < 1 || comboBoxCompany.SelectedIndex < 0 || numericUpDownPrice.Value <= 0)
|
throw new Exception("Имеются незаполненны поля");
|
||||||
{
|
|
||||||
throw new Exception("Имеются незаполненны поля");
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_orderRepository.CreateOrder(Order.CreateOperation(0, comboBoxCompany.SelectedIndex, numericUpDownPrice.Value, CreateListServiceFromDataGrid()));
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
try
|
||||||
private List<OrderService> CreateListServiceFromDataGrid()
|
|
||||||
{
|
{
|
||||||
var list = new List<OrderService>();
|
_orderRepository.CreateOrder(Order.CreateOperation(0, comboBoxCompany.SelectedIndex, numericUpDownPrice.Value, CreateListServiceFromDataGrid()));
|
||||||
foreach (DataGridViewRow row in dataGridView.Rows)
|
Close();
|
||||||
{
|
|
||||||
if (row.Cells["ColumService"].Value == null || row.Cells["ColumQuantity"].Value == null || row.Cells["ColumnExecutionDate"].Value == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
list.Add(OrderService.CreateOperation(0, 0, Convert.ToInt32(row.Cells["ColumnServices"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), Convert.ToDateTime(row.Cells["ColumnExecutionDate"].Value)));
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
private List<OrderService> CreateListServiceFromDataGrid()
|
||||||
|
{
|
||||||
|
var list = new List<OrderService>();
|
||||||
|
foreach (DataGridViewRow row in dataGridView.Rows)
|
||||||
|
{
|
||||||
|
if (row.Cells["ColumService"].Value == null || row.Cells["ColumQuantity"].Value == null || row.Cells["ColumnExecutionDate"].Value == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
list.Add(OrderService.CreateOperation(0, 0, Convert.ToInt32(row.Cells["ColumnServices"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), Convert.ToDateTime(row.Cells["ColumnExecutionDate"].Value)));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,81 +1,71 @@
|
|||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
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;
|
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ITServiceManager.Forms
|
namespace ITServiceManager.Forms;
|
||||||
|
|
||||||
|
public partial class FormOrders : Form
|
||||||
{
|
{
|
||||||
public partial class FormOrders : Form
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IOrderRepository _orderRepository;
|
||||||
|
public FormOrders(IUnityContainer container, IOrderRepository orderRepository)
|
||||||
{
|
{
|
||||||
private readonly IUnityContainer _container;
|
InitializeComponent();
|
||||||
private readonly IOrderRepository _orderRepository;
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
public FormOrders(IUnityContainer container, IOrderRepository orderRepository)
|
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||||
|
}
|
||||||
|
private void FormOrders_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
LoadList();
|
||||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
|
||||||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
|
||||||
}
|
}
|
||||||
private void FormOrders_Load(object sender, EventArgs e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
try
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
{
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_container.Resolve<FormOrder>().ShowDialog();
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonRemove_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_orderRepository.DeleteOrder(findId);
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void LoadList() => dataGridView.DataSource = _orderRepository.ReadOrders();
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
|
||||||
{
|
|
||||||
id = 0;
|
|
||||||
if (dataGridView.SelectedRows.Count < 1)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<FormOrder>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRemove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_orderRepository.DeleteOrder(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadList() => dataGridView.DataSource = _orderRepository.ReadOrders();
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,15 @@
|
|||||||
label1 = new Label();
|
label1 = new Label();
|
||||||
label2 = new Label();
|
label2 = new Label();
|
||||||
checkedListBoxType = new CheckedListBox();
|
checkedListBoxType = new CheckedListBox();
|
||||||
|
textBoxName = new TextBox();
|
||||||
|
labelName = new Label();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
buttonCancel.Location = new Point(358, 367);
|
buttonCancel.Location = new Point(310, 318);
|
||||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
buttonCancel.Name = "buttonCancel";
|
buttonCancel.Name = "buttonCancel";
|
||||||
buttonCancel.Size = new Size(128, 37);
|
buttonCancel.Size = new Size(112, 28);
|
||||||
buttonCancel.TabIndex = 7;
|
buttonCancel.TabIndex = 7;
|
||||||
buttonCancel.Text = "Отмена";
|
buttonCancel.Text = "Отмена";
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
@ -49,10 +50,9 @@
|
|||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
buttonAdd.Location = new Point(99, 367);
|
buttonAdd.Location = new Point(84, 318);
|
||||||
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
buttonAdd.Name = "buttonAdd";
|
buttonAdd.Name = "buttonAdd";
|
||||||
buttonAdd.Size = new Size(128, 37);
|
buttonAdd.Size = new Size(112, 28);
|
||||||
buttonAdd.TabIndex = 6;
|
buttonAdd.TabIndex = 6;
|
||||||
buttonAdd.Text = "Добавить";
|
buttonAdd.Text = "Добавить";
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
@ -60,49 +60,70 @@
|
|||||||
//
|
//
|
||||||
// richTextBoxDescription
|
// richTextBoxDescription
|
||||||
//
|
//
|
||||||
richTextBoxDescription.Location = new Point(278, 159);
|
richTextBoxDescription.Location = new Point(240, 207);
|
||||||
|
richTextBoxDescription.Margin = new Padding(3, 2, 3, 2);
|
||||||
richTextBoxDescription.Name = "richTextBoxDescription";
|
richTextBoxDescription.Name = "richTextBoxDescription";
|
||||||
richTextBoxDescription.Size = new Size(265, 175);
|
richTextBoxDescription.Size = new Size(232, 87);
|
||||||
richTextBoxDescription.TabIndex = 9;
|
richTextBoxDescription.TabIndex = 9;
|
||||||
richTextBoxDescription.Text = "";
|
richTextBoxDescription.Text = "";
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
label1.AutoSize = true;
|
label1.AutoSize = true;
|
||||||
label1.Location = new Point(68, 36);
|
label1.Location = new Point(57, 52);
|
||||||
label1.Name = "label1";
|
label1.Name = "label1";
|
||||||
label1.Size = new Size(83, 20);
|
label1.Size = new Size(67, 15);
|
||||||
label1.TabIndex = 4;
|
label1.TabIndex = 4;
|
||||||
label1.Text = "Тип услуги";
|
label1.Text = "Тип услуги";
|
||||||
//
|
//
|
||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
label2.AutoSize = true;
|
label2.AutoSize = true;
|
||||||
label2.Location = new Point(52, 179);
|
label2.Location = new Point(57, 239);
|
||||||
label2.Name = "label2";
|
label2.Name = "label2";
|
||||||
label2.Size = new Size(127, 20);
|
label2.Size = new Size(102, 15);
|
||||||
label2.TabIndex = 8;
|
label2.TabIndex = 8;
|
||||||
label2.Text = "Описание услуги";
|
label2.Text = "Описание услуги";
|
||||||
//
|
//
|
||||||
// checkedListBoxType
|
// checkedListBoxType
|
||||||
//
|
//
|
||||||
checkedListBoxType.FormattingEnabled = true;
|
checkedListBoxType.FormattingEnabled = true;
|
||||||
checkedListBoxType.Location = new Point(278, 12);
|
checkedListBoxType.Location = new Point(240, 29);
|
||||||
|
checkedListBoxType.Margin = new Padding(3, 2, 3, 2);
|
||||||
checkedListBoxType.Name = "checkedListBoxType";
|
checkedListBoxType.Name = "checkedListBoxType";
|
||||||
checkedListBoxType.Size = new Size(265, 114);
|
checkedListBoxType.Size = new Size(232, 76);
|
||||||
checkedListBoxType.TabIndex = 10;
|
checkedListBoxType.TabIndex = 10;
|
||||||
//
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
textBoxName.Location = new Point(240, 142);
|
||||||
|
textBoxName.Name = "textBoxName";
|
||||||
|
textBoxName.Size = new Size(232, 23);
|
||||||
|
textBoxName.TabIndex = 11;
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
labelName.AutoSize = true;
|
||||||
|
labelName.Location = new Point(57, 142);
|
||||||
|
labelName.Name = "labelName";
|
||||||
|
labelName.Size = new Size(59, 15);
|
||||||
|
labelName.TabIndex = 12;
|
||||||
|
labelName.Text = "Название";
|
||||||
|
//
|
||||||
// FormService
|
// FormService
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(584, 451);
|
ClientSize = new Size(511, 362);
|
||||||
|
Controls.Add(labelName);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
Controls.Add(checkedListBoxType);
|
Controls.Add(checkedListBoxType);
|
||||||
Controls.Add(richTextBoxDescription);
|
Controls.Add(richTextBoxDescription);
|
||||||
Controls.Add(label2);
|
Controls.Add(label2);
|
||||||
Controls.Add(buttonCancel);
|
Controls.Add(buttonCancel);
|
||||||
Controls.Add(buttonAdd);
|
Controls.Add(buttonAdd);
|
||||||
Controls.Add(label1);
|
Controls.Add(label1);
|
||||||
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
Name = "FormService";
|
Name = "FormService";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "Услуга";
|
Text = "Услуга";
|
||||||
@ -118,5 +139,7 @@
|
|||||||
private Label label1;
|
private Label label1;
|
||||||
private Label label2;
|
private Label label2;
|
||||||
private CheckedListBox checkedListBoxType;
|
private CheckedListBox checkedListBoxType;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private Label labelName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,6 @@
|
|||||||
using ITServiceManager.Entities.Enums;
|
using ITServiceManager.Entities.Enums;
|
||||||
using ITServiceManager.Entities;
|
using ITServiceManager.Entities;
|
||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
using Microsoft.VisualBasic.FileIO;
|
|
||||||
|
|
||||||
namespace ITServiceManager.Forms;
|
namespace ITServiceManager.Forms;
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ public partial class FormService : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textBoxName.Text = service.ServiceName;
|
||||||
richTextBoxDescription.Text = service.Description;
|
richTextBoxDescription.Text = service.Description;
|
||||||
_serviceId = value;
|
_serviceId = value;
|
||||||
}
|
}
|
||||||
@ -58,7 +57,7 @@ public partial class FormService : Form
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (checkedListBoxType.CheckedItems.Count == 0 ||
|
if (checkedListBoxType.CheckedItems.Count == 0 ||
|
||||||
string.IsNullOrWhiteSpace(richTextBoxDescription.Text))
|
string.IsNullOrWhiteSpace(richTextBoxDescription.Text) || string.IsNullOrWhiteSpace(textBoxName.Text))
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
@ -87,6 +86,6 @@ public partial class FormService : Form
|
|||||||
serviceType |= (ServiceType)elem;
|
serviceType |= (ServiceType)elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Service.CreateEntity(id, serviceType, richTextBoxDescription.Text);
|
return Service.CreateEntity(id, serviceType, textBoxName.Text, richTextBoxDescription.Text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
|
|
||||||
Version 2.0
|
Version 2.0
|
||||||
|
|
||||||
@ -48,7 +48,7 @@
|
|||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
@ -2,35 +2,34 @@ using ITServiceManager.Repositories.Implementations;
|
|||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ITServiceManager
|
namespace ITServiceManager;
|
||||||
|
|
||||||
|
internal static class Program
|
||||||
{
|
{
|
||||||
internal static class Program
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
{
|
{
|
||||||
/// <summary>
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
/// The main entry point for the application.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
/// </summary>
|
ApplicationConfiguration.Initialize();
|
||||||
[STAThread]
|
Application.Run(CreateContainer().Resolve<FormItCompany>());
|
||||||
static void Main()
|
|
||||||
{
|
}
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
|
||||||
Application.Run(CreateContainer().Resolve<FormItCompany>());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IUnityContainer CreateContainer()
|
private static IUnityContainer CreateContainer()
|
||||||
{
|
{
|
||||||
var container = new UnityContainer();
|
var container = new UnityContainer();
|
||||||
container.RegisterType<IOrderRepository, OrderRepository>();
|
container.RegisterType<IOrderRepository, OrderRepository>();
|
||||||
container.RegisterType<IAppointmentRepository, AppointmentRepository>();
|
container.RegisterType<IAppointmentRepository, AppointmentRepository>();
|
||||||
container.RegisterType<IServiceRepository, ServiceRepository>();
|
container.RegisterType<IServiceRepository, ServiceRepository>();
|
||||||
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
|
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
|
||||||
container.RegisterType<ICompanyRepository, CompanyRepository>();
|
container.RegisterType<ICompanyRepository, CompanyRepository>();
|
||||||
|
|
||||||
container.RegisterType<IConnectionString, ConnectionString>();
|
container.RegisterType<IConnectionString, ConnectionString>();
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user