Улучшайзинги 1
This commit is contained in:
parent
59aad56527
commit
d8084733ab
@ -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)
|
||||
|
@ -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 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)
|
||||
|
@ -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; }
|
||||
|
@ -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> FuelFuelSale { get; private set; } = [];
|
||||
|
||||
public static FuelSale CreateElement(int id, int cashierId, DateTime saleDate, decimal totalPrice, IEnumerable<FuelFuelSale> fuelFuelSale)
|
||||
@ -35,15 +49,11 @@ public class FuelSale
|
||||
};
|
||||
}
|
||||
|
||||
public static FuelSale CreateElement(TempFuelFuelSale tempFuelFuelSale, IEnumerable<FuelFuelSale> fuelFuelSale)
|
||||
public void SetFuelFuelSale(IEnumerable<FuelFuelSale> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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> SuppliersFuelFuel { get; private set; } = [];
|
||||
|
||||
public static SuppliersFuel CreateElement(int id, int suppliersId, DateTime date, IEnumerable<SuppliersFuelFuel> suppliersFuelFuel)
|
||||
@ -31,18 +44,11 @@ public class SuppliersFuel
|
||||
};
|
||||
}
|
||||
|
||||
public static SuppliersFuel CreateElement(TempSuppliersFuelFuel tempSuppliersFuelFuel,
|
||||
IEnumerable<SuppliersFuelFuel> suppliersFuelFuel)
|
||||
public void SetSuppliersFuelFuel(IEnumerable<SuppliersFuelFuel> suppliersFuelFuel)
|
||||
{
|
||||
return new SuppliersFuel
|
||||
if (suppliersFuelFuel != null && suppliersFuelFuel.Any())
|
||||
{
|
||||
Id = tempSuppliersFuelFuel.Id,
|
||||
|
||||
SuppliersId = tempSuppliersFuelFuel.SuppliersId,
|
||||
|
||||
Date = tempSuppliersFuelFuel.Date,
|
||||
|
||||
SuppliersFuelFuel = suppliersFuelFuel
|
||||
};
|
||||
SuppliersFuelFuel = suppliersFuelFuel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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; }
|
||||
}
|
@ -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; }
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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<TempFuelFuelSale>(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<int, List<FuelFuelSale>>();
|
||||
|
||||
var fuelSales = connection.Query<FuelSale, FuelFuelSale, FuelSale>(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)
|
||||
{
|
||||
|
@ -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<TempSuppliersFuelFuel>(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<int, List<SuppliersFuelFuel>>();
|
||||
|
||||
var suppliersFuels = connection.Query<SuppliersFuel, SuppliersFuelFuel, SuppliersFuel>(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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user