Skip to content

Commit

Permalink
More validations added #612
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Jan 12, 2022
1 parent 273fbfa commit f2bf316
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions 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
Expand All @@ -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":
Expand All @@ -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<string, string> 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))
{
Expand All @@ -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.");
}
Expand Down

0 comments on commit f2bf316

Please sign in to comment.