diff --git a/ProjectOptika/Scripts/Entities/Accessories.cs b/ProjectOptika/Scripts/Entities/Accessories.cs index b3747ce..f6dc492 100644 --- a/ProjectOptika/Scripts/Entities/Accessories.cs +++ b/ProjectOptika/Scripts/Entities/Accessories.cs @@ -1,4 +1,5 @@ using ProjectOptika.Scripts.Entities.Enums; +using System.ComponentModel; namespace ProjectOptika.Scripts.Entities { @@ -6,18 +7,25 @@ namespace ProjectOptika.Scripts.Entities { public int ID { get; private set; } + [DisplayName("Название")] public string Name { get; private set; } + [DisplayName("Название бренда")] public string Brand { get; private set; } + [DisplayName("Стоимость")] public int Cost { get; private set; } + [DisplayName("Количество на складе")] public int StockAvailability { get; private set; } + [DisplayName("Количество в магазине")] public int AvailabilityStore { get; private set; } + [DisplayName("Дата поставки")] public DateTime DeliveryDate { get; private set; } + [DisplayName("Категория")] public CategoryType CategoryName { get; private set; } public static Accessories CreateEntity(int id, string name, string brand, int cost, int stockAvailability, int availabilityStore, DateTime deliveryDate, CategoryType categoryName) diff --git a/ProjectOptika/Scripts/Entities/AccessoriesOrder.cs b/ProjectOptika/Scripts/Entities/AccessoriesOrder.cs index 7c12c91..46e309c 100644 --- a/ProjectOptika/Scripts/Entities/AccessoriesOrder.cs +++ b/ProjectOptika/Scripts/Entities/AccessoriesOrder.cs @@ -8,13 +8,16 @@ public int Count { get; private set; } - public static AccessoriesOrder CreateElement(int id, int accesoryId, int count) + public string AccessoryName { get; private set; } = string.Empty; + + public static AccessoriesOrder CreateElement(int id, int accesoryId, int count, string? accessoryName = null) { return new AccessoriesOrder { ID = id, AccesoryId = accesoryId, - Count = count + Count = count, + AccessoryName = accessoryName }; } } diff --git a/ProjectOptika/Scripts/Entities/Client.cs b/ProjectOptika/Scripts/Entities/Client.cs index d74ca73..abe67aa 100644 --- a/ProjectOptika/Scripts/Entities/Client.cs +++ b/ProjectOptika/Scripts/Entities/Client.cs @@ -1,4 +1,5 @@ using ProjectOptika.Scripts.Entities.Enums; +using System.ComponentModel; namespace ProjectOptika.Scripts.Entities { @@ -6,16 +7,23 @@ namespace ProjectOptika.Scripts.Entities { public int ID { get; private set; } + [DisplayName("Тип клиента")] public ClientType ClientType { get; private set; } + [DisplayName("Имя")] public string FirstName { get; private set; } + [DisplayName("Отчество")] public string SecondName { get; private set; } + [DisplayName("Фамилия")] public string Surname { get; private set; } + [DisplayName("Номер телефона")] public string PhoneNumber { get; private set; } + public string FullName => $"{FirstName} {SecondName} {Surname}"; + public static Client CreateEntity(int id, ClientType clientType, string firstName, string secondName, string surname, string phoneNumber) { return new Client diff --git a/ProjectOptika/Scripts/Entities/Employee.cs b/ProjectOptika/Scripts/Entities/Employee.cs index 6ab44eb..03f0d31 100644 --- a/ProjectOptika/Scripts/Entities/Employee.cs +++ b/ProjectOptika/Scripts/Entities/Employee.cs @@ -1,4 +1,5 @@ using ProjectOptika.Scripts.Entities.Enums; +using System.ComponentModel; namespace ProjectOptika.Scripts.Entities { @@ -6,14 +7,20 @@ namespace ProjectOptika.Scripts.Entities { public int ID { get; private set; } + [DisplayName("Тип сотрудника")] public PositionEmployee PositionEmployee { get; private set; } + [DisplayName("Имя")] public string FirstName { get; private set; } + [DisplayName("Отчество")] public string SecondName { get; private set; } + [DisplayName("Фамилия")] public string Surname { get; private set; } + public string FullName => $"{FirstName} {SecondName} {Surname}"; + public static Employee CreateEntity(int id, PositionEmployee positionEmployee, string firstName, string secondName, string surname) { return new Employee { diff --git a/ProjectOptika/Scripts/Entities/Order.cs b/ProjectOptika/Scripts/Entities/Order.cs index 514faf4..4065666 100644 --- a/ProjectOptika/Scripts/Entities/Order.cs +++ b/ProjectOptika/Scripts/Entities/Order.cs @@ -1,19 +1,45 @@ -namespace ProjectOptika.Scripts.Entities +using System.ComponentModel; + +namespace ProjectOptika.Scripts.Entities { public class Order { public int ID { get; private set; } + [Browsable(false)] public int EmployeeID { get; private set; } + [Browsable(false)] public int ClientID { get; private set; } + [DisplayName("Дата заказа")] public DateTime OrderDate { get; private set; } + [DisplayName("Общая стоимость")] public double TotalCost { get; private set; } + [DisplayName("Клиент")] + public string ClientFullName { get; private set; } + + [DisplayName("Работник")] + public string EmployeeFullName { get; private set; } + + [DisplayName("Заказ")] + public string AccessoryOrder => AccesoriesOrders != null ? + string.Join(", ", AccesoriesOrders.Select(x => x != null ? $"{x.AccessoryName} {x.Count}" : string.Empty)) : + string.Empty; + + [Browsable(false)] public IEnumerable AccesoriesOrders { get; private set; } = []; + public void SetAccessriesOrderReplenishment(IEnumerable accesoriesOrders) + { + if (accesoriesOrders != null && accesoriesOrders.Any()) + { + AccesoriesOrders = accesoriesOrders; + } + } + public static Order CreateOperation(int id, int employeeID, int clientID, double totalCost, IEnumerable accesoriesOrders) { return new Order { diff --git a/ProjectOptika/Scripts/Entities/Specifications.cs b/ProjectOptika/Scripts/Entities/Specifications.cs index 26be3ce..7261eff 100644 --- a/ProjectOptika/Scripts/Entities/Specifications.cs +++ b/ProjectOptika/Scripts/Entities/Specifications.cs @@ -1,19 +1,30 @@ -namespace ProjectOptika.Scripts.Entities +using System.ComponentModel; + +namespace ProjectOptika.Scripts.Entities { public class Specifications { public int ID { get; private set; } + [Browsable(false)] public int AccessoriesID { get; private set; } + [DisplayName("Наименование аксессуара")] + public string AccessoriesName { get; private set; } + + [DisplayName("Материал")] public string Material { get; private set; } + [DisplayName("Астигматизм")] public string Astigmatism { get; private set; } + [DisplayName("Диоптрийность")] public string Dioptericity { get; private set; } + [DisplayName("Страна изготовителя")] public string OriginCountry { get; private set; } + [DisplayName("Время производства")] public double TimeProduction { get; private set; } public static Specifications CreateEntity(int id, int accessoriesID, string material, string astigmatism, string dioptericity, string originCountry, double timeProduction) diff --git a/ProjectOptika/Scripts/Forms/FormAccessories.cs b/ProjectOptika/Scripts/Forms/FormAccessories.cs index 6e9de83..d94aec5 100644 --- a/ProjectOptika/Scripts/Forms/FormAccessories.cs +++ b/ProjectOptika/Scripts/Forms/FormAccessories.cs @@ -79,7 +79,11 @@ namespace ProjectOptika.Scripts.Forms } } - private void LoadList() => dataGridView.DataSource = _accessoriesRepositories.GetAccessories(); + private void LoadList() + { + dataGridView.DataSource = _accessoriesRepositories.GetAccessories(); + dataGridView.Columns["ID"].Visible = false; + } private bool TryGetIdentifierFromSelectedRows(out int id) { diff --git a/ProjectOptika/Scripts/Forms/FormClients.cs b/ProjectOptika/Scripts/Forms/FormClients.cs index 5fd525b..aa7bf21 100644 --- a/ProjectOptika/Scripts/Forms/FormClients.cs +++ b/ProjectOptika/Scripts/Forms/FormClients.cs @@ -79,7 +79,12 @@ namespace ProjectOptika.Scripts.Forms } } - private void LoadList() => dataGridView.DataSource = _clientRepositories.GetClients(); + private void LoadList() + { + dataGridView.DataSource = _clientRepositories.GetClients(); + dataGridView.Columns["ID"].Visible = false; + dataGridView.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRows(out int id) { diff --git a/ProjectOptika/Scripts/Forms/FormEmplyees.cs b/ProjectOptika/Scripts/Forms/FormEmplyees.cs index 325aeeb..0d7f92c 100644 --- a/ProjectOptika/Scripts/Forms/FormEmplyees.cs +++ b/ProjectOptika/Scripts/Forms/FormEmplyees.cs @@ -79,7 +79,12 @@ namespace ProjectOptika.Scripts.Forms } } - private void LoadList() => dataGridView.DataSource = _employeeRepositories.GetEmployees(); + private void LoadList() + { + dataGridView.DataSource = _employeeRepositories.GetEmployees(); + dataGridView.Columns["ID"].Visible = false; + dataGridView.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRows(out int id) { diff --git a/ProjectOptika/Scripts/Forms/FormItemOrder.cs b/ProjectOptika/Scripts/Forms/FormItemOrder.cs index 0f46faa..26962d3 100644 --- a/ProjectOptika/Scripts/Forms/FormItemOrder.cs +++ b/ProjectOptika/Scripts/Forms/FormItemOrder.cs @@ -15,11 +15,11 @@ namespace ProjectOptika.Scripts.Forms throw new ArgumentNullException(nameof(orderRepository)); comboBoxEmployee.DataSource = employeeRepository.GetEmployees(); - comboBoxEmployee.DisplayMember = "Surname"; + comboBoxEmployee.DisplayMember = "FullName"; comboBoxEmployee.ValueMember = "ID"; comboBoxClient.DataSource = clientRepositiory.GetClients(); - comboBoxClient.DisplayMember = "Surname"; + comboBoxClient.DisplayMember = "FullName"; comboBoxClient.ValueMember = "ID"; ColumnAccessory.DataSource = accessoriesRepository.GetAccessories(); diff --git a/ProjectOptika/Scripts/Forms/FormItemOrders.Designer.cs b/ProjectOptika/Scripts/Forms/FormItemOrders.Designer.cs index a9b1ed2..bcaf21a 100644 --- a/ProjectOptika/Scripts/Forms/FormItemOrders.Designer.cs +++ b/ProjectOptika/Scripts/Forms/FormItemOrders.Designer.cs @@ -76,7 +76,7 @@ dataGridView.AllowUserToResizeRows = false; dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Dock = DockStyle.Fill; + dataGridView.Dock = DockStyle.Left; dataGridView.Location = new Point(0, 0); dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; @@ -84,7 +84,7 @@ dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersWidth = 51; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(800, 450); + dataGridView.Size = new Size(693, 450); dataGridView.TabIndex = 9; // // FormItemOrders diff --git a/ProjectOptika/Scripts/Forms/FormItemOrders.cs b/ProjectOptika/Scripts/Forms/FormItemOrders.cs index 9b66a4c..2e32bef 100644 --- a/ProjectOptika/Scripts/Forms/FormItemOrders.cs +++ b/ProjectOptika/Scripts/Forms/FormItemOrders.cs @@ -30,8 +30,12 @@ namespace ProjectOptika.Scripts.Forms } } - private void LoadList() => dataGridView.DataSource = - _orderRepository.GetOrders(); + private void LoadList() + { + dataGridView.DataSource = _orderRepository.GetOrders(); + dataGridView.Columns["ID"].Visible = false; + dataGridView.Columns["OrderDate"].DefaultCellStyle.Format = "dd MM yyyy"; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectOptika/Scripts/Forms/FormSpecifications.cs b/ProjectOptika/Scripts/Forms/FormSpecifications.cs index 9ad8c5b..97b3413 100644 --- a/ProjectOptika/Scripts/Forms/FormSpecifications.cs +++ b/ProjectOptika/Scripts/Forms/FormSpecifications.cs @@ -79,7 +79,11 @@ namespace ProjectOptika.Scripts.Forms } } - private void LoadList() => dataGridView.DataSource = _specificationRepositories.GetSpecifications(); + private void LoadList() + { + dataGridView.DataSource = _specificationRepositories.GetSpecifications(); + dataGridView.Columns["ID"].Visible = false; + } private bool TryGetIdentifierFromSelectedRows(out int id) { diff --git a/ProjectOptika/Scripts/Reports/ChartReport.cs b/ProjectOptika/Scripts/Reports/ChartReport.cs index 9c7c825..2495003 100644 --- a/ProjectOptika/Scripts/Reports/ChartReport.cs +++ b/ProjectOptika/Scripts/Reports/ChartReport.cs @@ -21,7 +21,7 @@ namespace ProjectOptika.Scripts.Reports { new PdfBuilder(filePath) .AddHeader("Учет оплат клиентов") - .AddPieChart($"Оплаты клиентов", GetData(dateTime)) + .AddPieChart($"Оплаты клиентов за {dateTime: dd MMMM yyyy}", GetData(dateTime)) .Build(); return true; } @@ -33,18 +33,12 @@ namespace ProjectOptika.Scripts.Reports } private List<(string Caption, double Value)> GetData(DateTime dateTime) { - var orders = _orderRepository.GetOrders() - .Where(x => x.OrderDate.Date == dateTime.Date) - .ToList(); - - var totalCosts = orders.Count; - - return orders - .GroupBy(x => x.ClientID, (key, group) => new { - ClientID = key, + return _orderRepository.GetOrders(startDate: dateTime.Date, endDate: dateTime.Date.AddDays(1)) + .GroupBy(x => x.ClientFullName, (key, group) => new { + Client = key, Count = group.Sum(x => x.TotalCost) }) - .Select(x => (x.ClientID.ToString(), (double)x.Count / totalCosts * 100)) + .Select(x => (x.Client, (double)x.Count)) .ToList(); } } diff --git a/ProjectOptika/Scripts/Reports/TableReport.cs b/ProjectOptika/Scripts/Reports/TableReport.cs index 1fcbd92..c33eff4 100644 --- a/ProjectOptika/Scripts/Reports/TableReport.cs +++ b/ProjectOptika/Scripts/Reports/TableReport.cs @@ -27,7 +27,7 @@ namespace ProjectOptika.Scripts.Reports { new ExcelBuilder(filePath) .AddHeader("Сводка по заказам", 0, 4) - .AddParagraph("за период", 0) + .AddParagraph($"за период c {startDate: dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0) .AddTable([15, 20, 25], GetData(emplyeeID, startDate, endDate)) .Build(); return true; @@ -39,11 +39,11 @@ namespace ProjectOptika.Scripts.Reports } } - private List GetData(int emplyeeID, DateTime startDate, DateTime endDate) + private List GetData(int employeeID, DateTime startDate, DateTime endDate) { - var orders = _orderRepository.GetOrders(startDate, endDate); + var orders = _orderRepository.GetOrders(startDate: startDate, endDate: endDate, employeeID: employeeID); var employees = _employeeRepository.GetEmployees(); - var employeesNames = _employeeRepository.GetEmployees().ToDictionary(d => d.ID, d => d.Surname); + var employeesNames = _employeeRepository.GetEmployees().ToDictionary(d => d.ID, d => d.FullName); var clientsNames = _clientRepositiory.GetClients().ToList(); var data = orders @@ -54,7 +54,6 @@ namespace ProjectOptika.Scripts.Reports ClientID = r.ClientID, TotalCost = r.TotalCost }) - .Where(x => x.EmployeeID == emplyeeID) .OrderBy(x => x.Date) .GroupBy(x => x.Date) .Select(g => new @@ -70,7 +69,7 @@ namespace ProjectOptika.Scripts.Reports result.Add(new string[] { entry.Date.ToString("dd.MM.yyyy"), - employeesNames.ContainsKey(emplyeeID) ? employeesNames[emplyeeID] : string.Empty, + employeesNames.ContainsKey(employeeID) ? employeesNames[employeeID] : string.Empty, entry.Totals.ToString(), }); } diff --git a/ProjectOptika/Scripts/Repositories/Implementations/OrderRepository.cs b/ProjectOptika/Scripts/Repositories/Implementations/OrderRepository.cs index e4f49a5..ffb84d6 100644 --- a/ProjectOptika/Scripts/Repositories/Implementations/OrderRepository.cs +++ b/ProjectOptika/Scripts/Repositories/Implementations/OrderRepository.cs @@ -85,13 +85,73 @@ namespace ProjectOptika.Scripts.Repositories.Implementations _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + + if (startDate.HasValue) + { + builder.AddCondition("z.OrderDate >= @startDate"); + } + if (endDate.HasValue) + { + builder.AddCondition("z.OrderDate <= @endDate"); + } + if (id.HasValue) + { + builder.AddCondition("z.ID = @id"); + } + if (employeeID.HasValue) + { + builder.AddCondition("z.EmployeeID = @employeeID"); + } + if (clientID.HasValue) + { + builder.AddCondition("z.ClientID = @clientID"); + } + if (totalCost.HasValue) + { + builder.AddCondition("z.TotalCost = @totalCost"); + } + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT * FROM Zakaz"; - var orders = - connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", - JsonConvert.SerializeObject(orders)); - return orders; + var querySelect = @$" +SELECT + z.*, + CONCAT(c.Surname, ' ', c.FirstName) as ClientFullName, + CONCAT(e.Surname, ' ', e.FirstName) as EmployeeFullName, + + a.Name as AccessoryName, + ao.AccessoriesID, + ao.Count + +FROM Zakaz z +LEFT JOIN Client c ON c.ID = z.ClientID +LEFT JOIN Employee e ON e.ID = z.EmployeeID + +INNER JOIN AccessoriesOrder ao ON ao.ZakazID = z.ID +LEFT JOIN Accessories a ON a.ID = ao.AccessoriesID +{builder.Build()}"; + var orderHelperDict = new Dictionary>(); + var orderes = new Dictionary>(); + var orders = connection.Query(querySelect, + (order, accessoriesOrders) => + { + if (!orderHelperDict.TryGetValue(order.ID, out var z)) + { + z = new List(); + orderHelperDict.Add(order.ID, z); + } + z.Add(accessoriesOrders); + return order; + }, splitOn: "AccessoryName", param: new { startDate, endDate, totalCost, id, employeeID, clientID }); + + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orders)); + + return orderHelperDict.Select(x => + { + var r = orders.First(y => y.ID == x.Key); + r.SetAccessriesOrderReplenishment(x.Value); + return r; + }).ToArray(); } catch (Exception ex) { diff --git a/ProjectOptika/Scripts/Repositories/QueryBuilder.cs b/ProjectOptika/Scripts/Repositories/QueryBuilder.cs new file mode 100644 index 0000000..f81d5f3 --- /dev/null +++ b/ProjectOptika/Scripts/Repositories/QueryBuilder.cs @@ -0,0 +1,27 @@ +using System.Text; + +internal class QueryBuilder +{ + private readonly StringBuilder _builder; + public QueryBuilder() + { + _builder = new(); + } + public QueryBuilder AddCondition(string condition) + { + if (_builder.Length > 0) + { + _builder.Append(" AND "); + } + _builder.Append(condition); + return this; + } + public string Build() + { + if (_builder.Length == 0) + { + return string.Empty; + } + return $"WHERE {_builder}"; + } +}