Рефакторинг
This commit is contained in:
commit
aefbbc4347
@ -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,8 +1,8 @@
|
|||||||
using ITServiceManager.Entities;
|
using ITServiceManager.Entities;
|
||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
|
|
||||||
namespace ITServiceManager.Forms
|
namespace ITServiceManager.Forms;
|
||||||
{
|
|
||||||
public partial class FormAppointment : Form
|
public partial class FormAppointment : Form
|
||||||
{
|
{
|
||||||
private readonly IAppointmentRepository _appointmentRepository;
|
private readonly IAppointmentRepository _appointmentRepository;
|
||||||
@ -20,8 +20,8 @@ namespace ITServiceManager.Forms
|
|||||||
throw new
|
throw new
|
||||||
InvalidDataException(nameof(appointment));
|
InvalidDataException(nameof(appointment));
|
||||||
}
|
}
|
||||||
comboBoxEmployee.SelectedItem = appointment.EmployeeId;
|
comboBoxEmployee.SelectedIndex = appointment.EmployeeId;
|
||||||
comboBoxOrder.SelectedItem = appointment.OrderId;
|
comboBoxOrder.SelectedIndex = appointment.OrderId;
|
||||||
_appointmentId = value;
|
_appointmentId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -51,7 +51,6 @@ namespace ITServiceManager.Forms
|
|||||||
dateTimePickerEnd.ValueChanged += DateTimePickerEnd_ValueChanged;
|
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 == "В процессе")
|
||||||
@ -84,7 +83,9 @@ namespace ITServiceManager.Forms
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
private Appointment CreateAppointment(int id)
|
private Appointment CreateAppointment(int id)
|
||||||
{
|
{
|
||||||
DateTime? endDate = dateTimePickerEnd.CustomFormat == "В процессе" ? (DateTime?)null : dateTimePickerEnd.Value;
|
DateTime? endDate = dateTimePickerEnd.CustomFormat == "В процессе" ? (DateTime?)null : dateTimePickerEnd.Value;
|
||||||
@ -92,5 +93,6 @@ namespace ITServiceManager.Forms
|
|||||||
return Appointment.CreateOperation(id, (int)comboBoxOrder.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, Convert.ToDateTime(dateTimePickerStart.Value),
|
return Appointment.CreateOperation(id, (int)comboBoxOrder.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, Convert.ToDateTime(dateTimePickerStart.Value),
|
||||||
endDate);
|
endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -80,7 +80,6 @@
|
|||||||
buttonRemove.Size = new Size(86, 101);
|
buttonRemove.Size = new Size(86, 101);
|
||||||
buttonRemove.TabIndex = 3;
|
buttonRemove.TabIndex = 3;
|
||||||
buttonRemove.UseVisualStyleBackColor = true;
|
buttonRemove.UseVisualStyleBackColor = true;
|
||||||
buttonRemove.Click += buttonRemove_Click;
|
|
||||||
//
|
//
|
||||||
// buttonUpdate
|
// buttonUpdate
|
||||||
//
|
//
|
||||||
|
@ -1,18 +1,8 @@
|
|||||||
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;
|
|
||||||
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 IUnityContainer _container;
|
||||||
@ -77,27 +67,5 @@ namespace ITServiceManager.Forms
|
|||||||
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonRemove_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_appointmentRepository.DeleteAppointment(findId);
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,8 @@
|
|||||||
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 IUnityContainer _container;
|
||||||
@ -103,4 +94,3 @@ namespace ITServiceManager.Forms
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,17 +1,8 @@
|
|||||||
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 IUnityContainer _container;
|
||||||
@ -111,7 +102,4 @@ namespace ITServiceManager.Forms
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using ITServiceManager.Entities;
|
using ITServiceManager.Entities;
|
||||||
using ITServiceManager.Repositories;
|
using ITServiceManager.Repositories;
|
||||||
|
|
||||||
namespace ITServiceManager.Forms;
|
namespace ITServiceManager.Forms;
|
||||||
|
|
||||||
public partial class FormOrder : Form
|
public partial class FormOrder : Form
|
||||||
@ -15,7 +16,7 @@ public partial class FormOrder : Form
|
|||||||
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";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,8 @@
|
|||||||
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 IUnityContainer _container;
|
||||||
@ -78,4 +69,3 @@ namespace ITServiceManager.Forms
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -34,12 +34,13 @@
|
|||||||
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(128, 37);
|
||||||
buttonCancel.TabIndex = 7;
|
buttonCancel.TabIndex = 7;
|
||||||
@ -49,8 +50,7 @@
|
|||||||
//
|
//
|
||||||
// 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(128, 37);
|
||||||
buttonAdd.TabIndex = 6;
|
buttonAdd.TabIndex = 6;
|
||||||
@ -60,25 +60,26 @@
|
|||||||
//
|
//
|
||||||
// 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(127, 20);
|
||||||
label2.TabIndex = 8;
|
label2.TabIndex = 8;
|
||||||
@ -87,22 +88,42 @@
|
|||||||
// 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(8F, 20F);
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,7 +31,7 @@ public partial class FormService : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textBoxName.Text = service.ServiceName;
|
||||||
richTextBoxDescription.Text = service.Description;
|
richTextBoxDescription.Text = service.Description;
|
||||||
_serviceId = value;
|
_serviceId = value;
|
||||||
}
|
}
|
||||||
@ -58,7 +58,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 +87,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ using Unity.Microsoft.Logging;
|
|||||||
using Serilog;
|
using Serilog;
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ITServiceManager
|
namespace ITServiceManager;
|
||||||
{
|
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -22,7 +22,6 @@ namespace ITServiceManager
|
|||||||
Application.Run(CreateContainer().Resolve<FormItCompany>());
|
Application.Run(CreateContainer().Resolve<FormItCompany>());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IUnityContainer CreateContainer()
|
private static IUnityContainer CreateContainer()
|
||||||
{
|
{
|
||||||
var container = new UnityContainer();
|
var container = new UnityContainer();
|
||||||
@ -51,5 +50,5 @@ namespace ITServiceManager
|
|||||||
.CreateLogger());
|
.CreateLogger());
|
||||||
return loggerFactory;
|
return loggerFactory;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -64,8 +64,8 @@ public class ServiceRepository : IServiceRepository
|
|||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Services (ServiceType, Description)
|
INSERT INTO Services (ServiceType, ServiceName, Description)
|
||||||
VALUES (@ServiceType, @Description)";
|
VALUES (@ServiceType, @ServiceName, @Description)";
|
||||||
connection.Execute(queryInsert, service);
|
connection.Execute(queryInsert, service);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -85,6 +85,7 @@ public class ServiceRepository : IServiceRepository
|
|||||||
UPDATE Services
|
UPDATE Services
|
||||||
SET
|
SET
|
||||||
ServiceType=@ServiceType,
|
ServiceType=@ServiceType,
|
||||||
|
ServiceName=@ServiceName,
|
||||||
Description=@Description
|
Description=@Description
|
||||||
WHERE Id=@Id";
|
WHERE Id=@Id";
|
||||||
connection.Execute(queryUpdate, service);
|
connection.Execute(queryUpdate, service);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user