| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using PRSDesktop.Integrations.V6;
- namespace PRSDesktop.Integrations.V6.Grids;
- public 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.Replace('\n', ' '), _e);
- if (_e.Any())
- {
- errors.Add($"The query for {typeof(T).Name} has some errors:");
- errors.AddRange(_e);
- }
- }
-
-
-
- protected override void DoValidate(V6Settings[] 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");
- if (_item.ImportDesigns == V6DesignType.Approved)
- {
- if (String.IsNullOrWhiteSpace(_item.PacketTemplate))
- errors.Add("Packet Template my not be blank!");
- else
- {
- var _found = Client
- .Query(new InABox.Core.Filter<ManufacturingTemplate>(x => x.Code).IsEqualTo(_item.PacketTemplate),
- Columns.None<ManufacturingTemplate>()).Rows.Any();
- if (!_found)
- errors.Add($"Packet Template [{_item.PacketTemplate}] does not exist!");
- }
- }
- CheckV6Queries(_item);
-
- Validate<V6Project>(_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 void CheckV6Queries(V6Settings item)
- {
- item.QuoteSQL = string.IsNullOrWhiteSpace(item.QuoteSQL) ? V6Project.SQL : item.QuoteSQL;
- item.ElevationSQL = string.IsNullOrWhiteSpace(item.ElevationSQL) ? V6Elevation.SQL : item.ElevationSQL;
- item.DrawingsSQL = string.IsNullOrWhiteSpace(item.DrawingsSQL) ? V6Drawings.SQL : item.DrawingsSQL;
- item.FinishSQL = string.IsNullOrWhiteSpace(item.FinishSQL) ? V6Finish.SQL : item.FinishSQL;
- item.ProfileSQL = string.IsNullOrWhiteSpace(item.ProfileSQL) ? V6Profile.SQL : item.ProfileSQL;
- item.GasketSQL = string.IsNullOrWhiteSpace(item.GasketSQL) ? V6Gasket.SQL : item.GasketSQL;
- item.ComponentSQL = string.IsNullOrWhiteSpace(item.ComponentSQL) ? V6Component.SQL : item.ComponentSQL;
- item.GlassSQL = string.IsNullOrWhiteSpace(item.GlassSQL) ? V6Glass.SQL : item.GlassSQL;
- item.LabourSQL = string.IsNullOrWhiteSpace(item.LabourSQL) ? V6Labour.SQL : item.LabourSQL;
- }
- }
|