Skip to content

Commit

Permalink
Feature/UI improvements (#4)
Browse files Browse the repository at this point in the history
* Changed (UI, Log Format, etc.).
* Added new Popup (Button - Add FetchXML) to add FetchXml directly inside the tool
* Added error log coloring
  • Loading branch information
AshotHambardzumyan authored Nov 7, 2022
1 parent 4406f04 commit 86d051e
Show file tree
Hide file tree
Showing 26 changed files with 1,629 additions and 318 deletions.
350 changes: 236 additions & 114 deletions DataMigrationUtility/DataMigrationUtilityControl.cs

Large diffs are not rendered by default.

401 changes: 283 additions & 118 deletions DataMigrationUtility/DataMigrationUtilityControl.designer.cs

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions DataMigrationUtility/DataMigrationUtilityControl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="CheckBox.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Edit.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Remove.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="fetchXmlDataBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="dataGridViewImageColumn1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABGdBTUEAALGPC/xhBQAAAMpJREFUSEvt
kkEOAUEQRfsKIg5j5RRiwdopCIfAjgu4A6ewcQkkdgTvt66kWXYXq3nJy8zUJL+qayY0JCZ4xkF8cmaO
z+QdR+iGhd9wm927nCSffK0CWJNTfKrAwrWSR3KDml51fZNi8vAhjlENVJMzLCbfue1ZVzVTXe+L+Z5c
9NHW4jJ5E/7BX8LlVAXQ32Lhel9FG1eosCOqiVu40UE7hVkdrl1337eRFtpJXCZf4AXzJlqX21r2qGmv
2FPBmwPucIn2azb8khBeej9bMttRkj8AAAAASUVORK5CYII=
</value>
</data>
<data name="dataGridViewImageColumn2.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAABGdBTUEAALGPC/xhBQAAAg5JREFUSEu1
1kuoTVEcx/FThAGRx5A8I2EihQETDMhzICOPkTkxMRATBndmpEShxICShAy8ZsjIKwy8Iu9CefP98lu1
uWffc87t+ten/Vt7r7XOOfvstc5ptFkTcRaf8DPHM5iAPqmBuAsn/4I3Odq+A693XEMxvmI1nPAxZuac
R9ue93q1v+Nrqx+m4yMc3Fsf4DzO163Oo9mg3jqHv2oIrv0Hg9GtFvSh2nqOZh+9U89QWxfRbFCnLqC2
9sJOD3EyWS9xuNKWbc+Xtv1fJDtPbW2GnfzSpiTrFkZU2hqJ25X2ZDxK3oTaWgI7vcUgfE/bwQOSC6+X
BfkDLsJvaS9GbblHlUmG42myW4lV9i4ns3wztp9gUrJ63NNcpWWiWbiS/BVWuefvfrf+nLd9GYuSP6M/
eizvv53X4FCy3AgfJPsJvV3l2kFsTL6JlnUCdt6Gncnyi76R7K48Klk7sDv5OFpW6bwfG5I1FpeSr2Nc
stbjaPIutKwysQtzfrKm4VSyL+ZOW67Nw9VkX7BlzYGdfWLGJMvzR5JPY26yRuNV8my0LB9dO/vsuzv7
tNheiLIjHEN5mvyVHJYsx7dVZbuYivvJK9GVfACrku9hRrKPeNtV1sdS+ONjXovtyXuwLtk/GCuSXS9t
1z44yHf2vpJfJ7sYy8L0esmOa7u2wkGd2oK2azmaTdLKMvxTjcYv+h87rN852tcAAAAASUVORK5CYII=
</value>
</data>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>34</value>
</metadata>
Expand Down
108 changes: 108 additions & 0 deletions DataMigrationUtility/Forms/Popup/Popup.Designer.cs

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

148 changes: 148 additions & 0 deletions DataMigrationUtility/Forms/Popup/Popup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.Xml;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

namespace XrmMigrationUtility.Forms.Popup
{
internal partial class Popup : Form
{
public bool IsEdit { get; set; }
public int EditIndex { get; set; }
public List<string> FetchXmls { get; private set; }
public TextBox TextBoxFetch { get; private set; }

private string _currentFetchXml;


public Popup()
{
InitializeComponent();
FetchXmls = new List<string>();
TextBoxFetch = textBoxFetch;
MinimumSize = new Size(350, 250);
}

private void BtnBrowseFile_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Title = "Select FetchXML File ";
openFileDialog.Filter = "XML File (*.xml)|*.xml";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(openFileDialog.FileName);
_currentFetchXml = xmlDoc.OuterXml;
textBoxFetch.Text = string.Empty;
}
try
{
if (openFileDialog.FileName != "")
{
int index = 0;
int startIndex = 0;
while (index >= 0)
{
index = _currentFetchXml.IndexOf(">", index);
if (index == -1)
{
break;
}
textBoxFetch.Text += _currentFetchXml.Substring(startIndex, ++index - startIndex);
textBoxFetch.Text += Environment.NewLine;
startIndex = index;
}
textBoxFetch.Text = textBoxFetch.Text.Remove(textBoxFetch.Text.Length - 2, 2);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}

private void BtnOk_Click(object sender, EventArgs e)
{
bool isValidXml = CheckXml();
if (isValidXml)
{
if (!IsEdit)
{
if (IsFetchDuplicate())
return;

FetchXmls.Add(_currentFetchXml);
}
else
{
if (FetchXmls[EditIndex] != _currentFetchXml)
{
if (IsFetchDuplicate())
return;
}
}
DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("FetchXML is not valid", "Invalid FetchXML", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private bool IsFetchDuplicate()
{
if (FetchXmls.Contains(textBoxFetch.Text))
{
MessageBox.Show("This FetchXML already exists. A duplicate FetchXML cannot be added.", "Duplicate FetchXML", MessageBoxButtons.OK, MessageBoxIcon.Error);
return true;
}
return false;
}

private bool CheckXml()
{
if (string.IsNullOrEmpty(textBoxFetch.Text)) return false;

string word = "</fetch>";
int index = textBoxFetch.Text.IndexOf(word);
int validFetchLength = index + word.Length;
string detail = textBoxFetch.Text.Trim();
string fetch = textBoxFetch.Text.Substring(0, validFetchLength);
string spaceInFetch = textBoxFetch.Text.Substring(validFetchLength, textBoxFetch.Text.Length - validFetchLength);

if (string.IsNullOrWhiteSpace(spaceInFetch))
{
textBoxFetch.Text = fetch;
}
if (!detail.StartsWith("<") && !detail.EndsWith(">")) return false;

XmlDocument xml = new XmlDocument();
try
{
xml.LoadXml(string.Format("<Root>{0}</Root>", detail));
}
catch (XmlException)
{
return false;
}

if (textBoxFetch.Text.Length > validFetchLength) return false;

_currentFetchXml = textBoxFetch.Text;

return true;
}

private void BtnCancel_Click(object sender, EventArgs e)
{
if (textBoxFetch.Text != null)
{
textBoxFetch.Text = string.Empty;
}
Close();
}
}
}
Loading

0 comments on commit 86d051e

Please sign in to comment.