ПИбд-22 Морозов Д.В. Лабораторная 3 #8
@ -15,7 +15,7 @@ namespace ProjectRepairCompany.Forms
|
||||
public partial class FormDirectoryReport : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
public FormDirectoryReport(UnityContainer container)
|
||||
public FormDirectoryReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectRepairCompany.Reports;
|
||||
|
||||
internal class DocReport
|
||||
public class DocReport
|
||||
{
|
||||
private readonly IStorageRepository _storageRepository;
|
||||
private readonly IMasterRepository _masterRepository;
|
||||
@ -18,7 +18,7 @@ internal class DocReport
|
||||
private readonly ILogger<DocReport> _logger;
|
||||
public DocReport(IMasterRepository masterRepository, IDetailRepository detailRepository, IStorageRepository storageRepository, ILogger<DocReport> logger)
|
||||
{
|
||||
_masterRepository = masterRepository
|
||||
_masterRepository = masterRepository
|
||||
?? throw new ArgumentNullException(nameof(masterRepository));
|
||||
_detailRepository = detailRepository
|
||||
?? throw new ArgumentNullException(nameof(detailRepository));
|
||||
|
@ -1,106 +1,106 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectRepairCompany.Entities;
|
||||
using ProjectRepairCompany.Repositories;
|
||||
using ProjectRepairCompany.Repositories.Implementations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
//using ProjectRepairCompany.Entities;
|
||||
//using ProjectRepairCompany.Repositories;
|
||||
//using ProjectRepairCompany.Repositories.Implementations;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
||||
|
||||
namespace ProjectRepairCompany.Reports;
|
||||
//namespace ProjectRepairCompany.Reports;
|
||||
|
||||
internal class TableReport
|
||||
{
|
||||
private readonly IStorageDetailRepository _storageDetailRepository;
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly ILogger<TableReport> _logger;
|
||||
//internal class TableReport
|
||||
//{
|
||||
// private readonly IStorageDetailRepository _storageDetailRepository;
|
||||
// private readonly IOrderRepository _orderRepository;
|
||||
// private readonly ILogger<TableReport> _logger;
|
||||
|
||||
internal static readonly string[] item = { "Деталь", "Дата", "Количество пришло", "Количество ушло" };
|
||||
// internal static readonly string[] item = { "Деталь", "Дата", "Количество пришло", "Количество ушло" };
|
||||
|
||||
public TableReport(IStorageDetailRepository storageDetailRepository, IOrderRepository orderRepository, ILogger<TableReport> logger)
|
||||
{
|
||||
_storageDetailRepository = storageDetailRepository ?? throw new ArgumentNullException(nameof(storageDetailRepository));
|
||||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
// public TableReport(IStorageDetailRepository storageDetailRepository, IOrderRepository orderRepository, ILogger<TableReport> logger)
|
||||
// {
|
||||
// _storageDetailRepository = storageDetailRepository ?? throw new ArgumentNullException(nameof(storageDetailRepository));
|
||||
// _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||
// _logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
// }
|
||||
|
||||
public bool CreateTable(string filePath, int detailId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по движению деталей", 1, 4)
|
||||
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 1)
|
||||
.AddTable(new[] { 20, 15, 15, 15 }, GetData(detailId, startDate, endDate))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// public bool CreateTable(string filePath, int detailId, DateTime startDate, DateTime endDate)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// new ExcelBuilder(filePath)
|
||||
// .AddHeader("Сводка по движению деталей", 1, 4)
|
||||
// .AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 1)
|
||||
// .AddTable(new[] { 20, 15, 15, 15 }, GetData(detailId, startDate, endDate))
|
||||
// .Build();
|
||||
// return true;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// _logger.LogError(ex, "Ошибка при формировании документа");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
private List<string[]> GetData(int detailId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
// Получаем данные о пополнении склада
|
||||
var storageData = _storageDetailRepository
|
||||
.ReadStorageDetails()
|
||||
.Where(x => x.SupplyDate >= startDate && x.SupplyDate <= endDate && x.DetailId == detailId)
|
||||
.Select(x => new
|
||||
{
|
||||
x.DetailId,
|
||||
Date = x.SupplyDate, // Дата поступления
|
||||
CountIn = x.DetailCount, // Количество пришло
|
||||
CountOut = (int?)null // Нет исходящих
|
||||
})
|
||||
.OrderBy(x => x.Date); // Сортировка по дате поступления
|
||||
// private List<string[]> GetData(int detailId, DateTime startDate, DateTime endDate)
|
||||
// {
|
||||
// // Получаем данные о пополнении склада
|
||||
// var storageData = _storageDetailRepository
|
||||
// .ReadStorageDetails()
|
||||
// .Where(x => x.SupplyDate >= startDate && x.SupplyDate <= endDate && x.DetailId == detailId)
|
||||
// .Select(x => new
|
||||
// {
|
||||
// x.DetailId,
|
||||
// Date = x.SupplyDate, // Дата поступления
|
||||
// CountIn = x.DetailCount, // Количество пришло
|
||||
// CountOut = (int?)null // Нет исходящих
|
||||
// })
|
||||
// .OrderBy(x => x.Date); // Сортировка по дате поступления
|
||||
|
||||
// Получаем данные о заказах
|
||||
var orderData = _orderRepository
|
||||
.ReadOrders()
|
||||
.Where(x => x.DateIssue >= startDate && x.DateIssue <= endDate)
|
||||
.SelectMany(x => x.OrderDetails) // Извлекаем все детали из заказов
|
||||
.Where(orderDetail => orderDetail.DetailId == detailId)
|
||||
.Select(orderDetail => new
|
||||
{
|
||||
DetailId = orderDetail.DetailId,
|
||||
Date = orderDetail.Order.DateIssue, // Дата заказа
|
||||
CountIn = (int?)null, // Нет поступлений
|
||||
CountOut = orderDetail.DetailCount // Количество ушло
|
||||
})
|
||||
.OrderBy(x => x.Date); // Сортировка по дате заказа
|
||||
// // Получаем данные о заказах
|
||||
// var orderData = _orderRepository
|
||||
// .ReadOrders()
|
||||
// .Where(x => x.DateIssue >= startDate && x.DateIssue <= endDate)
|
||||
// .SelectMany(x => x.OrderDetails) // Извлекаем все детали из заказов
|
||||
// .Where(orderDetail => orderDetail.DetailId == detailId)
|
||||
// .Select(orderDetail => new
|
||||
// {
|
||||
// DetailId = orderDetail.DetailId,
|
||||
// Date = orderDetail.Order.DateIssue, // Дата заказа
|
||||
// CountIn = (int?)null, // Нет поступлений
|
||||
// CountOut = orderDetail.DetailCount // Количество ушло
|
||||
// })
|
||||
// .OrderBy(x => x.Date); // Сортировка по дате заказа
|
||||
|
||||
// Объединяем данные из двух источников
|
||||
var combinedData = storageData
|
||||
.Union(orderData)
|
||||
.OrderBy(x => x.Date) // Сортируем все данные по дате
|
||||
.ToList();
|
||||
// // Объединяем данные из двух источников
|
||||
// var combinedData = storageData
|
||||
// .Union(orderData)
|
||||
// .OrderBy(x => x.Date) // Сортируем все данные по дате
|
||||
// .ToList();
|
||||
|
||||
// Формируем итоговую таблицу
|
||||
var result = new List<string[]> { item }
|
||||
.Union(combinedData.Select(x => new string[]
|
||||
{
|
||||
x.DetailId.ToString(), // Деталь
|
||||
x.Date.ToString("dd.MM.yyyy"), // Дата
|
||||
x.CountIn?.ToString() ?? string.Empty, // Количество пришло
|
||||
x.CountOut?.ToString() ?? string.Empty // Количество ушло
|
||||
}))
|
||||
.Union(new[]
|
||||
{
|
||||
new string[]
|
||||
{
|
||||
"Всего",
|
||||
"",
|
||||
combinedData.Sum(x => x.CountIn ?? 0).ToString(), // Суммируем все поступления
|
||||
combinedData.Sum(x => x.CountOut ?? 0).ToString() // Суммируем все исходящие
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
// // Формируем итоговую таблицу
|
||||
// var result = new List<string[]> { item }
|
||||
// .Union(combinedData.Select(x => new string[]
|
||||
// {
|
||||
// x.DetailId.ToString(), // Деталь
|
||||
// x.Date.ToString("dd.MM.yyyy"), // Дата
|
||||
// x.CountIn?.ToString() ?? string.Empty, // Количество пришло
|
||||
// x.CountOut?.ToString() ?? string.Empty // Количество ушло
|
||||
// }))
|
||||
// .Union(new[]
|
||||
// {
|
||||
|
||||
// new string[]
|
||||
// {
|
||||
// "Всего",
|
||||
// "",
|
||||
// combinedData.Sum(x => x.CountIn ?? 0).ToString(), // Суммируем все поступления
|
||||
// combinedData.Sum(x => x.CountOut ?? 0).ToString() // Суммируем все исходящие
|
||||
// }
|
||||
// })
|
||||
// .ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
// return result;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@ -109,4 +109,4 @@ internal class TableReport
|
||||
|
||||
|
||||
|
||||
}
|
||||
//}
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Много пустых строк