diff --git a/GasStation/GasStation/Entities/Cashier.cs b/GasStation/GasStation/Entities/Cashier.cs index 23003f4..3c9c05a 100644 --- a/GasStation/GasStation/Entities/Cashier.cs +++ b/GasStation/GasStation/Entities/Cashier.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using GasStation.Entities.Enums; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace GasStation.Entities; @@ -11,10 +13,15 @@ public class Cashier { public int Id { get; private set; } + [DisplayName("Имя")] public string FirstName { get; private set; } = string.Empty; + [DisplayName("Фамилия")] public string LastName { get; private set; } = string.Empty; + public string FullName => $"{LastName} {FirstName}"; + + [DisplayName("Должность кассира")] public CashierPost CashierPost { get; private set; } public static Cashier CreateEntity(int id, string first, string last, CashierPost cashierPost) diff --git a/GasStation/GasStation/Entities/Fuel.cs b/GasStation/GasStation/Entities/Fuel.cs index cfb5757..a53e2bf 100644 --- a/GasStation/GasStation/Entities/Fuel.cs +++ b/GasStation/GasStation/Entities/Fuel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,9 +11,11 @@ namespace GasStation.Entities; public class Fuel { public int Id { get; private set; } - + + [DisplayName("Цена")] public int Cost { get; private set; } + [DisplayName("Тип топлива")] public FuelType Type { get; private set; } public static Fuel CreateEntity(int id, int cost, FuelType type) diff --git a/GasStation/GasStation/Entities/FuelFuelSale.cs b/GasStation/GasStation/Entities/FuelFuelSale.cs index 489b21b..64deeb3 100644 --- a/GasStation/GasStation/Entities/FuelFuelSale.cs +++ b/GasStation/GasStation/Entities/FuelFuelSale.cs @@ -6,6 +6,8 @@ public class FuelFuelSale public int FuelId { get; private set; } + public int FuelName { get; private set; } + public int Quantity { get; private set; } public decimal Price { get; private set; } diff --git a/GasStation/GasStation/Entities/FuelSale.cs b/GasStation/GasStation/Entities/FuelSale.cs index 92e7f71..568b2cf 100644 --- a/GasStation/GasStation/Entities/FuelSale.cs +++ b/GasStation/GasStation/Entities/FuelSale.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using GasStation.Entities.Enums; using ProjectGasStation.Entities; namespace GasStation.Entities; @@ -11,12 +13,24 @@ public class FuelSale { public int Id { get; private set; } + [Browsable(false)] public int CashierId { get; private set; } + [DisplayName("Дата продажи")] public DateTime SaleDate { get; private set; } + [DisplayName("Общая стоимость")] public decimal TotalPrice { get; private set; } + [DisplayName("Кассир")] + public string CashierName { get; private set; } = string.Empty; + + [DisplayName("Топливо")] + public string Fuel => FuelFuelSale != null ? + string.Join(", ", FuelFuelSale.Select(x => $"{(FuelType)x.FuelName} {x.Quantity}")) : + string.Empty; + + [Browsable(false)] public IEnumerable FuelFuelSale { get; private set; } = []; public static FuelSale CreateElement(int id, int cashierId, DateTime saleDate, decimal totalPrice, IEnumerable fuelFuelSale) @@ -35,15 +49,11 @@ public class FuelSale }; } - public static FuelSale CreateElement(TempFuelFuelSale tempFuelFuelSale, IEnumerable fuelFuelSale) + public void SetFuelFuelSale(IEnumerable fuelFuelSale) { - return new FuelSale + if (fuelFuelSale != null && fuelFuelSale.Any()) { - Id = tempFuelFuelSale.Id, - CashierId = tempFuelFuelSale.CashierId, - SaleDate = tempFuelFuelSale.SaleDate, - TotalPrice = tempFuelFuelSale.TotalPrice, - FuelFuelSale = fuelFuelSale - }; + FuelFuelSale = fuelFuelSale; + } } } diff --git a/GasStation/GasStation/Entities/Suppliers.cs b/GasStation/GasStation/Entities/Suppliers.cs index d5c89bf..ba4d749 100644 --- a/GasStation/GasStation/Entities/Suppliers.cs +++ b/GasStation/GasStation/Entities/Suppliers.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,8 +12,10 @@ public class Supplier { public int Id { get; private set; } + [DisplayName("Бренд")] public string Brand { get; private set; } = string.Empty; + [DisplayName("Поставляемое топливо")] public SupppliersFuelType Types { get; private set; } public static Supplier CreateEntity(int id, string brand, SupppliersFuelType types) diff --git a/GasStation/GasStation/Entities/SuppliersFuel.cs b/GasStation/GasStation/Entities/SuppliersFuel.cs index 0026d59..281d6a7 100644 --- a/GasStation/GasStation/Entities/SuppliersFuel.cs +++ b/GasStation/GasStation/Entities/SuppliersFuel.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using GasStation.Entities.Enums; using ProjectGasStation.Entities; namespace GasStation.Entities; @@ -11,10 +13,21 @@ public class SuppliersFuel { public int Id { get; private set; } + [Browsable(false)] public int SuppliersId { get; private set; } + [DisplayName("Бренд поставщика")] + public string SuppliersBrand { get; private set; } = string.Empty; + + [DisplayName("Дата поставки")] public DateTime Date { get; private set; } + [DisplayName("Топливо")] + public string Fuel => SuppliersFuelFuel != null ? + string.Join(", ", SuppliersFuelFuel.Select(x => $"{(FuelType)x.FuelName} {x.Quantity}")) : + string.Empty; + + [Browsable(false)] public IEnumerable SuppliersFuelFuel { get; private set; } = []; public static SuppliersFuel CreateElement(int id, int suppliersId, DateTime date, IEnumerable suppliersFuelFuel) @@ -31,18 +44,11 @@ public class SuppliersFuel }; } - public static SuppliersFuel CreateElement(TempSuppliersFuelFuel tempSuppliersFuelFuel, - IEnumerable suppliersFuelFuel) + public void SetSuppliersFuelFuel(IEnumerable suppliersFuelFuel) { - return new SuppliersFuel - { - Id = tempSuppliersFuelFuel.Id, - - SuppliersId = tempSuppliersFuelFuel.SuppliersId, - - Date = tempSuppliersFuelFuel.Date, - - SuppliersFuelFuel = suppliersFuelFuel - }; + if (suppliersFuelFuel != null && suppliersFuelFuel.Any()) + { + SuppliersFuelFuel = suppliersFuelFuel; + } } } diff --git a/GasStation/GasStation/Entities/SuppliersFuelFuel.cs b/GasStation/GasStation/Entities/SuppliersFuelFuel.cs index df25514..fc82525 100644 --- a/GasStation/GasStation/Entities/SuppliersFuelFuel.cs +++ b/GasStation/GasStation/Entities/SuppliersFuelFuel.cs @@ -4,6 +4,7 @@ public class SuppliersFuelFuel { public int Id { get; private set; } public int FuelId { get; private set; } + public int FuelName { get; private set; } public int Quantity { get; private set; } public static SuppliersFuelFuel CreateSuppliersFuelFuel(int id, int fuelId, int quantity) { diff --git a/GasStation/GasStation/Entities/TempFuelFuelSale.cs b/GasStation/GasStation/Entities/TempFuelFuelSale.cs deleted file mode 100644 index f9e9cea..0000000 --- a/GasStation/GasStation/Entities/TempFuelFuelSale.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GasStation.Entities; - -public class TempFuelFuelSale -{ - public int Id { get; private set; } - public int CashierId { get; private set; } - public DateTime SaleDate { get; private set; } - public int TotalPrice { get; private set; } - public int FuelId { get; private set; } - public int Quantity { get; private set; } -} diff --git a/GasStation/GasStation/Entities/TempSuppliersFuelFuel.cs b/GasStation/GasStation/Entities/TempSuppliersFuelFuel.cs deleted file mode 100644 index 238c61b..0000000 --- a/GasStation/GasStation/Entities/TempSuppliersFuelFuel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GasStation.Entities; - -public class TempSuppliersFuelFuel -{ - public int Id { get; private set; } - public int SuppliersId { get; private set; } - public DateTime Date { get; private set; } - public int FuelId { get; private set; } - public int Quantity { get; private set; } -} diff --git a/GasStation/GasStation/Forms/FormCashiers.cs b/GasStation/GasStation/Forms/FormCashiers.cs index 9784008..b42f97c 100644 --- a/GasStation/GasStation/Forms/FormCashiers.cs +++ b/GasStation/GasStation/Forms/FormCashiers.cs @@ -93,7 +93,12 @@ public partial class FormCashiers : Form } } - private void LoadList() => dataGridView.DataSource = _cashierRepository.ReadCashiers(); + private void LoadList() + { + dataGridView.DataSource = _cashierRepository.ReadCashiers(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/GasStation/GasStation/Forms/FormFuelSale.cs b/GasStation/GasStation/Forms/FormFuelSale.cs index ccde5dd..f747a14 100644 --- a/GasStation/GasStation/Forms/FormFuelSale.cs +++ b/GasStation/GasStation/Forms/FormFuelSale.cs @@ -25,7 +25,7 @@ public partial class FormFuelSale : Form _fuelSalesRepository = fuelSalesRepository ?? throw new ArgumentNullException(nameof(fuelSalesRepository)); comboBoxCashier.DataSource = cashierRepository.ReadCashiers(); - comboBoxCashier.DisplayMember = "FirstName"; + comboBoxCashier.DisplayMember = "FullName"; comboBoxCashier.ValueMember = "Id"; ColumnFuel.DataSource = fuelRepository.ReadFuels(); diff --git a/GasStation/GasStation/Forms/FormFuelSales.cs b/GasStation/GasStation/Forms/FormFuelSales.cs index 3fe5779..16b3559 100644 --- a/GasStation/GasStation/Forms/FormFuelSales.cs +++ b/GasStation/GasStation/Forms/FormFuelSales.cs @@ -73,7 +73,12 @@ public partial class FormFuelSales : Form } } - private void LoadList() => dataGridViewData.DataSource = _fuelSalesRepository.ReadFuelSale(); + private void LoadList() + { + dataGridViewData.DataSource = _fuelSalesRepository.ReadFuelSale(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["SaleDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm"; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/GasStation/GasStation/Forms/FormFuels.cs b/GasStation/GasStation/Forms/FormFuels.cs index 4587ab8..1b8ed7e 100644 --- a/GasStation/GasStation/Forms/FormFuels.cs +++ b/GasStation/GasStation/Forms/FormFuels.cs @@ -95,7 +95,11 @@ public partial class FormFuels : Form } } - private void LoadList() => dataGridView.DataSource = _fuelRepository.ReadFuels(); + private void LoadList() + { + dataGridView.DataSource = _fuelRepository.ReadFuels(); + dataGridView.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/GasStation/GasStation/Forms/FormSupplierFuels.cs b/GasStation/GasStation/Forms/FormSupplierFuels.cs index 65993eb..5cd4a1e 100644 --- a/GasStation/GasStation/Forms/FormSupplierFuels.cs +++ b/GasStation/GasStation/Forms/FormSupplierFuels.cs @@ -72,7 +72,12 @@ public partial class FormSupplierFuels : Form } } - private void LoadList() => dataGridViewData.DataSource = _suppliersFuelRepository.ReadSuppliersFuels(); + private void LoadList() + { + dataGridViewData.DataSource = _suppliersFuelRepository.ReadSuppliersFuels(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "dd.MM.yyyy"; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/GasStation/GasStation/Forms/FormSuppliers.cs b/GasStation/GasStation/Forms/FormSuppliers.cs index c21201b..8b0da04 100644 --- a/GasStation/GasStation/Forms/FormSuppliers.cs +++ b/GasStation/GasStation/Forms/FormSuppliers.cs @@ -93,7 +93,11 @@ public partial class FormSuppliers : Form } } - private void LoadList() => dataGridView.DataSource = _supplierRepository.ReadSuppliers(); + private void LoadList() + { + dataGridView.DataSource = _supplierRepository.ReadSuppliers(); + dataGridView.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/GasStation/GasStation/Repositories/Implementations/FuelSalesRepository.cs b/GasStation/GasStation/Repositories/Implementations/FuelSalesRepository.cs index 818693c..8559380 100644 --- a/GasStation/GasStation/Repositories/Implementations/FuelSalesRepository.cs +++ b/GasStation/GasStation/Repositories/Implementations/FuelSalesRepository.cs @@ -98,13 +98,39 @@ public class FuelSalesRepository : IFuelSalesRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT fs.*, ffs.FuelId, ffs.Quantity FROM FuelSale fs - INNER JOIN FuelFuelSale ffs on ffs.FuelSaleId = fs.Id"; - var fuelSales = connection.Query(querySelect); + var querySelect = @"SELECT + fs.*, + CONCAT(s.LastName, ' ', s.FirstName) as CashierName, + ffs.FuelId, + ffs.Quantity, + f.Type as FuelName + FROM FuelSale fs + LEFT JOIN Cashier s on s.Id = fs.CashierId + INNER JOIN FuelFuelSale ffs on ffs.FuelSaleId = fs.Id + LEFT JOIN Fuel f on f.id = ffs.FuelId"; + var salesDict = new Dictionary>(); + + var fuelSales = connection.Query(querySelect, + (sale, fuelSale) => + { + if (!salesDict.TryGetValue(sale.Id, out var fss)) + { + fss = []; + salesDict.Add(sale.Id, fss); + } + + fss.Add(fuelSale); + return sale; + }, splitOn: "FuelId", param: new { dateFrom, dateTo, fuelId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(fuelSales)); - return fuelSales.GroupBy(x => x.Id, y => y, (key, value) => FuelSale.CreateElement(value.First(), - value.Select(z => FuelFuelSale.CreateFuelFuelSale(0, z.FuelId, z.Quantity,0)))).ToList(); + + return salesDict.Select(x => + { + var fs = fuelSales.First(y => y.Id == x.Key); + fs.SetFuelFuelSale(x.Value); + return fs; + }).ToArray(); } catch (Exception ex) { diff --git a/GasStation/GasStation/Repositories/Implementations/SuppliersFuelRepository.cs b/GasStation/GasStation/Repositories/Implementations/SuppliersFuelRepository.cs index 80967b3..dd63814 100644 --- a/GasStation/GasStation/Repositories/Implementations/SuppliersFuelRepository.cs +++ b/GasStation/GasStation/Repositories/Implementations/SuppliersFuelRepository.cs @@ -95,14 +95,40 @@ public class SuppliersFuelRepository : ISuppliersFuelRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT cf.*, cff.FuelId, cff.Quantity FROM SuppliersFuel cf - INNER JOIN SuppliersFuelFuel cff on cff.SuppliersFuelId = cf.Id"; - var suppliersFuels = connection.Query(querySelect); + var querySelect = @"SELECT + cf.*, + c.Brand as SuppliersBrand, + cff.FuelId, + cff.Quantity, + f.Type as FuelName + FROM SuppliersFuel cf + LEFT JOIN Supplier c on c.Id = cf.SuppliersId + INNER JOIN SuppliersFuelFuel cff on cff.SuppliersFuelId = cf.Id + LEFT JOIN Fuel f on f.Id = cff.FuelId"; + + var suppliersDict = new Dictionary>(); + + var suppliersFuels = connection.Query(querySelect, + (suppliers, suppliersFuel) => + { + if (!suppliersDict.TryGetValue(suppliers.Id, out var ccf)) + { + ccf = []; + suppliersDict.Add(suppliers.Id, ccf); + } + + ccf.Add(suppliersFuel); + return suppliers; + }, splitOn: "FuelId", param: new { dateFrom, dateTo, fuelId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(suppliersFuels)); - return suppliersFuels.GroupBy(x => x.Id, y => y, - (key, value) => SuppliersFuel.CreateElement(value.First(), - value.Select(z => SuppliersFuelFuel.CreateSuppliersFuelFuel(0, z.FuelId, z.Quantity)))).ToList(); + + return suppliersDict.Select(x => + { + var cf = suppliersFuels.First(y => y.Id == x.Key); + cf.SetSuppliersFuelFuel(x.Value); + return cf; + }).ToArray(); } catch (Exception ex) { @@ -110,4 +136,4 @@ public class SuppliersFuelRepository : ISuppliersFuelRepository throw; } } -} +} \ No newline at end of file