Add in C# Project

This commit is contained in:
Tyrel Souza 2023-07-27 14:37:01 -04:00
parent bac7d9ac9d
commit 0ccf9fb429
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
18 changed files with 593 additions and 24 deletions

2
.gitignore vendored
View File

@ -285,4 +285,4 @@ tags.temp
# End of https://www.toptal.com/developers/gitignore/api/tags,python,django
.idea

5
BenchtopPDF/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/

View File

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/.idea.BenchtopPDF.iml
/modules.xml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchtopPDF", "BenchtopPDF\BenchtopPDF.csproj", "{552E9774-67EF-461E-AECD-80130D33D891}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{552E9774-67EF-461E-AECD-80130D33D891}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{552E9774-67EF-461E-AECD-80130D33D891}.Debug|Any CPU.Build.0 = Debug|Any CPU
{552E9774-67EF-461E-AECD-80130D33D891}.Release|Any CPU.ActiveCfg = Release|Any CPU
{552E9774-67EF-461E-AECD-80130D33D891}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue">/usr/lib/mono/msbuild/15.0/bin/MSBuild.dll</s:String></wpf:ResourceDictionary>

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{552E9774-67EF-461E-AECD-80130D33D891}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BenchtopPDF</RootNamespace>
<AssemblyName>BenchtopPDF</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<LangVersion>default</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="HarfBuzzSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\HarfBuzzSharp.2.8.2.4-preview.89\lib\net462\HarfBuzzSharp.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="QuestPDF, Version=2023.6.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\QuestPDF.2023.6.1\lib\net462\QuestPDF.dll</HintPath>
</Reference>
<Reference Include="SkiaSharp, Version=2.88.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\SkiaSharp.2.88.4-preview.89\lib\net462\SkiaSharp.dll</HintPath>
</Reference>
<Reference Include="SkiaSharp.HarfBuzz, Version=2.88.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\SkiaSharp.HarfBuzz.2.88.3\lib\net462\SkiaSharp.HarfBuzz.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="SheetDocument.cs" />
<Compile Include="SheetModel.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="BenchTopLogo.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\SkiaSharp.NativeAssets.macOS.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.macOS.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.NativeAssets.macOS.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.macOS.targets'))" />
<Error Condition="!Exists('..\packages\SkiaSharp.NativeAssets.Win32.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.Win32.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.NativeAssets.Win32.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.Win32.targets'))" />
<Error Condition="!Exists('..\packages\SkiaSharp.NativeAssets.Linux.NoDependencies.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.Linux.NoDependencies.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.NativeAssets.Linux.NoDependencies.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.Linux.NoDependencies.targets'))" />
<Error Condition="!Exists('..\packages\HarfBuzzSharp.NativeAssets.macOS.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.macOS.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\HarfBuzzSharp.NativeAssets.macOS.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.macOS.targets'))" />
<Error Condition="!Exists('..\packages\HarfBuzzSharp.NativeAssets.Win32.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.Win32.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\HarfBuzzSharp.NativeAssets.Win32.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.Win32.targets'))" />
<Error Condition="!Exists('..\packages\HarfBuzzSharp.NativeAssets.Linux.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.Linux.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\HarfBuzzSharp.NativeAssets.Linux.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.Linux.targets'))" />
</Target>
<Import Project="..\packages\SkiaSharp.NativeAssets.macOS.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.macOS.targets" Condition="Exists('..\packages\SkiaSharp.NativeAssets.macOS.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.macOS.targets')" />
<Import Project="..\packages\SkiaSharp.NativeAssets.Win32.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.Win32.targets" Condition="Exists('..\packages\SkiaSharp.NativeAssets.Win32.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.Win32.targets')" />
<Import Project="..\packages\SkiaSharp.NativeAssets.Linux.NoDependencies.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.Linux.NoDependencies.targets" Condition="Exists('..\packages\SkiaSharp.NativeAssets.Linux.NoDependencies.2.88.4-preview.89\build\net462\SkiaSharp.NativeAssets.Linux.NoDependencies.targets')" />
<Import Project="..\packages\HarfBuzzSharp.NativeAssets.macOS.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.macOS.targets" Condition="Exists('..\packages\HarfBuzzSharp.NativeAssets.macOS.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.macOS.targets')" />
<Import Project="..\packages\HarfBuzzSharp.NativeAssets.Win32.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.Win32.targets" Condition="Exists('..\packages\HarfBuzzSharp.NativeAssets.Win32.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.Win32.targets')" />
<Import Project="..\packages\HarfBuzzSharp.NativeAssets.Linux.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.Linux.targets" Condition="Exists('..\packages\HarfBuzzSharp.NativeAssets.Linux.2.8.2.4-preview.89\build\net462\HarfBuzzSharp.NativeAssets.Linux.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,24 @@
using Newtonsoft.Json;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace BenchtopPDF
{
internal class Program
{
public static void Main(string[] args)
{
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 model = JsonConvert.DeserializeObject<Sheet>(data);
var document = new SheetDocument(model);
document.GeneratePdfAndShow();
}
}
}

View File

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BenchtopPDF")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BenchtopPDF")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("552E9774-67EF-461E-AECD-80130D33D891")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,170 @@
using System.Globalization;
using System.Linq;
using QuestPDF.Drawing;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace BenchtopPDF
{
public class SheetDocument : IDocument
{
public static Image LogoImage { get; } = Image.FromFile("BenchTopLogo.jpg");
public Sheet Model { get; }
public SheetDocument(Sheet model)
{
Model = model;
}
public DocumentMetadata GetMetadata() => DocumentMetadata.Default;
public DocumentSettings GetSettings()
{
return new DocumentSettings();
}
public void Compose(IDocumentContainer container)
{
container
.Page(page =>
{
page.Margin(50);
page.Header().Element(ComposeHeader);
page.Content().Element(ComposeContent);
page.Footer().AlignCenter().Text(text =>
{
text.CurrentPageNumber();
text.Span(" / ");
text.TotalPages();
});
});
}
void ComposeHeader(IContainer container)
{
container.Row(row =>
{
row.RelativeItem().Column(column =>
{
column
.Item().Text("Certificate Of Calibration")
.FontSize(20).SemiBold().FontColor(Colors.Blue.Medium);
column.Item().Text(text =>
{
text.Span("Issue date: ").SemiBold();
text.Span($"{Model.IssueDate:d}");
});
});
row.ConstantItem(175).Image(LogoImage);
});
}
void ComposeContent(IContainer container)
{
container.PaddingVertical(40).Column(column =>
{
column.Spacing(20);
column.Item().Row(row =>
{
row.RelativeItem().Component(new AddressComponent("From", Model.SellerAddress));
row.ConstantItem(50);
row.RelativeItem().Component(new AddressComponent("For", Model.CustomerAddress));
});
column.Item().Element(ComposeTable);
var totalPrice = Model.Items.Sum(x => x.Price * x.Quantity);
column.Item().PaddingRight(5).AlignRight().Text($"Grand total: {totalPrice:C}").SemiBold();
if (!string.IsNullOrWhiteSpace(Model.Comments))
column.Item().PaddingTop(25).Element(ComposeComments);
});
}
void ComposeTable(IContainer container)
{
var headerStyle = TextStyle.Default.SemiBold();
container.Table(table =>
{
table.ColumnsDefinition(columns =>
{
columns.ConstantColumn(25);
columns.RelativeColumn(3);
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
});
table.Header(header =>
{
header.Cell().Text("#");
header.Cell().Text("Product").Style(headerStyle);
header.Cell().AlignRight().Text("Unit price").Style(headerStyle);
header.Cell().AlignRight().Text("Quantity").Style(headerStyle);
header.Cell().AlignRight().Text("Total").Style(headerStyle);
header.Cell().ColumnSpan(5).PaddingTop(5).BorderBottom(1).BorderColor(Colors.Black);
});
foreach (var item in Model.Items)
{
var index = Model.Items.IndexOf(item) + 1;
table.Cell().Element(CellStyle).Text($"{index}");
table.Cell().Element(CellStyle).Text(item.Name);
table.Cell().Element(CellStyle).AlignRight().Text($"{item.Price:C}");
table.Cell().Element(CellStyle).AlignRight().Text($"{item.Quantity}");
table.Cell().Element(CellStyle).AlignRight().Text($"{item.Price * item.Quantity:C}");
static IContainer CellStyle(IContainer container) => container.BorderBottom(1).BorderColor(Colors.Grey.Lighten2).PaddingVertical(5);
}
});
}
void ComposeComments(IContainer container)
{
container.ShowEntire().Background(Colors.Grey.Lighten3).Padding(10).Column(column =>
{
column.Spacing(5);
column.Item().Text("Comments").FontSize(14).SemiBold();
column.Item().Text(Model.Comments);
});
}
}
public class AddressComponent : IComponent
{
private string Title { get; }
private Address Address { get; }
public AddressComponent(string title, Address address)
{
Title = title;
Address = address;
}
public void Compose(IContainer container)
{
container.ShowEntire().Column(column =>
{
column.Spacing(2);
column.Item().Text(Title).SemiBold();
column.Item().PaddingBottom(5).LineHorizontal(1);
column.Item().Text(Address.CompanyName);
column.Item().Text(Address.Street);
column.Item().Text($"{Address.City}, {Address.State}");
column.Item().Text(Address.Email);
column.Item().Text(Address.Phone);
});
}
}
}

View File

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace BenchtopPDF
{
/// Sheet myDeserializedClass = JsonConvert.DeserializeObject<Sheet>(myJsonResponse);
public class InstrumentFlow
{
public int Value { get; set; }
[JsonProperty("In Range")]
public bool InRange { get; set; }
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; }
public int Value { get; set; }
[JsonProperty("High Limit")]
public int HighLimit { get; set; }
}
public class Sheet
{
public string Instrument { get; set; }
[JsonProperty("Customer Name")]
public string CustomerName { get; set; }
[JsonProperty("Customer Address")]
public string CustomerAddress { get; set; }
[JsonProperty("Control Number")]
public string ControlNumber { get; set; }
[JsonProperty("Serial Number")]
public string SerialNumber { get; set; }
public double Accuracy { get; set; }
[JsonProperty("Barometric Pressure")]
public double BarometricPressure { get; set; }
public double Temperature { get; set; }
public int Humidity { get; set; }
public List<Transducer> Transducers { get; set; }
}
public class Transducer
{
public double Accuracy { get; set; }
[JsonProperty("Part Number")]
public string PartNumber { get; set; }
public string Value { get; set; }
[JsonProperty("Transducer Name")]
public string TransducerName { get; set; }
[JsonProperty("Transducer Type")]
public string TransducerType { get; set; }
[JsonProperty("Instrument Pressure")]
public List<InstrumentPressure> InstrumentPressure { get; set; }
[JsonProperty("Master Value")]
public List<MasterValue> MasterValue { get; set; }
[JsonProperty("Verify Date")]
public string VerifyDate { get; set; }
[JsonProperty("Verify Time")]
public string VerifyTime { get; set; }
[JsonProperty("Instrument Flow")]
public List<InstrumentFlow> InstrumentFlow { get; set; }
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="HarfBuzzSharp" version="2.8.2.4-preview.89" targetFramework="net48" />
<package id="HarfBuzzSharp.NativeAssets.Linux" version="2.8.2.4-preview.89" targetFramework="net48" />
<package id="HarfBuzzSharp.NativeAssets.Win32" version="2.8.2.4-preview.89" targetFramework="net48" />
<package id="HarfBuzzSharp.NativeAssets.macOS" version="2.8.2.4-preview.89" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
<package id="QuestPDF" version="2023.6.1" targetFramework="net48" />
<package id="SkiaSharp" version="2.88.4-preview.89" targetFramework="net48" />
<package id="SkiaSharp.HarfBuzz" version="2.88.3" targetFramework="net48" />
<package id="SkiaSharp.NativeAssets.Linux.NoDependencies" version="2.88.4-preview.89" targetFramework="net48" />
<package id="SkiaSharp.NativeAssets.Win32" version="2.88.4-preview.89" targetFramework="net48" />
<package id="SkiaSharp.NativeAssets.macOS" version="2.88.4-preview.89" targetFramework="net48" />
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
</packages>

27
README.md Normal file
View File

@ -0,0 +1,27 @@
# Benchtop Devices Project
Django app to parse data from Transducers and Hardware Calibration.
Returns a PDF and prints a label
## App Structure
```
├── benchtopdevices # Django Project
│   ├── benchtopdevices
│   └── sheets
└── BenchtopPDF # C# PDF Generator Project
   ├── BenchtopPDF
   └── packages
```
## TODO
- [x] Django app to take in data
- [x] Parse data
- [ ] Generate PDF
- [ ] Generate Label

View File

@ -1,7 +1,5 @@
from decimal import *
import re
import json
def in_range(index, value, master_values):
return (
@ -9,10 +7,12 @@ def in_range(index, value, master_values):
)
def parse_transducer(content, accuracy):
getcontext().prec = 6
def delta(index, value, master_values):
return abs(master_values[index]["Low Limit"] - value)
accuracy = Decimal(f"{accuracy/100.0}") # Comes in as Percent
def parse_transducer(content, accuracy):
accuracy = accuracy/100.0 # Comes in as Percent
transducer_data = []
# Split the content into sections based on the blank line
@ -50,7 +50,6 @@ def parse_transducer(content, accuracy):
"Value": value,
"Transducer Name": transducer_name,
"Transducer Type": transducer_type,
# "Setpoint Pressure": [],
"Instrument Pressure": [],
"Master Value": [],
"Instrument Flow": [],
@ -69,30 +68,30 @@ def parse_transducer(content, accuracy):
continue
# Toss anything else where it belongs
v = Decimal(value.split(" ")[0])
v = value.split(" ")[0]
key = re.match(r"(.*)\W(\d)", key)[1]
if key in transducer_info:
value = Decimal(value.split()[0])
value = int(float(value.split()[0])*1000)
# special case Master to get the limits
if "Master" in key:
hi = Decimal(Decimal(1.0) + accuracy)
lo = Decimal(Decimal(1.0) - accuracy)
hi = 1.0 + accuracy
lo = 1.0 - accuracy
transducer_info[key].append(
{
"Low Limit": lo,
"Value": value,
"High Limit": value * hi,
"Low Limit": int(value*lo),
"Master Value": value,
"High Limit": int(value * hi),
}
)
else:
transducer_info[key].append(value)
# Once we have the readings, and master values, we can do the math
transducer_info[f"Instrument {transducer_type}"] = [
{
"Value": v,
"In Range": in_range(idx, v, transducer_info["Master Value"]),
"Delta":"TODO"
"Delta": delta(idx, v, transducer_info["Master Value"])
}
for idx, v in enumerate(transducer_info[f"Instrument {transducer_type}"])
]
@ -108,9 +107,18 @@ def parse_transducer(content, accuracy):
if __name__ == "__main__":
from pprint import pprint
file_path = "./transducer_verify.txt"
with open(file_path, "r") as file:
content = file.read()
parsed_data = parse_transducer(content, 0.5)
pprint(parsed_data)
output = {
"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": parse_transducer(file.read(), 0.5)
}
print(json.dumps(output))

View File

@ -13,9 +13,35 @@
<form action="." method="post" enctype="multipart/form-data">
{% csrf_token %}
<table>
{{ form.as_p }}
<tdata>
<tr><td>Customer Name</td><td>{{ form.customer_name }}</td></tr>
<tr><td>Customer Address</td><td>{{ form.customer_address }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<tr><td>Instrument</td><td>{{ form.instrument }}</td></tr>
<tr><td>Control Number</td><td>{{ form.control_number }}</td></tr>
<tr><td>Serial Number</td><td>{{ form.serial_number }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<tr><td>Accuracy</td><td>{{ form.accuracy }}</td></tr>
<tr><td>Barometric Pressure (mbar)</td><td>{{ form.barometric_pressure }}</td></tr>
<tr><td>Temperature (&deg;F)</td><td>{{ form.temperature }}</td></tr>
<tr><td>Humidity</td><td>{{ form.humidity }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<tr><td>Report Type</td><td>{{ form.report_type }}</td></tr>
<tr><td>Configuration(s)</td><td>{{ form.configuration }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<tr><td>As Found: {{ form.as_found }}</td><td>As Left:{{ form.as_left }}</td></tr>
<tr><td colspan=2>One File: {{ form.both }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<tr><td>&nbsp;</td><td align="right"><input type="submit" value="Generate PDF and Label"></td></tr>
</tdata>
</table>
<input type="submit" value="Submit">
</form>
</div>
@ -91,4 +117,6 @@
}
}).mount("#app")
</script>
{% endverbatim %}
{% endverbatim %}
</body>
</html>