diff --git a/ITServiceManager/ITServiceManager/Entities/Appointment.cs b/ITServiceManager/ITServiceManager/Entities/Appointment.cs index e00f740..27bbd2d 100644 --- a/ITServiceManager/ITServiceManager/Entities/Appointment.cs +++ b/ITServiceManager/ITServiceManager/Entities/Appointment.cs @@ -9,7 +9,7 @@ public class Appointment [Browsable(false)] public int EmployeeId { get; private set; } - [Browsable(false)] + [DisplayName("Номер заказа")] public int OrderId { get; private set; } [DisplayName("Сотрудник")] diff --git a/ITServiceManager/ITServiceManager/Entities/Order.cs b/ITServiceManager/ITServiceManager/Entities/Order.cs index e6ee342..0c5c9d8 100644 --- a/ITServiceManager/ITServiceManager/Entities/Order.cs +++ b/ITServiceManager/ITServiceManager/Entities/Order.cs @@ -43,17 +43,4 @@ public class Order OrderService = orderService }; } - - public static Order CreateOperation(TempOrder tempOrder, IEnumerable orderService) - { - return new Order - { - Id = tempOrder.Id, - CompanyId = tempOrder.CompanyId, - Date = tempOrder.Date, - Price = tempOrder.Price, - OrderService = orderService - }; - } - } diff --git a/ITServiceManager/ITServiceManager/Entities/OrderService.cs b/ITServiceManager/ITServiceManager/Entities/OrderService.cs index 533c56a..4091607 100644 --- a/ITServiceManager/ITServiceManager/Entities/OrderService.cs +++ b/ITServiceManager/ITServiceManager/Entities/OrderService.cs @@ -9,7 +9,7 @@ public class OrderService public int Quantity { get; private set; } public DateTime ExecutionDate { get; private set; } - public static OrderService CreateOperation(int id, int serviceId, int serviceQuantity, DateTime executionDate) + public static OrderService CreateElement(int id, int serviceId, int serviceQuantity, DateTime executionDate) { return new OrderService { diff --git a/ITServiceManager/ITServiceManager/Entities/TempOrder.cs b/ITServiceManager/ITServiceManager/Entities/TempOrder.cs deleted file mode 100644 index 761b835..0000000 --- a/ITServiceManager/ITServiceManager/Entities/TempOrder.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace ITServiceManager.Entities; - -public class TempOrder -{ - public int Id { get; private set; } - public int CompanyId { get; private set; } - public int ServiceId { get; private set; } - public DateTime Date { get; private set; } - public decimal Price { get; private set; } - public int Quantity { get; private set; } - public DateTime ExecutionTime { get; private set; } -} diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs index e157b6d..b09929b 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointment.cs @@ -42,7 +42,7 @@ namespace ITServiceManager.Forms comboBoxOrder.ValueMember = "Id"; comboBoxEmployee.DataSource = employeeRepository.ReadEmployees(); - comboBoxEmployee.DisplayMember = "Name"; + comboBoxEmployee.DisplayMember = "FullName"; comboBoxEmployee.ValueMember = "Id"; dateTimePickerEnd.Format = DateTimePickerFormat.Custom; diff --git a/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs b/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs index 9af548e..ff77694 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormAppointments.cs @@ -1,108 +1,112 @@ 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; -namespace ITServiceManager.Forms -{ - public partial class FormAppointments : Form - { - private readonly IUnityContainer _container; - private readonly IAppointmentRepository _appointmentRepository; - public FormAppointments(IUnityContainer container, IAppointmentRepository appointmentRepository) - { - InitializeComponent(); - _container = container ?? throw new ArgumentNullException(nameof(container)); - _appointmentRepository = appointmentRepository ?? throw new ArgumentNullException(nameof(appointmentRepository)); - } - private void FormAppointments_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().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(); - form.Id = findId; - form.ShowDialog(); - LoadList(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при изменении", - MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void LoadList() - { - dataGridView.DataSource = _appointmentRepository.ReadAppointments(); - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["StartDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm"; - dataGridView.Columns["EndDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm"; - } - 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; - } +namespace ITServiceManager.Forms; - private void buttonRemove_Click(object sender, EventArgs e) +public partial class FormAppointments : Form +{ + private readonly IUnityContainer _container; + private readonly IAppointmentRepository _appointmentRepository; + public FormAppointments(IUnityContainer container, IAppointmentRepository appointmentRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _appointmentRepository = appointmentRepository ?? throw new ArgumentNullException(nameof(appointmentRepository)); + } + private void FormAppointments_Load(object sender, EventArgs e) + { + try { - if (!TryGetIdentifierFromSelectedRow(out var findId)) + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().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(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() + { + dataGridView.DataSource = _appointmentRepository.ReadAppointments(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["StartDate"].DefaultCellStyle.Format = "dd.MM.yyyy HH:mm"; + dataGridView.CellFormatting += (sender, e) => + { + if (dataGridView.Columns[e.ColumnIndex].Name == "EndDate") { - 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); + if (e.Value == null || e.Value == DBNull.Value) + { + e.Value = "В процессе"; + e.FormattingApplied = true; + } + else if (e.Value is DateTime endDate) + { + e.Value = endDate.ToString("dd.MM.yyyy HH:mm"); + e.FormattingApplied = true; + } } + }; + } + 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 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); } } } diff --git a/ITServiceManager/ITServiceManager/Forms/FormOrder.cs b/ITServiceManager/ITServiceManager/Forms/FormOrder.cs index 0a39fa6..24d54a7 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormOrder.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormOrder.cs @@ -45,9 +45,9 @@ public partial class FormOrder : Form { continue; } - list.Add(OrderService.CreateOperation(0, Convert.ToInt32(row.Cells["ColumnService"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), Convert.ToDateTime(row.Cells["ColumnExecutionDate"].Value))); + list.Add(OrderService.CreateElement(0, Convert.ToInt32(row.Cells["ColumnService"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), Convert.ToDateTime(row.Cells["ColumnExecutionDate"].Value))); } - return list; + return list.GroupBy(x => x.ServiceId, x => x.Quantity, (id, quantities) => OrderService.CreateElement(0, id, quantities.Sum(), list.First(x => x.ServiceId == id).ExecutionDate)).ToList(); } } diff --git a/ITServiceManager/ITServiceManager/Forms/FormServices.cs b/ITServiceManager/ITServiceManager/Forms/FormServices.cs index 4c5694b..9bfbf91 100644 --- a/ITServiceManager/ITServiceManager/Forms/FormServices.cs +++ b/ITServiceManager/ITServiceManager/Forms/FormServices.cs @@ -95,8 +95,11 @@ namespace ITServiceManager.Forms MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void LoadList() => dataGridView.DataSource = - _serviceRepository.ReadServices(); + private void LoadList() + { + dataGridView.DataSource = _serviceRepository.ReadServices(); + dataGridView.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { id = 0; diff --git a/ITServiceManager/ITServiceManager/Reports/TableReport.cs b/ITServiceManager/ITServiceManager/Reports/TableReport.cs index 4fe09cb..4b9855a 100644 --- a/ITServiceManager/ITServiceManager/Reports/TableReport.cs +++ b/ITServiceManager/ITServiceManager/Reports/TableReport.cs @@ -29,7 +29,7 @@ public class TableReport .AddHeader("Сводка по обслуживанию услуг", 0, 3) .AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0) - .AddTable([10, 10, 15, 15], GetData(employeeId, startDate, endDate)) + .AddTable([10, 10, 15], GetData(employeeId, startDate, endDate)) .Build(); return true; } @@ -48,9 +48,9 @@ public class TableReport .SelectMany(order => order.OrderService .Select(service => new { - EmployeeId = _appointmentRepository + EmployeeName = _appointmentRepository .ReadAppointments() - .FirstOrDefault(app => app.OrderId == order.Id)?.EmployeeId, + .FirstOrDefault(app => app.OrderId == order.Id)?.EmployeeName, Date = order.Date, Quantity = service.Quantity })) @@ -58,7 +58,8 @@ public class TableReport return new List() { item } .Union( data - .Select(x => new string[] { x.EmployeeId?.ToString() ?? "Не назначен", x.Date.ToString("dd.MM.yyyy"), x.Quantity.ToString()})) + .Select( + x => new string[] { x.EmployeeName ?? "Не назначен", x.Date.ToString("dd.MM.yyyy"), x.Quantity.ToString()})) .Union( [["Всего", string.Empty, data.Sum(x => x.Quantity).ToString()]]) .ToList(); diff --git a/ITServiceManager/ITServiceManager/Repositories/IOrderRepository.cs b/ITServiceManager/ITServiceManager/Repositories/IOrderRepository.cs index f61aaa6..3a7a5c1 100644 --- a/ITServiceManager/ITServiceManager/Repositories/IOrderRepository.cs +++ b/ITServiceManager/ITServiceManager/Repositories/IOrderRepository.cs @@ -4,7 +4,7 @@ namespace ITServiceManager.Repositories; public interface IOrderRepository { - IEnumerable ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? serviceId = null, int? companyId = null); + IEnumerable ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? serviceId = null, int? companyId = null); void CreateOrder(Order order); void DeleteOrder(int id); } diff --git a/ITServiceManager/ITServiceManager/Repositories/Implementations/AppointmentRepository.cs b/ITServiceManager/ITServiceManager/Repositories/Implementations/AppointmentRepository.cs index df2f045..9c9aadc 100644 --- a/ITServiceManager/ITServiceManager/Repositories/Implementations/AppointmentRepository.cs +++ b/ITServiceManager/ITServiceManager/Repositories/Implementations/AppointmentRepository.cs @@ -41,8 +41,9 @@ public class AppointmentRepository : IAppointmentRepository builder.AddCondition("ap.dateEnd >= @dateTo"); } using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @$"SELECT ap.*, e.Name as 'EmployeeName' - FROM Employees ap JOIN Employees e ON e.id = ap.EmployeeId + var querySelect = @$" + SELECT ap.*, CONCAT(e.LastName, ' ', e.FirstName) as EmployeeName + FROM Appointments ap LEFT JOIN Employees e ON e.id = ap.EmployeeId; {builder.Build()}"; var appointment = connection.Query(querySelect, new { employeeId, dateFrom, dateTo}); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(appointment)); diff --git a/ITServiceManager/ITServiceManager/Repositories/Implementations/OrderRepository.cs b/ITServiceManager/ITServiceManager/Repositories/Implementations/OrderRepository.cs index 4cbc9f1..ab99d84 100644 --- a/ITServiceManager/ITServiceManager/Repositories/Implementations/OrderRepository.cs +++ b/ITServiceManager/ITServiceManager/Repositories/Implementations/OrderRepository.cs @@ -24,25 +24,24 @@ public class OrderRepository : IOrderRepository var builder = new QueryBuilder(); if (dateFrom.HasValue) { - builder.AddCondition("Orders.Date >= @dateForm"); + builder.AddCondition("o.Date >= @dateFrom"); } if (dateTo.HasValue) { - builder.AddCondition("Orders.Date <= @dateTo"); + builder.AddCondition("o.Date <= @dateTo"); } - if (companyId.HasValue) + if (serviceId.HasValue) { - builder.AddCondition("Orders.CompanyId = @companyId"); + builder.AddCondition("os.ServiceId = @serviceId"); } using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = @$" - SELECT o.*, c.Name as CompanyName, os.serviceId, os.quantity, s.ServiceType + SELECT o.*, c.Name as CompanyName, os.serviceId, os.quantity, s.ServiceType as ServiceName FROM Orders AS o LEFT JOIN Companies c on c.Id = o.CompanyId INNER JOIN Order_Service AS os ON o.id = os.orderId LEFT JOIN Services s on s.Id = os.ServiceId - Where os.serviceId = @serviceId - {builder.Build}"; + {builder.Build()}"; var orderDict = new Dictionary>(); var orders = connection.Query(querySelect,