Closed Eduardomendesc closed 2 weeks ago
Hey @Eduardomendesc, of course you can! ByteSplicer is just a helper method, you don't need it to print anything!
the Printer.Write() method (or in your case Printer.WriteAsync()) intakes a byte[]
parameter, or even any amount of byte[]
parameters you wish to send to it!
So, you can just have a byte[]
variable that stores what you wish to print. You go through your ForEach, appending every byte into the variable, and lastly you call the Write method passing the variable as a parameter.
However if you really want to go the LINQ route, perhaps you would like to use Select() instead of ForEach(), something like this
/* .
.
.
*/
e.SetStyles(PrintStyle.FontB),
ByteSplicer.Combine(venda.VendaProdutos.Select(vendasPrd =>
{
ByteSplicer.Combine(
e.PrintLine(vendasPrd.Produto.Product_name),
e.PrintLine(vendasPrd.Qtd + " * " + vendasPrd.Preco_unitario + " " + vendasPrd.Total),
e.PrintLine("------------------------------------------------")
);
})),
e.RightAlign(),
/* .
.
.
*/
WARNING: I haven't tested this code, just trying to show you the concept idea.
I want to print, so I don't want to use the ByteSplicer.Combine method because I have a dynamic foreach in the product list. Is there any way to print without using ByteSplicer.Combine?
My code below:
public async Task Print(int IDVenda)
{
var hostnameOrIp = "180.22.2.37";
var port = 9100;
var printer = new ImmediateNetworkPrinter(new ImmediateNetworkPrinterSettings() { ConnectionString = $"{hostnameOrIp}:{port}", PrinterName = "TestPrinter" });
var response = false;
var e = new EPSON();
try
{
Venda venda = await dbfitaz.Vendas.FindAsync(IDVenda);
if (venda == null)
{
return Json(new { success = false, message = "Sales Not Found" }, JsonRequestBehavior.AllowGet);
}
}