Skip to content

Commit

Permalink
Use structured addresses in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed Jun 1, 2024
1 parent 217dceb commit 32bafdb
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Examples/Basic/Basic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AssemblyName>Codecrete.SwissQRBill.Examples.Basic</AssemblyName>
<RootNamespace>Codecrete.SwissQRBill.Examples.Basic</RootNamespace>
<Company>Codecrete</Company>
Expand Down
22 changes: 13 additions & 9 deletions Examples/Basic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ class Program
static void Main()
{
// Setup bill data
Bill bill = new Bill
var bill = new Bill
{
// creditor data
Account = "CH4431999123000889012",
Creditor = new Address
{
Name = "Robert Schneider AG",
AddressLine1 = "Rue du Lac 1268/2/22",
AddressLine2 = "2501 Biel",
Street = "Rue du Lac",
HouseNo = "1268/2/22",
PostalCode = "2501",
Town = "Biel",
CountryCode = "CH"
},

Expand All @@ -46,8 +48,10 @@ static void Main()
Debtor = new Address
{
Name = "Pia-Maria Rutschmann-Schnyder",
AddressLine1 = "Grosse Marktgasse 28",
AddressLine2 = "9400 Rorschach",
Street = "Grosse Marktgasse",
HouseNo = "28",
PostalCode = "9400",
Town = "Rorschach",
CountryCode = "CH"
},

Expand All @@ -65,19 +69,19 @@ static void Main()
};

// Generate QR bill as SVG
byte[] svg = QRBill.Generate(bill);
var svg = QRBill.Generate(bill);

// Save generated SVG file
const string path = "qrbill.svg";
var path = "qrbill.svg";
File.WriteAllBytes(path, svg);
Console.WriteLine($"SVG QR bill saved at { Path.GetFullPath(path) }");

// Generate QR bill as PNG
bill.Format.GraphicsFormat = GraphicsFormat.PNG;
byte[] png = QRBill.Generate(bill);
var png = QRBill.Generate(bill);

// Save generated PNG file
const string pngPath = "qrbill.png";
var pngPath = "qrbill.png";
File.WriteAllBytes(pngPath, png);
Console.WriteLine($"PNG QR bill saved at { Path.GetFullPath(pngPath) }");
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/MicrosoftWordAddIn/MicrosoftWordAddIn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<OutputPath>bin\Debug\</OutputPath>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
<DefineConstants>$(DefineConstants);DEBUG;TRACE</DefineConstants>
<WarningLevel>4</WarningLevel>
<WarningLevel>0</WarningLevel>
</PropertyGroup>
<!--
This section defines properties that are set when the "Release" configuration is selected.
Expand Down
22 changes: 9 additions & 13 deletions Examples/MicrosoftWordAddIn/ThisAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
// https://opensource.org/licenses/MIT
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;
using Codecrete.SwissQRBill.Generator;
using Codecrete.SwissQRBill.Windows;
using System.IO;
Expand Down Expand Up @@ -40,8 +32,10 @@ public void InsertQrBill()
Creditor = new Address
{
Name = "Robert Schneider AG",
AddressLine1 = "Rue du Lac 1268/2/22",
AddressLine2 = "2501 Biel",
Street = "Rue du Lac",
HouseNo = "1268/2/22",
PostalCode = "2501",
Town = "Biel",
CountryCode = "CH"
},

Expand All @@ -53,8 +47,10 @@ public void InsertQrBill()
Debtor = new Address
{
Name = "Pia-Maria Rutschmann-Schnyder",
AddressLine1 = "Grosse Marktgasse 28",
AddressLine2 = "9400 Rorschach",
Street = "Grosse Marktgasse",
HouseNo = "28",
PostalCode = "9400",
Town = "Rorschach",
CountryCode = "CH"
},

Expand All @@ -72,7 +68,7 @@ public void InsertQrBill()
};

// create EMF file
var path = Path.GetTempFileName();
var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
using (MetafileCanvas canvas = new MetafileCanvas(210, 110, "Arial"))
{
QRBill.Draw(bill, canvas);
Expand Down
3 changes: 2 additions & 1 deletion Examples/PDFsharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ static void Main()
Creditor = new Address
{
Name = "Seemannschaft Rapperswil",
AddressLine2 = "8640 Rapperswil",
PostalCode = "8640",
Town = "Rapperswil",
CountryCode = "CH"
},

Expand Down
14 changes: 8 additions & 6 deletions Examples/WinUI/WinUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public MainWindow()
Creditor = new Address
{
Name = "Robert Schneider AG",
AddressLine1 = "Rue du Lac 1268/2/22",
AddressLine2 = "2501 Biel",
Street = "Rue du Lac",
HouseNo = "1268/2/22",
PostalCode = "2501",
Town = "Biel",
CountryCode = "CH"
},

Expand All @@ -51,8 +53,10 @@ public MainWindow()
Debtor = new Address
{
Name = "Pia-Maria Rutschmann-Schnyder",
AddressLine1 = "Grosse Marktgasse 28",
AddressLine2 = "9400 Rorschach",
Street = "Grosse Marktgasse",
HouseNo = "28",
PostalCode = "9400",
Town = "Rorschach",
CountryCode = "CH"
},

Expand Down Expand Up @@ -95,14 +99,12 @@ private async void OnPrintClicked(object sender, RoutedEventArgs e)
printDocument.Preview += OnPreview;
printDocument.Print += OnPrint;

// var printManager = PrintManager.GetForCurrentView();
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
var printManager = PrintManagerInterop.GetForWindow(hWnd);

printManager.PrintTaskRequested += OnPrintTaskRequested;
try
{
// await PrintManager.ShowPrintUIAsync();
await PrintManagerInterop.ShowPrintUIForWindowAsync(hWnd);
}
finally
Expand Down
2 changes: 1 addition & 1 deletion Examples/WinUI/WinUI/WinUI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Codecrete.SwissQRBill.Examples.WinUI</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand Down
12 changes: 8 additions & 4 deletions Examples/WindowsForms/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public Form1()
Creditor = new Address
{
Name = "Robert Schneider AG",
AddressLine1 = "Rue du Lac 1268/2/22",
AddressLine2 = "2501 Biel",
Street = "Rue du Lac",
HouseNo = "1268/2/22",
PostalCode = "2501",
Town = "Biel",
CountryCode = "CH"
},

Expand All @@ -44,8 +46,10 @@ public Form1()
Debtor = new Address
{
Name = "Pia-Maria Rutschmann-Schnyder",
AddressLine1 = "Grosse Marktgasse 28",
AddressLine2 = "9400 Rorschach",
Street = "Grosse Marktgasse",
HouseNo = "28",
PostalCode = "9400",
Town = "Rorschach",
CountryCode = "CH"
},

Expand Down
5 changes: 3 additions & 2 deletions Examples/WindowsForms/QrBillControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public QrBillControl()
Creditor = new Address
{
Name = "Croce Rossa Svizzera - Sezione del Sottoceneri",
AddressLine1 = "Via alla Campagna",
AddressLine2 = "6900 Lugano",
Street = "Via alla Campagna",
PostalCode = "6900",
Town = "Lugano",
CountryCode = "CH"
},

Expand Down
4 changes: 2 additions & 2 deletions Examples/WindowsForms/WindowsForms.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0-windows7.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<RootNamespace>Codecrete.SwissQRBill.Examples.WindowsForms</RootNamespace>
</PropertyGroup>
Expand Down
12 changes: 8 additions & 4 deletions Examples/WindowsPresentationFoundation/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public MainWindow()
Creditor = new Address
{
Name = "Robert Schneider AG",
AddressLine1 = "Rue du Lac 1268/2/22",
AddressLine2 = "2501 Biel",
Street = "Rue du Lac",
HouseNo = "1268/2/22",
PostalCode = "2501",
Town = "Biel",
CountryCode = "CH"
},

Expand All @@ -42,8 +44,10 @@ public MainWindow()
Debtor = new Address
{
Name = "Pia-Maria Rutschmann-Schnyder",
AddressLine1 = "Grosse Marktgasse 28",
AddressLine2 = "9400 Rorschach",
Street = "Grosse Marktgasse",
HouseNo = "28",
PostalCode = "9400",
Town = "Rorschach",
CountryCode = "CH"
},

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0-windows7.0</TargetFramework>
<UseWPF>true</UseWPF>
<RootNamespace>Codecrete.SwissQRBill.Examples.Wpf</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand Down
26 changes: 15 additions & 11 deletions Examples/iText/iText/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ internal class Program
{
private static void Main(string[] args)
{
Bill bill = CreateBillData();
var bill = CreateBillData();

// Add QR bill to a copy of an existing PDF file
string destPath = "invoice-with-qr-bill.pdf";
using (FileStream fs = new FileStream(destPath, FileMode.Create))
using (IText7Canvas canvas = new IText7Canvas(OpenPdfInvoice("invoice-without-qr-bill.pdf"), fs, IText7Canvas.LastPage))
using (var fs = new FileStream(destPath, FileMode.Create))
using (var canvas = new IText7Canvas(OpenPdfInvoice("invoice-without-qr-bill.pdf"), fs, IText7Canvas.LastPage))
{
QRBill.Draw(bill, canvas);
}
Expand All @@ -38,7 +38,7 @@ private static void Main(string[] args)
// Generate QR bill in new file
string path = "qrbill.pdf";
bill.Format.SeparatorType = SeparatorType.DottedLineWithScissors;
using (IText7Canvas canvas = new IText7Canvas(path, 210, 297))
using (var canvas = new IText7Canvas(path, 210, 297))
{
QRBill.Draw(bill, canvas);
}
Expand All @@ -48,7 +48,7 @@ private static void Main(string[] args)

private static Bill CreateBillData()
{
Bill bill = new Bill
var bill = new Bill
{
Format = new BillFormat
{
Expand All @@ -59,17 +59,21 @@ private static Bill CreateBillData()
Creditor = new Address
{
Name = "Omnia Trading AG",
AddressLine1 = "Allmendweg 30",
AddressLine2 = "4528 Zuchwil",
Street = "Allmendweg",
HouseNo = "30",
PostalCode = "4528",
Town = "Zuchwil",
CountryCode = "CH"
},
Amount = 1756.05m,
Currency = "CHF",
Debtor = new Address
{
Name = "Machina Futura AG",
AddressLine1 = "Alte Fabrik 3A",
AddressLine2 = "8400 Winterthur",
Street = "Alte Fabrik",
HouseNo = "3A",
PostalCode = "8400",
Town = "Winterthur",
CountryCode = "CH"
},
UnstructuredMessage = "Auftrag 2830188 / Rechnung 2021007834"
Expand All @@ -81,8 +85,8 @@ private static Bill CreateBillData()

private static Stream OpenPdfInvoice(string filename)
{
Assembly assembly = Assembly.GetExecutingAssembly();
Stream resourceStream = assembly.GetManifestResourceStream(typeof(Program), $"PdfFile.{filename}");
var assembly = Assembly.GetExecutingAssembly();
var resourceStream = assembly.GetManifestResourceStream(typeof(Program), $"PdfFile.{filename}");
if (resourceStream == null)
{
throw new FileNotFoundException($"Resource not found: PdfFile.{filename}");
Expand Down
2 changes: 1 addition & 1 deletion Examples/iText/iText/iText.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AssemblyName>Codecrete.SwissQRBill.Examples.IText7</AssemblyName>
<RootNamespace>Codecrete.SwissQRBill.Examples.IText7</RootNamespace>
<Authors>Manuel Bleichenbacher</Authors>
Expand Down

0 comments on commit 32bafdb

Please sign in to comment.