Вроде всё работает
This commit is contained in:
parent
55d1dc935f
commit
1146563620
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,6 +10,7 @@ namespace ProjectOpticsSalon.Entites;
|
||||
public class Client
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Имя клиента")]
|
||||
public string Name { get; private set; }
|
||||
public static Client CreateClient(int id, string name)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,11 +10,10 @@ namespace ProjectOpticsSalon.Entites;
|
||||
public class Lens
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public float Dioptres { get; private set; } = 0;
|
||||
|
||||
public float Astigmatism { get; private set; } = 0;
|
||||
|
||||
[DisplayName("Характеристики линзы")]
|
||||
public string LensChars => $"D: {Dioptres}/ A: {Astigmatism}";
|
||||
public static Lens CreateLens(int id, float dioptres, float astigmatism)
|
||||
{
|
||||
return new Lens
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,13 +11,23 @@ namespace ProjectOpticsSalon.Entites;
|
||||
public class MakeOrder
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Цена")]
|
||||
|
||||
public int Price { get; private set; } = 0;
|
||||
[DisplayName("Дата заказа")]
|
||||
|
||||
public DateTime OrderDate { get; private set; }
|
||||
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
[DisplayName("Имя клиента")]
|
||||
public string ClientName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Статус заказа")]
|
||||
public OrderStatus OrderStatus { get; private set; }
|
||||
|
||||
[DisplayName("Список товаров")]
|
||||
public string ProductsList => Products != null ? string.Join(", ", Products.Select(x => $"{x.ProductId}")) : string.Empty;
|
||||
|
||||
public IEnumerable<Order_Product> Products { get; private set; } = [];
|
||||
public static MakeOrder CreateOrder(int id, int price, int client, OrderStatus orderStatus, IEnumerable<Order_Product> products)
|
||||
{
|
||||
@ -30,4 +41,12 @@ public class MakeOrder
|
||||
Products = products
|
||||
};
|
||||
}
|
||||
|
||||
public void SetOrderProduct(IEnumerable<Order_Product> orderProduct)
|
||||
{
|
||||
if (orderProduct != null && orderProduct.Any())
|
||||
{
|
||||
Products = orderProduct;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,13 @@ namespace ProjectOpticsSalon.Entites;
|
||||
public class Product
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Тип продукта")]
|
||||
public ProductType ProductType { get; private set; }
|
||||
[DisplayName("Материал оправы")]
|
||||
public FrameMaterial FrameMaterial { get; private set; } = 0;
|
||||
[DisplayName("ID левой линзы")]
|
||||
public int LeftLensId { get; private set; } = 0;
|
||||
[DisplayName("ID правой линзы")]
|
||||
public int RightLensId { get; private set; } = 0;
|
||||
public static Product CreateProduct(int id, ProductType productType, FrameMaterial frameMaterial, int leftLenseId, int rightLensId)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,9 +10,14 @@ namespace ProjectOpticsSalon.Entites;
|
||||
public class Production
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Стоимость компонентов")]
|
||||
public double ComponentsPrice { get; private set; }
|
||||
[DisplayName("Стоимость работы")]
|
||||
public double WorkPrice { get; private set; }
|
||||
[DisplayName("ID продукта")]
|
||||
public int ProductId { get; private set; }
|
||||
|
||||
[DisplayName("Дата производства")]
|
||||
public DateTime Date { get; private set; }
|
||||
public static Production CreateProduction(int id, double componentsPrice, double workPrice, int productId)
|
||||
{
|
||||
|
@ -91,7 +91,12 @@ public partial class FormClients : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _clientRepository.ReadClients();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _clientRepository.ReadClients();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -95,7 +95,13 @@ namespace ProjectOpticsSalon.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _lensRepository.ReadLens();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _lensRepository.ReadLens();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["LensChars"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -54,6 +54,12 @@ namespace ProjectOpticsSalon.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _orderRepository.ReadOrder();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _orderRepository.ReadOrder();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["ClientId"].Visible = false;
|
||||
dataGridViewData.Columns["Products"].Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,11 +62,11 @@ namespace ProjectOpticsSalon.Forms
|
||||
}
|
||||
|
||||
comboBoxLeftLens.DataSource = lensRepository.ReadLens();
|
||||
comboBoxLeftLens.DisplayMember = "Id";
|
||||
comboBoxLeftLens.DisplayMember = "LensChars";
|
||||
comboBoxLeftLens.ValueMember = "Id";
|
||||
|
||||
comboBoxRightLens.DataSource = lensRepository.ReadLens();
|
||||
comboBoxRightLens.DisplayMember= "Id";
|
||||
comboBoxRightLens.DisplayMember= "LensChars";
|
||||
comboBoxRightLens.ValueMember = "Id";
|
||||
|
||||
foreach (var elem in Enum.GetValues(typeof(FrameMaterial)))
|
||||
|
@ -71,7 +71,12 @@ namespace ProjectOpticsSalon.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _productionRepository.ReadProduction();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _productionRepository.ReadProduction();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -95,7 +95,11 @@ namespace ProjectOpticsSalon.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _productRepository.ReadProducts();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _productRepository.ReadProducts();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -41,8 +41,7 @@ public class ChartReport
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
return _productionRepository
|
||||
.ReadProduction()
|
||||
.Where(x => x.Date.Date == dateTime.Date)
|
||||
.ReadProduction(startDate: dateTime.Date, endDate: dateTime.Date)
|
||||
.GroupBy(
|
||||
x => x.Id,
|
||||
(key, group) => new
|
||||
@ -50,7 +49,7 @@ public class ChartReport
|
||||
Id = key,
|
||||
TotalPrice = group.Sum(y => y.WorkPrice+y.ComponentsPrice)
|
||||
})
|
||||
.Select(x => ($"{x.Id}", (double)x.TotalPrice))
|
||||
.Select(x => ($"{x.TotalPrice}", (double)x.TotalPrice))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,11 @@ public class TableReport
|
||||
private List<string[]> GetData(int clientId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var client = _clientRepository.ReadClientById(clientId);
|
||||
var productions = _productionRepository
|
||||
.ReadProduction(startDate, endDate, clientId)
|
||||
.Where(x => x.ProductId == clientId)
|
||||
.Select(x => new { client.Name, x.Date, Price = x.ComponentsPrice + x.WorkPrice, CountOrdered = (int?)1 })
|
||||
.ToList();
|
||||
var orders = _orderRepository
|
||||
.ReadOrder()
|
||||
.Where(x => x.OrderDate >= startDate && x.OrderDate <= endDate && x.ClientId == clientId && x.OrderStatus == OrderStatus.Ordered)
|
||||
|
@ -9,7 +9,7 @@ namespace ProjectOpticsSalon.Repositories;
|
||||
|
||||
public interface IProductionRepository
|
||||
{
|
||||
IEnumerable<Production> ReadProduction();
|
||||
IEnumerable<Production> ReadProduction(DateTime? startDate = null, DateTime? endDate = null, int? productId = null);
|
||||
Production ReadProductionById(int id);
|
||||
void CreateProduction(Production production);
|
||||
void UpdateProduction(Production production);
|
||||
|
@ -63,10 +63,36 @@ public class OrderRepository : IOrderRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM MakeOrder";
|
||||
var orders = connection.Query<MakeOrder>(querySelect);
|
||||
var querySelect = @"
|
||||
SELECT
|
||||
mo.*,
|
||||
c.name as ClientName,
|
||||
op.ProductId as ProductId
|
||||
FROM makeorder mo
|
||||
LEFT JOIN client c on c.Id = mo.ClientId
|
||||
LEFT JOIN Order_Product op on mo.Id = mo.Id";
|
||||
|
||||
|
||||
var ordersDict = new Dictionary<int, List<Order_Product>>();
|
||||
var orders = connection.Query<MakeOrder, Order_Product, MakeOrder>(querySelect,
|
||||
(order, order_product) =>
|
||||
{
|
||||
if (!ordersDict.TryGetValue(order.Id, out var frr))
|
||||
{
|
||||
frr = [];
|
||||
ordersDict.Add(order.Id, frr);
|
||||
}
|
||||
frr.Add(order_product);
|
||||
return order;
|
||||
}, splitOn: "ProductId");
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orders));
|
||||
return orders;
|
||||
return ordersDict.Select(x =>
|
||||
{
|
||||
var o = orders.First(y => y.Id == x.Key);
|
||||
o.SetOrderProduct(x.Value);
|
||||
return o;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -38,14 +38,34 @@ public class ProductionRepository : IProductionRepository
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Production> ReadProduction()
|
||||
public IEnumerable<Production> ReadProduction(DateTime? startDate = null, DateTime? endDate = null, int? productId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (startDate.HasValue)
|
||||
{
|
||||
builder.AddCondition("pr.Date >= @startDate");
|
||||
}
|
||||
if (endDate.HasValue)
|
||||
{
|
||||
builder.AddCondition("pr.Date <= @endDate");
|
||||
}
|
||||
if (productId.HasValue)
|
||||
{
|
||||
builder.AddCondition("pr.ProductId = @productId");
|
||||
}
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Production";
|
||||
var productions = connection.Query<Production>(querySelect);
|
||||
var querySelect = $@"
|
||||
SELECT
|
||||
pr.*,
|
||||
p.FrameMaterial
|
||||
FROM Production pr
|
||||
LEFT JOIN Product p ON p.Id = pr.ProductId
|
||||
{builder.Build()}";
|
||||
var productions = connection.Query<Production>(querySelect, new {startDate, endDate, productId});
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(productions));
|
||||
return productions;
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectOpticsSalon.Repositories.Implementations;
|
||||
|
||||
public 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}";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user