222 lines
8.5 KiB
C#
222 lines
8.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Layout;
|
|
using Avalonia.Media;
|
|
|
|
namespace Logof_Client;
|
|
|
|
public partial class ResultWindow : Window
|
|
{
|
|
public List<CheckBox> errortypecheckboxes = new();
|
|
public KasAddressList ur_addresses = new("Ergebnis_" + DateTime.Now.ToString("ddMMyy_HHmmss"));
|
|
public List<KasPerson> ur_result;
|
|
public List<CheckBox> warningtypecheckboxes = new();
|
|
|
|
public ResultWindow(List<KasPerson> result,
|
|
int addressSetID)
|
|
{
|
|
InitializeComponent();
|
|
ur_result = result;
|
|
ur_addresses = ur_addresses;
|
|
Load(result);
|
|
//ViewSingle(200552426);
|
|
}
|
|
|
|
private void GenerateView(List<KasPerson> result)
|
|
{
|
|
// Filter to only show persons with errors
|
|
var result_with_errors = result.Where(p => p.PersonError != null).ToList();
|
|
LblResultCount.Content = $"{result_with_errors.Count}/{ur_result.Count} Ergebnisse";
|
|
|
|
StkResults.Children.Clear();
|
|
foreach (var person in result_with_errors) StkResults.Children.Add(CreatePersonGrid(person));
|
|
}
|
|
|
|
private Grid CreatePersonGrid(KasPerson person)
|
|
{
|
|
var grid = new Grid
|
|
{
|
|
ColumnDefinitions = ColumnDefinitions.Parse("100,*,100,*,100,*"),
|
|
RowDefinitions = RowDefinitions.Parse("Auto"),
|
|
Margin = new Thickness(0, 5, 0, 5),
|
|
Background = new SolidColorBrush(Color.Parse("#F0F0F0"))
|
|
};
|
|
|
|
// Refsid
|
|
grid.Children.Add(new TextBlock
|
|
{
|
|
Text = "refsid: ",
|
|
FontWeight = FontWeight.Bold, Margin = new Thickness(5)
|
|
});
|
|
grid.Children.Add(new TextBlock { Text = person.refsid.ToString(), Margin = new Thickness(5) });
|
|
Grid.SetColumn(grid.Children[1], 1);
|
|
|
|
// PLZ
|
|
grid.Children.Add(new TextBlock { Text = "plz:", FontWeight = FontWeight.Bold, Margin = new Thickness(5) });
|
|
Grid.SetColumn(grid.Children[2], 2);
|
|
grid.Children.Add(new TextBlock { Text = person.plz, Margin = new Thickness(5) });
|
|
Grid.SetColumn(grid.Children[3], 3);
|
|
|
|
// PPLZ
|
|
grid.Children.Add(new TextBlock { Text = "errors:", FontWeight = FontWeight.Bold, Margin = new Thickness(5) });
|
|
Grid.SetColumn(grid.Children[4], 4);
|
|
grid.Children.Add(new TextBlock { Text = person.PersonError.GetString(), Margin = new Thickness(5) });
|
|
Grid.SetColumn(grid.Children[5], 5);
|
|
|
|
return grid;
|
|
}
|
|
|
|
private void ViewSingle(int refsid)
|
|
{
|
|
foreach (var result in ur_addresses.KasPersons)
|
|
if (result.refsid == refsid)
|
|
{
|
|
var wind = new Window();
|
|
var stp = new StackPanel();
|
|
stp.Orientation = Orientation.Horizontal;
|
|
stp.Margin = new Thickness(10);
|
|
var tb = new TextBlock();
|
|
var tb2 = new TextBlock();
|
|
tb.Text =
|
|
"refsid:\nanrede:\ntitel:\nvorname:\nadel:\nname:\nnamezus:\nanredzus:\nstrasse:\nstrasse2:\nplz:\nort:\nland:\npplz:\npostfach:\nname1:\nname2:\nname3:\nname4:\nname5:\nfunktion:\nfunktion2:\nabteilung:\nfunktionad:";
|
|
tb2.Text = result.refsid + "\n" + result.anrede + "\n" + result.titel + "\n" + result.vorname + "\n" +
|
|
result.adel + "\n" + result.name + "\n" + result.namezus + "\n" + result.anredzus + "\n" +
|
|
result.strasse + "\n" + result.strasse2 + "\n" + result.plz + "\n" + result.ort + "\n" +
|
|
result.land + "\n" + result.pplz + "\n" + result.postfach + "\n" + result.name1 + "\n" +
|
|
result.name2 + "\n" + result.name3 + "\n" + result.name4 + "\n" + result.name5 + "\n" +
|
|
result.funktion + "\n" + result.funktion2 + "\n" + result.abteilung + "\n" +
|
|
result.funktionad;
|
|
stp.Children.Add(tb);
|
|
stp.Children.Add(tb2);
|
|
wind.Content = stp;
|
|
wind.ShowInTaskbar = false;
|
|
wind.SizeToContent = SizeToContent.WidthAndHeight;
|
|
wind.Show();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void Load(List<KasPerson> result)
|
|
{
|
|
var knownErrors = new List<AddressCheck.ErrorTypes>();
|
|
var knownWarnings = new List<AddressCheck.WarningTypes>();
|
|
|
|
foreach (var person in result)
|
|
{
|
|
if (person.PersonError == null) continue;
|
|
|
|
foreach (var errtyp in person.PersonError.errors)
|
|
if (!knownErrors.Contains(errtyp))
|
|
knownErrors.Add(errtyp);
|
|
|
|
foreach (var wartyp in person.PersonError.warnings)
|
|
if (!knownWarnings.Contains(wartyp))
|
|
knownWarnings.Add(wartyp);
|
|
}
|
|
|
|
|
|
foreach (var errtype in knownErrors)
|
|
{
|
|
var cb = new CheckBox();
|
|
cb.IsChecked = true;
|
|
cb.Content = errtype.ToString();
|
|
cb.Click += (sender, e) => UpdateFilter();
|
|
errortypecheckboxes.Add(cb);
|
|
StpFilterOptions.Children.Add(cb);
|
|
}
|
|
|
|
foreach (var wartype in knownWarnings)
|
|
{
|
|
var cb = new CheckBox();
|
|
cb.IsChecked = true;
|
|
cb.Content = wartype.ToString();
|
|
cb.Click += (sender, e) => UpdateFilter();
|
|
warningtypecheckboxes.Add(cb);
|
|
StpFilterOptions.Children.Add(cb);
|
|
}
|
|
|
|
GenerateView(result);
|
|
}
|
|
|
|
private void BtnUpdateFilter_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void UpdateFilter()
|
|
{
|
|
var temp_result = new List<KasPerson>();
|
|
|
|
var checkedErrors = new HashSet<AddressCheck.ErrorTypes>();
|
|
var checkedWarnings = new HashSet<AddressCheck.WarningTypes>();
|
|
|
|
// safer parsing: use TryParse and trim the Content string
|
|
foreach (var cb in errortypecheckboxes)
|
|
if (cb.IsChecked == true)
|
|
{
|
|
var s = cb.Content?.ToString()?.Trim();
|
|
if (!string.IsNullOrEmpty(s) &&
|
|
Enum.TryParse<AddressCheck.ErrorTypes>(s, true, out var et))
|
|
checkedErrors.Add(et);
|
|
}
|
|
|
|
foreach (var cb in warningtypecheckboxes)
|
|
if (cb.IsChecked == true)
|
|
{
|
|
var s = cb.Content?.ToString()?.Trim();
|
|
if (!string.IsNullOrEmpty(s) &&
|
|
Enum.TryParse<AddressCheck.WarningTypes>(s, true, out var wt))
|
|
checkedWarnings.Add(wt);
|
|
}
|
|
|
|
// If no checkboxes are selected, show all persons with errors (default behavior)
|
|
if (checkedErrors.Count == 0 && checkedWarnings.Count == 0)
|
|
temp_result = ur_result.Where(p => p.PersonError != null).ToList();
|
|
else
|
|
foreach (var person in ur_result)
|
|
{
|
|
if (person.PersonError == null) continue;
|
|
|
|
var personErrors = person.PersonError.errors ?? Enumerable.Empty<AddressCheck.ErrorTypes>();
|
|
var personWarnings = person.PersonError.warnings ?? Enumerable.Empty<AddressCheck.WarningTypes>();
|
|
|
|
var matchesError = false;
|
|
var matchesWarning = false;
|
|
|
|
// only test errors if the user selected error-types
|
|
if (checkedErrors.Count > 0)
|
|
matchesError = personErrors.Any(err => checkedErrors.Contains(err));
|
|
|
|
// only test warnings if the user selected warning-types
|
|
if (checkedWarnings.Count > 0)
|
|
matchesWarning = personWarnings.Any(war => checkedWarnings.Contains(war));
|
|
|
|
// If at least one category matches (OR across categories), include person
|
|
if ((matchesError || matchesWarning) && !temp_result.Contains(person))
|
|
temp_result.Add(person);
|
|
}
|
|
|
|
LblResultCount.Content = $"{temp_result.Count}/{ur_result.Count} Ergebnisse";
|
|
|
|
StkResults.Children.Clear();
|
|
foreach (var person in temp_result) StkResults.Children.Add(CreatePersonGrid(person));
|
|
}
|
|
|
|
|
|
private void BtnShowSelected_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
// foreach (var selected in DgResult.SelectedItems)
|
|
// try
|
|
// {
|
|
// var _asKas = (KasPerson)selected;
|
|
// ViewSingle(_asKas.refsid);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Console.WriteLine(ex.Message);
|
|
// }
|
|
}
|
|
} |