| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using PRSDesktop.Integrations.Logikal;
- namespace PRSDesktop;
- public class LogikalSettingsGrid : DynamicItemsListGrid<LogikalSettings>
- {
- public override void LoadEditorButtons(LogikalSettings item, DynamicEditorButtons buttons)
- {
- base.LoadEditorButtons(item, buttons);
- buttons.Add("Reset Queries", null, item, ResetQueries);
- }
- private void ResetQueries(object sender, LogikalSettings item)
- {
- if (sender is EmbeddedDynamicEditorForm editor)
- {
- editor.SetEditorValue(nameof(LogikalSettings.FinishSQL), LogikalStyle.SQL);
- editor.SetEditorValue(nameof(LogikalSettings.BillOfMaterialsProfileSQL), LogikalProfile.BillOfMaterialsSQL);
- editor.SetEditorValue(nameof(LogikalSettings.DesignProfileSQL), LogikalProfile.DesignSQL);
- editor.SetEditorValue(nameof(LogikalSettings.GasketSQL), LogikalGasket.SQL);
- editor.SetEditorValue(nameof(LogikalSettings.ComponentSQL), LogikalComponent.SQL);
- editor.SetEditorValue(nameof(LogikalSettings.GlassSQL), LogikalGlass.SQL);
- editor.SetEditorValue(nameof(LogikalSettings.LabourSQL), LogikalLabour.SQL);
- }
- }
- private void ValidateSQL<T>(string tag, string sql, List<string> errors) where T : LogikalItem, new()
- {
- var t = new T();
- List<string> _e = new();
- t.ValidateQuery(sql.Replace("\r\n", " ").Replace('\r', ' ').Replace('\n', ' '), _e);
- if (_e.Any())
- {
- errors.Add($"The query for {tag} has some errors:");
- errors.AddRange(_e);
- }
- }
-
- protected override void DoValidate(LogikalSettings[] items, List<string> errors)
- {
- base.DoValidate(items, errors);
- var _item = items.FirstOrDefault();
- if (_item == null)
- return;
-
- if (Guid.Equals(_item.ProfileUom.ID, Guid.Empty))
- errors.Add("Profile UOM may not be blank");
-
- if (Guid.Equals(_item.GasketUom.ID, Guid.Empty))
- errors.Add("Gasket UOM may not be blank");
-
- if (Guid.Equals(_item.ComponentUom.ID, Guid.Empty))
- errors.Add("Component UOM may not be blank");
-
- if (Guid.Equals(_item.GlassUom.ID, Guid.Empty))
- errors.Add("Glass UOM may not be blank");
-
- CheckLogikalQueries(_item);
-
- ValidateSQL<LogikalGroup>("1. Groups", _item.GroupSQL, errors);
-
- ValidateSQL<LogikalStyle>("2. Finishes", _item.FinishSQL, errors);
-
- ValidateSQL<LogikalProfile>("3. Profiles - BOM", _item.BillOfMaterialsProfileSQL, errors);
- ValidateSQL<LogikalProfile>("3. Profiles - Design", _item.DesignProfileSQL, errors);
- ValidateSQL<LogikalGasket>("4. Gaskets", _item.GasketSQL, errors);
- ValidateSQL<LogikalComponent>("5. Components", _item.ComponentSQL, errors);
- ValidateSQL<LogikalGlass>("6. Glass", _item.GlassSQL, errors);
- ValidateSQL<LogikalLabour>("7. Labour", _item.LabourSQL, errors);
-
- }
-
- public void CheckLogikalQueries(LogikalSettings item)
- {
-
- item.GroupSQL = string.IsNullOrWhiteSpace(item.GroupSQL) ? LogikalGroup.SQL.Trim(' ','\r','\n') : item.GroupSQL;
- item.FinishSQL = string.IsNullOrWhiteSpace(item.FinishSQL) ? LogikalStyle.SQL.Trim(' ','\r','\n') : item.FinishSQL;
-
- item.BillOfMaterialsProfileSQL = string.IsNullOrWhiteSpace(item.BillOfMaterialsProfileSQL) ? LogikalProfile.BillOfMaterialsSQL.Trim(' ','\r','\n') : item.BillOfMaterialsProfileSQL;
- item.DesignProfileSQL = string.IsNullOrWhiteSpace(item.DesignProfileSQL) ? LogikalProfile.DesignSQL.Trim(' ','\r','\n') : item.DesignProfileSQL;
- item.GasketSQL = string.IsNullOrWhiteSpace(item.GasketSQL) ? LogikalGasket.SQL.Trim(' ','\r','\n') : item.GasketSQL;
- item.ComponentSQL = string.IsNullOrWhiteSpace(item.ComponentSQL) ? LogikalComponent.SQL.Trim(' ','\r','\n') : item.ComponentSQL;
- item.GlassSQL = string.IsNullOrWhiteSpace(item.GlassSQL) ? LogikalGlass.SQL.Trim(' ','\r','\n') : item.GlassSQL;
- item.LabourSQL = string.IsNullOrWhiteSpace(item.LabourSQL) ? LogikalLabour.SQL.Trim(' ','\r','\n') : item.LabourSQL;
- }
-
- }
|