2023-03-27 17:14:36 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.DailyReport;
|
2022-06-29 13:04:30 +05:00
|
|
|
|
using ClosedXML.Excel;
|
2023-03-29 16:05:57 +05:00
|
|
|
|
using System;
|
2023-03-27 17:14:36 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-06-29 13:04:30 +05:00
|
|
|
|
|
2023-04-18 16:22:53 +05:00
|
|
|
|
|
2022-06-29 13:04:30 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks
|
|
|
|
|
{
|
2023-03-29 10:26:10 +05:00
|
|
|
|
/// <summary>
|
2023-03-29 16:05:57 +05:00
|
|
|
|
/// Построение баланса времени
|
2023-03-29 10:26:10 +05:00
|
|
|
|
/// </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>
|
2023-03-29 16:05:57 +05:00
|
|
|
|
/// количество столбцов в таблице
|
2023-03-29 10:26:10 +05:00
|
|
|
|
/// </summary>
|
2023-03-29 16:05:57 +05:00
|
|
|
|
private const int countColumns = 3;
|
2023-03-29 10:26:10 +05:00
|
|
|
|
|
|
|
|
|
/// <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 16:05:57 +05:00
|
|
|
|
var rowsCount = (int)Math.Ceiling( 1d * OperationCategoriesCount / countColumns);
|
|
|
|
|
var colsCount = (1 + 1) * countColumns;
|
|
|
|
|
AddressBlockEnd = Title + (rowsCount, colsCount);
|
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 16:05:57 +05:00
|
|
|
|
var i = 0;
|
2023-03-29 10:26:10 +05:00
|
|
|
|
|
|
|
|
|
foreach (var operationCategory in OperationCategories)
|
|
|
|
|
{
|
2023-03-29 16:05:57 +05:00
|
|
|
|
var row = 2 + (int)Math.Floor(1d * i / countColumns);
|
|
|
|
|
var col = 1 + 2 *(i % countColumns);
|
|
|
|
|
i++;
|
2023-03-29 10:26:10 +05:00
|
|
|
|
|
2023-03-29 16:05:57 +05:00
|
|
|
|
sheet.Cell(AddressBlockBegin + (row, col))
|
|
|
|
|
._SetValue(operationCategory.Name, true);
|
|
|
|
|
sheet.Cell(AddressBlockBegin + (row, col + 1))
|
|
|
|
|
._SetValue(GetValue(operationCategory.Id), true);
|
2023-03-29 10:26:10 +05:00
|
|
|
|
}
|
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";
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-29 13:04:30 +05:00
|
|
|
|
}
|
2023-04-18 16:22:53 +05:00
|
|
|
|
|