2023-03-27 17:14:36 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.DailyReport;
|
2022-06-29 13:04:30 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks;
|
2022-04-29 15:39:12 +05:00
|
|
|
|
using ClosedXML.Excel;
|
2023-03-27 17:14:36 +05:00
|
|
|
|
using System.Collections.Generic;
|
2022-04-29 15:39:12 +05:00
|
|
|
|
using System.IO;
|
|
|
|
|
namespace AsbCloudInfrastructure.Services.DailyReport
|
|
|
|
|
{
|
2023-04-18 16:22:53 +05:00
|
|
|
|
|
2022-04-29 15:39:12 +05:00
|
|
|
|
public class DailyReportMakerExcel
|
|
|
|
|
{
|
2023-04-13 11:15:45 +05:00
|
|
|
|
private IEnumerable<WellOperationCategoryDto> OperationCategories = null!;
|
2023-03-27 17:14:36 +05:00
|
|
|
|
|
|
|
|
|
public Stream MakeReportFromBlocks(DailyReportDto dto, IEnumerable<WellOperationCategoryDto> operationCategories)
|
2022-06-17 13:20:48 +05:00
|
|
|
|
{
|
2023-03-27 17:14:36 +05:00
|
|
|
|
OperationCategories = operationCategories;
|
|
|
|
|
|
2022-06-17 13:20:48 +05:00
|
|
|
|
using var workbook = new XLWorkbook();
|
2023-03-27 17:14:36 +05:00
|
|
|
|
FillExampleBlocks(workbook, dto);
|
2022-06-17 13:20:48 +05:00
|
|
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
|
|
|
workbook.SaveAs(memoryStream, new SaveOptions { });
|
|
|
|
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
return memoryStream;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-30 16:01:46 +05:00
|
|
|
|
private void FillExampleBlocks(XLWorkbook workbook, DailyReportDto dto)
|
2022-06-24 11:41:46 +05:00
|
|
|
|
{
|
2022-07-05 11:30:25 +05:00
|
|
|
|
var sheet = workbook.Worksheets.Add(dto.Head.ReportDate.ToString("dd.MM.yyyy"));
|
2022-07-06 09:21:35 +05:00
|
|
|
|
var addressStart = new CellAddress(sheet, 2, 2);
|
2022-07-05 11:30:25 +05:00
|
|
|
|
var blockHeader = new HeadBlock(addressStart, dto.Head);
|
2022-06-24 11:41:46 +05:00
|
|
|
|
addressStart = blockHeader.AddressBlockEnd + (1, 0);
|
2022-07-06 09:21:35 +05:00
|
|
|
|
addressStart.ColumnNumber = 2;
|
2022-07-05 11:30:25 +05:00
|
|
|
|
var blockBha = new BhaBlock(addressStart, dto.Bha);
|
2022-06-29 13:04:30 +05:00
|
|
|
|
addressStart = blockBha.AddressBlockEnd + (1, 0);
|
2022-07-06 09:21:35 +05:00
|
|
|
|
addressStart.ColumnNumber = 2;
|
2023-03-27 17:14:36 +05:00
|
|
|
|
var timeBalance = new TimeBalanceBlock(addressStart, dto.TimeBalance, OperationCategories);
|
2022-06-30 16:01:46 +05:00
|
|
|
|
addressStart = timeBalance.AddressBlockEnd + (1, 0);
|
2022-07-06 09:21:35 +05:00
|
|
|
|
addressStart.ColumnNumber = 2;
|
2022-07-25 18:02:39 +05:00
|
|
|
|
var blockDimensionless = new DimensionlessBlock(addressStart, dto.NoDrilling);
|
2022-06-30 16:01:46 +05:00
|
|
|
|
addressStart = blockDimensionless.AddressBlockEnd + (1, 0);
|
2022-07-06 09:21:35 +05:00
|
|
|
|
addressStart.ColumnNumber = 2;
|
|
|
|
|
var blockSaub = new SaubBlock(addressStart, dto.Saub, blockHeader);
|
2022-07-04 05:29:16 +05:00
|
|
|
|
addressStart = blockSaub.AddressBlockEnd + (1, 0);
|
2022-07-05 11:30:25 +05:00
|
|
|
|
blockDimensionless.SaubBlock = blockSaub;
|
2022-07-06 09:21:35 +05:00
|
|
|
|
addressStart.ColumnNumber = 2;
|
2022-07-05 11:30:25 +05:00
|
|
|
|
var blockSign = new SignBlock(addressStart, dto.Sign);
|
2022-06-30 16:01:46 +05:00
|
|
|
|
addressStart = blockSign.AddressBlockEnd + (1, 0);
|
2022-07-06 09:21:35 +05:00
|
|
|
|
addressStart.ColumnNumber = 2;
|
2022-06-24 11:41:46 +05:00
|
|
|
|
blockHeader.Draw(sheet);
|
2022-06-29 13:04:30 +05:00
|
|
|
|
blockBha.Draw(sheet);
|
|
|
|
|
timeBalance.Draw(sheet);
|
2022-06-30 16:01:46 +05:00
|
|
|
|
blockDimensionless.Draw(sheet);
|
2022-07-04 05:29:16 +05:00
|
|
|
|
blockSaub.Draw(sheet);
|
2022-09-29 12:29:10 +05:00
|
|
|
|
blockSign.Draw(sheet);
|
|
|
|
|
//sheet.Columns().AdjustToContents(); // Adjust column width
|
|
|
|
|
sheet.Rows().AdjustToContents();
|
2023-03-27 17:14:36 +05:00
|
|
|
|
}
|
2022-04-29 15:39:12 +05:00
|
|
|
|
}
|
2023-04-18 16:22:53 +05:00
|
|
|
|
|
2022-04-29 15:39:12 +05:00
|
|
|
|
}
|
2022-06-17 13:20:48 +05:00
|
|
|
|
|