private List <SavedFormat> GetSavedFormats() { List <SavedFormat> savedFormats = new List <SavedFormat>(); using (SavedFormatProvider provider = new SavedFormatProvider()) { savedFormats = provider.GetSavedFormats(); } return(savedFormats); }
private void OnDeleteFormat_Click(object sender, RoutedEventArgs e) { dynamic item = PrinterFormatsListView.SelectedItem; long formatId = long.Parse(item.FormatId); using (SavedFormatProvider provider = new SavedFormatProvider()) { provider.Delete(formatId); } RefreshFormats(); }
private void GetFormatVariables(object sender, DoWorkEventArgs e) { object[] parameters = e.Argument as object[]; dynamic selectedFormat = parameters[0] as dynamic; string lastFormatOpened = (string)parameters[1]; string lastFormatOpenedSource = (string)parameters[2]; string lastFormatOpenedContents = (string)parameters[3]; object[] results = new object[4]; long formatId = long.Parse(selectedFormat.FormatId); lastFormatOpened = selectedFormat.FormatDrive + selectedFormat.FormatName + selectedFormat.FormatExtension; lastFormatOpenedSource = selectedFormat.FormatSource; try { OpenConnection(); ZebraPrinterLinkOs printer = ZebraPrinterFactory.GetLinkOsPrinter(printerConnection); if (lastFormatOpenedSource.Equals("Sample") && formatId > 0) { using (SavedFormatProvider provider = new SavedFormatProvider()) { lastFormatOpenedContents = provider.GetFormatContents(formatId); } } else { byte[] formatInBytes = printer.RetrieveFormatFromPrinter(lastFormatOpened); lastFormatOpenedContents = Encoding.UTF8.GetString(formatInBytes); } fieldDescDataVars = printer.GetVariableFields(lastFormatOpenedContents).ToList(); fieldDescDataVars = FormatFieldDescriptionDataVars(fieldDescDataVars); formatVariableCollection = new ObservableCollection <FormatVariable>(); for (int i = 0; i < fieldDescDataVars.Count; ++i) { formatVariableCollection.Add(new FormatVariable { FieldName = fieldDescDataVars[i].FieldName, FieldValue = "" }); } results[0] = lastFormatOpened; results[1] = lastFormatOpenedSource; results[2] = lastFormatOpenedContents; results[3] = formatVariableCollection; e.Result = results; } catch (ConnectionException error) { errorMessage = "Connection Error: " + error.Message; } finally { CloseConnection(); } }
private void OnSaveFormat_Click(object sender, RoutedEventArgs e) { try { printerActionsWindow = new PrinterActionsWindow("Saving format...") { Owner = this }; dynamic selectedItem = PrinterFormatsListView.SelectedItem; string formatDrive = selectedItem.FormatDrive; string formatName = selectedItem.FormatName; string extension = selectedItem.FormatExtension; Task.Run(() => { try { string format = GetFormatFromPrinter(formatDrive + formatName + extension); format = AddFormatLocationToFormat(format, formatDrive + formatName + extension); using (SavedFormatProvider provider = new SavedFormatProvider()) { provider.Insert(formatName, extension, format); } } finally { Dispatcher.Invoke(new Action(() => { printerActionsWindow.Close(); })); } }); printerActionsWindow.ShowDialog(); RefreshFormats(); } catch (Exception ex) { if (printerActionsWindow != null) { printerActionsWindow.Close(); } ShowErrorDialogWindow($"Save format error: {ex.Message}"); } }