forked from ddrilling/AsbCloudServer
69780e8aaf
Add example block
99 lines
3.6 KiB
C#
99 lines
3.6 KiB
C#
using AsbCloudApp.Data.DailyReportModel;
|
||
using ClosedXML.Excel;
|
||
using System.Linq;
|
||
|
||
namespace AsbCloudInfrastructure.Services.DailyReport
|
||
{
|
||
internal class BlockHeader : BlockAbstract
|
||
{
|
||
private readonly DailyReportHeadDto blockDto;
|
||
|
||
public CellAddress AddressTitle { get; }
|
||
public CellAddress AddressCustomer { get; }
|
||
public CellAddress AddressDriller { get; }
|
||
public CellAddress AddressPeriod { get; }
|
||
public CellAddress AddressExampleData1 { get; }
|
||
public CellAddress[] AddressesExampleDataArray { get; }
|
||
|
||
/// <summary>
|
||
/// Значение нижняя правая ячейка блока
|
||
/// </summary>
|
||
public override CellAddress AddressBlockBegin { get; }
|
||
|
||
/// <summary>
|
||
/// Значение нижняя правая ячейка блока
|
||
/// </summary>
|
||
public override CellAddress AddressBlockEnd { get; }
|
||
|
||
public BlockHeader(CellAddress addressBlockBegin, DailyReportHeadDto blockDto)
|
||
{
|
||
AddressBlockBegin = addressBlockBegin.Copy();
|
||
|
||
this.blockDto = blockDto;
|
||
AddressTitle = addressBlockBegin + (0, 0);
|
||
AddressCustomer = addressBlockBegin + (1,0);
|
||
AddressDriller = addressBlockBegin + (2, 0);
|
||
AddressPeriod = addressBlockBegin + (3, 0);
|
||
AddressExampleData1 = addressBlockBegin + (5, 0);
|
||
|
||
AddressesExampleDataArray = new CellAddress[5];
|
||
for (int i = 0; i < 5; i++)
|
||
AddressesExampleDataArray[i] = addressBlockBegin + (6 + i, 0);
|
||
|
||
AddressBlockEnd = AddressesExampleDataArray.Last();
|
||
}
|
||
|
||
public override void Draw(IXLWorksheet sheet)
|
||
{
|
||
// значение в одну ячейку
|
||
sheet.Cell(AddressTitle)
|
||
._SetValue($"Суточная сводка бурения скважины: {blockDto.WellName}, куст: {blockDto.ClusterName}")
|
||
.Style.SetH1();
|
||
|
||
// значение в несколько ячеек с объединением
|
||
sheet._Range(AddressCustomer, AddressCustomer + (0,7))
|
||
._SetValue($"Заказчик: {blockDto.Customer}");
|
||
|
||
sheet.Cell(AddressDriller)
|
||
._SetValue($"Подрядчик: {blockDto.Contractor}");
|
||
|
||
sheet._Range(AddressExampleData1, AddressExampleData1 + (0, 4))
|
||
._SetValue(blockDto.BottomholeDepth); // для примера с будущей формулой
|
||
}
|
||
}
|
||
|
||
internal class BlockWithFormula : BlockAbstract
|
||
{
|
||
private readonly BlockHeader blockHeader;
|
||
|
||
public override CellAddress AddressBlockBegin { get; }
|
||
|
||
public override CellAddress AddressBlockEnd { get; }
|
||
|
||
public CellAddress AddressFomulaExample { get; set; }
|
||
|
||
public BlockWithFormula(CellAddress addressBlockBegin, BlockHeader blockHeader)
|
||
{
|
||
AddressFomulaExample = addressBlockBegin + (0, 0);
|
||
AddressBlockBegin = addressBlockBegin.Copy();
|
||
AddressBlockEnd = addressBlockBegin + (1, 0);
|
||
this.blockHeader = blockHeader;
|
||
}
|
||
|
||
public override void Draw(IXLWorksheet sheet)
|
||
{
|
||
var formula = string.Format("{0}/5", blockHeader.AddressExampleData1.ToString());
|
||
|
||
sheet.Cell(AddressFomulaExample)
|
||
.SetFormulaA1(formula);
|
||
}
|
||
}
|
||
|
||
internal abstract class BlockAbstract
|
||
{
|
||
public abstract CellAddress AddressBlockBegin { get; }
|
||
public abstract CellAddress AddressBlockEnd { get; }
|
||
public abstract void Draw(IXLWorksheet sheet);
|
||
}
|
||
}
|