parse data and put in table

This commit is contained in:
Tyrel Souza 2023-07-28 01:02:22 -04:00
parent 1592002820
commit 229734ef46
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
2 changed files with 115 additions and 41 deletions

View File

@ -77,8 +77,8 @@ namespace BenchtopPDF
row.RelativeItem().Component(new AddressComponent("For"));
});
foreach (var item in Sheet.Transducers) {
column.Item().Element(ComposeTable);
foreach (var transducer in Sheet.Transducers) {
column.Item().Component(new TableComponent(transducer));
}
// var totalPrice = Sheet.Items.Sum(x => x.Price * x.Quantity);
@ -91,46 +91,7 @@ namespace BenchtopPDF
void ComposeTable(IContainer container)
{
var headerStyle = TextStyle.Default.SemiBold();
container.Table(table =>
{
table.ColumnsDefinition(columns =>
{
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
});
table.Header(header =>
{
header.Cell().Text("Point #").Style(headerStyle);
header.Cell().AlignRight().Text("Master Value").Style(headerStyle);
header.Cell().AlignRight().Text("Low Limit").Style(headerStyle);
header.Cell().AlignRight().Text("High Limit").Style(headerStyle);
header.Cell().AlignRight().Text("DUT").Style(headerStyle);
header.Cell().AlignRight().Text("Delta").Style(headerStyle);
header.Cell().ColumnSpan(6).PaddingTop(5).BorderBottom(1).BorderColor(Colors.Black);
});
foreach (var item in Sheet.Transducers)
{
var index = Sheet.Transducers.IndexOf(item) + 1;
table.Cell().Element(CellStyle).Text($"{index}");
table.Cell().Element(CellStyle).Text(item.PartNumber);
table.Cell().Element(CellStyle).AlignRight().Text($"{item.Accuracy}");
table.Cell().Element(CellStyle).AlignRight().Text($"{item.TransducerName}");
table.Cell().Element(CellStyle).AlignRight().Text($"{item.VerifyDate}");
table.Cell().Element(CellStyle).AlignRight().Text($"{item.VerifyDate}");
static IContainer CellStyle(IContainer container) => container.BorderBottom(1).BorderColor(Colors.Grey.Lighten2).PaddingVertical(5);
}
});
}
void ComposeComments(IContainer container)
@ -164,4 +125,116 @@ namespace BenchtopPDF
});
}
}
public class TableComponent : IComponent
{
private Transducer t { get; }
public TableComponent(Transducer tt)
{
t = tt;
}
public void Compose(IContainer container)
{
var headerStyle = TextStyle.Default.SemiBold();
container.Table(table =>
{
table.ColumnsDefinition(columns =>
{
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
});
table.Header(header =>
{
header.Cell().Text("Point #").Style(headerStyle);
header.Cell().AlignRight().Text("Master Value").Style(headerStyle);
header.Cell().AlignRight().Text("Low Limit").Style(headerStyle);
header.Cell().AlignRight().Text("High Limit").Style(headerStyle);
header.Cell().AlignRight().Text("DUT").Style(headerStyle);
header.Cell().AlignRight().Text("Delta").Style(headerStyle);
header.Cell().ColumnSpan(6).PaddingTop(5).BorderBottom(1).BorderColor(Colors.Black);
});
switch (t.TransducerType)
{
case "Flow":
{
foreach (var flow in t.InstrumentFlow)
{
var index = t.InstrumentFlow.IndexOf(flow) + 1;
var masterValue = t.MasterValue[t.InstrumentFlow.IndexOf(flow)];
if (flow.InRange)
{
StandardRow(table, index, masterValue, flow.Value, flow.Delta);
}
else
{
OutOfRangeRow(table, index, masterValue, flow.Value, flow.Delta);
}
}
break;
}
case "Pressure":
{
foreach (var pressure in t.InstrumentPressure)
{
var index = t.InstrumentPressure.IndexOf(pressure) + 1;
var masterValue = t.MasterValue[t.InstrumentPressure.IndexOf(pressure)];
if (pressure.InRange)
{
StandardRow(table, index, masterValue, pressure.Value, pressure.Delta);
}
else
{
OutOfRangeRow(table, index, masterValue, pressure.Value, pressure.Delta);
} }
break;
}
}
});
}
private void StandardRow(TableDescriptor table, int index, MasterValue masterValue, int value, int delta)
{
static IContainer CellStyle(IContainer container) => container
.BorderBottom(1)
.BorderColor(Colors.Transparent)
.PaddingVertical(5);
table.Cell().Element(CellStyle).Text($"{index}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.Value / 1000.0}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.LowLimit / 1000.0}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.HighLimit / 1000.0}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{value / 1000.0}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{delta / 1000.0}").FontSize(10);
}
private void OutOfRangeRow(TableDescriptor table, int index, MasterValue masterValue, int value, int delta)
{
static IContainer CellStyle(IContainer container) => container
.BorderBottom(1)
.BorderColor(Colors.Grey.Lighten3)
.Background(Colors.Grey.Lighten3)
.PaddingVertical(5);
table.Cell().Element(CellStyle).Text($"{index}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.Value / 1000.0}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.LowLimit / 1000.0}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.HighLimit / 1000.0}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{value / 1000.0}").FontSize(10);
table.Cell().Element(CellStyle).AlignRight().Text($"{delta / 1000.0}").FontSize(10);
}
}
}

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace BenchtopPDF
{
/// Sheet myDeserializedClass = JsonConvert.DeserializeObject<Sheet>(myJsonResponse);