From 229734ef4697748b264524ec9471689b4291eda7 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 28 Jul 2023 01:02:22 -0400 Subject: [PATCH] parse data and put in table --- BenchtopPDF/BenchtopPDF/SheetDocument.cs | 155 +++++++++++++++++------ BenchtopPDF/BenchtopPDF/SheetModel.cs | 1 + 2 files changed, 115 insertions(+), 41 deletions(-) diff --git a/BenchtopPDF/BenchtopPDF/SheetDocument.cs b/BenchtopPDF/BenchtopPDF/SheetDocument.cs index f2bd226..17dc5b3 100644 --- a/BenchtopPDF/BenchtopPDF/SheetDocument.cs +++ b/BenchtopPDF/BenchtopPDF/SheetDocument.cs @@ -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); + } + + } } \ No newline at end of file diff --git a/BenchtopPDF/BenchtopPDF/SheetModel.cs b/BenchtopPDF/BenchtopPDF/SheetModel.cs index 36c87d6..c07e9ab 100644 --- a/BenchtopPDF/BenchtopPDF/SheetModel.cs +++ b/BenchtopPDF/BenchtopPDF/SheetModel.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using Newtonsoft.Json; + namespace BenchtopPDF { /// Sheet myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse);