2023-03-27 17:14:36 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.DailyReport;
|
|
|
|
|
using AsbCloudDb.Model;
|
2022-06-29 13:04:30 +05:00
|
|
|
|
using ClosedXML.Excel;
|
2023-03-27 17:14:36 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-06-29 13:04:30 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks
|
|
|
|
|
{
|
2023-03-29 10:26:10 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Пострение баланса времени
|
|
|
|
|
/// </summary>
|
2022-06-29 13:04:30 +05:00
|
|
|
|
class TimeBalanceBlock : BlockAbstract
|
|
|
|
|
{
|
2023-03-29 10:26:10 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Начальная ячейка
|
|
|
|
|
/// </summary>
|
2022-06-29 13:04:30 +05:00
|
|
|
|
public override CellAddress AddressBlockBegin { get; }
|
2023-03-29 10:26:10 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конечная ячейка
|
|
|
|
|
/// </summary>
|
2022-06-29 13:04:30 +05:00
|
|
|
|
public override CellAddress AddressBlockEnd { get; }
|
|
|
|
|
|
2023-03-29 10:26:10 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ячейка с заголовком
|
|
|
|
|
/// </summary>
|
|
|
|
|
private CellAddress Title { get { return AddressBlockBegin + (1, 3); } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Статистика по операциям
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Dictionary<int, double> OperationsStatistics { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Категории операций
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IEnumerable<WellOperationCategoryDto> OperationCategories { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// количество стобцов в таблице
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly int CountColumns = 3;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// количество категорий операций
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int OperationCategoriesCount { get { return OperationCategories.Count(); } }
|
2023-03-27 17:14:36 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TimeBalanceBlock(CellAddress addressBlockBegin, TimeBalanceDto blockDto, IEnumerable<WellOperationCategoryDto> operationCategories)
|
2022-06-29 13:04:30 +05:00
|
|
|
|
{
|
|
|
|
|
AddressBlockBegin = addressBlockBegin.Copy();
|
2023-03-27 17:14:36 +05:00
|
|
|
|
|
|
|
|
|
OperationsStatistics = blockDto.OperationsStat;
|
|
|
|
|
OperationCategories = operationCategories;
|
|
|
|
|
|
2023-03-29 10:26:10 +05:00
|
|
|
|
var rowColumn = (CountColumns * 2) + (OperationCategoriesCount % CountColumns == 0 ? 0 : 2);
|
|
|
|
|
var cellColumn = OperationCategoriesCount % CountColumns;
|
|
|
|
|
AddressBlockEnd = AddressBlockBegin + (rowColumn, cellColumn);
|
2022-06-29 13:04:30 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Draw(IXLWorksheet sheet)
|
|
|
|
|
{
|
2023-03-27 17:14:36 +05:00
|
|
|
|
|
|
|
|
|
sheet.Range(Title.RowNumber, Title.ColumnNumber, Title.RowNumber, Title.ColumnNumber + 1)
|
2023-03-22 11:29:53 +05:00
|
|
|
|
.Merge()
|
|
|
|
|
.SetValue("БАЛАНС ВРЕМЕНИ");
|
2023-03-27 17:14:36 +05:00
|
|
|
|
|
2023-03-29 10:26:10 +05:00
|
|
|
|
var rowColumn = 2;
|
|
|
|
|
var cellColumn = 1;
|
|
|
|
|
var rowsCountInColumn = OperationCategoriesCount / CountColumns;
|
|
|
|
|
if (OperationCategoriesCount % CountColumns != 0)
|
|
|
|
|
rowsCountInColumn++;
|
|
|
|
|
|
|
|
|
|
foreach (var operationCategory in OperationCategories)
|
|
|
|
|
{
|
|
|
|
|
sheet.Cell(AddressBlockBegin + (rowColumn, cellColumn))
|
|
|
|
|
._SetValue(GetCaption(operationCategory.Id), true);
|
|
|
|
|
sheet.Cell(AddressBlockBegin + (rowColumn, cellColumn + 1))
|
|
|
|
|
._SetValue(GetValue(operationCategory.Id), true);
|
|
|
|
|
|
|
|
|
|
if (rowColumn <= rowsCountInColumn)
|
|
|
|
|
rowColumn++;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rowColumn = 2;
|
|
|
|
|
cellColumn = cellColumn + 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-29 13:04:30 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 17:14:36 +05:00
|
|
|
|
private string GetValue(int categoryId)
|
|
|
|
|
{
|
|
|
|
|
if (OperationsStatistics.TryGetValue(categoryId, out double duration))
|
|
|
|
|
return $"{duration}";
|
|
|
|
|
return "0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetCaption(int categoryId)
|
|
|
|
|
{
|
|
|
|
|
var caption = OperationCategories.FirstOrDefault(o => o.Id == categoryId)?.Name ?? string.Empty;
|
|
|
|
|
return caption;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-29 13:04:30 +05:00
|
|
|
|
}
|
|
|
|
|
|