|
@@ -1,4 +1,7 @@
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
+using System.Linq.Expressions;
|
|
using Comal.Classes;
|
|
using Comal.Classes;
|
|
using InABox.Clients;
|
|
using InABox.Clients;
|
|
using InABox.Core;
|
|
using InABox.Core;
|
|
@@ -7,8 +10,97 @@ using InABox.Wpf;
|
|
|
|
|
|
namespace PRSDesktop;
|
|
namespace PRSDesktop;
|
|
|
|
|
|
|
|
+
|
|
public static class SystemSetupActions
|
|
public static class SystemSetupActions
|
|
{
|
|
{
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private class V6SettingsGrid : DynamicItemsListGrid<V6Settings>
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ private void Validate<T>(string sql, List<string> errors) where T : V6Object, new()
|
|
|
|
+ {
|
|
|
|
+ var t = new T();
|
|
|
|
+ List<string> _e = new();
|
|
|
|
+ t.ValidateQuery(sql,_e);
|
|
|
|
+ if (_e.Any())
|
|
|
|
+ {
|
|
|
|
+ errors.Add($"The query for {typeof(T).Name} has some errors:");
|
|
|
|
+ errors.AddRange(_e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void ValidateUom(V6Settings settings, string uomcode, List<string> errors, IEnumerable<ProductDimensionUnit> uoms, params string[] checks)
|
|
|
|
+ {
|
|
|
|
+ var _uomvalue = CoreUtils.GetPropertyValue(settings, uomcode) as string;
|
|
|
|
+ if (string.IsNullOrWhiteSpace(_uomvalue))
|
|
|
|
+ {
|
|
|
|
+ errors.Add($"{uomcode.SplitCamelCase()} may not be blank!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var _uom = uoms.FirstOrDefault(x => string.Equals(x.Code, _uomvalue));
|
|
|
|
+ if (_uom == null)
|
|
|
|
+ {
|
|
|
|
+ errors.Add($"{uomcode.SplitCamelCase()}: {_uomvalue} is not a value Unit of Measure!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<string> _missing = new();
|
|
|
|
+ foreach (var _check in checks)
|
|
|
|
+ {
|
|
|
|
+ var _enabled = (bool)(CoreUtils.GetPropertyValue(_uom, _check) ?? false);
|
|
|
|
+ if (!_enabled)
|
|
|
|
+ _missing.Add(_check);
|
|
|
|
+ }
|
|
|
|
+ if (_missing.Any())
|
|
|
|
+ errors.Add($"{_uomvalue} is missing the following checks: {string.Join(", ",_missing)}");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected override void DoValidate(V6Settings[] items, List<string> errors)
|
|
|
|
+ {
|
|
|
|
+ base.DoValidate(items, errors);
|
|
|
|
+
|
|
|
|
+ var _item = items.FirstOrDefault();
|
|
|
|
+ if (_item == null)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ var _uoms = Client.Query(new Filter<ProductDimensionUnit>().All(), Columns.All<ProductDimensionUnit>()).ToObjects<ProductDimensionUnit>().ToArray();
|
|
|
|
+ if (_item.ImportCosts != V6ImportCosts.None)
|
|
|
|
+ {
|
|
|
|
+ ValidateUom(_item, nameof(V6Settings.ProfileUom), errors, _uoms, nameof(ProductDimensionUnit.HasLength));
|
|
|
|
+ ValidateUom(_item, nameof(V6Settings.ComponentUom), errors, _uoms, nameof(ProductDimensionUnit.HasQuantity));
|
|
|
|
+ ValidateUom(_item, nameof(V6Settings.GlassUom), errors, _uoms, nameof(ProductDimensionUnit.HasHeight), nameof(ProductDimensionUnit.HasWidth));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (_item.ImportDesigns == V6ImportDesigns.ToManufacturing)
|
|
|
|
+ {
|
|
|
|
+ if (String.IsNullOrWhiteSpace(_item.PacketTemplate))
|
|
|
|
+ errors.Add("Packet Template my not be blank!");
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var _found = Client
|
|
|
|
+ .Query(new Filter<ManufacturingTemplate>(x => x.Code).IsEqualTo(_item.PacketTemplate),
|
|
|
|
+ Columns.None<ManufacturingTemplate>()).Rows.Any();
|
|
|
|
+ if (!_found)
|
|
|
|
+ errors.Add($"Packet Template [{_item.PacketTemplate}] does not exist!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _item.CheckSQL();
|
|
|
|
+ Validate<V6Quote>(_item.QuoteSQL, errors);
|
|
|
|
+ Validate<V6Elevation>(_item.ElevationSQL, errors);
|
|
|
|
+ Validate<V6Drawings>(_item.DrawingsSQL, errors);
|
|
|
|
+ Validate<V6Profile>(_item.ProfileSQL, errors);
|
|
|
|
+ Validate<V6Component>(_item.ComponentSQL, errors);
|
|
|
|
+ Validate<V6Labour>(_item.LabourSQL, errors);
|
|
|
|
+ Validate<V6Glass>(_item.GlassSQL, errors);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
public static void ERPStatuses(IPanelHost host)
|
|
public static void ERPStatuses(IPanelHost host)
|
|
{
|
|
{
|
|
host.CreateSetupActionIfCanView<LogikalSettings>("Logikal Settings", PRSDesktop.Resources.logikal, (action) =>
|
|
host.CreateSetupActionIfCanView<LogikalSettings>("Logikal Settings", PRSDesktop.Resources.logikal, (action) =>
|
|
@@ -34,7 +126,8 @@ public static class SystemSetupActions
|
|
).Rows
|
|
).Rows
|
|
.FirstOrDefault()?
|
|
.FirstOrDefault()?
|
|
.ToObject<V6Settings>() ?? new V6Settings();
|
|
.ToObject<V6Settings>() ?? new V6Settings();
|
|
- var grid = new DynamicItemsListGrid<V6Settings>();
|
|
|
|
|
|
+ v6.CheckSQL();
|
|
|
|
+ var grid = new V6SettingsGrid();
|
|
if (grid.EditItems(new V6Settings[] { v6 }))
|
|
if (grid.EditItems(new V6Settings[] { v6 }))
|
|
{
|
|
{
|
|
Client.Save(v6, "Updated Settings");
|
|
Client.Save(v6, "Updated Settings");
|