using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Controls.Primitives; using Avalonia.Platform.Storage; using Logof_Client.Wiki; namespace Logof_Client; public partial class MainWindow : Window { public static MainWindow _instance; private Country _selectedCountry; private string _selectedWikiFilePath; private bool _suppressCountryRefresh; private WikiService _wikiService; public Uri filePath; public MainWindow() { InitializeComponent(); //Hide(); var s = new StartupWindow(); //s.Show(); _instance = this; WindowState = WindowState.Maximized; Global.Load(); Settings.Load(); LoadPdfExportOptions(); HookPdfExportOptionEvents(); RefreshCountryView(); // Initialize wiki integration _wikiService = new WikiService(); try { PopulateNavTree(); NavTree.SelectionChanged += NavTree_SelectionChanged; OpenFolderButton.Click += OpenFolderButton_Click; EditButton.Click += EditButton_Click; // populate wiki settings UI if present try { if (!string.IsNullOrWhiteSpace(Global._instance.wiki_storage_path)) TbWikiPath.Text = Global._instance.wiki_storage_path; } catch { } try { BtnWikiPath.Click += BtnWikiPath_Click; BtnFontPath.Click += BtnFontPath_Click; BtnConfigPath.Click += BtnConfigPath_Click; } catch { } } catch { } //Thread.Sleep(3000); //Show(); } private async void StartAddressCheck(int addresSetID) { //var addresses = DataImport.ImportKasAddressList(path); // Ihr Code hier var progressWindow = new ProgressWindow(); progressWindow.Show(_instance); var processor = new AddressCheck(progressWindow); var result = await processor.Perform(addresSetID); // foreach (var item in result) // { // } progressWindow.Close(); new ResultWindow(result, addresSetID).Show(); Settings.Save(); //await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig"); } private async void StartAddressShortener(KasAddressList set) { //var addresses = DataImport.ImportKasAddressList(path); // Ihr Code hier var progressWindow = new ProgressWindow(); progressWindow.Show(_instance); var processor = new AddressShortener(progressWindow); await processor.Perform(set); // foreach (var item in result) // { // } progressWindow.Close(); Settings.Save(); //await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig"); } // private async void StartAddressRepair(Uri path) // { // var addresses = DataImport.ImportKasAddressList(path); // Ihr Code hier // var progressWindow = new ProgressWindow(); // // progressWindow.Show(_instance); // // var processor = new AddressRepair(progressWindow); // //var result = await processor.Perform(addresses.Item2, errors); // // // progressWindow.Close(); // // // //new ResultWindow(result, addresses.Item2).Show(); // //await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig"); // } private void MnuExit_OnClick(object? sender, RoutedEventArgs e) { Environment.Exit(0); } private void MnuAbout_OnClick(object? sender, RoutedEventArgs e) { try { Process.Start(new ProcessStartInfo { FileName = "https://mypapercloud.de/logof/", UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen }); } catch (Exception ex) { Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}"); } } private void MnuHelp_OnClick(object? sender, RoutedEventArgs e) { try { Process.Start(new ProcessStartInfo { FileName = "https://mypapercloud.de/logof/wiki/", UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen }); } catch (Exception ex) { Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}"); } } private void MnuGit_OnClick(object? sender, RoutedEventArgs e) { try { Process.Start(new ProcessStartInfo { FileName = "https://git.mypapercloud.de/fierke/logofclient", UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen }); } catch (Exception ex) { Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}"); } } private void BtnCheck_OnClick(object? sender, RoutedEventArgs e) { MakeCalcManVisible(); if (LstCustomerAdressSets.SelectedIndex == -1) { MessageBox.Show(null, "Bitte zunächst ein Adress-Set auswählen", "Kein Adress-Set ausgewählt"); return; } StartAddressCheck(((KasAddressList)LstCustomerAdressSets.SelectedItem).ID); } private void BtnCombine_OnClick(object? sender, RoutedEventArgs e) { GrdCalcMan.IsVisible = false; GrdCombineTypes.IsVisible = true; GrdExportMarginOptions.IsVisible = false; } private void MakeCalcManVisible() { GrdCalcMan.IsVisible = true; GrdCombineTypes.IsVisible = false; GrdExportMarginOptions.IsVisible = false; } private async void NavTree_SelectionChanged(object? sender, SelectionChangedEventArgs e) { if (NavTree.SelectedItem is TreeViewItem t && t.Tag is WikiItem item && !item.IsFolder) { _selectedWikiFilePath = item.Path; var text = await _wikiService.LoadFileContentAsync(item.Path); try { PreviewPanel.Children.Clear(); var rendered = MarkdownRenderer.Render(text ?? string.Empty); PreviewPanel.Children.Add(rendered); } catch { // fallback: plain text PreviewPanel.Children.Clear(); PreviewPanel.Children.Add(new TextBlock { Text = text ?? string.Empty }); } EditButton.IsEnabled = true; } else { _selectedWikiFilePath = null; EditButton.IsEnabled = false; } } public void PopulateNavTree(string? expandToPath = null, string? selectPath = null) { var roots = _wikiService.GetRootItems(); var nodes = new List(); foreach (var r in roots) nodes.Add(BuildNode(r)); NavTree.ItemsSource = nodes; if (!string.IsNullOrWhiteSpace(expandToPath)) ExpandAndFindNode(nodes, expandToPath, out _); if (!string.IsNullOrWhiteSpace(selectPath) && ExpandAndFindNode(nodes, selectPath, out var selectedNode) && selectedNode != null) NavTree.SelectedItem = selectedNode; } private TreeViewItem BuildNode(WikiItem item) { var node = new TreeViewItem { Header = item.Name, Tag = item }; if (item.IsFolder) foreach (var c in item.Children) node.Items.Add(BuildNode(c)); return node; } private string GetSelectedWikiTargetDirectory() { var wikiRoot = Global._instance.wiki_storage_path; if (NavTree.SelectedItem is TreeViewItem treeItem && treeItem.Tag is WikiItem selectedItem) { if (selectedItem.IsFolder) return selectedItem.Path; var parentDir = Path.GetDirectoryName(selectedItem.Path); if (!string.IsNullOrWhiteSpace(parentDir)) return parentDir; } return wikiRoot; } private static bool PathsEqual(string left, string right) { var normalizedLeft = Path.GetFullPath(left) .TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); var normalizedRight = Path.GetFullPath(right) .TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); var comparison = OperatingSystem.IsWindows() ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; return string.Equals(normalizedLeft, normalizedRight, comparison); } private bool ExpandAndFindNode(IEnumerable nodes, string targetPath, out TreeViewItem? foundNode) { foreach (var node in nodes) if (TryExpandToPath(node, targetPath, out foundNode)) return true; foundNode = null; return false; } private bool TryExpandToPath(TreeViewItem node, string targetPath, out TreeViewItem? foundNode) { if (node.Tag is WikiItem item && PathsEqual(item.Path, targetPath)) { foundNode = node; return true; } foreach (var childRaw in node.Items) if (childRaw is TreeViewItem childNode && TryExpandToPath(childNode, targetPath, out foundNode)) { node.IsExpanded = true; return true; } foundNode = null; return false; } private void OpenFolderButton_Click(object? sender, RoutedEventArgs e) { var path = Global._instance.wiki_storage_path; if (!Directory.Exists(path)) return; try { Process.Start(new ProcessStartInfo { FileName = path, UseShellExecute = true }); } catch { } } private async void BtnWikiPath_Click(object? sender, RoutedEventArgs e) { var top = GetTopLevel(this); var folder = await top.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions { Title = "Wiki Pfad wählen", AllowMultiple = false }); if (folder == null || folder.Count == 0) return; var chosen = folder[0].Path; TbWikiPath.Text = chosen.ToString(); Global._instance.wiki_storage_path = chosen.ToString(); Global.Save(); // reinit wiki service and reload tree _wikiService = new WikiService(); PopulateNavTree(); } private async void BtnFontPath_Click(object? sender, RoutedEventArgs e) { var top = GetTopLevel(this); var folder = await top.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions { Title = "Font Pfad wählen", AllowMultiple = false }); if (folder == null || folder.Count == 0) return; var chosen = folder[0].Path; TbFontPath.Text = chosen.ToString(); Global._instance.font_path = chosen.ToString(); Global.Save(); } private async void BtnConfigPath_Click(object? sender, RoutedEventArgs e) { var top = GetTopLevel(this); var folder = await top.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions { Title = "Config Pfad wählen", AllowMultiple = false }); if (folder == null || folder.Count == 0) return; var chosen = folder[0].Path; TbConfigPath.Text = chosen.ToString(); Global._instance.config_path = chosen.ToString(); Global.Save(); MessageBox.Show(this, "Bitte starten Sie das Programm neu, um die Änderungen wirksam zu machen.", "Achtung"); } private async void StartCombine(List address_lists, int owner_id, string type, CombineAddresses.CombineType comb_type) { var progressWindow = new ProgressWindow(); progressWindow.Show(_instance); var processor = new CombineAddresses(progressWindow); var result = await processor.Perform(address_lists, type, comb_type, CbMergeExportUnmerged.IsChecked, CbMergeDeleteOld.IsChecked); if (result.Item1 != null) result.Item1.owner_id = owner_id; if (result.Item2 != null) result.Item2.owner_id = owner_id; if (result.Item1 != null) Settings._instance.addressSets.addresses.Add(result.Item1); if (result.Item2 != null) Settings._instance.addressSets.addresses.Add(result.Item2); Settings.Save(); progressWindow.Close(); //new ResultWindow(result, addresSetID).Show(); } private void BtnSettingsAddCustomer_OnClick(object? sender, RoutedEventArgs e) { Settings._instance.customers.customers.Add(new Customer()); TbSettingsCustomerDescription.Text = ""; TbSettingsCustomerName.Text = ""; TbSettingsCustomerPatchInfo.Text = ""; Settings.Save(); RefreshCustomerItems(); try { LstSettingsCustomers.SelectedIndex = LstSettingsCustomers.Items.Count - 1; } catch { } } private void TbSettingsCustomerName_OnTextChanged(object? sender, TextChangedEventArgs e) { if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return; foreach (var customer in Settings._instance.customers.customers) if (customer.ID == Settings._instance.customers.current.ID) customer.name = TbSettingsCustomerName.Text; //Settings.Save(); //RefreshCustomerItems(); } private void LstSettingsCustomers_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) { if (LstSettingsCustomers.SelectedIndex < 0) return; Settings._instance.customers.current = ((Customer)LstSettingsCustomers.SelectedItems[0]); //foreach (var customer in Settings._instance.customers.customers) //if (customer.ID == Settings._instance.customers.current.ID) //{ TbSettingsCustomerDescription.Text = Settings._instance.customers.current.description; TbSettingsCustomerName.Text = Settings._instance.customers.current.name; TbSettingsCustomerSenderAddress.Text = Settings._instance.customers.current.sender_address; TbSettingsCustomerCsvSeparator.Text = Settings._instance.customers.current.separator.ToString(); if (Settings._instance.customers.current.patch != null) TbSettingsCustomerPatchInfo.Text = Settings._instance.customers.current.patch.ToString(); else TbSettingsCustomerPatchInfo.Text = ""; //} } private async void EditButton_Click(object? sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(_selectedWikiFilePath)) { await MessageBox.Show(this, "Bitte wählen Sie zunächst eine Wiki-Datei aus.", "Keine Datei ausgewählt"); return; } EditorWindow ew = new(_selectedWikiFilePath); ew.Show(); //await MessageBox.Show(this, "Edit feature is currently disabled.", "Edit Disabled"); } public void RefreshCustomerItems(int index = 0) { if (LstCustomers.Items.Count > 0) LstCustomers.SelectedIndex = -1; else LstCustomers.SelectedItem = null; LstCustomers.Items.Clear(); if (LstSettingsCustomers.Items.Count > 0) LstSettingsCustomers.SelectedIndex = -1; else LstSettingsCustomers.SelectedItem = null; LstSettingsCustomers.Items.Clear(); foreach (var customer in Settings._instance.customers.customers) { LstCustomers.Items.Add(customer); LstSettingsCustomers.Items.Add(customer); } try { LstSettingsCustomers.SelectedIndex = index; } catch { } } private void TbSettingsCustomerDescription_OnTextChanged(object? sender, TextChangedEventArgs e) { if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return; foreach (var customer in Settings._instance.customers.customers) if (customer.ID == Settings._instance.customers.current.ID) customer.description = TbSettingsCustomerDescription.Text; //Settings.Save(); } private void BtnSettingsSaveCustomerData_OnClick(object? sender, RoutedEventArgs e) { Settings.Save(); RefreshCustomerItems(LstSettingsCustomers.SelectedIndex); } private void LstCustomers_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) { MakeCalcManVisible(); if (LstCustomers.SelectedItems == null || LstCustomers.SelectedIndex == -1) return; var customer_id = ((Customer)LstCustomers.SelectedItem).ID; RefreshAddressSetListItems(customer_id); } private async void BtnCustomerAddressSetImport_OnClick(object? sender, RoutedEventArgs e) { MakeCalcManVisible(); var opts = new FilePickerOpenOptions(); opts.Title = "Address-Set importieren..."; opts.AllowMultiple = false; var type = new FilePickerFileType("CSV-Dateien (*.csv)"); type.Patterns = new[] { "*.csv" }; opts.FileTypeFilter = new[] { type }; var paths = await StorageProvider.OpenFilePickerAsync(opts); if (paths?.Count <= 0) return; if (LstCustomers.SelectedIndex < 0) return; var selected_path = paths[0].Path; foreach (var customer in Settings._instance.customers.customers) if (customer == ((Customer)LstCustomers.SelectedItems[0])) { if (customer.patch == null) { var got = await DataImport.ImportKasAddressList(selected_path, null, customer.separator); if (!got.Item1) { Console.WriteLine("Error while importing. Please try another file."); } else { got.Item2.SetOwner(customer.ID); Settings._instance.addressSets.addresses.Add(got.Item2); } //var customer_id = int.Parse(LstCustomers.SelectedItem.ToString().Split(" - ")[0]); RefreshAddressSetListItems(customer.ID); } else { var got = await DataImport.ImportKasAddressList(selected_path, customer.patch, customer.separator); if (!got.Item1) { Console.WriteLine("Error while importing. Please try another file."); } else { got.Item2.SetOwner(customer.ID); Settings._instance.addressSets.addresses.Add(got.Item2); } //var customer_id = int.Parse(LstCustomers.SelectedItem.ToString().Split(" - ")[0]); RefreshAddressSetListItems(customer.ID); } } Settings.Save(); } public void RefreshAddressSetListItems(int customer_id) { BtnCheck.IsEnabled = false; BtnCombine.IsEnabled = false; BtnGenerateLabels.IsEnabled = false; BtnRepair.IsEnabled = false; BtnShorten.IsEnabled = false; if (LstCustomers.SelectedIndex < 0) return; LstCustomerAdressSets.SelectedItems = null; LstCustomerAdressSets.Items.Clear(); foreach (var k in Settings._instance.addressSets.addresses) foreach (var customer in Settings._instance.customers.customers) if (customer.ID == k.owner_id && customer.ID == customer_id) LstCustomerAdressSets.Items.Add(k); } private void LstCustomerAdressSets_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) { MakeCalcManVisible(); if (LstCustomerAdressSets.SelectedItems == null || LstCustomerAdressSets.SelectedIndex == -1) { BtnCheck.IsEnabled = false; BtnCombine.IsEnabled = false; BtnGenerateLabels.IsEnabled = false; BtnRepair.IsEnabled = false; BtnShorten.IsEnabled = false; } else { BtnCheck.IsEnabled = true; BtnCombine.IsEnabled = true; BtnGenerateLabels.IsEnabled = true; BtnShorten.IsEnabled = true; // BtnRepair.IsEnabled = true; // BtnShorten.IsEnabled = true; } } private async void BtnSettingsImportCustomerAddressPatch_OnClick(object? sender, RoutedEventArgs e) { if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return; var opts = new FilePickerOpenOptions(); opts.Title = "Address-Patch für " + LstSettingsCustomers.SelectedItems[0] + "importieren..."; opts.AllowMultiple = false; var type = new FilePickerFileType("ADPAC-Dateien (*.adpac)"); type.Patterns = new[] { "*.adpac" }; opts.FileTypeFilter = new[] { type }; var paths = await StorageProvider.OpenFilePickerAsync(opts); if (paths?.Count <= 0) return; //if (LstSettingsCustomers.SelectedIndex < 0) return; var selected_path = paths[0].Path; foreach (var customer in Settings._instance.customers.customers) if (customer.ID == ((Customer)LstSettingsCustomers.SelectedItems[0]).ID) customer.patch = AddressPatch.Import(selected_path); Settings.Save(); } private void TbSettingsCustomerCsvSeparator_OnTextChanged(object? sender, TextChangedEventArgs e) { if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return; var sep = !string.IsNullOrEmpty(TbSettingsCustomerCsvSeparator.Text) ? TbSettingsCustomerCsvSeparator.Text : ","; foreach (var customer in Settings._instance.customers.customers) if (customer.ID == Settings._instance.customers.current.ID) try { customer.separator = Convert.ToChar(sep); } catch (FormatException ex) { MessageBox.Show(this, "Error while converting: " + ex.Message, "Could not parse"); } catch (Exception ex) { MessageBox.Show(this, "Unknown Error: " + ex.Message, "Error"); } } private void BtnCombineDifference_OnClick(object? sender, RoutedEventArgs e) { var list = new List(); foreach (var item in LstCustomerAdressSets.SelectedItems) list.Add((KasAddressList)item); try { StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem), "difference", GetCombiningTyp()); } catch { } } private void BtnCombineUnion_OnClick(object? sender, RoutedEventArgs e) { var list = new List(); foreach (var item in LstCustomerAdressSets.SelectedItems) list.Add((KasAddressList)item); try { StartCombine(list, Convert.ToInt32((LstCustomers.SelectedItem as Customer).ID), "union", GetCombiningTyp()); } catch { } } private void BtnCombineIntersection_OnClick(object? sender, RoutedEventArgs e) { var list = new List(); foreach (var item in LstCustomerAdressSets.SelectedItems) list.Add((KasAddressList)item); try { StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "intersection", GetCombiningTyp()); } catch { } } public CombineAddresses.CombineType GetCombiningTyp() { if (RbComprefsid.IsChecked == true) { return CombineAddresses.CombineType.refsid; } else if (RbCompfinAd.IsChecked == true) { return CombineAddresses.CombineType.final_adress; } return CombineAddresses.CombineType.none; } private void BtnCombineSymmetricDifference_OnClick(object? sender, RoutedEventArgs e) { var list = new List(); foreach (var item in LstCustomerAdressSets.SelectedItems) list.Add((KasAddressList)item); StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "symdiff", GetCombiningTyp()); } private async void BtnGenerateLabels_OnClick(object? sender, RoutedEventArgs e) { GrdCalcMan.IsVisible = false; GrdCombineTypes.IsVisible = false; GrdExportMarginOptions.IsVisible = true; LoadPdfExportOptions(); } private async void BtnStartGenerateLabels_OnClick(object? sender, RoutedEventArgs e) { SavePdfExportOptions(); var saveDialog = new SaveFileDialog { DefaultExtension = "pdf", Filters = { new FileDialogFilter { Name = "PDF-Dateien", Extensions = { "pdf" } } } }; // hier nach winpafd prüfen var filePath = await saveDialog.ShowAsync(this); if (!string.IsNullOrEmpty(filePath)) { if (Uri.TryCreate(filePath, UriKind.Absolute, out var uri) && uri.IsFile) { filePath = uri.LocalPath; } var builder = new PdfBuilder(Settings._instance.pdfExport); builder.CreateAddressLabelPdfFromAddressSetWithPlaceholder( ((KasAddressList)LstCustomerAdressSets.SelectedItem).ID, "Company Logo/Info", filePath ); } } private void HookPdfExportOptionEvents() { var controls = GetPdfExportControls(); foreach (var control in controls) control.ValueChanged += PdfExportOption_OnValueChanged; } private void LoadPdfExportOptions() { var options = Settings._instance.pdfExport ?? new PdfExportSettings(); NudExpMargCellPaddingTop.Value = (decimal)options.cellPaddingTopMm; NudExpMargCellPaddingBot.Value = (decimal)options.cellPaddingBottomMm; NudExpMargCellPaddingLeft.Value = (decimal)options.cellPaddingLeftMm; NudExpMargCellPaddingRight.Value = (decimal)options.cellPaddingRightMm; TbExpMargMarginTop.Value = (decimal)options.pageMarginTopMm; TbExpMargMarginBottom.Value = (decimal)options.pageMarginBottomMm; TbExpMargMarginLeft.Value = (decimal)options.pageMarginLeftMm; TbExpMargMarginRight.Value = (decimal)options.pageMarginRightMm; TbExpMargRowsPerPage.Value = options.rowsPerPage; NudExpMargColumnsPerPage.Value = options.columnsPerPage; NudExpMargFontSize.Value = (decimal)options.fontSize; NudExpMargSmallFontSize.Value = (decimal)options.smallFontSize; } private void SavePdfExportOptions() { Settings._instance.pdfExport = new PdfExportSettings { cellPaddingTopMm = ReadDouble(NudExpMargCellPaddingTop), cellPaddingBottomMm = ReadDouble(NudExpMargCellPaddingBot), cellPaddingLeftMm = ReadDouble(NudExpMargCellPaddingLeft), cellPaddingRightMm = ReadDouble(NudExpMargCellPaddingRight), pageMarginTopMm = ReadDouble(TbExpMargMarginTop), pageMarginBottomMm = ReadDouble(TbExpMargMarginBottom), pageMarginLeftMm = ReadDouble(TbExpMargMarginLeft), pageMarginRightMm = ReadDouble(TbExpMargMarginRight), rowsPerPage = ReadInt(TbExpMargRowsPerPage, 7), columnsPerPage = ReadInt(NudExpMargColumnsPerPage, 3), fontSize = ReadDouble(NudExpMargFontSize), smallFontSize = ReadDouble(NudExpMargSmallFontSize) }; Settings.Save(); } private void PdfExportOption_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e) { SavePdfExportOptions(); } private double ReadDouble(NumericUpDown control) { return (double)(control.Value ?? 0); } private int ReadInt(NumericUpDown control, int fallback) { return (int)Math.Round(control.Value ?? fallback); } private NumericUpDown[] GetPdfExportControls() { return [ NudExpMargCellPaddingTop, NudExpMargCellPaddingBot, NudExpMargCellPaddingLeft, NudExpMargCellPaddingRight, TbExpMargMarginTop, TbExpMargMarginBottom, TbExpMargMarginLeft, TbExpMargMarginRight, TbExpMargRowsPerPage, NudExpMargColumnsPerPage, NudExpMargFontSize, NudExpMargSmallFontSize ]; } private void TbSettingsCustomerSenderAddress_OnTextChanged(object? sender, TextChangedEventArgs e) { if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return; foreach (var customer in Settings._instance.customers.customers) if (customer.ID == Settings._instance.customers.current.ID) customer.sender_address = TbSettingsCustomerSenderAddress.Text; } // Country Section private void BtnSettingsRemoveCountry_OnClick(object? sender, RoutedEventArgs e) { if (_selectedCountry != null) { Global._instance.countries.Remove(_selectedCountry); _selectedCountry = null; } RefreshCountryView(); } public void RefreshCountryView() { if (_suppressCountryRefresh) return; try { _suppressCountryRefresh = true; Global.Save(); var alt_index = LbSettingsAlternatives.SelectedIndex; var country_index = CountryList.SelectedIndex; LbSettingsAlternatives.Items.Clear(); try { CountryList.Items.Clear(); } catch { } foreach (var c in Global._instance.countries) CountryList.Items.Add(c.name); try { CountryList.SelectedIndex = country_index; } catch { } try { _selectedCountry = Country.GetByName(CountryList.SelectedItems[0].ToString()); } catch { _selectedCountry = null; } if (_selectedCountry == null) return; //Console.WriteLine("Refreshing alternatives..."); foreach (var a in _selectedCountry.alternatives) LbSettingsAlternatives.Items.Add(a); //Console.WriteLine(a); TbSettingsCountryName.Text = _selectedCountry.name; TbSettingsCountryTranslation.Text = _selectedCountry.translation; try { LbSettingsAlternatives.SelectedIndex = alt_index; } catch { } } finally { _suppressCountryRefresh = false; } } private void BtnSettingsRemoveSelectedAlternatives_OnClick(object? sender, RoutedEventArgs e) { foreach (var selected in LbSettingsAlternatives.SelectedItems) try { _selectedCountry.alternatives.Remove(selected.ToString()); } catch { Console.WriteLine("Error while removing country alternative"); } RefreshCountryView(); } private void BtnSettingsNewCountryAlternative_OnClick(object? sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(TbSettingsNewCountryAlternative.Text)) return; _selectedCountry.alternatives.Add(TbSettingsNewCountryAlternative.Text.Trim()); RefreshCountryView(); } private void TbSettingsCountryTranslation_OnTextChanged(object? sender, TextChangedEventArgs e) { if (!string.IsNullOrWhiteSpace(TbSettingsCountryTranslation.Text)) { _selectedCountry.translation = TbSettingsCountryTranslation.Text.Trim(); RefreshCountryView(); } } private void TbSettingsCountryName_OnTextChanged(object? sender, TextChangedEventArgs e) { if (!string.IsNullOrWhiteSpace(TbSettingsCountryName.Text)) { _selectedCountry.name = TbSettingsCountryName.Text.Trim(); RefreshCountryView(); } } private void BtnSettingsNewCountry_OnClick(object? sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(TbSettingsNewCountry.Text)) return; Global._instance.countries.Add(new Country(TbSettingsNewCountry.Text)); RefreshCountryView(); } private void CountryList_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) { _selectedCountry = Country.GetByName(CountryList.SelectedItems[0].ToString()); RefreshCountryView(); } private void BtnSettingsInsertDefaultCountries_OnClick(object? sender, RoutedEventArgs e) { ISO3166.Country[] countries = ISO3166.Country.List; foreach (var countryie in countries) Global._instance.countries.Add(new Country(countryie.Name, countryie.Name, new List { countryie.ThreeLetterCode, countryie.TwoLetterCode })); RefreshCountryView(); } private async void BtnWikiAddFile_OnClick(object? sender, RoutedEventArgs e) { var result = await NamingWindow.Show(this); if (string.IsNullOrWhiteSpace(result)) return; result = result.Trim(); if (!result.EndsWith(".md", StringComparison.OrdinalIgnoreCase)) result += ".md"; if (!Directory.Exists(Global._instance.wiki_storage_path)) Directory.CreateDirectory(Global._instance.wiki_storage_path); try { var targetDirectory = GetSelectedWikiTargetDirectory(); Directory.CreateDirectory(targetDirectory); var newFilePath = Path.Combine(targetDirectory, result); File.WriteAllText(newFilePath, ""); PopulateNavTree(targetDirectory, newFilePath); } catch (Exception ex) { MessageBox.Show(this, ex.StackTrace, "Fehler"); } } private async void BtnWikiAddFolder_OnClick(object? sender, RoutedEventArgs e) { var result = await NamingWindow.Show(this); if (string.IsNullOrWhiteSpace(result)) return; result = result.Trim(); if (!Directory.Exists(Global._instance.wiki_storage_path)) Directory.CreateDirectory(Global._instance.wiki_storage_path); try { var targetDirectory = GetSelectedWikiTargetDirectory(); var newFolderPath = Path.Combine(targetDirectory, result); Directory.CreateDirectory(newFolderPath); PopulateNavTree(targetDirectory, newFolderPath); } catch (Exception ex) { MessageBox.Show(this, ex.StackTrace, "Fehler"); } } private async void MnIAdSetRename_OnClick(object? sender, RoutedEventArgs e) { var id = (LstCustomerAdressSets.SelectedItems[0] as KasAddressList).ID; var cus_id = ((Customer)LstCustomers.SelectedItems[0]).ID; var curr_set = new KasAddressList(""); foreach (var set in Settings._instance.addressSets.addresses) if (set.ID == id) { curr_set = set; } if (LstCustomerAdressSets.SelectedItems.Count > 0) try { var result = await NamingWindow.Show(this, curr_set.Name); if (result != null) { curr_set.Name = result; Settings.Save(); RefreshAddressSetListItems(cus_id); return; } } catch (Exception ex) { MessageBox.Show(this, ex.StackTrace, "Fehler"); } } private void BtnDeleteCustomer_OnClick(object? sender, RoutedEventArgs e) { if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return; try { Settings._instance.customers.customers.Remove((Customer)LstSettingsCustomers.SelectedItem); } catch (Exception ex) { MessageBox.Show(this, "Unknown Error: " + ex.Message, "Error"); } RefreshCustomerItems(); } private void BtnShorten_OnClick(object? sender, RoutedEventArgs e) { MakeCalcManVisible(); if (LstCustomerAdressSets.SelectedIndex == -1) { MessageBox.Show(null, "Bitte zunächst ein Adress-Set auswählen", "Kein Adress-Set ausgewählt"); return; } StartAddressShortener((KasAddressList)LstCustomerAdressSets.SelectedItem); } private void ChangeCSVDivider(object sender, RoutedEventArgs e) { try { string div = (sender as Button).Content as string; if (div == "TAB") div = "\t"; if (div == "SPACE") div = " "; TbSettingsCustomerCsvSeparator.Text = div; Settings.Save(); } catch { Console.WriteLine("Error while parsing"); } } }