This commit is contained in:
Егор Пыжов 2024-12-15 02:35:08 +04:00
commit 34a074f709
16 changed files with 224 additions and 233 deletions

View File

@ -11,14 +11,16 @@ public class Service
public ServiceType ServiceType { get; private set; }
[DisplayName("Описание")]
public string ServiceName { 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
{
Id = id,
ServiceType = type,
ServiceName = name,
Description = description
};
}

View File

@ -1,41 +1,41 @@
using ITServiceManager.Entities;
using ITServiceManager.Repositories;
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;
private int? _appointmentId;
public int Id
set
{
set
try
{
try
var appointment =
_appointmentRepository.ReadAppointmentById(value);
if (appointment == null)
{
var appointment =
_appointmentRepository.ReadAppointmentById(value);
if (appointment == null)
{
throw new
InvalidDataException(nameof(appointment));
}
comboBoxEmployee.SelectedItem = appointment.EmployeeId;
comboBoxOrder.SelectedItem = appointment.OrderId;
_appointmentId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
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));
}
public FormAppointment(IAppointmentRepository appointmentRepository, IEmployeeRepository employeeRepository, IOrderRepository orderRepository)
{
InitializeComponent();
_appointmentRepository = appointmentRepository ??
throw new ArgumentNullException(nameof(appointmentRepository));
comboBoxOrder.DataSource = orderRepository.ReadOrders();
comboBoxOrder.DisplayMember = "FullName";
@ -50,47 +50,49 @@ namespace ITServiceManager.Forms
dateTimePickerEnd.ValueChanged += DateTimePickerEnd_ValueChanged;
}
private void DateTimePickerEnd_ValueChanged(object sender, EventArgs e)
}
private void DateTimePickerEnd_ValueChanged(object sender, EventArgs e)
{
if (dateTimePickerEnd.CustomFormat == "В процессе")
{
if (dateTimePickerEnd.CustomFormat == "В процессе")
{
dateTimePickerEnd.CustomFormat = "dd.MM.yyyy HH:mm";
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0)
{
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)
{
DateTime? endDate = dateTimePickerEnd.CustomFormat == "В процессе" ? (DateTime?)null : dateTimePickerEnd.Value;
return Appointment.CreateOperation(id, (int)comboBoxOrder.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, Convert.ToDateTime(dateTimePickerStart.Value),
endDate);
dateTimePickerEnd.CustomFormat = "dd.MM.yyyy HH:mm";
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0)
{
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)
{
DateTime? endDate = dateTimePickerEnd.CustomFormat == "В процессе" ? (DateTime?)null : dateTimePickerEnd.Value;
return Appointment.CreateOperation(id, (int)comboBoxOrder.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, Convert.ToDateTime(dateTimePickerStart.Value),
endDate);
}
}

View File

@ -80,7 +80,6 @@
buttonRemove.Size = new Size(86, 101);
buttonRemove.TabIndex = 3;
buttonRemove.UseVisualStyleBackColor = true;
buttonRemove.Click += buttonRemove_Click;
//
// buttonUpdate
//

View File

@ -1,21 +1,12 @@
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;
namespace ITServiceManager.Forms
namespace ITServiceManager.Forms;
public partial class FormCompanies : Form
{
public partial class FormCompanies : Form
{
private readonly IUnityContainer _container;
private readonly ICompanyRepository _companyRepository;
private readonly IUnityContainer _container;
private readonly ICompanyRepository _companyRepository;
public FormCompanies(IUnityContainer container, ICompanyRepository companyRepository)
{
@ -102,9 +93,8 @@ namespace ITServiceManager.Forms
return true;
}
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -1,77 +1,68 @@
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;
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;
private readonly IEmployeeRepository _employeeRepository;
public FormEmployees(IUnityContainer container, IEmployeeRepository
employeeRepository)
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_employeeRepository = employeeRepository ??
throw new
ArgumentNullException(nameof(employeeRepository));
}
private void FormEmployees_Load(object sender, EventArgs e)
{
try
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_employeeRepository = employeeRepository ??
throw new
ArgumentNullException(nameof(employeeRepository));
LoadList();
}
private void FormEmployees_Load(object sender, EventArgs e)
catch (Exception ex)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
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<FormEmployee>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_container.Resolve<FormEmployee>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
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);
}
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)
{
@ -116,7 +107,4 @@ namespace ITServiceManager.Forms
return true;
}
}
}

View File

@ -1,5 +1,6 @@
using ITServiceManager.Entities;
using ITServiceManager.Repositories;
namespace ITServiceManager.Forms;
public partial class FormOrder : Form
@ -15,7 +16,7 @@ public partial class FormOrder : Form
comboBoxCompany.ValueMember = "Id";
ColumnService.DataSource = serviceRepository.ReadServices();
ColumnService.DisplayMember = "ServiceType";
ColumnService.DisplayMember = "ServiceName";
ColumnService.ValueMember = "Id";
}

View File

@ -1,13 +1,4 @@
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;
namespace ITServiceManager.Forms

View File

@ -34,12 +34,13 @@
label1 = new Label();
label2 = new Label();
checkedListBoxType = new CheckedListBox();
textBoxName = new TextBox();
labelName = new Label();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Location = new Point(358, 367);
buttonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Location = new Point(310, 318);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(128, 37);
buttonCancel.TabIndex = 7;
@ -49,8 +50,7 @@
//
// buttonAdd
//
buttonAdd.Location = new Point(99, 367);
buttonAdd.Margin = new Padding(3, 4, 3, 4);
buttonAdd.Location = new Point(84, 318);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(128, 37);
buttonAdd.TabIndex = 6;
@ -60,25 +60,26 @@
//
// 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.Size = new Size(265, 175);
richTextBoxDescription.Size = new Size(232, 87);
richTextBoxDescription.TabIndex = 9;
richTextBoxDescription.Text = "";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(68, 36);
label1.Location = new Point(57, 52);
label1.Name = "label1";
label1.Size = new Size(83, 20);
label1.Size = new Size(67, 15);
label1.TabIndex = 4;
label1.Text = "Тип услуги";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(52, 179);
label2.Location = new Point(57, 239);
label2.Name = "label2";
label2.Size = new Size(127, 20);
label2.TabIndex = 8;
@ -87,22 +88,42 @@
// checkedListBoxType
//
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.Size = new Size(265, 114);
checkedListBoxType.Size = new Size(232, 76);
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
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(584, 451);
ClientSize = new Size(511, 362);
Controls.Add(labelName);
Controls.Add(textBoxName);
Controls.Add(checkedListBoxType);
Controls.Add(richTextBoxDescription);
Controls.Add(label2);
Controls.Add(buttonCancel);
Controls.Add(buttonAdd);
Controls.Add(label1);
Margin = new Padding(3, 2, 3, 2);
Name = "FormService";
StartPosition = FormStartPosition.CenterScreen;
Text = "Услуга";
@ -118,5 +139,7 @@
private Label label1;
private Label label2;
private CheckedListBox checkedListBoxType;
private TextBox textBoxName;
private Label labelName;
}
}

View File

@ -31,7 +31,7 @@ public partial class FormService : Form
}
}
textBoxName.Text = service.ServiceName;
richTextBoxDescription.Text = service.Description;
_serviceId = value;
}
@ -58,7 +58,7 @@ public partial class FormService : Form
try
{
if (checkedListBoxType.CheckedItems.Count == 0 ||
string.IsNullOrWhiteSpace(richTextBoxDescription.Text))
string.IsNullOrWhiteSpace(richTextBoxDescription.Text) || string.IsNullOrWhiteSpace(textBoxName.Text))
{
throw new Exception("Имеются незаполненные поля");
}
@ -87,6 +87,6 @@ public partial class FormService : Form
serviceType |= (ServiceType)elem;
}
return Service.CreateEntity(id, serviceType, richTextBoxDescription.Text);
return Service.CreateEntity(id, serviceType, textBoxName.Text, richTextBoxDescription.Text);
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -6,50 +6,49 @@ using Unity.Microsoft.Logging;
using Serilog;
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>
/// The main entry point for the application.
/// </summary>
[STAThread]
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()
{
var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<IOrderRepository, OrderRepository>();
container.RegisterType<IAppointmentRepository, AppointmentRepository>();
container.RegisterType<IServiceRepository, ServiceRepository>();
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
container.RegisterType<ICompanyRepository, CompanyRepository>();
container.RegisterType<IConnectionString, ConnectionString>();
return container;
}
private static LoggerFactory CreateLoggerFactory()
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build())
.CreateLogger());
return loggerFactory;
}
// 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()
{
var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<IOrderRepository, OrderRepository>();
container.RegisterType<IAppointmentRepository, AppointmentRepository>();
container.RegisterType<IServiceRepository, ServiceRepository>();
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
container.RegisterType<ICompanyRepository, CompanyRepository>();
container.RegisterType<IConnectionString, ConnectionString>();
return container;
}
private static LoggerFactory CreateLoggerFactory()
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build())
.CreateLogger());
return loggerFactory;
}
}

View File

@ -1,6 +1,4 @@
using ITServiceManager.Entities;
using ITServiceManager.Repositories;
using ITServiceManager.Repositories.Implementations;
using ITServiceManager.Repositories;
using Microsoft.Extensions.Logging;
namespace ITServiceManager.Reports;

View File

@ -30,7 +30,7 @@ public class DocReport
}
if (includeServices)
{
builder.AddParagraph("Услуги").AddTable([2400, 2400], GetServices());
builder.AddParagraph("Услуги").AddTable([2400, 2400, 2400], GetServices());
}
if (includeEmployees)
{
@ -69,10 +69,10 @@ public class DocReport
private List<string[]> GetServices()
{
return [
["Тип услуги", "Описание"],
["Название услуги", "Тип услуги", "Описание"],
.. _serviceRepository
.ReadServices()
.Select(x => new string[] { x.ServiceType.ToString(), x.Description }),
.Select(x => new string[] {x.ServiceName, x.ServiceType.ToString(), x.Description }),
];
}
}

View File

@ -1,7 +1,4 @@

using ITServiceManager.Entities;
using ITServiceManager.Repositories;
using ITServiceManager.Repositories.Implementations;
using ITServiceManager.Repositories;
using Microsoft.Extensions.Logging;
namespace ITServiceManager.Reports;

View File

@ -64,8 +64,8 @@ public class ServiceRepository : IServiceRepository
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Services (ServiceType, Description)
VALUES (@ServiceType, @Description)";
INSERT INTO Services (ServiceType, ServiceName, Description)
VALUES (@ServiceType, @ServiceName, @Description)";
connection.Execute(queryInsert, service);
}
catch (Exception ex)
@ -85,6 +85,7 @@ public class ServiceRepository : IServiceRepository
UPDATE Services
SET
ServiceType=@ServiceType,
ServiceName=@ServiceName,
Description=@Description
WHERE Id=@Id";
connection.Execute(queryUpdate, service);