Method to get printers and printers for receipt

Method to get printers and printers for receipt

Song Nghia - Technical Consultant

private ReadOnlyCollection GetPrinters(RequestContext context, string hardwareProfileId, ReceiptType receiptType)
{
 Terminal terminal = context.GetTerminal();
 if (string.IsNullOrEmpty(hardwareProfileId))
 {
  hardwareProfileId = terminal.HardwareProfile;
 }

 GetPrintersDataRequest getPrintersByReceiptTypeDataRequest = new GetPrintersDataRequest(terminal.TerminalId, receiptType, QueryResultSettings.AllRecords, hardwareProfileId);
 IEnumerable printers = context.Execute>(getPrintersByReceiptTypeDataRequest).PagedEntityCollection.Results;
 Printer printer = printers.FirstOrDefault(p => p.PrinterType == (int)DeviceType.WindowsPrinter);

 return new List() { printer }.AsReadOnly();
}

private ReadOnlyCollection GetPrinterForHardcodeReceipt(RequestContext context, string hardwareProfileId, ReceiptType receiptType)
{
 Terminal terminal = context.GetTerminal();
 if (string.IsNullOrEmpty(hardwareProfileId))
  hardwareProfileId = terminal.HardwareProfile;
 GetHardwareProfileDataRequest profileDataRequest = new GetHardwareProfileDataRequest(hardwareProfileId, QueryResultSettings.SingleRecord);
 HardwareProfile entity = context.Runtime.Execute>((Request)profileDataRequest, context).Entity;
 if (entity != null && entity.Printers != null && entity.Printers.Any())
 {
  HardwareProfilePrinter hardwareProfilePrinter = entity.Printers.FirstOrDefault((Func)(printer => (uint)printer.DeviceType > 0U));
  if (hardwareProfilePrinter != null)
   return new List()
 {
  new Printer()
  {
    ReceiptType = receiptType,
    PrintBehavior = PrintBehavior.Always,
    Terminal = terminal == null ? 0L : terminal.RecordId,
    HardwareProfileId = hardwareProfileId,
    Name = hardwareProfilePrinter.DeviceName,
    PrinterType = (int) hardwareProfilePrinter.DeviceType
  }
 }.AsReadOnly();
 }
 return new List().AsReadOnly();
}
Previous Post
Next Post

post written by: