diff --git a/DataImport.cs b/DataImport.cs index ed13ee8..6d34019 100644 --- a/DataImport.cs +++ b/DataImport.cs @@ -133,8 +133,7 @@ public class DataImport foreach (var hasProp in hasProperties) { var fieldName = hasProp.Name.Substring(4); - - if (fieldName == "refsid") refsid_existing = true; + var hasObj = hasProp.GetValue(patch); var has = hasObj is bool b && b; @@ -162,7 +161,7 @@ public class DataImport var altIdx = Array.FindIndex(headers, h => string.Equals(h, fieldName, StringComparison.OrdinalIgnoreCase) || string.Equals(h, fieldName + "_is", StringComparison.OrdinalIgnoreCase)); - + if (altIdx >= 0 && altIdx < parts.Length) resolvedValue = parts[altIdx]; else @@ -179,7 +178,7 @@ public class DataImport } var new_refsid = last_refsid; - if (!refsid_existing) + if (!patch.has_refsid) new_refsid = GenerateNewRefsid(); else new_refsid = ParseInt(GetField("refsid")); @@ -227,7 +226,19 @@ public class DataImport int GenerateNewRefsid() { - last_refsid++; + + int biggest = last_refsid; + foreach (var set in Settings._instance.addressSets.addresses) + { + foreach (var address in set.KasPersons) + { + if (biggest < address.refsid) + { + biggest = address.refsid+1; + } + } + } + last_refsid = biggest+1; return last_refsid; } }