using AsbCloudApp.Data; using AsbCloudApp.Data.DailyReport; using AsbCloudDb.Model; using ClosedXML.Excel; using System.Collections.Generic; using System.Linq; namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks { class TimeBalanceBlock : BlockAbstract { public override CellAddress AddressBlockBegin { get; } public Dictionary OperationsStatistics { get; set; } public IEnumerable OperationCategories { get; set; } public override CellAddress AddressBlockEnd { get; } public CellAddress Title { get { return AddressBlockBegin + (1, 3); } } public TimeBalanceBlock(CellAddress addressBlockBegin, TimeBalanceDto blockDto, IEnumerable operationCategories) { AddressBlockBegin = addressBlockBegin.Copy(); OperationsStatistics = blockDto.OperationsStat; OperationCategories = operationCategories; AddressBlockEnd = AddressBlockBegin + (7, 6); } public override void Draw(IXLWorksheet sheet) { sheet.Range(Title.RowNumber, Title.ColumnNumber, Title.RowNumber, Title.ColumnNumber + 1) .Merge() .SetValue("БАЛАНС ВРЕМЕНИ"); sheet.Cell(AddressBlockBegin + (2, 1)) ._SetValue(GetCaption(WellOperationCategory.Knbk), true); sheet.Cell(AddressBlockBegin + (3, 1)) ._SetValue(GetCaption(WellOperationCategory.IdMechanicalDrilling), true); sheet.Cell(AddressBlockBegin + (4, 1)) ._SetValue(GetCaption(WellOperationCategory.MeasurementStat), true); sheet.Cell(AddressBlockBegin + (5, 1)) ._SetValue(GetCaption(WellOperationCategory.NormalizedWellDiameter), true); sheet.Cell(AddressBlockBegin + (6, 1)) ._SetValue(GetCaption(WellOperationCategory.Building), true); sheet.Cell(AddressBlockBegin + (7, 1)) ._SetValue(GetValue(WellOperationCategory.SPO), true); sheet.Cell(AddressBlockBegin + (2, 2)) ._SetValue(GetValue(WellOperationCategory.Knbk)); sheet.Cell(AddressBlockBegin + (3, 2)) ._SetValue(GetValue(WellOperationCategory.IdMechanicalDrilling)); sheet.Cell(AddressBlockBegin + (4, 2)) ._SetValue(GetValue(WellOperationCategory.MeasurementStat)); sheet.Cell(AddressBlockBegin + (5, 2)) ._SetValue(GetValue(WellOperationCategory.NormalizedWellDiameter)); sheet.Cell(AddressBlockBegin + (6, 2)) ._SetValue(GetValue(WellOperationCategory.Building)); sheet.Cell(AddressBlockBegin + (7, 2)) ._SetValue(GetValue(WellOperationCategory.SPO)); sheet.Cell(AddressBlockBegin + (2, 3)) ._SetValue(GetCaption(WellOperationCategory.CasingRunning)); sheet.Cell(AddressBlockBegin + (3, 3)) ._SetValue(GetCaption(WellOperationCategory.Cementing)); sheet.Cell(AddressBlockBegin + (4, 3)) ._SetValue(GetCaption(WellOperationCategory.AuxiliaryWorkFastening)); sheet.Cell(AddressBlockBegin + (5, 3)) ._SetValue(GetCaption(WellOperationCategory.AssemblyOrDisassemblyGIS)); sheet.Cell(AddressBlockBegin + (6, 3)) ._SetValue(GetCaption(WellOperationCategory.SPO2)); sheet.Cell(AddressBlockBegin + (7, 3)) ._SetValue(GetCaption(WellOperationCategory.GIS)); sheet.Cell(AddressBlockBegin + (2, 4)) ._SetValue(GetValue(WellOperationCategory.CasingRunning)); sheet.Cell(AddressBlockBegin + (3, 4)) ._SetValue(GetValue(WellOperationCategory.Cementing)); sheet.Cell(AddressBlockBegin + (4, 4)) ._SetValue(GetValue(WellOperationCategory.AuxiliaryWorkFastening)); sheet.Cell(AddressBlockBegin + (5, 4)) ._SetValue(GetValue(WellOperationCategory.AssemblyOrDisassemblyGIS)); sheet.Cell(AddressBlockBegin + (6, 4)) ._SetValue(GetValue(WellOperationCategory.SPO2)); sheet.Cell(AddressBlockBegin + (7, 4)) ._SetValue(GetValue(WellOperationCategory.GIS)); sheet.Cell(AddressBlockBegin + (2, 5)) ._SetValue(GetCaption(WellOperationCategory.FlushingOBR)); sheet.Cell(AddressBlockBegin + (3, 5)) ._SetValue(GetCaption(WellOperationCategory.AuxiliaryWork)); sheet.Cell(AddressBlockBegin + (4, 5)) ._SetValue(GetCaption(WellOperationCategory.EquipmentRepair)); sheet.Cell(AddressBlockBegin + (5, 5)) ._SetValue(GetCaption(WellOperationCategory.EmergencyWork)); sheet.Cell(AddressBlockBegin + (6, 5)) ._SetValue(GetCaption(WellOperationCategory.Complication)); sheet.Cell(AddressBlockBegin + (7, 5)) ._SetValue(GetCaption(WellOperationCategory.OperationsNotIncludedGGD)); sheet.Cell(AddressBlockBegin + (2, 6)) ._SetValue(GetValue(WellOperationCategory.FlushingOBR)); sheet.Cell(AddressBlockBegin + (3, 6)) ._SetValue(GetValue(WellOperationCategory.AuxiliaryWork)); sheet.Cell(AddressBlockBegin + (4, 6)) ._SetValue(GetValue(WellOperationCategory.EquipmentRepair)); sheet.Cell(AddressBlockBegin + (5, 6)) ._SetValue(GetValue(WellOperationCategory.EmergencyWork)); sheet.Cell(AddressBlockBegin + (6, 6)) ._SetValue(GetValue(WellOperationCategory.Complication)); sheet.Cell(AddressBlockBegin + (7, 6)) ._SetValue(GetValue(WellOperationCategory.OperationsNotIncludedGGD)); } 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; } } }