private List <String> GetTemplateVariables(string selectedTemplate) { List <string> templateVariables = null; ZebraCardPrinter zebraCardPrinter = null; try { connection.Open(); zebraCardPrinter = ZebraCardPrinterFactory.GetInstance(connection); ZebraCardTemplate zebraCardTemplate = new ZebraCardTemplate(zebraCardPrinter); zebraCardTemplate.SetTemplateFileDirectory(Properties.Settings.Default.TemplateFileDirectory); templateVariables = zebraCardTemplate.GetTemplateFields(selectedTemplate + ".xml"); } catch (Exception error) { errorMessage = $"Connection Error: {error.Message}"; } finally { ConnectionHelper.CleanUpQuietly(zebraCardPrinter, connection); } return(templateVariables); }
private void PrintTemplate(string selectedTemplate) { ZebraCardPrinter zebraCardPrinter = null; try { int quantity = 0; Application.Current.Dispatcher.Invoke(() => { quantity = int.Parse(Quantity_ComboBox.Text); }); connection.Open(); zebraCardPrinter = ZebraCardPrinterFactory.GetInstance(connection); PrinterStatusInfo statusInfo = zebraCardPrinter.GetPrinterStatus(); if (statusInfo.ErrorInfo.Value > 0) { throw new ZebraCardException($"{statusInfo.Status} ({statusInfo.ErrorInfo.Description}). Please correct the issue and try again."); } else if (statusInfo.AlarmInfo.Value > 0) { throw new ZebraCardException($"{statusInfo.Status} ({statusInfo.AlarmInfo.Description}). Please correct the issue and try again."); } else { ZebraCardTemplate zebraCardTemplate = new ZebraCardTemplate(zebraCardPrinter); zebraCardTemplate.SetTemplateFileDirectory(Properties.Settings.Default.TemplateFileDirectory); zebraCardTemplate.SetTemplateImageDirectory(Properties.Settings.Default.TemplateImageDirectory); Dictionary <string, string> templateData = GetTemplateData(); TemplateJob templateJob = zebraCardTemplate.GenerateTemplateJob(selectedTemplate + ".xml", templateData); int jobId = zebraCardPrinter.PrintTemplate(quantity, templateJob); } } catch (Exception error) { MessageBoxHelper.ShowError(error.Message); } finally { ConnectionHelper.CleanUpQuietly(zebraCardPrinter, connection); } }