Initial commit
Initial commit til Git. V2 er deployed
This commit is contained in:
136
PointOfSale/Pos.Ui/EpsonPrinter/Services/EpsonPrintService.cs
Normal file
136
PointOfSale/Pos.Ui/EpsonPrinter/Services/EpsonPrintService.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using EpsonPrinter.Model;
|
||||
using ESCPOS_NET;
|
||||
using ESCPOS_NET.Emitters;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EpsonPrinter.Services
|
||||
{
|
||||
public class EpsonPrintService
|
||||
{
|
||||
private readonly SerialPrinter _serialPrinter;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public EpsonPrintService(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
string comPort = _config["PrintSettings:ComPort"];
|
||||
int baudRate = Convert.ToInt32(_config["PrintSettings:BaudRate"]);
|
||||
_serialPrinter = new SerialPrinter(comPort,baudRate);
|
||||
|
||||
}
|
||||
|
||||
private void PrintReceipt(ReceiptModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void PrintSaleOfDay(SaleOfDayModel model)
|
||||
{
|
||||
ICommandEmitter e = new EPSON();
|
||||
Init(e);
|
||||
PrintSaleOfDay(model,e);
|
||||
}
|
||||
|
||||
private void Init(ICommandEmitter e)
|
||||
{
|
||||
_serialPrinter.Write(e.Initialize());
|
||||
_serialPrinter.Write(e.Enable());
|
||||
_serialPrinter.Write(e.CodePage(CodePage.ISO8859_15_LATIN9));
|
||||
_serialPrinter.Write(e.EnableAutomaticStatusBack());
|
||||
}
|
||||
|
||||
//private void PrintReceipt(ReceiptModel model, ICommandEmitter e)
|
||||
//{
|
||||
// List<byte[][]> printBytes = new List<byte[][]>();
|
||||
// PrintHeader printHeader = new PrintHeader(e);
|
||||
// printBytes.AddRange(printHeader.Print(model.Header));
|
||||
|
||||
// PrintBody printBody = new PrintBody(e,_config);
|
||||
// printBytes.AddRange(printBody.Print(model.BodyModel));
|
||||
|
||||
// PrintFooter printFooter = new PrintFooter(e);
|
||||
// printBytes.AddRange(printFooter.Print(model.Footer));
|
||||
|
||||
// //And at last, print
|
||||
// byte[][] array = printBytes.SelectMany(c => c).ToArray();
|
||||
|
||||
// _serialPrinter.Write(array);
|
||||
// _serialPrinter.Write(e.FeedLines(5));
|
||||
// _serialPrinter.Write(e.FullCut());
|
||||
|
||||
//}
|
||||
private void PrintSaleOfDay(SaleOfDayModel model, ICommandEmitter e)
|
||||
{
|
||||
List<byte[][]> data = new List<byte[][]>();
|
||||
|
||||
int printWidth = Convert.ToInt32(_config["PrintSettings:PrintWidth"])-8;
|
||||
PrintString printString = new PrintString();
|
||||
|
||||
byte[][] dateBytes =
|
||||
{
|
||||
e.SetStyles(PrintStyle.DoubleWidth),
|
||||
e.LeftAlign(),
|
||||
e.PrintLine($"Dato: {model.Date:dd-MM-yyyy}")
|
||||
};
|
||||
data.Add(dateBytes);
|
||||
|
||||
byte[][] seperater =
|
||||
{
|
||||
e.SetStyles(PrintStyle.None),
|
||||
e.LeftAlign(),
|
||||
e.PrintLine($"-----------------------------------")
|
||||
};
|
||||
data.Add(seperater);
|
||||
|
||||
|
||||
foreach (SaleOfDayDetail saleOfDayDetail in model.SaleOfDayDetail)
|
||||
{
|
||||
//string pS = printString.MakePrintString(printWidth, saleOfDayDetail.Category, saleOfDayDetail.TotalSale.ToString(CultureInfo.InvariantCulture));
|
||||
string pS = $"{saleOfDayDetail.Category} : {saleOfDayDetail.TotalSale.ToString("#.#0")}";
|
||||
byte[][] totalPrice =
|
||||
{
|
||||
e.SetStyles(PrintStyle.DoubleWidth),
|
||||
e.LeftAlign(),
|
||||
e.PrintLine(pS)
|
||||
};
|
||||
data.Add(totalPrice);
|
||||
}
|
||||
|
||||
data.Add(seperater);
|
||||
|
||||
//string totalSale = printString.MakePrintString(printWidth, "Salg", model.TotalSale.ToString(CultureInfo.InvariantCulture));
|
||||
string totalSale = $"Total salg: {model.TotalSale.ToString("#.#0")}";
|
||||
byte[][] tSBytes =
|
||||
{
|
||||
e.SetStyles(PrintStyle.DoubleWidth),
|
||||
e.LeftAlign(),
|
||||
e.PrintLine(totalSale)
|
||||
};
|
||||
data.Add(tSBytes);
|
||||
|
||||
//string totalCustomer = printString.MakePrintString(printWidth, "Kunder", model.TotalCustomers.ToString());
|
||||
string totalCustomer = $"Antal kunder: {model.TotalCustomers}";
|
||||
byte[][] tCBytes =
|
||||
{
|
||||
e.SetStyles(PrintStyle.DoubleWidth),
|
||||
e.LeftAlign(),
|
||||
e.PrintLine(totalCustomer)
|
||||
};
|
||||
data.Add(tCBytes);
|
||||
|
||||
byte[][] array = data.SelectMany(c => c).ToArray();
|
||||
_serialPrinter.Write(array);
|
||||
_serialPrinter.Write(e.FeedLines(5));
|
||||
_serialPrinter.Write(e.FullCut());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
24
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintAlignment.cs
Normal file
24
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintAlignment.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using EpsonPrinter.Enums;
|
||||
using ESCPOS_NET.Emitters;
|
||||
|
||||
namespace EpsonPrinter.Services
|
||||
{
|
||||
public class PrintAlignment
|
||||
{
|
||||
public byte[] GetTextAlignment(ICommandEmitter e, AlignmentEnum alignment)
|
||||
{
|
||||
if (alignment == AlignmentEnum.Left)
|
||||
return e.LeftAlign();
|
||||
|
||||
if (alignment == AlignmentEnum.Right)
|
||||
return e.RightAlign();
|
||||
|
||||
return e.CenterAlign();
|
||||
}
|
||||
}
|
||||
}
|
||||
117
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintBody.cs
Normal file
117
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintBody.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using EpsonPrinter.Model;
|
||||
using ESCPOS_NET.Emitters;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace EpsonPrinter.Services
|
||||
{
|
||||
public class PrintBody
|
||||
{
|
||||
private ICommandEmitter _e;
|
||||
private IConfiguration _config;
|
||||
|
||||
private int productMaxWidth;
|
||||
|
||||
public PrintBody(ICommandEmitter e, IConfiguration config)
|
||||
{
|
||||
_e = e;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public List<byte[][]> Print(BodyModel model)
|
||||
{
|
||||
List<byte[][]> data = new List<byte[][]>();
|
||||
|
||||
byte[][] headerModel =
|
||||
{
|
||||
_e.SetStyles(PrintStyle.None),
|
||||
_e.LeftAlign(),
|
||||
_e.PrintLine($"Dato.........: {model.ReceiptTime}"),
|
||||
_e.PrintLine($"Ekspedient...: {model.Staff}"),
|
||||
_e.PrintLine($"Kvittering...: {model.ReceiptNumber}"),
|
||||
_e.FeedLines(1)
|
||||
};
|
||||
data.Add(headerModel);
|
||||
|
||||
int printWidth = Convert.ToInt32(_config["PrintSettings:PrintWidth"]);
|
||||
foreach (BodyProductModel product in model.Products)
|
||||
{
|
||||
//Size of product is max half of recipt
|
||||
string totalProductLine = MakeProductNameString(product.Product, printWidth);
|
||||
totalProductLine += MakeProductNumber(product.NoOfProduct, product.Price);
|
||||
totalProductLine = MakeTotalProductPrice(totalProductLine, product.TotalPrice,printWidth);
|
||||
|
||||
byte[][] p =
|
||||
{
|
||||
_e.PrintLine(totalProductLine)
|
||||
};
|
||||
data.Add(p);
|
||||
}
|
||||
|
||||
PrintString printString = new PrintString();
|
||||
string totalPricePrint = printString.MakePrintString(printWidth, $"Total: ", $"{model.TotalPrice:F} DKK");
|
||||
byte[][] totalPrice =
|
||||
{
|
||||
_e.FeedLines(1),
|
||||
_e.SetStyles(PrintStyle.Bold | PrintStyle.DoubleHeight),
|
||||
_e.RightAlign(),
|
||||
_e.PrintLine(totalPricePrint)
|
||||
};
|
||||
data.Add(totalPrice);
|
||||
|
||||
byte[][] vat =
|
||||
{
|
||||
_e.FeedLines(1),
|
||||
_e.SetStyles(PrintStyle.None),
|
||||
_e.LeftAlign(),
|
||||
_e.PrintLine(MakeVat(printWidth,model.TotalVat))
|
||||
};
|
||||
data.Add(vat);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private string MakeProductNameString(string product, int totalWidth)
|
||||
{
|
||||
string productString = product;
|
||||
productMaxWidth = (totalWidth / 2) - 5;
|
||||
int productLength = product.Length;
|
||||
if (productLength < productMaxWidth)
|
||||
{
|
||||
|
||||
for (int i = productLength; i < productMaxWidth; i++)
|
||||
{
|
||||
productString += ".";
|
||||
}
|
||||
}
|
||||
|
||||
return productString;
|
||||
}
|
||||
|
||||
private string MakeProductNumber(int noOfProduct, decimal price)
|
||||
{
|
||||
return $"{noOfProduct} á {price:F} DKK :";
|
||||
}
|
||||
|
||||
private string MakeTotalProductPrice(string buffer, decimal totalPrice, int printWidth)
|
||||
{
|
||||
PrintString printString = new PrintString();
|
||||
string p = $"{totalPrice:F} DKK";
|
||||
string makePrintString = printString.MakePrintString(printWidth, buffer, p);
|
||||
return makePrintString;
|
||||
}
|
||||
|
||||
private string MakeVat(int printWidth, decimal vat)
|
||||
{
|
||||
PrintString printString = new PrintString();
|
||||
string vatDesc = $"Moms udgør 25% :";
|
||||
string v = $"{vat:F} DKK";
|
||||
string vatString = printString.MakePrintString(printWidth, vatDesc, v);
|
||||
return vatString;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintFooter.cs
Normal file
47
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintFooter.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using EpsonPrinter.Model;
|
||||
using ESCPOS_NET;
|
||||
using ESCPOS_NET.Emitters;
|
||||
|
||||
namespace EpsonPrinter.Services
|
||||
{
|
||||
public class PrintFooter
|
||||
{
|
||||
private ICommandEmitter _e;
|
||||
|
||||
public PrintFooter(ICommandEmitter e)
|
||||
{
|
||||
_e = e;
|
||||
}
|
||||
|
||||
public List<byte[][]> Print(List<FooterModel> model)
|
||||
{
|
||||
List<byte[][]> data = new List<byte[][]>();
|
||||
PrintStyleCombination printStyleCombination = new PrintStyleCombination();
|
||||
PrintAlignment printAlignment = new PrintAlignment();
|
||||
byte[][] feedLines =
|
||||
{
|
||||
_e.FeedLines(1)
|
||||
};
|
||||
data.Add(feedLines);
|
||||
foreach (FooterModel footerModel in model)
|
||||
{
|
||||
|
||||
PrintStyle printStyle = printStyleCombination.Combine(footerModel.PrintStyles);
|
||||
byte[][] bytes = {
|
||||
_e.SetStyles(PrintStyle.None),
|
||||
printAlignment.GetTextAlignment(_e,footerModel.TextAlignment),
|
||||
_e.SetStyles(printStyle),
|
||||
_e.PrintLine(footerModel.Value),
|
||||
_e.FeedLines(footerModel.FeedingLines)
|
||||
};
|
||||
data.Add(bytes);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintHeader.cs
Normal file
47
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintHeader.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using EpsonPrinter.Model;
|
||||
using ESCPOS_NET;
|
||||
using ESCPOS_NET.Emitters;
|
||||
using ESCPOS_NET.Utilities;
|
||||
|
||||
namespace EpsonPrinter.Services
|
||||
{
|
||||
public class PrintHeader
|
||||
{
|
||||
private ICommandEmitter _e;
|
||||
|
||||
public PrintHeader(ICommandEmitter e)
|
||||
{
|
||||
_e = e;
|
||||
}
|
||||
|
||||
public List<Byte[][]> Print(List<HeaderModel> model)
|
||||
{
|
||||
List<byte[][]> data = new List<byte[][]>();
|
||||
PrintStyleCombination printStyleCombination = new PrintStyleCombination();
|
||||
PrintAlignment printAlignment = new PrintAlignment();
|
||||
foreach (HeaderModel headerModel in model)
|
||||
{
|
||||
|
||||
PrintStyle printStyle = printStyleCombination.Combine(headerModel.PrintStyles);
|
||||
byte[][] bytes = {
|
||||
_e.SetStyles(PrintStyle.None),
|
||||
printAlignment.GetTextAlignment(_e,headerModel.TextAlignment),
|
||||
_e.SetStyles(printStyle),
|
||||
_e.PrintLine(headerModel.Value),
|
||||
_e.FeedLines(headerModel.FeedingLines)
|
||||
};
|
||||
data.Add(bytes);
|
||||
}
|
||||
byte[][] feedLines =
|
||||
{
|
||||
_e.FeedLines(1)
|
||||
};
|
||||
data.Add(feedLines);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintString.cs
Normal file
44
PointOfSale/Pos.Ui/EpsonPrinter/Services/PrintString.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EpsonPrinter.Services
|
||||
{
|
||||
public class PrintString
|
||||
{
|
||||
/// <summary>
|
||||
/// An appropriate interval is converted into the length of
|
||||
/// the tab about two texts. And make a printing data.
|
||||
/// </summary>
|
||||
/// <param name="iLineChars">
|
||||
/// The width of the territory which it prints on is converted into the number of
|
||||
/// characters, and that value is specified.
|
||||
/// </param>
|
||||
/// <param name="strBuf">
|
||||
/// It is necessary as an information for deciding the interval of the text.
|
||||
/// </param>
|
||||
/// <param name="strPrice">
|
||||
/// It is necessary as an information for deciding the interval of the text, too.
|
||||
/// </param>
|
||||
/// <returns>printing data.
|
||||
/// </returns>
|
||||
public String MakePrintString(int iLineChars, String strBuf, String strPrice)
|
||||
{
|
||||
int iSpaces = 0;
|
||||
String tab = "";
|
||||
try
|
||||
{
|
||||
iSpaces = iLineChars - (strBuf.Length + strPrice.Length);
|
||||
for (int j = 0; j < iSpaces; j++)
|
||||
{
|
||||
tab += " ";
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return strBuf + tab + strPrice;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using EpsonPrinter.Enums;
|
||||
using EpsonPrinter.Model;
|
||||
using ESCPOS_NET.Emitters;
|
||||
|
||||
namespace EpsonPrinter.Services
|
||||
{
|
||||
public class PrintStyleCombination
|
||||
{
|
||||
public PrintStyle Combine(PrintStyleModel printStyleModel)
|
||||
{
|
||||
|
||||
//Bold
|
||||
if (printStyleModel.Bold && !printStyleModel.DoubleHeight && !printStyleModel.DoubleWidth && !printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.Bold;
|
||||
|
||||
if (printStyleModel.Bold && printStyleModel.DoubleHeight && !printStyleModel.DoubleWidth && !printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.Bold | PrintStyle.DoubleHeight;
|
||||
|
||||
if(printStyleModel.Bold && printStyleModel.DoubleHeight && printStyleModel.DoubleWidth && !printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.Bold | PrintStyle.DoubleHeight | PrintStyle.DoubleWidth;
|
||||
|
||||
if (printStyleModel.Bold && printStyleModel.DoubleHeight && printStyleModel.DoubleWidth && printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.Bold | PrintStyle.DoubleHeight | PrintStyle.DoubleWidth | PrintStyle.FontB;
|
||||
|
||||
if (printStyleModel.Bold && printStyleModel.DoubleHeight && printStyleModel.DoubleWidth && printStyleModel.FontB && printStyleModel.Underline)
|
||||
return PrintStyle.Bold | PrintStyle.DoubleHeight | PrintStyle.DoubleWidth | PrintStyle.FontB | PrintStyle.Underline;
|
||||
|
||||
//DoubleHeight
|
||||
if (printStyleModel.DoubleHeight && !printStyleModel.DoubleWidth && !printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.DoubleHeight;
|
||||
|
||||
if (printStyleModel.DoubleHeight && printStyleModel.DoubleWidth && !printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.DoubleHeight | PrintStyle.DoubleWidth;
|
||||
|
||||
if (printStyleModel.DoubleHeight && printStyleModel.DoubleWidth && printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.DoubleHeight | PrintStyle.DoubleWidth | PrintStyle.FontB;
|
||||
|
||||
if (printStyleModel.DoubleHeight && printStyleModel.DoubleWidth && printStyleModel.FontB && printStyleModel.Underline)
|
||||
return PrintStyle.DoubleHeight | PrintStyle.DoubleWidth | PrintStyle.FontB | PrintStyle.Underline;
|
||||
|
||||
//DoubleWidth
|
||||
if (printStyleModel.DoubleWidth && !printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.DoubleWidth;
|
||||
|
||||
if (printStyleModel.DoubleWidth && printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.DoubleWidth | PrintStyle.FontB;
|
||||
|
||||
if (printStyleModel.DoubleWidth && printStyleModel.FontB && printStyleModel.Underline)
|
||||
return PrintStyle.DoubleWidth | PrintStyle.FontB | PrintStyle.Underline;
|
||||
|
||||
//FontB
|
||||
if (printStyleModel.FontB && !printStyleModel.Underline)
|
||||
return PrintStyle.FontB;
|
||||
|
||||
if(printStyleModel.FontB && printStyleModel.Underline)
|
||||
return PrintStyle.FontB | PrintStyle.Underline;
|
||||
|
||||
//Underline
|
||||
if (printStyleModel.Underline)
|
||||
return PrintStyle.Underline;
|
||||
|
||||
return PrintStyle.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user