Skip to content

Commit

Permalink
Merge branch 'live-changes' of https://github.com/MarkMpn/FetchXMLBui…
Browse files Browse the repository at this point in the history
…lder into MarkMpn-live-changes
  • Loading branch information
rappen committed Feb 20, 2020
2 parents e41c4ed + 8d61eb8 commit 72da9cd
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 35 deletions.
31 changes: 31 additions & 0 deletions FetchXmlBuilder/Controls/FetchXmlElementControlBase.cs
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -15,16 +16,38 @@ public class FetchXmlElementControlBase : UserControl, IDefinitionSavable
private Dictionary<string, string> collec;
private Dictionary<string, string> original;
private string controlsCheckSum = "";

static FetchXmlElementControlBase()
{
// Create the small warning icon to use for user feedback
// https://stackoverflow.com/questions/3031124/is-there-a-way-to-get-different-sizes-of-the-windows-system-icons-in-net
Size iconSize = SystemInformation.SmallIconSize;
Bitmap bitmap = new Bitmap(iconSize.Width, iconSize.Height);

using (Graphics g = Graphics.FromImage(bitmap))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(SystemIcons.Warning.ToBitmap(), new Rectangle(Point.Empty, iconSize));
}

WarningIcon = Icon.FromHandle(bitmap.GetHicon());
}

protected static Icon WarningIcon { get; }

public void InitializeFXB(Dictionary<string, string> collection, FetchXmlBuilder fetchXmlBuilder, TreeBuilderControl tree, TreeNode node)
{
fxb = fetchXmlBuilder;
Node = node;
Tree = tree;
if (collection != null)
{
collec = collection;
}
else if (node != null)
{
collec = (Dictionary<string, string>)node.Tag;
}

original = new Dictionary<string, string>(collec);
PopulateControls();
Expand All @@ -48,7 +71,9 @@ protected override void OnValidating(CancelEventArgs e)
base.OnValidating(e);

if (RequiresSave())
{
e.Cancel = !Save(false);
}
}

protected virtual bool RequiresSave()
Expand All @@ -61,14 +86,18 @@ public virtual bool Save(bool silent)
try
{
if (!ValidateControls(silent))
{
return false;
}

SaveInternal(silent);
}
catch (ArgumentNullException ex)
{
if (!silent)
{
MessageBox.Show(ex.Message, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}

return false;
}
Expand Down Expand Up @@ -126,5 +155,7 @@ protected override bool ProcessKeyPreview(ref Message m)

return base.ProcessKeyPreview(ref m);
}


}
}
8 changes: 8 additions & 0 deletions FetchXmlBuilder/Controls/attributeControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions FetchXmlBuilder/Controls/attributeControl.cs
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Xrm.Sdk.Metadata;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Cinteros.Xrm.FetchXmlBuilder.Controls
Expand All @@ -22,6 +23,7 @@ public attributeControl(TreeNode node, AttributeMetadata[] attributes, TreeBuild
InitializeComponent();
this.attributes = attributes;
InitializeFXB(null, null, tree, node);
warningProvider.Icon = WarningIcon;
}

protected override void PopulateControls()
Expand Down Expand Up @@ -52,22 +54,19 @@ protected override bool ValidateControls(bool silent)
if (string.IsNullOrWhiteSpace(cmbAttribute.Text))
{
if (!silent)
{
errorProvider.SetError(cmbAttribute, "Attribute is required");

valid = false;
}
else if (cmbAttribute.SelectedIndex == -1)
{
if (!silent)
errorProvider.SetError(cmbAttribute, "Attribute is not valid");
}

valid = false;
}

if (TreeBuilderControl.IsFetchAggregate(Node) && string.IsNullOrWhiteSpace(txtAlias.Text))
{
if (!silent)
{
errorProvider.SetError(txtAlias, "Alias must be specified in aggregate queries");
}

valid = false;
}
Expand Down Expand Up @@ -103,20 +102,29 @@ private void EnableAggregateControls()

private void cmbAttribute_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
warningProvider.SetError(cmbAttribute, null);
errorProvider.SetError(cmbAttribute, null);

if (string.IsNullOrWhiteSpace(cmbAttribute.Text))
{
errorProvider.SetError(cmbAttribute, "Attribute is required");
}
else if (cmbAttribute.SelectedIndex == -1)
errorProvider.SetError(cmbAttribute, "Attribute is not valid");
else
errorProvider.SetError(cmbAttribute, null);
{
warningProvider.SetError(cmbAttribute, "Attribute is not valid");
}
}

private void txtAlias_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (TreeBuilderControl.IsFetchAggregate(Node) && string.IsNullOrWhiteSpace(txtAlias.Text))
{
errorProvider.SetError(txtAlias, "Alias must be specified in aggregate queries");
}
else
{
errorProvider.SetError(txtAlias, null);
}
}
}
}
3 changes: 3 additions & 0 deletions FetchXmlBuilder/Controls/attributeControl.resx
Expand Up @@ -120,4 +120,7 @@
<metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="warningProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>140, 17</value>
</metadata>
</root>
10 changes: 10 additions & 0 deletions FetchXmlBuilder/Controls/conditionControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 38 additions & 2 deletions FetchXmlBuilder/Controls/conditionControl.cs
Expand Up @@ -20,6 +20,7 @@ public conditionControl(TreeNode node, FetchXmlBuilder fetchXmlBuilder, TreeBuil
InitializeComponent();
InitializeFXB(null, fetchXmlBuilder, tree, node);
RefreshAttributes();
warningProvider.Icon = WarningIcon;
}

protected override void PopulateControls()
Expand Down Expand Up @@ -62,7 +63,9 @@ protected override bool RequiresSave()
protected override void SaveInternal(bool silent)
{
if (!silent && cmbOperator.SelectedItem != null && cmbOperator.SelectedItem is OperatorItem)
{
ExtractCommaSeparatedValues();
}

base.SaveInternal(silent);
}
Expand All @@ -88,11 +91,11 @@ private void ExtractCommaSeparatedValues()

protected override bool ValidateControls(bool silent)
{
var result = false;
var result = true;
Control errorControl = null;
var error = "";

if (cmbAttribute.SelectedIndex == -1)
if (string.IsNullOrWhiteSpace(cmbAttribute.Text))
{
errorControl = cmbAttribute;
error = "Attribute is required";
Expand Down Expand Up @@ -237,7 +240,9 @@ protected override bool ValidateControls(bool silent)
if (!string.IsNullOrWhiteSpace(error))
{
if (!silent)
{
errorProvider.SetError(errorControl, error);
}

result = false;
}
Expand Down Expand Up @@ -375,6 +380,37 @@ private void cmbAttribute_SelectedIndexChanged(object sender, EventArgs e)
}
UpdateValueField();
}

private void cmbAttribute_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
errorProvider.SetError(cmbAttribute, null);
warningProvider.SetError(cmbAttribute, null);

if (string.IsNullOrWhiteSpace(cmbAttribute.Text))
{
errorProvider.SetError(cmbAttribute, "Attribute is required");
}
else if (cmbAttribute.SelectedIndex == -1)
{
warningProvider.SetError(cmbAttribute, "Attribute is not valid");
}
}

private void cmbOperator_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (string.IsNullOrEmpty(cmbOperator.Text))
{
errorProvider.SetError(cmbOperator, "Operator is required");
}
else if (cmbOperator.SelectedIndex == -1)
{
errorProvider.SetError(cmbOperator, "Operator is not valid");
}
else
{
errorProvider.SetError(cmbOperator, null);
}
}
}

public class EntityNode
Expand Down
3 changes: 3 additions & 0 deletions FetchXmlBuilder/Controls/conditionControl.resx
Expand Up @@ -120,4 +120,7 @@
<metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="warningProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>140, 17</value>
</metadata>
</root>
20 changes: 19 additions & 1 deletion FetchXmlBuilder/Controls/entityControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 72da9cd

Please sign in to comment.