forked from ddrilling/AsbCloudServer
94 lines
3.0 KiB
C#
94 lines
3.0 KiB
C#
using AsbCloudApp.Data;
|
||
using AsbCloudApp.Data.DailyReport;
|
||
using ClosedXML.Excel;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
|
||
namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks
|
||
{
|
||
/// <summary>
|
||
/// Построение баланса времени
|
||
/// </summary>
|
||
class TimeBalanceBlock : BlockAbstract
|
||
{
|
||
/// <summary>
|
||
/// Начальная ячейка
|
||
/// </summary>
|
||
public override CellAddress AddressBlockBegin { get; }
|
||
|
||
/// <summary>
|
||
/// Конечная ячейка
|
||
/// </summary>
|
||
public override CellAddress AddressBlockEnd { get; }
|
||
|
||
/// <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 const int countColumns = 3;
|
||
|
||
/// <summary>
|
||
/// количество категорий операций
|
||
/// </summary>
|
||
private int OperationCategoriesCount { get { return OperationCategories.Count(); } }
|
||
|
||
|
||
public TimeBalanceBlock(CellAddress addressBlockBegin, TimeBalanceDto blockDto, IEnumerable<WellOperationCategoryDto> operationCategories)
|
||
{
|
||
AddressBlockBegin = addressBlockBegin.Copy();
|
||
|
||
OperationsStatistics = blockDto.OperationsStat;
|
||
OperationCategories = operationCategories;
|
||
|
||
var rowsCount = (int)Math.Ceiling( 1d * OperationCategoriesCount / countColumns);
|
||
var colsCount = (1 + 1) * countColumns;
|
||
AddressBlockEnd = Title + (rowsCount, colsCount);
|
||
}
|
||
|
||
public override void Draw(IXLWorksheet sheet)
|
||
{
|
||
sheet.Range(Title.RowNumber, Title.ColumnNumber, Title.RowNumber, Title.ColumnNumber + 1)
|
||
.Merge()
|
||
.SetValue("БАЛАНС ВРЕМЕНИ");
|
||
|
||
var i = 0;
|
||
|
||
foreach (var operationCategory in OperationCategories)
|
||
{
|
||
var row = 2 + (int)Math.Floor(1d * i / countColumns);
|
||
var col = 1 + 2 *(i % countColumns);
|
||
i++;
|
||
|
||
sheet.Cell(AddressBlockBegin + (row, col))
|
||
._SetValue(operationCategory.Name, true);
|
||
sheet.Cell(AddressBlockBegin + (row, col + 1))
|
||
._SetValue(GetValue(operationCategory.Id), true);
|
||
}
|
||
}
|
||
|
||
private string GetValue(int categoryId)
|
||
{
|
||
if (OperationsStatistics.TryGetValue(categoryId, out double duration))
|
||
return $"{duration}";
|
||
return "0";
|
||
}
|
||
}
|
||
}
|
||
|