diff --git a/FetchXmlBuilder/AppCode/Validations.cs b/FetchXmlBuilder/AppCode/Validations.cs index 33abb869..c7e05ba2 100644 --- a/FetchXmlBuilder/AppCode/Validations.cs +++ b/FetchXmlBuilder/AppCode/Validations.cs @@ -1,8 +1,5 @@ using Cinteros.Xrm.FetchXmlBuilder.Controls; -using Cinteros.Xrm.FetchXmlBuilder.DockControls; using Microsoft.Xrm.Sdk.Metadata; -using System; -using System.Collections.Generic; using System.Windows.Forms; namespace Cinteros.Xrm.FetchXmlBuilder.AppCode @@ -12,6 +9,8 @@ internal static class Validations internal static ControlValidationResult GetWarning(TreeNode node, FetchXmlBuilder fxb) { var name = TreeNodeHelper.GetAttributeFromNode(node, "name"); + var attribute = TreeNodeHelper.GetAttributeFromNode(node, "attribute"); + var parententity = TreeNodeHelper.ForThisNodeEntityName(node); switch (node.Name) { case "fetch": @@ -35,23 +34,22 @@ internal static ControlValidationResult GetWarning(TreeNode node, FetchXmlBuilde { return new ControlValidationResult(ControlValidationLevel.Warning, "Attribute Name must be included."); } - if (fxb.entities != null && node.Parent.Tag is Dictionary partag && partag.ContainsKey("name")) + if (fxb.entities != null) { - var parname = partag["name"]; - if (fxb.GetAttribute(parname, name) is AttributeMetadata metaatt) + if (fxb.GetAttribute(parententity, name) is AttributeMetadata metaatt) { - if (metaatt.IsValidForGrid.Value == false) + if (metaatt.IsValidForGrid.Value == false && metaatt.IsPrimaryId.Value != true) { return new ControlValidationResult(ControlValidationLevel.Warning, $"Attribute '{name}' has 'IsValidForGrid=false'."); } } else { - return new ControlValidationResult(ControlValidationLevel.Warning, $"Attribute '{name}' is not in the table '{parname}'."); + return new ControlValidationResult(ControlValidationLevel.Warning, $"Attribute '{name}' is not in the table '{parententity}'."); } } var alias = TreeNodeHelper.GetAttributeFromNode(node, "alias"); - if (TreeBuilderControl.IsFetchAggregate(node)) + if (TreeNodeHelper.IsFetchAggregate(node)) { if (string.IsNullOrWhiteSpace(alias)) { @@ -73,11 +71,39 @@ internal static ControlValidationResult GetWarning(TreeNode node, FetchXmlBuilde } break; case "condition": + if (string.IsNullOrWhiteSpace(attribute)) + { + return new ControlValidationResult(ControlValidationLevel.Warning, "Attribute must be included."); + } + var entityname = TreeNodeHelper.GetAttributeFromNode(node, "entityname"); + if (!string.IsNullOrWhiteSpace(entityname) && !TreeNodeHelper.ForThisNodeEntityIsRoot(node)) + { + return new ControlValidationResult(ControlValidationLevel.Error, "Cannot enter Entity for Link-Entity condition."); + } + if (string.IsNullOrWhiteSpace(entityname) && fxb.entities != null) + { + if (fxb.GetAttribute(parententity, attribute) is AttributeMetadata metaatt) + { + if (metaatt.IsValidForGrid.Value == false) + { + // return new ControlValidationResult(ControlValidationLevel.Error, $"Attribute '{attribute}' has 'IsValidForGrid=false'."); + } + } + else + { + return new ControlValidationResult(ControlValidationLevel.Warning, $"Attribute '{attribute}' is not in the table '{parententity}'."); + } + + } break; case "value": + if (string.IsNullOrWhiteSpace(TreeNodeHelper.GetAttributeFromNode(node, "#text"))) + { + return new ControlValidationResult(ControlValidationLevel.Warning, "Value should be added."); + } break; case "order": - if (string.IsNullOrWhiteSpace(TreeNodeHelper.GetAttributeFromNode(node, "attribute"))) + if (string.IsNullOrWhiteSpace(attribute)) { return new ControlValidationResult(ControlValidationLevel.Warning, "Order Name must be included."); }