private void UpdateSettingsTable() { Connection connection = null; try { connection = connectionSelector.GetConnection(); connection.Open(); ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection); ZebraPrinterLinkOs printer = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter); if (printer != null) { Dictionary <string, Sdk.Settings.Setting> settings = printer.GetAllSettings(); Application.Current.Dispatcher.Invoke(() => { if (settings != null) { foreach (string key in settings.Keys) { viewModel.Settings.Add(new Setting { Key = key, Value = settings[key].Value, Range = printer.GetSettingRange(key) }); } } else { MessageBoxCreator.ShowError("Error reading settings", "Settings Error"); } printerSettingsGrid.UnselectAll(); }); } else { MessageBoxCreator.ShowError("Connected printer does not support settings", "Connection Error"); } } catch (ConnectionException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (ZebraPrinterLanguageUnknownException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (SettingsException e) { MessageBoxCreator.ShowError(e.Message, "Settings Error"); } catch (Exception e) { MessageBoxCreator.ShowError(e.Message, "Save Settings Error"); } finally { SetButtonStates(true); try { if (connection != null) { connection.Close(); } } catch (ConnectionException) { } } }
private void UpdateSettingsTable(Connection connection, string printerLanguage) { ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(printer); Dictionary <string, Setting> settings = linkOsPrinter.GetAllSettings(); if (settings.ContainsKey(DeviceLanguagesSgd)) { settings[DeviceLanguagesSgd].Value = printerLanguage; } if (settings != null) { Device.BeginInvokeOnMainThread(() => { foreach (string key in settings.Keys) { Entry entry = new Entry { Text = settings[key].Value, }; entry.TextChanged += (object s, TextChangedEventArgs e) => { if (key != null) { if (modifiedSettings.ContainsKey(key)) { modifiedSettings[key] = e.NewTextValue; } else { modifiedSettings.Add(key, e.NewTextValue); } } }; SettingsTableSection.Add(new ViewCell { View = new StackLayout { Padding = new Thickness(15), HorizontalOptions = LayoutOptions.FillAndExpand, Children = { new Label { Text = key, FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)), FontAttributes = FontAttributes.Bold }, entry, new Label { Text = $"Type: {linkOsPrinter.GetSettingType(key)}, Range: {linkOsPrinter.GetSettingRange(key)}" } } } }); } }); } else { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert("Settings Error", "Error reading settings", "OK"); }); } }