[chore:] implemented union (combiner) and its usage
This commit is contained in:
@@ -154,6 +154,7 @@
|
|||||||
Margin="5,0,0,0">
|
Margin="5,0,0,0">
|
||||||
<Button HorizontalAlignment="Stretch" MinWidth="240"
|
<Button HorizontalAlignment="Stretch" MinWidth="240"
|
||||||
HorizontalContentAlignment="Center" x:Name="BtnCombineUnion"
|
HorizontalContentAlignment="Center" x:Name="BtnCombineUnion"
|
||||||
|
Click="BtnCombineUnion_OnClick"
|
||||||
Margin="0,0,0,10">
|
Margin="0,0,0,10">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="SquaresUnite" Width="36" Height="36" />
|
<LucideIcon Kind="SquaresUnite" Width="36" Height="36" />
|
||||||
|
|||||||
@@ -240,14 +240,14 @@ public partial class MainWindow : Window
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void StartDifference(List<KasAddressList> address_lists, int owner_id)
|
private async void StartCombine(List<KasAddressList> address_lists, int owner_id, string type)
|
||||||
{
|
{
|
||||||
var progressWindow = new ProgressWindow();
|
var progressWindow = new ProgressWindow();
|
||||||
|
|
||||||
progressWindow.Show(_instance);
|
progressWindow.Show(_instance);
|
||||||
|
|
||||||
var processor = new CombineAddresses(progressWindow);
|
var processor = new CombineAddresses(progressWindow);
|
||||||
var result = await processor.Perform(address_lists, "difference");
|
var result = await processor.Perform(address_lists, type);
|
||||||
|
|
||||||
result.owner_id = owner_id;
|
result.owner_id = owner_id;
|
||||||
Settings._instance.addressSets.addresses.Add(result);
|
Settings._instance.addressSets.addresses.Add(result);
|
||||||
@@ -258,6 +258,7 @@ public partial class MainWindow : Window
|
|||||||
//new ResultWindow(result, addresSetID).Show();
|
//new ResultWindow(result, addresSetID).Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void BtnSettingsAddCustomer_OnClick(object? sender, RoutedEventArgs e)
|
private void BtnSettingsAddCustomer_OnClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Settings._instance.customers.customers.Add(new Customer());
|
Settings._instance.customers.customers.Add(new Customer());
|
||||||
@@ -499,6 +500,16 @@ public partial class MainWindow : Window
|
|||||||
list.Add(Settings._instance.addressSets.GetAddressSetByID(
|
list.Add(Settings._instance.addressSets.GetAddressSetByID(
|
||||||
Convert.ToInt32(item.ToString().Split(" - ")[0])));
|
Convert.ToInt32(item.ToString().Split(" - ")[0])));
|
||||||
|
|
||||||
StartDifference(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]));
|
StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "difference");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnCombineUnion_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var list = new List<KasAddressList>();
|
||||||
|
foreach (var item in LstCustomerAdressSets.SelectedItems)
|
||||||
|
list.Add(Settings._instance.addressSets.GetAddressSetByID(
|
||||||
|
Convert.ToInt32(item.ToString().Split(" - ")[0])));
|
||||||
|
|
||||||
|
StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "union");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ public class CombineAddresses
|
|||||||
var res = await Task.Run(async () =>
|
var res = await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
if (type == "difference") return Difference(address_lists);
|
if (type == "difference") return Difference(address_lists);
|
||||||
|
if (type == "union") return Union(address_lists);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -89,12 +90,12 @@ public class CombineAddresses
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<KasAddressList> Difference(List<KasAddressList> address_lists,
|
public async Task<KasAddressList> Difference(List<KasAddressList> address_lists,
|
||||||
DifferenceProgress? progress = null)
|
Progress? progress = null)
|
||||||
{
|
{
|
||||||
if (address_lists == null || address_lists.Count == 0)
|
if (address_lists == null || address_lists.Count == 0)
|
||||||
return new KasAddressList("difference");
|
return new KasAddressList("difference");
|
||||||
|
|
||||||
progress ??= new DifferenceProgress
|
progress ??= new Progress
|
||||||
{
|
{
|
||||||
TotalPersons = address_lists.Sum(l => l.KasPersons.Count),
|
TotalPersons = address_lists.Sum(l => l.KasPersons.Count),
|
||||||
ComparedPersons = 0
|
ComparedPersons = 0
|
||||||
@@ -126,10 +127,40 @@ public class CombineAddresses
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<KasAddressList> Union()
|
public async Task<KasAddressList> Union(List<KasAddressList> address_lists, Progress progress = null)
|
||||||
{
|
{
|
||||||
return null;
|
var result = new KasAddressList("union");
|
||||||
|
|
||||||
|
if (address_lists == null || address_lists.Count == 0)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
var total = address_lists.Sum(l => l.KasPersons.Count);
|
||||||
|
var processed = 0;
|
||||||
|
|
||||||
|
foreach (var list in address_lists)
|
||||||
|
foreach (var person in list.KasPersons)
|
||||||
|
{
|
||||||
|
if (!result.KasPersons.Any(existing => CompareAddresses(existing, person)))
|
||||||
|
result.KasPersons.Add(person);
|
||||||
|
|
||||||
|
processed++;
|
||||||
|
var percent = processed / (double)total * 100;
|
||||||
|
var logMessage =
|
||||||
|
$"{percent:F1}%: Person mit {person.refsid} hinzugefügt (aktuell {result.KasPersons.Count} Einträge)";
|
||||||
|
|
||||||
|
// Sicher, nicht blockierend:
|
||||||
|
if (progress != null)
|
||||||
|
{
|
||||||
|
if (Dispatcher.UIThread.CheckAccess())
|
||||||
|
progress.LogAction?.Invoke(logMessage);
|
||||||
|
else
|
||||||
|
Dispatcher.UIThread.Post(() => progress.LogAction?.Invoke(logMessage));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<KasAddressList> MoveDuplicatesToNew()
|
public async Task<KasAddressList> MoveDuplicatesToNew()
|
||||||
{
|
{
|
||||||
@@ -207,7 +238,7 @@ public class CombineAddresses
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DifferenceProgress
|
public class Progress
|
||||||
{
|
{
|
||||||
public int TotalPersons { get; set; } // Gesamtzahl der zu prüfenden Personen
|
public int TotalPersons { get; set; } // Gesamtzahl der zu prüfenden Personen
|
||||||
public int ComparedPersons { get; set; } // Schon verglichene Personen
|
public int ComparedPersons { get; set; } // Schon verglichene Personen
|
||||||
|
|||||||
Reference in New Issue
Block a user