Лабораторная работа №4
This commit is contained in:
parent
eb7deb1b80
commit
12f27b653f
@ -1,4 +1,5 @@
|
||||
using ProjectWarehouse.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWarehouse.Entities;
|
||||
|
||||
@ -6,12 +7,16 @@ public class Components
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public decimal Price { get; private set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public double Count { get; private set; }
|
||||
|
||||
[DisplayName("Тип компонента")]
|
||||
public Type_Components TypeComponentsId { get; private set; }
|
||||
|
||||
public static Components CreateEntity(int id, string name, decimal price, double count, Type_Components typeComponentsId)
|
||||
|
@ -1,22 +1,33 @@
|
||||
namespace ProjectWarehouse.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWarehouse.Entities;
|
||||
|
||||
public class Components_Production
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int ProductionId { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int ComponentsId { get; private set; }
|
||||
|
||||
[DisplayName("Продукция")]
|
||||
public string ProductionName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Комплекующие")]
|
||||
public string ComponentsName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; private set; }
|
||||
|
||||
public static Components_Production CreateElement(int id, int componentsID, int count)
|
||||
public static Components_Production CreateElement(int id, int productionId, int componentsId, int count)
|
||||
{
|
||||
return new Components_Production
|
||||
{
|
||||
Id = id,
|
||||
ProductionId = componentsID,
|
||||
ComponentsId = componentsID,
|
||||
ProductionId = productionId,
|
||||
ComponentsId = componentsId,
|
||||
Count = count
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectWarehouse.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWarehouse.Entities;
|
||||
|
||||
@ -6,10 +7,15 @@ public class Employee
|
||||
{
|
||||
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 EmployeePost EmployeePostId { get; private set; }
|
||||
|
||||
public static Employee CreateEntity(int id, string first, string last,
|
||||
|
@ -1,15 +1,23 @@
|
||||
namespace ProjectWarehouse.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWarehouse.Entities;
|
||||
|
||||
public class Inventory
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public double Quantity { get; private set; }
|
||||
|
||||
[DisplayName("Брак")]
|
||||
public bool IsDefect { get; private set; }
|
||||
|
||||
public int ComponentsId { get; private set; }
|
||||
|
||||
[DisplayName("Компонент")]
|
||||
public string ComponentsName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public static Inventory CreateEntity(int id, double quantity, bool isDefect, int ComponentsID)
|
||||
|
@ -1,15 +1,22 @@
|
||||
namespace ProjectWarehouse.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWarehouse.Entities;
|
||||
|
||||
public class OrderRequest
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public double Quantity { get; private set; }
|
||||
|
||||
[DisplayName("Дата заявки")]
|
||||
public DateTime DateOrder { get; private set; }
|
||||
|
||||
public int ComponentsId { get; private set; }
|
||||
|
||||
[DisplayName("Компонент")]
|
||||
public string ComponentsName { get; private set; } = string.Empty;
|
||||
|
||||
public static OrderRequest CreateEntity(int id, double quantity, int componentsID)
|
||||
{
|
||||
return new OrderRequest
|
||||
|
@ -1,17 +1,31 @@
|
||||
namespace ProjectWarehouse.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectWarehouse.Entities;
|
||||
|
||||
public class Production
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Описание")]
|
||||
public string Description { get; private set; } = string.Empty;
|
||||
|
||||
public int EmployeeId { get; private set; }
|
||||
|
||||
[DisplayName("Сотрудник")]
|
||||
public string EmployeeName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
[DisplayName("Компоненты")]
|
||||
public string Components => Components_Productions != null ?
|
||||
string.Join(", ", Components_Productions.Select(x => $"{x.ProductionName} {x.ComponentsName} {x.Count}")) :
|
||||
string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<Components_Production> Components_Productions { get; private set; } = [];
|
||||
|
||||
public static Production CreateEntity(int id, string name, string description, int employeeId, IEnumerable<Components_Production> components_Productions)
|
||||
@ -27,13 +41,11 @@ public class Production
|
||||
};
|
||||
}
|
||||
|
||||
public static Production CreateEntity(TempComponents_Production tempComponents_Production, IEnumerable<Components_Production> components_Productions)
|
||||
public void SetComponents_Production(IEnumerable<Components_Production> components_Productions)
|
||||
{
|
||||
return new Production
|
||||
if (components_Productions != null && components_Productions.Any())
|
||||
{
|
||||
Id = tempComponents_Production.Id,
|
||||
Date = tempComponents_Production.Date,
|
||||
Components_Productions = components_Productions
|
||||
};
|
||||
Components_Productions = components_Productions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
namespace ProjectWarehouse.Entities;
|
||||
|
||||
public class TempComponents_Production
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public DateTime Date { get; private set; }
|
||||
|
||||
public int ComponentsId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
}
|
@ -86,7 +86,11 @@ namespace ProjectWarehouse.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _componentsRepository.ReadComponents();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _componentsRepository.ReadComponents();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -86,7 +86,12 @@ namespace ProjectWarehouse.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _employeeRepository.ReadEmployees();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _employeeRepository.ReadEmployees();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["FullName"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -44,7 +44,12 @@ namespace ProjectWarehouse.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _inventoryRepository.ReadInventory();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _inventoryRepository.ReadInventory();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||
}
|
||||
|
||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
@ -43,6 +43,10 @@ namespace ProjectWarehouse.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _orderRequestRepository.ReadOrderRequest();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _orderRequestRepository.ReadOrderRequest();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace ProjectWarehouse.Forms
|
||||
throw new ArgumentNullException(nameof(productionRepository));
|
||||
|
||||
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
|
||||
comboBoxEmployee.DisplayMember = "FirstName";
|
||||
comboBoxEmployee.DisplayMember = "FullName";
|
||||
comboBoxEmployee.ValueMember = "Id";
|
||||
|
||||
ColumnComponents.DataSource = componentsRepository.ReadComponents();
|
||||
@ -55,12 +55,12 @@ namespace ProjectWarehouse.Forms
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.Add(Components_Production.CreateElement(0,
|
||||
list.Add(Components_Production.CreateElement(0, 0,
|
||||
Convert.ToInt32(row.Cells["ColumnComponents"].Value),
|
||||
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
|
||||
}
|
||||
return list.GroupBy(x => x.ComponentsId, x => x.Count, (id, counts) =>
|
||||
Components_Production.CreateElement(0, id, counts.Sum())).ToList();
|
||||
Components_Production.CreateElement(0, 0, id, counts.Sum())).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -66,7 +66,11 @@ namespace ProjectWarehouse.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)
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectWarehouse.Entities;
|
||||
using ProjectWarehouse.Repositories;
|
||||
|
||||
namespace ProjectWarehouse.Reports;
|
||||
@ -22,9 +24,10 @@ internal class ChartReport
|
||||
try
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Пополнение склада")
|
||||
.AddPieChart("Полученные компоненты", GetData(dateTime))
|
||||
.Build();
|
||||
.AddHeader("Пополнение склада")
|
||||
.AddPieChart($"Полученные компоненты на {dateTime:dd MMMM yyyy}", GetData(dateTime))
|
||||
.Build();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -37,9 +40,8 @@ internal class ChartReport
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
return _inventoryRepository
|
||||
.ReadInventory()
|
||||
.Where(x => x.Date.Date == dateTime.Date)
|
||||
.GroupBy(x => x.ComponentsId)
|
||||
.ReadInventory(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||
.GroupBy(x => x.ComponentsName)
|
||||
.Select(group => (
|
||||
Caption: $"Компонент {group.Key}",
|
||||
Value: group.Sum(x => x.Quantity)
|
||||
|
@ -43,8 +43,9 @@ internal class TableReport
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по движению комлектующих", 0, 4)
|
||||
.AddParagraph("за период", 0).
|
||||
AddTable([10, 10, 15, 15], GetData(componentsId, startDate, endDate)).Build();
|
||||
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0)
|
||||
.AddTable([10, 10, 15, 15], GetData(componentsId, startDate, endDate))
|
||||
.Build();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -60,8 +61,7 @@ internal class TableReport
|
||||
{
|
||||
// Получаем данные по приходам (Production)
|
||||
var productionData = _productionRepository
|
||||
.ReadProduction()
|
||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Components_Productions.Any(y => y.ComponentsId == componentsId))
|
||||
.ReadProduction(dateFrom: startDate, dateTo: endDate, componentsId: componentsId)
|
||||
.Select(x => new MovementData
|
||||
{
|
||||
Date = x.Date,
|
||||
@ -71,7 +71,7 @@ internal class TableReport
|
||||
.ToList();
|
||||
|
||||
var orderRequestData = _orderRequestRepository
|
||||
.ReadOrderRequest()
|
||||
.ReadOrderRequest(dateFrom: startDate, dateTo: endDate, componentsId: componentsId)
|
||||
.Where(x => x.DateOrder >= startDate && x.DateOrder <= endDate && x.ComponentsId == componentsId)
|
||||
.Select(x => new MovementData
|
||||
{
|
||||
@ -82,7 +82,7 @@ internal class TableReport
|
||||
.ToList();
|
||||
|
||||
var inventoryData = _inventoryRepository
|
||||
.ReadInventory()
|
||||
.ReadInventory(dateFrom: startDate, dateTo: endDate, componentsId: componentsId)
|
||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.ComponentsId == componentsId)
|
||||
.Select(x => new MovementData
|
||||
{
|
||||
@ -106,17 +106,17 @@ internal class TableReport
|
||||
combinedData.Select(x => new string[]
|
||||
{
|
||||
"",
|
||||
x.Date.ToString("yyyy-MM-dd"),
|
||||
x.CountIn?.ToString("F2") ?? string.Empty,
|
||||
x.CountOut?.ToString("F2") ?? string.Empty
|
||||
x.Date.ToString("dd.MM.yyyy"),
|
||||
x.CountIn?.ToString("N0") ?? string.Empty,
|
||||
x.CountOut?.ToString("N0") ?? string.Empty
|
||||
})
|
||||
)
|
||||
.Union(new[] {
|
||||
new string[]
|
||||
{
|
||||
"Всего", "",
|
||||
combinedData.Sum(x => x.CountIn ?? 0).ToString("F2"),
|
||||
combinedData.Sum(x => x.CountOut ?? 0).ToString("F2")
|
||||
combinedData.Sum(x => x.CountIn ?? 0).ToString("N0"),
|
||||
combinedData.Sum(x => x.CountOut ?? 0).ToString("N0")
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
|
@ -4,7 +4,7 @@ namespace ProjectWarehouse.Repositories;
|
||||
|
||||
public interface IInventoryRepository
|
||||
{
|
||||
IEnumerable<Inventory> ReadInventory();
|
||||
IEnumerable<Inventory> ReadInventory(DateTime? dateFrom = null, DateTime? dateTo = null, int? componentsId = null, int? employeeId = null);
|
||||
|
||||
Inventory ReadInventoryById(int id);
|
||||
|
||||
|
@ -4,7 +4,7 @@ namespace ProjectWarehouse.Repositories;
|
||||
|
||||
public interface IOrderRequestRepository
|
||||
{
|
||||
IEnumerable<OrderRequest> ReadOrderRequest(DateTime? dateForm = null, DateTime? dateTo = null, double? quantity = null, int? componentsID = null);
|
||||
IEnumerable<OrderRequest> ReadOrderRequest(DateTime? dateFrom = null, DateTime? dateTo = null, double? quantity = null, int? componentsId = null);
|
||||
|
||||
void CreateOrderRequest(OrderRequest orderRequest);
|
||||
}
|
@ -4,7 +4,7 @@ namespace ProjectWarehouse.Repositories;
|
||||
|
||||
public interface IProductionRepository
|
||||
{
|
||||
IEnumerable<Production> ReadProduction();
|
||||
IEnumerable<Production> ReadProduction(DateTime? dateFrom = null, DateTime? dateTo = null, int? componentsId = null, int? employeeId = null);
|
||||
|
||||
void CreateProduction(Production production);
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class InventoryRepository : IInventoryRepository
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Inventory> ReadInventory()
|
||||
public IEnumerable<Inventory> ReadInventory(DateTime? dateFrom = null, DateTime? dateTo = null, int? componentsId = null, int? employeeId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
|
@ -36,7 +36,7 @@ public class OrderRequestRepository : IOrderRequestRepository
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<OrderRequest> ReadOrderRequest(DateTime? dateForm = null, DateTime? dateTo = null, double? quantity = null, int? componentsID = null)
|
||||
public IEnumerable<OrderRequest> ReadOrderRequest(DateTime? dateFrom = null, DateTime? dateTo = null, double? quantity = null, int? componentsId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
|
@ -32,8 +32,8 @@ public class ProductionRepository : IProductionRepository
|
||||
SELECT MAX(id) FROM Production";
|
||||
var productionId = connection.QueryFirst<int>(queryInsert, production, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO Components_Production (ComponentsId, Count)
|
||||
VALUES (@ComponentsId, @Count)";
|
||||
INSERT INTO Components_Production (ProductionId, ComponentsId, Count)
|
||||
VALUES (@ProductionId, @ComponentsId, @Count)";
|
||||
foreach (var elem in production.Components_Productions)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
@ -73,20 +73,64 @@ public class ProductionRepository : IProductionRepository
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<Production> ReadProduction()
|
||||
public IEnumerable<Production> ReadProduction(DateTime? dateFrom = null, DateTime? dateTo = null, int? componentsId = null, int? employeeId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateFrom.HasValue)
|
||||
{
|
||||
builder.AddCondition("fr.Date >= @dateFrom");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("fr.Date <= @dateTo");
|
||||
}
|
||||
if (componentsId.HasValue)
|
||||
{
|
||||
builder.AddCondition("fr.FeedId = @feedId");
|
||||
}
|
||||
if (employeeId.HasValue)
|
||||
{
|
||||
builder.AddCondition("fr.EmployeeId = @employeeId");
|
||||
}
|
||||
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT fr.*, ffr.ComponentsId, ffr.Count FROM Production fr
|
||||
INNER JOIN Components_Production ffr ON ffr.ProductionId = fr.Id";
|
||||
var production = connection.Query<TempComponents_Production>(querySelect);
|
||||
var querySelect = $@"SELECT
|
||||
fr.*,
|
||||
CONCAT(e.LastName, ' ', e.FirstName) as EmployeeName,
|
||||
ffr.ProductionId,
|
||||
ffr.ComponentsId,
|
||||
ffr.Count,
|
||||
f.Name as 'ComponentsName'
|
||||
FROM Production fr
|
||||
LEFT JOIN Employees e on e.Id = fr.EmployeeId
|
||||
INNER JOIN Components_Production ffr ON ffr.ProductionId = fr.Id
|
||||
LEFT JOIN Components f on f.Id = ffr.ComponentsId
|
||||
{builder.Build()}";
|
||||
var productionDict = new Dictionary<int, List<Components_Production>>();
|
||||
|
||||
var production = connection.Query<Production, Components_Production, Production>(querySelect,
|
||||
(productions, production) =>
|
||||
{
|
||||
if (!productionDict.TryGetValue(productions.Id, out var frr))
|
||||
{
|
||||
frr = [];
|
||||
productionDict.Add(productions.Id, frr);
|
||||
}
|
||||
|
||||
frr.Add(production);
|
||||
return productions;
|
||||
}, splitOn: "ComponentsId", param: new { dateFrom, dateTo, componentsId, employeeId });
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(production));
|
||||
return production.GroupBy(x => x.Id, y => y,
|
||||
(key, value) => Production.CreateEntity(value.First(),
|
||||
value.Select(z => Components_Production.CreateElement(0, z.ComponentsId, z.Count)))).ToList();
|
||||
|
||||
return productionDict.Select(x =>
|
||||
{
|
||||
var fr = production.First(y => y.Id == x.Key);
|
||||
fr.SetComponents_Production(x.Value);
|
||||
return fr;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -0,0 +1,32 @@
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectWarehouse.Repositories.Implementations;
|
||||
|
||||
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}";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user