templates support

This commit is contained in:
EugeneTes
2026-01-21 15:56:37 +01:00
parent 729679d283
commit 9fbc61dede
60 changed files with 5678 additions and 14 deletions

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Inspectron.Epson.Templates\Inspectron.Epson.Templates.csproj" />
<ProjectReference Include="..\Inspectron.Epson\Inspectron.Epson.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="kitchen-u220.template">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,100 @@
using Inspectron.Epson;
using Inspectron.Epson.PrintServer.Printers.Utils;
using Inspectron.Epson.PrintServer.Printers.Utils.KitchenReceipt;
using Inspectron.Epson.Templates.Configuration;
using Inspectron.Epson.Templates.Interpreter;
using Inspectron.Epson.Templates.Language;
using System.Text.Json;
var receipt = new KitchenReceipt
{
Title = "Warme Küche",
TransactionDateTime = new DateTime(2025, 10, 23, 12, 18, 0),
ReceiptNumber = "132018166",
WaiterName = "Mariano Amato",
WaiterId = "32 (VK Restaurant)",
TableNumber = "22",
SpecialInstruction = "Next dish"
};
// Add dishes (this section can be empty if no dishes were ordered)
receipt.Gangs.Add(new Gang(2, "Gang"));
receipt.Gangs[0].Dishes.Add(new Dish(1, "Avocado Sashimi")
{
Modifications = new DishModifications
{
Removed = new List<string> { "Wasabi" },
Added = new List<string> { "Extra Ginger" }
},
Comment = "No soy sauce"
});
receipt.Gangs[0].Dishes.Add(new Dish(1, "Baby Spinach Salad with Truffl"));
receipt.Gangs[0].Dishes.Add(new Dish(1, "Beef Tataki")
{
Modifications = new DishModifications
{
Removed = new List<string> { "Onion" },
Added = new List<string> { "Extra Sauce" }
},
Comment = "Medium rare"
});
receipt.Gangs[0].Dishes.Add(new Dish(1, "Salmon Taco")
{
Modifications = new DishModifications
{
Added = new List<string> { "Extra Lime" }
}
});
// Add additional info
var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
var lexer = new Lexer(File.ReadAllText("kitchen-u220.template"));
var parser = new Parser(lexer.Tokenize().Tokens);
var template = parser.Parse().Template;
PrinterProfile _profileT30 = new("tm-t30iii", "TM-T30III", 48, 24, false);
PrinterProfile _profile220 = new("tm-220", "TM-220", 33, 18, true);
var interpreter = new TemplateInterpreter(_profile220);
var printCommands = interpreter.Interpret(template, serializedReceipt);
Console.WriteLine("=== PRINT COMMANDS ===\n");
var printer = new HtmlPrinter(@".\test.html", paperWidth: 258);
await printer.ConnectAsync("");
bool useDelay = false;
//var printer = new EpsonPrinter();
//await printer.ConnectAsync("127.0.0.1", 8888);
if (useDelay) await Task.Delay(200);
await printer.FeedLinesAsync(1);
//await printer.SetCustomLineSpacing(22);
foreach (var command in printCommands)
{
string attributes = "";
if (command.IsBig) attributes += "[BIG] ";
if (command.IsBold) attributes += "[BOLD] ";
if (command.IsRed) attributes += "[RED] ";
Console.WriteLine($"{attributes}{command.Text}");
await printer.SetBiggerFontTM220(command.IsBig, command.IsTall , secondaryFont: false);
if (useDelay) await Task.Delay(200);
await printer.SetRedColor(command.IsRed);
if (useDelay) await Task.Delay(200);
await printer.SetEmphasized(command.IsBold);
if (useDelay) await Task.Delay(200);
await printer.PrintTextAsync(command.Text + "\n");
if (useDelay) await Task.Delay(200);
}
await printer.FeedLinesAsync(5);
if (useDelay) await Task.Delay(200 * 5);
await printer.CutAsync();

View File

@@ -0,0 +1,57 @@
#red,big,center# {Title} #
---
#center# {TransactionDateTime:dd-MMM-yy HH:mm} Nr.:{ReceiptNumber} #
#center# {WaiterName} #
#center# {WaiterId} #
#big,bold,center# Tisch: {TableNumber} #
@if SpecialInstruction
#big,bold,center# {SpecialInstruction} #
@end
---
@foreach gang in Gangs
#red,big,center# {gang.Id}. {gang.Name} #
@foreach dish in gang.Dishes
#tall# {dish.Number}x {dish.Name} #
@if dish.Modifications.Removed.count > 0
@foreach removed in dish.Modifications.Removed
#bold,tall# - {removed} #
@end
@end
@if dish.Modifications.Added.count > 0
@foreach added in dish.Modifications.Added
#bold,tall# + {added} #
@end
@end
@if dish.Comment
#bold,tall# Comment: {dish.Comment} #
@end
@end
@end
@if Gangs.count > 0
---
@end
@foreach dish in Dishes
#tall# {dish.Number}x {dish.Name} #
@if dish.Modifications.Removed.count > 0
@foreach removed in dish.Modifications.Removed
#bold,tall# - {removed} #
@end
@end
@if dish.Modifications.Added.count > 0
@foreach added in dish.Modifications.Added
#bold,tall# + {added} #
@end
@end
@if dish.Comment
#bold,tall# Comment: {dish.Comment} #
@end
@end
@if Dishes.count > 0
---
@end