/// <summary> /// Prints to printer. /// </summary> /// <param name="printerMap">The printer map.</param> /// <param name="formMod">The form mod.</param> /// <param name="formType">Type of the form.</param> /// <param name="posTransaction">The pos transaction.</param> /// <param name="copyReceipt">if set to <c>true</c> [copy receipt].</param> /// <returns></returns> internal static bool PrintFormTransaction( PrinterAssociation printerMap, FormModulation formMod, FormType formType, IPosTransaction posTransaction, bool copyReceipt) { FormInfo formInfo = printerMap.PrinterFormInfo; bool result = false; // Checking for header only. if (formInfo.HeaderTemplate == null) { // Note: This is allowed now that we have multiple printers... result = false; } else if (PrintingActions.ShouldWePrint(formInfo, formType, copyReceipt, printerMap)) { result = true; try { formMod.GetTransformedTransaction(formInfo, (RetailTransaction)posTransaction); if (formInfo.PrintAsSlip) { printerMap.Printer.PrintSlip(formInfo.Header, formInfo.Details, formInfo.Footer); } else { // Note: In this API Errors are handled in the printer and exceptions do not bubble up. printerMap.Printer.PrintReceipt(formInfo.Header + formInfo.Details + formInfo.Footer); } } catch (Exception ex) { NetTracer.Warning("Printing [Printing] - Exception while printing receipt"); POSFormsManager.ShowPOSErrorDialog(new PosisException(1003, ex)); result = false; } } return(result); }
/// <summary> /// Print form layout with specified content. /// </summary> /// <param name="formMod">Form modulation.</param> /// <param name="formInfo">Form info.</param> /// <param name="formType">Form type.</param> /// <param name="copyReceipt">Flag to identify if this is a copy.</param> /// <param name="getPrintTextHandler">Handler that is called to construct text for printing.</param> private static void PrintFormLayout( PrinterAssociation printerMap, FormModulation formMod, FormType formType, bool copyReceipt, bool formInfoTemplateRequired, GetTextHandler getPrintTextHandler) { FormInfo formInfo = printerMap.PrinterFormInfo; // Checking if formType requires template. if (formInfoTemplateRequired && (formInfo.HeaderTemplate == null)) { // 13038: Could not print the receipt because the receipt format could not be found. Printing.InternalApplication.Services.Dialog.ShowMessage(13038, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (PrintingActions.ShouldWePrint(formInfo, formType, copyReceipt, printerMap)) { try { string textToPrint = getPrintTextHandler(formMod, formInfo); if (formInfo.PrintAsSlip) { printerMap.Printer.PrintSlip(textToPrint); } else { printerMap.Printer.PrintReceipt(textToPrint); } } catch (Exception ex) { NetTracer.Warning("Printing [Print] - Exception while printing receipt"); POSFormsManager.ShowPOSErrorDialog(new PosisException(1003, ex)); } } }
/// <summary> /// Gets the printer identifier. /// </summary> /// <param name="printerAssociation">The printer association.</param> /// <returns>a printer identifier string</returns> private static string GetPrinterIdentifier(PrinterAssociation printerAssociation) { string result; if ((printerAssociation != null) && (printerAssociation.Printer != null)) { result = printerAssociation.Printer.DeviceDescription; if (string.IsNullOrWhiteSpace(result)) { // Fallback to device name if no description provided result = printerAssociation.Printer.DeviceName; if (string.IsNullOrWhiteSpace(result)) { // Fallback to "printer" if no device description or name is provided. result = ApplicationLocalizer.Language.Translate(10080); // "Unidentified printer" } } } else { // Fallback to "printer" if no device description or name is provided. result = ApplicationLocalizer.Language.Translate(10080); // "Unidentified printer" } return(result); }
/// <summary> /// Checks if the application should ask whether to print out the respective form and then asks the question. /// Returns true if it should not as the question. /// Returns the users choice if it should ask the question. /// </summary> /// <param name="formInfo">The form info.</param> /// <param name="formType">Type of the form.</param> /// <param name="copyReceipt">if set to <c>true</c> [copy receipt].</param> /// <param name="printerAssociation">The printer association.</param> /// <returns></returns> private static bool ShouldWePrint(FormInfo formInfo, FormType formType, bool copyReceipt, PrinterAssociation printerAssociation) { bool retval = true; string printerIdentifier = GetPrinterIdentifier(printerAssociation); // If this is a copy, then we always print everything without asking. if (copyReceipt) { NetTracer.Information("Printing::ShouldWePrint: This is a copy. We always print everything without asking."); return(retval); } if (formInfo.PrintBehaviour == (int)PrintBehaviour.PromptUser) { string formatMsg = string.Format( ApplicationLocalizer.Language.Translate(10081), // {0} \n Printer: {1} ApplicationLocalizer.Language.Translate(GetPromptTextId(formType)), // e.g. Do you want to print a receipt? printerIdentifier); DialogResult dialogResult = Printing.InternalApplication.Services.Dialog.ShowMessage( formatMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { retval = false; } } else if (formInfo.PrintBehaviour == (int)PrintBehaviour.DoNotPrint) { retval = false; } return(retval); }