Skip to content

Commit 86d051e

Browse files
Feature/UI improvements (#4)
* Changed (UI, Log Format, etc.). * Added new Popup (Button - Add FetchXML) to add FetchXml directly inside the tool * Added error log coloring
1 parent 4406f04 commit 86d051e

26 files changed

+1629
-318
lines changed

DataMigrationUtility/DataMigrationUtilityControl.cs

Lines changed: 236 additions & 114 deletions
Large diffs are not rendered by default.

DataMigrationUtility/DataMigrationUtilityControl.designer.cs

Lines changed: 283 additions & 118 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DataMigrationUtility/DataMigrationUtilityControl.resx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,42 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<metadata name="CheckBox.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
121+
<value>True</value>
122+
</metadata>
123+
<metadata name="Edit.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
124+
<value>True</value>
125+
</metadata>
126+
<metadata name="Remove.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
127+
<value>True</value>
128+
</metadata>
129+
<metadata name="fetchXmlDataBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
130+
<value>17, 17</value>
131+
</metadata>
132+
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
133+
<data name="dataGridViewImageColumn1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
134+
<value>
135+
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABGdBTUEAALGPC/xhBQAAAMpJREFUSEvt
136+
kkEOAUEQRfsKIg5j5RRiwdopCIfAjgu4A6ewcQkkdgTvt66kWXYXq3nJy8zUJL+qayY0JCZ4xkF8cmaO
137+
z+QdR+iGhd9wm927nCSffK0CWJNTfKrAwrWSR3KDml51fZNi8vAhjlENVJMzLCbfue1ZVzVTXe+L+Z5c
138+
9NHW4jJ5E/7BX8LlVAXQ32Lhel9FG1eosCOqiVu40UE7hVkdrl1337eRFtpJXCZf4AXzJlqX21r2qGmv
139+
2FPBmwPucIn2azb8khBeej9bMttRkj8AAAAASUVORK5CYII=
140+
</value>
141+
</data>
142+
<data name="dataGridViewImageColumn2.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
143+
<value>
144+
iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAABGdBTUEAALGPC/xhBQAAAg5JREFUSEu1
145+
1kuoTVEcx/FThAGRx5A8I2EihQETDMhzICOPkTkxMRATBndmpEShxICShAy8ZsjIKwy8Iu9CefP98lu1
146+
uWffc87t+ten/Vt7r7XOOfvstc5ptFkTcRaf8DPHM5iAPqmBuAsn/4I3Odq+A693XEMxvmI1nPAxZuac
147+
R9ue93q1v+Nrqx+m4yMc3Fsf4DzO163Oo9mg3jqHv2oIrv0Hg9GtFvSh2nqOZh+9U89QWxfRbFCnLqC2
148+
9sJOD3EyWS9xuNKWbc+Xtv1fJDtPbW2GnfzSpiTrFkZU2hqJ25X2ZDxK3oTaWgI7vcUgfE/bwQOSC6+X
149+
BfkDLsJvaS9GbblHlUmG42myW4lV9i4ns3wztp9gUrJ63NNcpWWiWbiS/BVWuefvfrf+nLd9GYuSP6M/
150+
eizvv53X4FCy3AgfJPsJvV3l2kFsTL6JlnUCdt6Gncnyi76R7K48Klk7sDv5OFpW6bwfG5I1FpeSr2Nc
151+
stbjaPIutKwysQtzfrKm4VSyL+ZOW67Nw9VkX7BlzYGdfWLGJMvzR5JPY26yRuNV8my0LB9dO/vsuzv7
152+
tNheiLIjHEN5mvyVHJYsx7dVZbuYivvJK9GVfACrku9hRrKPeNtV1sdS+ONjXovtyXuwLtk/GCuSXS9t
153+
1z44yHf2vpJfJ7sYy8L0esmOa7u2wkGd2oK2azmaTdLKMvxTjcYv+h87rN852tcAAAAASUVORK5CYII=
154+
</value>
155+
</data>
120156
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
121157
<value>34</value>
122158
</metadata>

DataMigrationUtility/Forms/Popup/Popup.Designer.cs

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
using System;
2+
using System.Xml;
3+
using System.Drawing;
4+
using System.Windows.Forms;
5+
using System.Collections.Generic;
6+
7+
namespace XrmMigrationUtility.Forms.Popup
8+
{
9+
internal partial class Popup : Form
10+
{
11+
public bool IsEdit { get; set; }
12+
public int EditIndex { get; set; }
13+
public List<string> FetchXmls { get; private set; }
14+
public TextBox TextBoxFetch { get; private set; }
15+
16+
private string _currentFetchXml;
17+
18+
19+
public Popup()
20+
{
21+
InitializeComponent();
22+
FetchXmls = new List<string>();
23+
TextBoxFetch = textBoxFetch;
24+
MinimumSize = new Size(350, 250);
25+
}
26+
27+
private void BtnBrowseFile_Click(object sender, EventArgs e)
28+
{
29+
using (OpenFileDialog openFileDialog = new OpenFileDialog())
30+
{
31+
openFileDialog.Title = "Select FetchXML File ";
32+
openFileDialog.Filter = "XML File (*.xml)|*.xml";
33+
if (openFileDialog.ShowDialog() == DialogResult.OK)
34+
{
35+
XmlDocument xmlDoc = new XmlDocument();
36+
xmlDoc.Load(openFileDialog.FileName);
37+
_currentFetchXml = xmlDoc.OuterXml;
38+
textBoxFetch.Text = string.Empty;
39+
}
40+
try
41+
{
42+
if (openFileDialog.FileName != "")
43+
{
44+
int index = 0;
45+
int startIndex = 0;
46+
while (index >= 0)
47+
{
48+
index = _currentFetchXml.IndexOf(">", index);
49+
if (index == -1)
50+
{
51+
break;
52+
}
53+
textBoxFetch.Text += _currentFetchXml.Substring(startIndex, ++index - startIndex);
54+
textBoxFetch.Text += Environment.NewLine;
55+
startIndex = index;
56+
}
57+
textBoxFetch.Text = textBoxFetch.Text.Remove(textBoxFetch.Text.Length - 2, 2);
58+
}
59+
}
60+
catch (Exception ex)
61+
{
62+
MessageBox.Show(ex.Message);
63+
}
64+
}
65+
}
66+
67+
private void BtnOk_Click(object sender, EventArgs e)
68+
{
69+
bool isValidXml = CheckXml();
70+
if (isValidXml)
71+
{
72+
if (!IsEdit)
73+
{
74+
if (IsFetchDuplicate())
75+
return;
76+
77+
FetchXmls.Add(_currentFetchXml);
78+
}
79+
else
80+
{
81+
if (FetchXmls[EditIndex] != _currentFetchXml)
82+
{
83+
if (IsFetchDuplicate())
84+
return;
85+
}
86+
}
87+
DialogResult = DialogResult.OK;
88+
}
89+
else
90+
{
91+
MessageBox.Show("FetchXML is not valid", "Invalid FetchXML", MessageBoxButtons.OK, MessageBoxIcon.Error);
92+
}
93+
}
94+
95+
private bool IsFetchDuplicate()
96+
{
97+
if (FetchXmls.Contains(textBoxFetch.Text))
98+
{
99+
MessageBox.Show("This FetchXML already exists. A duplicate FetchXML cannot be added.", "Duplicate FetchXML", MessageBoxButtons.OK, MessageBoxIcon.Error);
100+
return true;
101+
}
102+
return false;
103+
}
104+
105+
private bool CheckXml()
106+
{
107+
if (string.IsNullOrEmpty(textBoxFetch.Text)) return false;
108+
109+
string word = "</fetch>";
110+
int index = textBoxFetch.Text.IndexOf(word);
111+
int validFetchLength = index + word.Length;
112+
string detail = textBoxFetch.Text.Trim();
113+
string fetch = textBoxFetch.Text.Substring(0, validFetchLength);
114+
string spaceInFetch = textBoxFetch.Text.Substring(validFetchLength, textBoxFetch.Text.Length - validFetchLength);
115+
116+
if (string.IsNullOrWhiteSpace(spaceInFetch))
117+
{
118+
textBoxFetch.Text = fetch;
119+
}
120+
if (!detail.StartsWith("<") && !detail.EndsWith(">")) return false;
121+
122+
XmlDocument xml = new XmlDocument();
123+
try
124+
{
125+
xml.LoadXml(string.Format("<Root>{0}</Root>", detail));
126+
}
127+
catch (XmlException)
128+
{
129+
return false;
130+
}
131+
132+
if (textBoxFetch.Text.Length > validFetchLength) return false;
133+
134+
_currentFetchXml = textBoxFetch.Text;
135+
136+
return true;
137+
}
138+
139+
private void BtnCancel_Click(object sender, EventArgs e)
140+
{
141+
if (textBoxFetch.Text != null)
142+
{
143+
textBoxFetch.Text = string.Empty;
144+
}
145+
Close();
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)