|
@@ -3,6 +3,7 @@ using InABox.Core;
|
|
|
using InABox.Database;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Configuration.Provider;
|
|
|
using System.Linq;
|
|
|
using System.Linq.Expressions;
|
|
|
using System.Text;
|
|
@@ -10,6 +11,7 @@ using System.Threading.Tasks;
|
|
|
using Syncfusion.Windows.Tools.Controls;
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
using System.Reflection;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
using FastReport.Utils;
|
|
|
|
|
|
namespace PRS.Shared
|
|
@@ -26,6 +28,7 @@ namespace PRS.Shared
|
|
|
DataUpdater.RegisterUpdateScript("7.00", Update_7_00);
|
|
|
DataUpdater.RegisterUpdateScript("7.06", Update_7_06);
|
|
|
DataUpdater.RegisterUpdateScript("7.14", Update_7_14);
|
|
|
+ DataUpdater.RegisterUpdateScript("7.19", Update_7_19);
|
|
|
}
|
|
|
|
|
|
private static Dictionary<string, Tuple<string, string>> _6_31_module_map = new()
|
|
@@ -570,5 +573,55 @@ namespace PRS.Shared
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Trigger the calculation of Digital Form Numbers
|
|
|
+ /// </summary>
|
|
|
+ /// <returns>true (always)</returns>
|
|
|
+ private static bool Update_7_19()
|
|
|
+ {
|
|
|
+ // Find all classes that derive from EntityForm
|
|
|
+ var formtypes = CoreUtils.TypeList(
|
|
|
+ new[]
|
|
|
+ {
|
|
|
+ typeof(Setout).Assembly
|
|
|
+ },
|
|
|
+ myType =>
|
|
|
+ myType is { IsClass: true, IsAbstract: false, IsGenericType: false }
|
|
|
+ && myType.IsSubclassOf(typeof(Entity))
|
|
|
+ && myType.GetInterfaces().Contains(typeof(IEntityForm))
|
|
|
+ ).ToArray();
|
|
|
+
|
|
|
+ foreach (var formtype in formtypes)
|
|
|
+ {
|
|
|
+ var columns = Columns.Create(formtype).Add("ID").Add("Number");
|
|
|
+ var forms = DbFactory.Provider.Query(formtype, null, columns);
|
|
|
+ var nullforms = forms.Rows
|
|
|
+ .Where(r => String.IsNullOrWhiteSpace(r.Get<String>("Number")))
|
|
|
+ .Select(r=>r.ToObject(formtype))
|
|
|
+ .OfType<Entity>()
|
|
|
+ .ToArray();
|
|
|
+
|
|
|
+ if (!nullforms.Any())
|
|
|
+ continue;
|
|
|
+
|
|
|
+ var maxvalue = forms.Rows.Select(r => Regex.Match(r.Get<String>("Number") ?? "", @"(?<=-)\d+")?.Value ?? "0")
|
|
|
+ .MaxBy(x => x) ?? "0";
|
|
|
+ int.TryParse(maxvalue, out int iNumber);
|
|
|
+
|
|
|
+ String format = null;
|
|
|
+ foreach (var form in nullforms)
|
|
|
+ {
|
|
|
+ format ??= (form as IStringAutoIncrement)?.AutoIncrementFormat() ?? "{0:D8}";
|
|
|
+ iNumber++;
|
|
|
+ CoreUtils.SetPropertyValue(form, "Number", String.Format(format, iNumber));
|
|
|
+ }
|
|
|
+
|
|
|
+ DbFactory.Provider.Save(formtype, nullforms);
|
|
|
+
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|