diff --git a/BenchtopPDF/BenchtopPDF/Program.cs b/BenchtopPDF/BenchtopPDF/Program.cs index 7b1cf21..d12e631 100644 --- a/BenchtopPDF/BenchtopPDF/Program.cs +++ b/BenchtopPDF/BenchtopPDF/Program.cs @@ -13,7 +13,9 @@ namespace BenchtopPDF { QuestPDF.Settings.License = LicenseType.Community; // TODO get json from file - var data = "{\"Instrument\": \"CTS0JODFDASH\", \"Customer Name\": \"Anthony Souza\", \"Customer Address\": \"PO Box 357, West Chesterfield, NH 03466\", \"Control Number\": \"123123\", \"Serial Number\": \"123313\", \"Accuracy\": 0.5, \"Barometric Pressure\": 1013.25, \"Temperature\": 50.3, \"Humidity\": 27, \"Transducers\": [{\"Accuracy\": 0.005, \"Part Number\": \"D34-442\", \"Value\": \"115PSIA\", \"Transducer Name\": \"1\", \"Transducer Type\": \"Pressure\", \"Instrument Pressure\": [{\"Value\": 0, \"In Range\": true, \"Delta\": 0}, {\"Value\": 20002, \"In Range\": true, \"Delta\": 102}, {\"Value\": 39997, \"In Range\": true, \"Delta\": 197}, {\"Value\": 60010, \"In Range\": true, \"Delta\": 310}, {\"Value\": 80001, \"In Range\": true, \"Delta\": 401}, {\"Value\": 100002, \"In Range\": true, \"Delta\": 502}], \"Master Value\": [{\"Low Limit\": 0, \"Master Value\": 0, \"High Limit\": 0}, {\"Low Limit\": 19900, \"Master Value\": 20000, \"High Limit\": 20099}, {\"Low Limit\": 39800, \"Master Value\": 40000, \"High Limit\": 40199}, {\"Low Limit\": 59700, \"Master Value\": 60000, \"High Limit\": 60299}, {\"Low Limit\": 79600, \"Master Value\": 80000, \"High Limit\": 80399}, {\"Low Limit\": 99500, \"Master Value\": 100000, \"High Limit\": 100499}], \"Verify Date\": \"07/20/22\", \"Verify Time\": \"11:20:26\"}, {\"Accuracy\": 0.005, \"Part Number\": \"A12-221\", \"Value\": \"250SCCM\", \"Transducer Name\": \"2\", \"Transducer Type\": \"Flow\", \"Master Value\": [{\"Low Limit\": 0, \"Master Value\": 0, \"High Limit\": 0}, {\"Low Limit\": 24875, \"Master Value\": 25000, \"High Limit\": 25124}, {\"Low Limit\": 49750, \"Master Value\": 50000, \"High Limit\": 50249}, {\"Low Limit\": 74625, \"Master Value\": 75000, \"High Limit\": 75374}, {\"Low Limit\": 99500, \"Master Value\": 100000, \"High Limit\": 100499}, {\"Low Limit\": 124375, \"Master Value\": 125000, \"High Limit\": 125624}, {\"Low Limit\": 149250, \"Master Value\": 150000, \"High Limit\": 150749}, {\"Low Limit\": 174125, \"Master Value\": 175000, \"High Limit\": 175874}, {\"Low Limit\": 199000, \"Master Value\": 200000, \"High Limit\": 200999}, {\"Low Limit\": 223875, \"Master Value\": 225000, \"High Limit\": 226124}, {\"Low Limit\": 248750, \"Master Value\": 250000, \"High Limit\": 251249}], \"Instrument Flow\": [{\"Value\": -82, \"In Range\": false, \"Delta\": 82}, {\"Value\": 24802, \"In Range\": false, \"Delta\": 73}, {\"Value\": 49664, \"In Range\": false, \"Delta\": 86}, {\"Value\": 74836, \"In Range\": true, \"Delta\": 211}, {\"Value\": 99416, \"In Range\": false, \"Delta\": 84}, {\"Value\": 125289, \"In Range\": true, \"Delta\": 914}, {\"Value\": 150205, \"In Range\": true, \"Delta\": 955}, {\"Value\": 175290, \"In Range\": true, \"Delta\": 1165}, {\"Value\": 200165, \"In Range\": true, \"Delta\": 1165}, {\"Value\": 224748, \"In Range\": true, \"Delta\": 873}, {\"Value\": 249825, \"In Range\": true, \"Delta\": 1075}], \"Verify Date\": \"07/15/21\", \"Verify Time\": \"14:55:10\"}]}"; + var data = + @"{""Instrument"": ""CTS0JODFDASH"", ""Customer Name"": ""Anthony Souza"", ""Customer Address"": ""PO Box 357, West Chesterfield, NH 03466"", ""Control Number"": ""123123"", ""Serial Number"": ""123313"", ""Accuracy"": 0.5, ""Barometric Pressure"": 1013.25, ""Temperature"": 50.3, ""Humidity"": 27, ""Transducers"": [{""Accuracy"": 0.005, ""Part Number"": ""D34-442"", ""Value"": 115, ""Unit"": ""PSIA"", ""Limit ABS"": 575, ""Transducer Name"": ""1"", ""Transducer Type"": ""Pressure"", ""Gauge Reading"": [{""Value"": 0, ""In Range"": true, ""Delta"": 575}, {""Value"": 20002, ""In Range"": true, ""Delta"": 577}, {""Value"": 39997, ""In Range"": true, ""Delta"": 572}, {""Value"": 60010, ""In Range"": true, ""Delta"": 585}, {""Value"": 80001, ""In Range"": true, ""Delta"": 576}, {""Value"": 100002, ""In Range"": true, ""Delta"": 577}], ""Master Value"": [{""Low Limit"": -575, ""Master Value"": 0, ""High Limit"": 575}, {""Low Limit"": 19425, ""Master Value"": 20000, ""High Limit"": 20575}, {""Low Limit"": 39425, ""Master Value"": 40000, ""High Limit"": 40575}, {""Low Limit"": 59425, ""Master Value"": 60000, ""High Limit"": 60575}, {""Low Limit"": 79425, ""Master Value"": 80000, ""High Limit"": 80575}, {""Low Limit"": 99425, ""Master Value"": 100000, ""High Limit"": 100575}], ""Verify Date"": ""07/20/22"", ""Verify Time"": ""11:20:26""}, {""Accuracy"": 0.005, ""Part Number"": ""A12-221"", ""Value"": 250, ""Unit"": ""SCCM"", ""Limit ABS"": 1250, ""Transducer Name"": ""2"", ""Transducer Type"": ""Flow"", ""Gauge Reading"": [{""Value"": -82, ""In Range"": true, ""Delta"": 1168}, {""Value"": 24802, ""In Range"": true, ""Delta"": 1052}, {""Value"": 49664, ""In Range"": true, ""Delta"": 914}, {""Value"": 74836, ""In Range"": true, ""Delta"": 1086}, {""Value"": 99416, ""In Range"": true, ""Delta"": 666}, {""Value"": 125289, ""In Range"": true, ""Delta"": 1539}, {""Value"": 150205, ""In Range"": true, ""Delta"": 1455}, {""Value"": 175290, ""In Range"": true, ""Delta"": 1540}, {""Value"": 200165, ""In Range"": true, ""Delta"": 1415}, {""Value"": 224748, ""In Range"": true, ""Delta"": 998}, {""Value"": 249825, ""In Range"": true, ""Delta"": 1075}], ""Master Value"": [{""Low Limit"": -1250, ""Master Value"": 0, ""High Limit"": 1250}, {""Low Limit"": 23750, ""Master Value"": 25000, ""High Limit"": 26250}, {""Low Limit"": 48750, ""Master Value"": 50000, ""High Limit"": 51250}, {""Low Limit"": 73750, ""Master Value"": 75000, ""High Limit"": 76250}, {""Low Limit"": 98750, ""Master Value"": 100000, ""High Limit"": 101250}, {""Low Limit"": 123750, ""Master Value"": 125000, ""High Limit"": 126250}, {""Low Limit"": 148750, ""Master Value"": 150000, ""High Limit"": 151250}, {""Low Limit"": 173750, ""Master Value"": 175000, ""High Limit"": 176250}, {""Low Limit"": 198750, ""Master Value"": 200000, ""High Limit"": 201250}, {""Low Limit"": 223750, ""Master Value"": 225000, ""High Limit"": 226250}, {""Low Limit"": 248750, ""Master Value"": 250000, ""High Limit"": 251250}], ""Verify Date"": ""07/15/21"", ""Verify Time"": ""14:55:10""}]} +"; var model = JsonConvert.DeserializeObject(data); var document = new SheetDocument(model); diff --git a/BenchtopPDF/BenchtopPDF/SheetDocument.cs b/BenchtopPDF/BenchtopPDF/SheetDocument.cs index 17dc5b3..717bc4a 100644 --- a/BenchtopPDF/BenchtopPDF/SheetDocument.cs +++ b/BenchtopPDF/BenchtopPDF/SheetDocument.cs @@ -36,9 +36,7 @@ namespace BenchtopPDF page.Footer().AlignCenter().Text(text => { - text.CurrentPageNumber(); - text.Span(" / "); - text.TotalPages(); + text.Span(" Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eget ligula vehicula, efficitur massa vitae, ullamcorper ligula. Nulla at varius nunc. Quisque nec scelerisque velit. Vestibulum accumsan, lacus vitae auctor commodo, elit elit posuere mauris, vel mollis risus risus ut nibh. Phasellus risus velit, tincidunt eu molestie et, maximus ut velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Etiam eu arcu vel metus iaculis maximus at in purus. Proin diam eros, sodales vel faucibus ut, varius id metus. Donec sed ipsum a mauris varius fringilla. Nulla a nulla quis tellus finibus vehicula."); }); }); } @@ -138,7 +136,9 @@ namespace BenchtopPDF public void Compose(IContainer container) { var headerStyle = TextStyle.Default.SemiBold(); - container.Table(table => + container + .DefaultTextStyle(x => x.FontSize(10)) + .Table(table => { table.ColumnsDefinition(columns => { @@ -152,54 +152,30 @@ namespace BenchtopPDF table.Header(header => { - header.Cell().Text("Point #").Style(headerStyle); + header.Cell().ColumnSpan(6).PaddingBottom(0).BorderBottom(1) + .BorderColor(Colors.Black).AlignCenter().Text($"Data (IN {t.Unit})"); + + header.Cell().AlignCenter().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("High Limit").Style(headerStyle); header.Cell().AlignRight().Text("Delta").Style(headerStyle); - header.Cell().ColumnSpan(6).PaddingTop(5).BorderBottom(1).BorderColor(Colors.Black); }); - - switch (t.TransducerType) + + foreach (var i in t.GaugeReading) { - case "Flow": + var index = t.GaugeReading.IndexOf(i) + 1; + var masterValue = t.MasterValue[t.GaugeReading.IndexOf(i)]; + + if (i.InRange) { - 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; + StandardRow(table, index, masterValue, i.Value, i.Delta); } - case "Pressure": + else { - 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; + OutOfRangeRow(table, index, masterValue, i.Value, i.Delta); } } }); @@ -208,32 +184,34 @@ namespace BenchtopPDF private void StandardRow(TableDescriptor table, int index, MasterValue masterValue, int value, int delta) { static IContainer CellStyle(IContainer container) => container + .DefaultTextStyle(x => x.FontSize(8)) .BorderBottom(1) - .BorderColor(Colors.Transparent) - .PaddingVertical(5); + .BorderColor(Colors.Grey.Medium) + .PaddingVertical(2); - 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); + table.Cell().Element(CellStyle).AlignCenter().Text($"{index}"); + table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.Value / 1000.0:F3}"); + table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.LowLimit / 1000.0:F3}"); + table.Cell().Element(CellStyle).AlignRight().Text($"{value / 1000.0:F3}"); + table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.HighLimit / 1000.0:F3}"); + table.Cell().Element(CellStyle).AlignRight().Text($"{delta / 1000.0:F3}"); } private void OutOfRangeRow(TableDescriptor table, int index, MasterValue masterValue, int value, int delta) { static IContainer CellStyle(IContainer container) => container + .DefaultTextStyle(x => x.FontSize(8)) .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); + table.Cell().Element(CellStyle).AlignCenter().Text($"{index}").FontSize(10); + table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.Value / 1000.0:F3}").FontSize(10); + table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.LowLimit / 1000.0:F3}").FontSize(10); + table.Cell().Element(CellStyle).AlignRight().Text($"{value / 1000.0:F3}").FontSize(10).FontColor(Colors.Red.Medium); + table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.HighLimit / 1000.0:F3}").FontSize(10); + table.Cell().Element(CellStyle).AlignRight().Text($"{delta / 1000.0:F3}").FontSize(10); } } diff --git a/BenchtopPDF/BenchtopPDF/SheetModel.cs b/BenchtopPDF/BenchtopPDF/SheetModel.cs index c07e9ab..7fd120a 100644 --- a/BenchtopPDF/BenchtopPDF/SheetModel.cs +++ b/BenchtopPDF/BenchtopPDF/SheetModel.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json; namespace BenchtopPDF { /// Sheet myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); - public class InstrumentFlow + public class GaugeReading { public int Value { get; set; } @@ -15,19 +15,13 @@ namespace BenchtopPDF public int Delta { get; set; } } - public class InstrumentPressure - { - public int Value { get; set; } - - [JsonProperty("In Range")] - public bool InRange { get; set; } - public int Delta { get; set; } - } public class MasterValue { [JsonProperty("Low Limit")] public int LowLimit { get; set; } + + [JsonProperty("Master Value")] public int Value { get; set; } [JsonProperty("High Limit")] @@ -64,7 +58,13 @@ namespace BenchtopPDF [JsonProperty("Part Number")] public string PartNumber { get; set; } - public string Value { get; set; } + + public int Value { get; set; } + + public string Unit { get; set; } + + [JsonProperty("Limit ABS")] + public int LimitABS { get; set; } [JsonProperty("Transducer Name")] public string TransducerName { get; set; } @@ -72,8 +72,8 @@ namespace BenchtopPDF [JsonProperty("Transducer Type")] public string TransducerType { get; set; } - [JsonProperty("Instrument Pressure")] - public List InstrumentPressure { get; set; } + [JsonProperty("Gauge Reading")] + public List GaugeReading { get; set; } [JsonProperty("Master Value")] public List MasterValue { get; set; } @@ -84,8 +84,6 @@ namespace BenchtopPDF [JsonProperty("Verify Time")] public string VerifyTime { get; set; } - [JsonProperty("Instrument Flow")] - public List InstrumentFlow { get; set; } }