private TemplateJob CreateTemplateJob() { Dictionary <string, string> fieldDataMap = new Dictionary <string, string>(); foreach (TemplateVariable templateVariable in viewModel.VariableData) { if (!string.IsNullOrEmpty(templateVariable.Value)) { fieldDataMap.Add(templateVariable.Variable, templateVariable.Value); } } string templateName = Path.GetFileNameWithoutExtension(viewModel.TemplateFilename); return(zebraCardTemplate.GenerateTemplateJob(templateName, fieldDataMap)); }
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); } }