From a6e1f9986d5856129482932ed5375f16f4b59356 Mon Sep 17 00:00:00 2001 From: Mark Carrington Date: Thu, 20 Feb 2020 16:38:18 +0000 Subject: [PATCH 1/2] Coding standards! --- .../Controls/FetchXmlElementControlBase.cs | 10 ++++++++++ FetchXmlBuilder/Controls/attributeControl.cs | 16 ++++++++++++++++ FetchXmlBuilder/Controls/conditionControl.cs | 4 ++++ FetchXmlBuilder/Controls/linkEntityControl.cs | 18 ++++++++++++++++++ FetchXmlBuilder/Controls/orderControl.cs | 12 ++++++++++++ 5 files changed, 60 insertions(+) diff --git a/FetchXmlBuilder/Controls/FetchXmlElementControlBase.cs b/FetchXmlBuilder/Controls/FetchXmlElementControlBase.cs index 95e2a608..9477ddee 100644 --- a/FetchXmlBuilder/Controls/FetchXmlElementControlBase.cs +++ b/FetchXmlBuilder/Controls/FetchXmlElementControlBase.cs @@ -22,9 +22,13 @@ public void InitializeFXB(Dictionary collection, FetchXmlBuilder Node = node; Tree = tree; if (collection != null) + { collec = collection; + } else if (node != null) + { collec = (Dictionary)node.Tag; + } original = new Dictionary(collec); PopulateControls(); @@ -48,7 +52,9 @@ protected override void OnValidating(CancelEventArgs e) base.OnValidating(e); if (RequiresSave()) + { e.Cancel = !Save(false); + } } protected virtual bool RequiresSave() @@ -61,14 +67,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; } diff --git a/FetchXmlBuilder/Controls/attributeControl.cs b/FetchXmlBuilder/Controls/attributeControl.cs index 07053136..1da720d2 100644 --- a/FetchXmlBuilder/Controls/attributeControl.cs +++ b/FetchXmlBuilder/Controls/attributeControl.cs @@ -52,14 +52,18 @@ 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; } @@ -67,7 +71,9 @@ protected override bool ValidateControls(bool silent) if (TreeBuilderControl.IsFetchAggregate(Node) && string.IsNullOrWhiteSpace(txtAlias.Text)) { if (!silent) + { errorProvider.SetError(txtAlias, "Alias must be specified in aggregate queries"); + } valid = false; } @@ -104,19 +110,29 @@ private void EnableAggregateControls() private void cmbAttribute_Validating(object sender, System.ComponentModel.CancelEventArgs e) { 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); + } } 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); + } } } } \ No newline at end of file diff --git a/FetchXmlBuilder/Controls/conditionControl.cs b/FetchXmlBuilder/Controls/conditionControl.cs index 79bbb4a6..29c86172 100644 --- a/FetchXmlBuilder/Controls/conditionControl.cs +++ b/FetchXmlBuilder/Controls/conditionControl.cs @@ -62,7 +62,9 @@ protected override bool RequiresSave() protected override void SaveInternal(bool silent) { if (!silent && cmbOperator.SelectedItem != null && cmbOperator.SelectedItem is OperatorItem) + { ExtractCommaSeparatedValues(); + } base.SaveInternal(silent); } @@ -237,7 +239,9 @@ protected override bool ValidateControls(bool silent) if (!string.IsNullOrWhiteSpace(error)) { if (!silent) + { errorProvider.SetError(errorControl, error); + } result = false; } diff --git a/FetchXmlBuilder/Controls/linkEntityControl.cs b/FetchXmlBuilder/Controls/linkEntityControl.cs index e31ebdfc..528efe7e 100644 --- a/FetchXmlBuilder/Controls/linkEntityControl.cs +++ b/FetchXmlBuilder/Controls/linkEntityControl.cs @@ -248,7 +248,9 @@ protected override bool ValidateControls(bool silent) if (cmbEntity.SelectedIndex == -1) { if (!silent) + { errorProvider.SetError(cmbEntity, "Entity is required"); + } valid = false; } @@ -257,7 +259,9 @@ protected override bool ValidateControls(bool silent) if (cmbFrom.SelectedIndex == -1) { if (!silent) + { errorProvider.SetError(cmbFrom, "From attribute is required"); + } valid = false; } @@ -265,7 +269,9 @@ protected override bool ValidateControls(bool silent) if (cmbTo.SelectedIndex == -1) { if (!silent) + { errorProvider.SetError(cmbTo, "To attribute is required"); + } valid = false; } @@ -276,25 +282,37 @@ protected override bool ValidateControls(bool silent) private void cmbEntity_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (cmbEntity.SelectedIndex == -1) + { errorProvider.SetError(cmbEntity, "Entity is required"); + } else + { errorProvider.SetError(cmbEntity, null); + } } private void cmbFrom_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (cmbFrom.SelectedIndex == -1) + { errorProvider.SetError(cmbFrom, "From attribute is required"); + } else + { errorProvider.SetError(cmbFrom, null); + } } private void cmbTo_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (cmbTo.SelectedIndex == -1) + { errorProvider.SetError(cmbTo, "To attribute is required"); + } else + { errorProvider.SetError(cmbTo, null); + } } } } \ No newline at end of file diff --git a/FetchXmlBuilder/Controls/orderControl.cs b/FetchXmlBuilder/Controls/orderControl.cs index 3ba54f78..ca4fb811 100644 --- a/FetchXmlBuilder/Controls/orderControl.cs +++ b/FetchXmlBuilder/Controls/orderControl.cs @@ -79,7 +79,9 @@ protected override bool ValidateControls(bool silent) if (cmbAttribute.Enabled && cmbAttribute.SelectedIndex == -1) { if (!silent) + { errorProvider.SetError(cmbAttribute, "Attribute is required"); + } valid = false; } @@ -87,7 +89,9 @@ protected override bool ValidateControls(bool silent) if (cmbAlias.Enabled && cmbAlias.SelectedIndex == -1) { if (!silent) + { errorProvider.SetError(cmbAlias, "Alias is required"); + } valid = false; } @@ -98,17 +102,25 @@ protected override bool ValidateControls(bool silent) private void cmbAttribute_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (cmbAttribute.Enabled && cmbAttribute.SelectedIndex == -1) + { errorProvider.SetError(cmbAttribute, "Attribute is required"); + } else + { errorProvider.SetError(cmbAttribute, null); + } } private void cmbAlias_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (cmbAlias.Enabled && cmbAlias.SelectedIndex == -1) + { errorProvider.SetError(cmbAlias, "Alias is required"); + } else + { errorProvider.SetError(cmbAlias, null); + } } } } \ No newline at end of file From 8d61eb82b42d4fb1ec389270ae5c47af83c707fc Mon Sep 17 00:00:00 2001 From: Mark Carrington Date: Thu, 20 Feb 2020 17:18:41 +0000 Subject: [PATCH 2/2] Show metadata mismatches as warnings instead of errors --- .../Controls/FetchXmlElementControlBase.cs | 21 ++++++++++ .../Controls/attributeControl.Designer.cs | 8 ++++ FetchXmlBuilder/Controls/attributeControl.cs | 20 +++------ .../Controls/attributeControl.resx | 3 ++ .../Controls/conditionControl.Designer.cs | 10 +++++ FetchXmlBuilder/Controls/conditionControl.cs | 36 +++++++++++++++- .../Controls/conditionControl.resx | 3 ++ .../Controls/entityControl.Designer.cs | 20 ++++++++- FetchXmlBuilder/Controls/entityControl.cs | 33 +++++++++++++++ FetchXmlBuilder/Controls/entityControl.resx | 6 +++ .../Controls/linkEntityControl.Designer.cs | 8 ++++ FetchXmlBuilder/Controls/linkEntityControl.cs | 35 ++++++++++------ .../Controls/linkEntityControl.resx | 3 ++ .../Controls/orderControl.Designer.cs | 8 ++++ FetchXmlBuilder/Controls/orderControl.cs | 42 ++++++++++++------- FetchXmlBuilder/Controls/orderControl.resx | 3 ++ 16 files changed, 216 insertions(+), 43 deletions(-) diff --git a/FetchXmlBuilder/Controls/FetchXmlElementControlBase.cs b/FetchXmlBuilder/Controls/FetchXmlElementControlBase.cs index 9477ddee..5d64ca3e 100644 --- a/FetchXmlBuilder/Controls/FetchXmlElementControlBase.cs +++ b/FetchXmlBuilder/Controls/FetchXmlElementControlBase.cs @@ -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; @@ -15,6 +16,24 @@ public class FetchXmlElementControlBase : UserControl, IDefinitionSavable private Dictionary collec; private Dictionary 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 collection, FetchXmlBuilder fetchXmlBuilder, TreeBuilderControl tree, TreeNode node) { @@ -136,5 +155,7 @@ protected override bool ProcessKeyPreview(ref Message m) return base.ProcessKeyPreview(ref m); } + + } } diff --git a/FetchXmlBuilder/Controls/attributeControl.Designer.cs b/FetchXmlBuilder/Controls/attributeControl.Designer.cs index 698dd038..b1ab9bcc 100644 --- a/FetchXmlBuilder/Controls/attributeControl.Designer.cs +++ b/FetchXmlBuilder/Controls/attributeControl.Designer.cs @@ -41,7 +41,9 @@ private void InitializeComponent() this.chkUserTZ = new System.Windows.Forms.CheckBox(); this.chkDistinct = new System.Windows.Forms.CheckBox(); this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components); + this.warningProvider = new System.Windows.Forms.ErrorProvider(this.components); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).BeginInit(); this.SuspendLayout(); // // label2 @@ -195,6 +197,10 @@ private void InitializeComponent() // this.errorProvider.ContainerControl = this; // + // warningProvider + // + this.warningProvider.ContainerControl = this; + // // attributeControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -213,6 +219,7 @@ private void InitializeComponent() this.Name = "attributeControl"; this.Size = new System.Drawing.Size(293, 207); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -231,5 +238,6 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox chkUserTZ; private System.Windows.Forms.CheckBox chkDistinct; private System.Windows.Forms.ErrorProvider errorProvider; + private System.Windows.Forms.ErrorProvider warningProvider; } } diff --git a/FetchXmlBuilder/Controls/attributeControl.cs b/FetchXmlBuilder/Controls/attributeControl.cs index 1da720d2..3f688f1c 100644 --- a/FetchXmlBuilder/Controls/attributeControl.cs +++ b/FetchXmlBuilder/Controls/attributeControl.cs @@ -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 @@ -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() @@ -58,15 +60,6 @@ protected override bool ValidateControls(bool silent) 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)) { @@ -109,17 +102,16 @@ 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"); } } diff --git a/FetchXmlBuilder/Controls/attributeControl.resx b/FetchXmlBuilder/Controls/attributeControl.resx index 7a126f48..aa1202af 100644 --- a/FetchXmlBuilder/Controls/attributeControl.resx +++ b/FetchXmlBuilder/Controls/attributeControl.resx @@ -120,4 +120,7 @@ 17, 17 + + 140, 17 + \ No newline at end of file diff --git a/FetchXmlBuilder/Controls/conditionControl.Designer.cs b/FetchXmlBuilder/Controls/conditionControl.Designer.cs index 2de9a2cb..128c206e 100644 --- a/FetchXmlBuilder/Controls/conditionControl.Designer.cs +++ b/FetchXmlBuilder/Controls/conditionControl.Designer.cs @@ -40,7 +40,9 @@ private void InitializeComponent() this.cmbValue = new System.Windows.Forms.ComboBox(); this.lblValueHint = new System.Windows.Forms.Label(); this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components); + this.warningProvider = new System.Windows.Forms.ErrorProvider(this.components); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).BeginInit(); this.SuspendLayout(); // // label2 @@ -66,6 +68,7 @@ private void InitializeComponent() this.cmbAttribute.TabIndex = 2; this.cmbAttribute.Tag = "attribute|true"; this.cmbAttribute.SelectedIndexChanged += new System.EventHandler(this.cmbAttribute_SelectedIndexChanged); + this.cmbAttribute.Validating += new System.ComponentModel.CancelEventHandler(this.cmbAttribute_Validating); // // label4 // @@ -159,6 +162,7 @@ private void InitializeComponent() this.cmbOperator.TabIndex = 3; this.cmbOperator.Tag = "operator|true"; this.cmbOperator.SelectedIndexChanged += new System.EventHandler(this.cmbOperator_SelectedIndexChanged); + this.cmbOperator.Validating += new System.ComponentModel.CancelEventHandler(this.cmbOperator_Validating); // // label5 // @@ -233,6 +237,10 @@ private void InitializeComponent() // this.errorProvider.ContainerControl = this; // + // warningProvider + // + this.warningProvider.ContainerControl = this; + // // conditionControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -250,6 +258,7 @@ private void InitializeComponent() this.Name = "conditionControl"; this.Size = new System.Drawing.Size(311, 194); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -267,5 +276,6 @@ private void InitializeComponent() private System.Windows.Forms.ComboBox cmbValue; private System.Windows.Forms.Label lblValueHint; private System.Windows.Forms.ErrorProvider errorProvider; + private System.Windows.Forms.ErrorProvider warningProvider; } } diff --git a/FetchXmlBuilder/Controls/conditionControl.cs b/FetchXmlBuilder/Controls/conditionControl.cs index 29c86172..f3021fe4 100644 --- a/FetchXmlBuilder/Controls/conditionControl.cs +++ b/FetchXmlBuilder/Controls/conditionControl.cs @@ -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() @@ -90,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"; @@ -379,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 diff --git a/FetchXmlBuilder/Controls/conditionControl.resx b/FetchXmlBuilder/Controls/conditionControl.resx index 7a126f48..aa1202af 100644 --- a/FetchXmlBuilder/Controls/conditionControl.resx +++ b/FetchXmlBuilder/Controls/conditionControl.resx @@ -120,4 +120,7 @@ 17, 17 + + 140, 17 + \ No newline at end of file diff --git a/FetchXmlBuilder/Controls/entityControl.Designer.cs b/FetchXmlBuilder/Controls/entityControl.Designer.cs index 6d93a3bc..60d61fbe 100644 --- a/FetchXmlBuilder/Controls/entityControl.Designer.cs +++ b/FetchXmlBuilder/Controls/entityControl.Designer.cs @@ -28,8 +28,13 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.label2 = new System.Windows.Forms.Label(); this.cmbEntity = new System.Windows.Forms.ComboBox(); + this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components); + this.warningProvider = new System.Windows.Forms.ErrorProvider(this.components); + ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).BeginInit(); this.SuspendLayout(); // // label2 @@ -50,10 +55,19 @@ private void InitializeComponent() this.cmbEntity.FormattingEnabled = true; this.cmbEntity.Location = new System.Drawing.Point(7, 16); this.cmbEntity.Name = "cmbEntity"; - this.cmbEntity.Size = new System.Drawing.Size(204, 21); + this.cmbEntity.Size = new System.Drawing.Size(184, 21); this.cmbEntity.Sorted = true; this.cmbEntity.TabIndex = 27; this.cmbEntity.Tag = "name|true"; + this.cmbEntity.Validating += new System.ComponentModel.CancelEventHandler(this.cmbEntity_Validating); + // + // errorProvider + // + this.errorProvider.ContainerControl = this; + // + // warningProvider + // + this.warningProvider.ContainerControl = this; // // entityControl // @@ -63,6 +77,8 @@ private void InitializeComponent() this.Controls.Add(this.label2); this.Name = "entityControl"; this.Size = new System.Drawing.Size(214, 50); + ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -71,5 +87,7 @@ private void InitializeComponent() #endregion private System.Windows.Forms.Label label2; private System.Windows.Forms.ComboBox cmbEntity; + private System.Windows.Forms.ErrorProvider errorProvider; + private System.Windows.Forms.ErrorProvider warningProvider; } } diff --git a/FetchXmlBuilder/Controls/entityControl.cs b/FetchXmlBuilder/Controls/entityControl.cs index 02ad33da..93516078 100644 --- a/FetchXmlBuilder/Controls/entityControl.cs +++ b/FetchXmlBuilder/Controls/entityControl.cs @@ -17,6 +17,7 @@ public entityControl(Dictionary collection, FetchXmlBuilder fetc { InitializeComponent(); InitializeFXB(collection, fetchXmlBuilder, tree, null); + warningProvider.Icon = WarningIcon; } protected override void PopulateControls() @@ -31,5 +32,37 @@ protected override void PopulateControls() } } } + + protected override bool ValidateControls(bool silent) + { + var valid = base.ValidateControls(silent); + + if (string.IsNullOrWhiteSpace(cmbEntity.Text)) + { + valid = false; + + if (!silent) + { + errorProvider.SetError(cmbEntity, "Entity is requried"); + } + } + + return valid; + } + + private void cmbEntity_Validating(object sender, System.ComponentModel.CancelEventArgs e) + { + errorProvider.SetError(cmbEntity, null); + warningProvider.SetError(cmbEntity, null); + + if (string.IsNullOrWhiteSpace(cmbEntity.Text)) + { + errorProvider.SetError(cmbEntity, "Entity is required"); + } + else if (cmbEntity.SelectedIndex == -1) + { + warningProvider.SetError(cmbEntity, "Entity is not valid"); + } + } } } \ No newline at end of file diff --git a/FetchXmlBuilder/Controls/entityControl.resx b/FetchXmlBuilder/Controls/entityControl.resx index 29dcb1b3..aa1202af 100644 --- a/FetchXmlBuilder/Controls/entityControl.resx +++ b/FetchXmlBuilder/Controls/entityControl.resx @@ -117,4 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 140, 17 + \ No newline at end of file diff --git a/FetchXmlBuilder/Controls/linkEntityControl.Designer.cs b/FetchXmlBuilder/Controls/linkEntityControl.Designer.cs index 99943dfc..a592e486 100644 --- a/FetchXmlBuilder/Controls/linkEntityControl.Designer.cs +++ b/FetchXmlBuilder/Controls/linkEntityControl.Designer.cs @@ -44,7 +44,9 @@ private void InitializeComponent() this.label10 = new System.Windows.Forms.Label(); this.cmbRelationship = new System.Windows.Forms.ComboBox(); this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components); + this.warningProvider = new System.Windows.Forms.ErrorProvider(this.components); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).BeginInit(); this.SuspendLayout(); // // label2 @@ -217,6 +219,10 @@ private void InitializeComponent() // this.errorProvider.ContainerControl = this; // + // warningProvider + // + this.warningProvider.ContainerControl = this; + // // linkEntityControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -238,6 +244,7 @@ private void InitializeComponent() this.Name = "linkEntityControl"; this.Size = new System.Drawing.Size(247, 274); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -259,5 +266,6 @@ private void InitializeComponent() private System.Windows.Forms.Label label10; private System.Windows.Forms.ComboBox cmbRelationship; private System.Windows.Forms.ErrorProvider errorProvider; + private System.Windows.Forms.ErrorProvider warningProvider; } } diff --git a/FetchXmlBuilder/Controls/linkEntityControl.cs b/FetchXmlBuilder/Controls/linkEntityControl.cs index 528efe7e..94402c7a 100644 --- a/FetchXmlBuilder/Controls/linkEntityControl.cs +++ b/FetchXmlBuilder/Controls/linkEntityControl.cs @@ -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 @@ -20,6 +21,7 @@ public linkEntityControl(TreeNode node, FetchXmlBuilder fetchXmlBuilder, TreeBui { InitializeComponent(); InitializeFXB(null, fetchXmlBuilder, tree, node); + warningProvider.Icon = WarningIcon; } protected override void PopulateControls() @@ -245,7 +247,7 @@ protected override bool ValidateControls(bool silent) { var valid = base.ValidateControls(silent); - if (cmbEntity.SelectedIndex == -1) + if (string.IsNullOrWhiteSpace(cmbEntity.Text)) { if (!silent) { @@ -256,7 +258,7 @@ protected override bool ValidateControls(bool silent) } - if (cmbFrom.SelectedIndex == -1) + if (string.IsNullOrWhiteSpace(cmbFrom.Text)) { if (!silent) { @@ -266,7 +268,7 @@ protected override bool ValidateControls(bool silent) valid = false; } - if (cmbTo.SelectedIndex == -1) + if (string.IsNullOrWhiteSpace(cmbTo.Text)) { if (!silent) { @@ -281,37 +283,46 @@ protected override bool ValidateControls(bool silent) private void cmbEntity_Validating(object sender, System.ComponentModel.CancelEventArgs e) { - if (cmbEntity.SelectedIndex == -1) + errorProvider.SetError(cmbEntity, null); + warningProvider.SetError(cmbEntity, null); + + if (string.IsNullOrWhiteSpace(cmbEntity.Text)) { errorProvider.SetError(cmbEntity, "Entity is required"); } - else + else if (cmbEntity.SelectedIndex == -1) { - errorProvider.SetError(cmbEntity, null); + warningProvider.SetError(cmbEntity, "Entity is not valid"); } } private void cmbFrom_Validating(object sender, System.ComponentModel.CancelEventArgs e) { - if (cmbFrom.SelectedIndex == -1) + errorProvider.SetError(cmbFrom, null); + warningProvider.SetError(cmbFrom, null); + + if (string.IsNullOrWhiteSpace(cmbFrom.Text)) { errorProvider.SetError(cmbFrom, "From attribute is required"); } - else + else if (cmbFrom.SelectedIndex == -1) { - errorProvider.SetError(cmbFrom, null); + warningProvider.SetError(cmbFrom, "From attribute is not valid"); } } private void cmbTo_Validating(object sender, System.ComponentModel.CancelEventArgs e) { - if (cmbTo.SelectedIndex == -1) + errorProvider.SetError(cmbTo, null); + warningProvider.SetError(cmbTo, null); + + if (string.IsNullOrWhiteSpace(cmbTo.Text)) { errorProvider.SetError(cmbTo, "To attribute is required"); } - else + else if (cmbTo.SelectedIndex == -1) { - errorProvider.SetError(cmbTo, null); + warningProvider.SetError(cmbTo, "To attribute is not valid"); } } } diff --git a/FetchXmlBuilder/Controls/linkEntityControl.resx b/FetchXmlBuilder/Controls/linkEntityControl.resx index 7a126f48..aa1202af 100644 --- a/FetchXmlBuilder/Controls/linkEntityControl.resx +++ b/FetchXmlBuilder/Controls/linkEntityControl.resx @@ -120,4 +120,7 @@ 17, 17 + + 140, 17 + \ No newline at end of file diff --git a/FetchXmlBuilder/Controls/orderControl.Designer.cs b/FetchXmlBuilder/Controls/orderControl.Designer.cs index 79723211..97f56dee 100644 --- a/FetchXmlBuilder/Controls/orderControl.Designer.cs +++ b/FetchXmlBuilder/Controls/orderControl.Designer.cs @@ -35,7 +35,9 @@ private void InitializeComponent() this.chkDescending = new System.Windows.Forms.CheckBox(); this.cmbAlias = new System.Windows.Forms.ComboBox(); this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components); + this.warningProvider = new System.Windows.Forms.ErrorProvider(this.components); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).BeginInit(); this.SuspendLayout(); // // label2 @@ -101,6 +103,10 @@ private void InitializeComponent() // this.errorProvider.ContainerControl = this; // + // warningProvider + // + this.warningProvider.ContainerControl = this; + // // orderControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -113,6 +119,7 @@ private void InitializeComponent() this.Name = "orderControl"; this.Size = new System.Drawing.Size(224, 115); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.warningProvider)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -125,5 +132,6 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox chkDescending; private System.Windows.Forms.ComboBox cmbAlias; private System.Windows.Forms.ErrorProvider errorProvider; + private System.Windows.Forms.ErrorProvider warningProvider; } } diff --git a/FetchXmlBuilder/Controls/orderControl.cs b/FetchXmlBuilder/Controls/orderControl.cs index ca4fb811..6d6b55eb 100644 --- a/FetchXmlBuilder/Controls/orderControl.cs +++ b/FetchXmlBuilder/Controls/orderControl.cs @@ -2,6 +2,7 @@ using Cinteros.Xrm.FetchXmlBuilder.DockControls; using Microsoft.Xrm.Sdk.Metadata; using System.Collections.Generic; +using System.Drawing; using System.Windows.Forms; namespace Cinteros.Xrm.FetchXmlBuilder.Controls @@ -22,6 +23,7 @@ public orderControl(TreeNode node, AttributeMetadata[] attributes, TreeBuilderCo InitializeComponent(); InitializeFXB(null, null, tree, node); + warningProvider.Icon = WarningIcon; } protected override void PopulateControls() @@ -76,7 +78,7 @@ protected override bool ValidateControls(bool silent) { var valid = base.ValidateControls(silent); - if (cmbAttribute.Enabled && cmbAttribute.SelectedIndex == -1) + if (cmbAttribute.Enabled && string.IsNullOrWhiteSpace(cmbAttribute.Text)) { if (!silent) { @@ -86,7 +88,7 @@ protected override bool ValidateControls(bool silent) valid = false; } - if (cmbAlias.Enabled && cmbAlias.SelectedIndex == -1) + if (cmbAlias.Enabled && string.IsNullOrWhiteSpace(cmbAlias.Text)) { if (!silent) { @@ -101,25 +103,37 @@ protected override bool ValidateControls(bool silent) private void cmbAttribute_Validating(object sender, System.ComponentModel.CancelEventArgs e) { - if (cmbAttribute.Enabled && cmbAttribute.SelectedIndex == -1) - { - errorProvider.SetError(cmbAttribute, "Attribute is required"); - } - else + errorProvider.SetError(cmbAttribute, null); + warningProvider.SetError(cmbAttribute, null); + + if (cmbAttribute.Enabled) { - errorProvider.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 cmbAlias_Validating(object sender, System.ComponentModel.CancelEventArgs e) { - if (cmbAlias.Enabled && cmbAlias.SelectedIndex == -1) - { - errorProvider.SetError(cmbAlias, "Alias is required"); - } - else + errorProvider.SetError(cmbAlias, null); + warningProvider.SetError(cmbAlias, null); + + if (cmbAlias.Enabled) { - errorProvider.SetError(cmbAlias, null); + if (string.IsNullOrWhiteSpace(cmbAlias.Text)) + { + errorProvider.SetError(cmbAlias, "Alias is required"); + } + else if (cmbAlias.SelectedIndex == -1) + { + warningProvider.SetError(cmbAlias, "Alias is not valid"); + } } } } diff --git a/FetchXmlBuilder/Controls/orderControl.resx b/FetchXmlBuilder/Controls/orderControl.resx index 7a126f48..aa1202af 100644 --- a/FetchXmlBuilder/Controls/orderControl.resx +++ b/FetchXmlBuilder/Controls/orderControl.resx @@ -120,4 +120,7 @@ 17, 17 + + 140, 17 + \ No newline at end of file