1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Text;
|
---|
7 | using System.Windows.Forms;
|
---|
8 | using System.IO;
|
---|
9 | using System.Reflection;
|
---|
10 | using HeuristicLab.PluginInfrastructure;
|
---|
11 | using HeuristicLab.DataImporter.DbExplorer.Interfaces;
|
---|
12 | using HeuristicLab.DataImporter.Data;
|
---|
13 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
14 | using HeuristicLab.DataImporter.Data.Model;
|
---|
15 | using HeuristicLab.DataImporter.Data.View;
|
---|
16 | using HeuristicLab.DataImporter.DataProcessor.Command;
|
---|
17 | using System.Xml;
|
---|
18 | using HeuristicLab.Persistence.Default.Xml;
|
---|
19 |
|
---|
20 | namespace HeuristicLab.DataImporter.DataProcessor {
|
---|
21 | public partial class DataProcessorView : Form {
|
---|
22 | private DataSetView dataSetView;
|
---|
23 | private BackgroundWorker backgroundWorker;
|
---|
24 | private string lastSavedFile;
|
---|
25 | private ICommand lastSavedCommand;
|
---|
26 | private ProgressDialog progressDlg;
|
---|
27 |
|
---|
28 | private DataProcessorView() {
|
---|
29 | InitializeComponent();
|
---|
30 | this.HScroll = false;
|
---|
31 | this.HorizontalScroll.Visible = false;
|
---|
32 | backgroundWorker = new BackgroundWorker();
|
---|
33 | backgroundWorker.WorkerReportsProgress = true;
|
---|
34 | backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
|
---|
35 | backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
|
---|
36 | backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
|
---|
37 | }
|
---|
38 |
|
---|
39 | public DataProcessorView(DataProcessor dataProcessor)
|
---|
40 | : this() {
|
---|
41 | this.dataProcessor = dataProcessor;
|
---|
42 | this.dataProcessor.CommandChain.Changed += this.CommandChainChanged;
|
---|
43 | this.dataSetView = new DataSetView(this.dataProcessor.DataSet, this.dataProcessor.CommandChain);
|
---|
44 | this.dataSetView.StateChanged += new EventHandler(DataSetStateChanged);
|
---|
45 | this.dataSetView.Dock = DockStyle.Fill;
|
---|
46 | this.dataSetView.ColumnGroupMaxWidth = this.splitContainer1.Panel2.Width;
|
---|
47 | this.splitContainer1.Panel2.Controls.Add(this.dataSetView);
|
---|
48 | this.splitContainer1.Panel2.Resize += new EventHandler(Panel2_Resize);
|
---|
49 | FillItemList();
|
---|
50 |
|
---|
51 | IDbExplorer[] explorers = ApplicationManager.Manager.GetInstances<IDbExplorer>().ToArray();
|
---|
52 | ToolStripItem item;
|
---|
53 | foreach (IDbExplorer exp in explorers) {
|
---|
54 | item = new ToolStripMenuItem();
|
---|
55 | item.Text = exp.MenuItemDescription;
|
---|
56 | item.Tag = exp;
|
---|
57 | item.Click += new EventHandler(setGenericDBConnectionToolStripMenuItem_Click);
|
---|
58 | databaseToolStripMenuItem.DropDownItems.Add(item);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | private DataProcessor dataProcessor;
|
---|
63 | public DataProcessor DataProcessor {
|
---|
64 | get { return this.dataProcessor; }
|
---|
65 | }
|
---|
66 |
|
---|
67 | private bool UndoEnabled {
|
---|
68 | get { return this.undoToolStripButton.Enabled; }
|
---|
69 | set { this.undoToolStripButton.Enabled = value; this.undoToolStripMenuItem.Enabled = value; }
|
---|
70 | }
|
---|
71 | private bool RedoEnabled {
|
---|
72 | get { return this.redoToolStripButton.Enabled; }
|
---|
73 | set { this.redoToolStripButton.Enabled = value; this.redoToolStripMenuItem.Enabled = value; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | private bool SaveCommandChainEnabled {
|
---|
77 | get { return this.saveCommandChainToolStripButton.Enabled; }
|
---|
78 | set { this.saveCommandChainToolStripButton.Enabled = value; }
|
---|
79 | }
|
---|
80 |
|
---|
81 | #region CommandList
|
---|
82 |
|
---|
83 | private void listCommands_MouseDoubleClick(object sender, MouseEventArgs e) {
|
---|
84 | ListViewItem item = listCommands.HitTest(e.Location).Item;
|
---|
85 | if (item != null) {
|
---|
86 | ICommandGenerator generator = (ICommandGenerator)listCommands.FocusedItem;
|
---|
87 | if (generator.Enabled(dataSetView.State)) {
|
---|
88 | ICommand cmd = ((ICommandGenerator)generator).GenerateCommand(dataProcessor.DataSet);
|
---|
89 | if (cmd != null) {
|
---|
90 | try {
|
---|
91 | dataProcessor.CommandChain.Add(cmd);
|
---|
92 | }
|
---|
93 | catch (CommandExecutionException cee) {
|
---|
94 | MessageBox.Show(cee.Message, cee.Command.Description);
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | item.Selected = false;
|
---|
100 | }
|
---|
101 |
|
---|
102 | private void FillItemList() {
|
---|
103 | //sort after ViewableCommandInfoAttribute
|
---|
104 | IEnumerable<Type> commands = ApplicationManager.Manager.GetTypes(typeof(ICommand)).Select(t => new {
|
---|
105 | Command = t,
|
---|
106 | Attribute = (ViewableCommandInfoAttribute)Attribute.GetCustomAttribute(t, typeof(ViewableCommandInfoAttribute))
|
---|
107 | })
|
---|
108 | .Where(t => t.Attribute != null && !t.Command.IsAbstract)
|
---|
109 | .OrderBy(t => t.Attribute, new AttributeComparer())
|
---|
110 | .Select(t => t.Command);
|
---|
111 | ListViewItem item = null;
|
---|
112 | bool addGroup;
|
---|
113 | foreach (Type t in commands) {
|
---|
114 | item = (ListViewItem)Activator.CreateInstance(typeof(CommandListViewItem<>).MakeGenericType(t));
|
---|
115 | addGroup = true;
|
---|
116 | foreach (ListViewGroup grp in listCommands.Groups)
|
---|
117 | if (grp.Name == item.Group.Name) {
|
---|
118 | item.Group = grp;
|
---|
119 | addGroup = false;
|
---|
120 | break;
|
---|
121 | }
|
---|
122 | if (addGroup) {
|
---|
123 | listCommands.Groups.Add(item.Group);
|
---|
124 | }
|
---|
125 | listCommands.Items.Add(item);
|
---|
126 | }
|
---|
127 | UpdateListViewItems();
|
---|
128 | }
|
---|
129 |
|
---|
130 | public void DataSetStateChanged(object sender, EventArgs e) {
|
---|
131 | UpdateListViewItems();
|
---|
132 | }
|
---|
133 |
|
---|
134 | private void UpdateListViewItems() {
|
---|
135 | foreach (ICommandGenerator generator in listCommands.Items) {
|
---|
136 | if (generator.Enabled(dataSetView.State))
|
---|
137 | ((ListViewItem)generator).ForeColor = Color.Black;
|
---|
138 | else
|
---|
139 | ((ListViewItem)generator).ForeColor = Color.LightGray;
|
---|
140 | }
|
---|
141 | }
|
---|
142 | #endregion
|
---|
143 |
|
---|
144 | private void CommandChainChanged(object sender, EventArgs e) {
|
---|
145 | #region undo & redo updates
|
---|
146 | this.UndoEnabled = !this.dataProcessor.CommandChain.FirstCommandReached;
|
---|
147 | this.RedoEnabled = !this.dataProcessor.CommandChain.LastCommandReached;
|
---|
148 | this.SaveCommandChainEnabled = !this.dataProcessor.CommandChain.FirstCommandReached;
|
---|
149 | this.undoToolStripButton.ToolTipText = this.dataProcessor.CommandChain.PreviousCommandDescription;
|
---|
150 | this.redoToolStripButton.ToolTipText = this.dataProcessor.CommandChain.NextCommandDescription;
|
---|
151 |
|
---|
152 | //needed to update tooltip if it is currently being shown - taken from
|
---|
153 | //http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=167320
|
---|
154 | System.Reflection.FieldInfo f = this.toolStrip.GetType().GetField("currentlyActiveTooltipItem", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
---|
155 | if (object.ReferenceEquals(f.GetValue(this.toolStrip), this.undoToolStripButton)) {
|
---|
156 | // Need to set currentlyActiveTooltipItem to null, so the call to UpdateToolTip actually does the update
|
---|
157 | f.SetValue(this.toolStrip, null);
|
---|
158 | System.Reflection.MethodInfo m = this.toolStrip.GetType().GetMethod("UpdateToolTip", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
---|
159 | m.Invoke(this.toolStrip, new object[] { this.undoToolStripButton });
|
---|
160 | }
|
---|
161 | f = this.toolStrip.GetType().GetField("currentlyActiveTooltipItem", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
---|
162 | if (object.ReferenceEquals(f.GetValue(this.toolStrip), this.redoToolStripButton)) {
|
---|
163 | // Need to set currentlyActiveTooltipItem to null, so the call to UpdateToolTip actually does the update
|
---|
164 | f.SetValue(this.toolStrip, null);
|
---|
165 | System.Reflection.MethodInfo m = this.toolStrip.GetType().GetMethod("UpdateToolTip", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
---|
166 | m.Invoke(this.toolStrip, new object[] { this.redoToolStripButton });
|
---|
167 | }
|
---|
168 | #endregion
|
---|
169 |
|
---|
170 | #region macro recording
|
---|
171 | Bitmap image;
|
---|
172 | string toolTipText;
|
---|
173 | if (dataProcessor.CommandChain.IsMacroRecording) {
|
---|
174 | image = Properties.Resources.StopHS;
|
---|
175 | toolTipText = "Stop Macro recording";
|
---|
176 | } else {
|
---|
177 | image = Properties.Resources.RecordHS;
|
---|
178 | toolTipText = "Start Macro recording";
|
---|
179 | }
|
---|
180 |
|
---|
181 | recordMacroToolStripButton.Image = image;
|
---|
182 | recordMacroToolStripButton.ToolTipText = toolTipText;
|
---|
183 | f = this.toolStrip.GetType().GetField("currentlyActiveTooltipItem", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
---|
184 | if (object.ReferenceEquals(f.GetValue(this.toolStrip), this.recordMacroToolStripButton)) {
|
---|
185 | // Need to set currentlyActiveTooltipItem to null, so the call to UpdateToolTip actually does the update
|
---|
186 | f.SetValue(this.toolStrip, null);
|
---|
187 | System.Reflection.MethodInfo m = this.toolStrip.GetType().GetMethod("UpdateToolTip", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
---|
188 | m.Invoke(this.toolStrip, new object[] { this.recordMacroToolStripButton });
|
---|
189 | }
|
---|
190 | #endregion
|
---|
191 |
|
---|
192 | if (!string.IsNullOrEmpty(lastSavedFile)) {
|
---|
193 | if (lastSavedCommand != this.dataProcessor.CommandChain.LastExecutedCommand && !lastSavedFile.Contains('*'))
|
---|
194 | this.Text = "Data Importer - " + lastSavedFile + "*";
|
---|
195 | else
|
---|
196 | this.Text = "Data Importer - " + lastSavedFile;
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | private void chbReorderColumns_CheckedChanged(object sender, EventArgs e) {
|
---|
201 | this.dataSetView.AllowReorderColumns = chbReorder.CheckBoxControl.Checked;
|
---|
202 |
|
---|
203 | if (chbReorder.CheckBoxControl.Checked) {
|
---|
204 | foreach (ListViewItem item in listCommands.Items)
|
---|
205 | item.ForeColor = Color.LightGray;
|
---|
206 | listCommands.Enabled = false;
|
---|
207 | } else {
|
---|
208 | Dictionary<string, int[]> dictionary = new Dictionary<string, int[]>();
|
---|
209 | int[] displayIndices;
|
---|
210 | for (int i = this.dataSetView.Controls.Count - 1; i >= 0; i--) {
|
---|
211 | displayIndices = ((ColumnGroupView)this.dataSetView.Controls[i]).DisplayIndexes;
|
---|
212 | //check if displayIndices are ordered, otherwise the array is added to the list
|
---|
213 | for (int j = 0; j < displayIndices.Length; j++) {
|
---|
214 | if (j != 0 && ((displayIndices[j] - displayIndices[j - 1]) != 1)) {
|
---|
215 | ColumnGroup columnGroup = this.dataSetView.DataSet.ColumnGroups.ElementAt(this.dataSetView.Controls.Count - 1 - i);
|
---|
216 | dictionary[columnGroup.Name] = displayIndices;
|
---|
217 | break;
|
---|
218 | }
|
---|
219 | }
|
---|
220 | }
|
---|
221 | if (dictionary.Count != 0)
|
---|
222 | this.dataProcessor.CommandChain.Add(new ReorderColumnsCommand(this.dataProcessor.DataSet, dictionary));
|
---|
223 |
|
---|
224 | listCommands.Enabled = true;
|
---|
225 | UpdateListViewItems();
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | private void UpdateDataSetView() {
|
---|
230 | this.dataSetView.Dispose();
|
---|
231 | this.dataSetView = new DataSetView(this.dataProcessor.DataSet, this.dataProcessor.CommandChain);
|
---|
232 | this.dataSetView.StateChanged += new EventHandler(DataSetStateChanged);
|
---|
233 | UpdateListViewItems();
|
---|
234 |
|
---|
235 | this.dataSetView.Dock = DockStyle.Fill;
|
---|
236 | this.splitContainer1.Panel2.Controls.Clear();
|
---|
237 | this.splitContainer1.Panel2.Controls.Add(this.dataSetView);
|
---|
238 | this.dataSetView.ColumnGroupMaxWidth = this.splitContainer1.Panel2.Width;
|
---|
239 | this.dataProcessor.CommandChain.Changed += this.CommandChainChanged;
|
---|
240 | GC.Collect();
|
---|
241 | }
|
---|
242 |
|
---|
243 | private void Panel2_Resize(object sender, EventArgs e) {
|
---|
244 | this.dataSetView.ColumnGroupMaxWidth = this.splitContainer1.Panel2.Width;
|
---|
245 | }
|
---|
246 |
|
---|
247 |
|
---|
248 | #region BackgroundWorker
|
---|
249 | private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
250 | CommandChain temp = (CommandChain)e.Argument;
|
---|
251 | int i = 0;
|
---|
252 | int max = temp.CommandsCount;
|
---|
253 | foreach (DataSetCommandBase cmd in temp) {
|
---|
254 | //update description
|
---|
255 | backgroundWorker.ReportProgress(i * 100 / max, cmd.Description);
|
---|
256 | cmd.DataSet = dataProcessor.DataSet;
|
---|
257 | if (cmd is DatabaseCommandBase)
|
---|
258 | ((DatabaseCommandBase)cmd).DbExplorer = this.dataProcessor.DatabaseExplorer;
|
---|
259 | this.dataProcessor.CommandChain.Add(cmd, false);
|
---|
260 | i++;
|
---|
261 | }
|
---|
262 | }
|
---|
263 |
|
---|
264 | private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
265 | progressDlg.ProgressBar.Value = 100;
|
---|
266 | progressDlg.Refresh();
|
---|
267 | this.Enabled = true;
|
---|
268 | UpdateDataSetView();
|
---|
269 | progressDlg.Close();
|
---|
270 | if (e.Error != null) {
|
---|
271 | string message = e.Error.Message;
|
---|
272 | if (e.Error is CommandExecutionException)
|
---|
273 | message += Environment.NewLine + "Command: " +
|
---|
274 | ((CommandExecutionException)e.Error).Command.GetType().ToString();
|
---|
275 | MessageBox.Show(message, "Error occured during loading of command chain");
|
---|
276 | }
|
---|
277 | this.dataProcessor.CommandChain.FireChanged();
|
---|
278 | }
|
---|
279 |
|
---|
280 | private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
|
---|
281 | progressDlg.Label.Text = (string)e.UserState;
|
---|
282 | progressDlg.ProgressBar.Value = e.ProgressPercentage;
|
---|
283 | progressDlg.Refresh();
|
---|
284 | }
|
---|
285 | #endregion
|
---|
286 |
|
---|
287 | #region GUI actions
|
---|
288 | private void NewFile() {
|
---|
289 | if (!CheckUnsavedChanges())
|
---|
290 | return;
|
---|
291 | this.DataProcessor.Reset();
|
---|
292 | this.lastSavedFile = "";
|
---|
293 | this.Text = "Data Importer";
|
---|
294 | UpdateDataSetView();
|
---|
295 | }
|
---|
296 |
|
---|
297 | private void Open() {
|
---|
298 | if (!CheckUnsavedChanges())
|
---|
299 | return;
|
---|
300 | OpenFileDialog dlg = new OpenFileDialog();
|
---|
301 | dlg.Filter = "DataImporter file (*.dhl)|*.dhl|All files (*.*)|*.*";
|
---|
302 | dlg.RestoreDirectory = true;
|
---|
303 | if (dlg.ShowDialog() == DialogResult.OK) {
|
---|
304 | try {
|
---|
305 | DataProcessor dp = (DataProcessor)XmlParser.Deserialize(dlg.FileName);
|
---|
306 | dp.DatabaseExplorer = this.dataProcessor.DatabaseExplorer;
|
---|
307 | this.lastSavedFile = dlg.FileName;
|
---|
308 | this.Text = "Data Importer - " + lastSavedFile;
|
---|
309 | this.dataProcessor.Reset();
|
---|
310 | this.dataProcessor = dp;
|
---|
311 | }
|
---|
312 | catch (XmlException e) {
|
---|
313 | MessageBox.Show(e.Message, "Error occured during file open.");
|
---|
314 | }
|
---|
315 | finally {
|
---|
316 | this.lastSavedCommand = null;
|
---|
317 | UpdateDataSetView();
|
---|
318 | this.dataProcessor.CommandChain.FireChanged();
|
---|
319 | }
|
---|
320 | }
|
---|
321 | }
|
---|
322 |
|
---|
323 | private bool CheckUnsavedChanges() {
|
---|
324 | if (this.lastSavedCommand != this.dataProcessor.CommandChain.LastExecutedCommand) {
|
---|
325 | DialogResult result = MessageBox.Show("Save changes (Yes), discard changes (No) or cancel the current action (Cancel)?", "Warning", MessageBoxButtons.YesNoCancel);
|
---|
326 | if (result == DialogResult.Yes)
|
---|
327 | this.Save();
|
---|
328 | else if (result == DialogResult.Cancel)
|
---|
329 | return false;
|
---|
330 | }
|
---|
331 | return true;
|
---|
332 | }
|
---|
333 |
|
---|
334 | private void Save() {
|
---|
335 | if (string.IsNullOrEmpty(this.lastSavedFile))
|
---|
336 | this.SaveAs();
|
---|
337 | else
|
---|
338 | this.Save(this.lastSavedFile);
|
---|
339 | }
|
---|
340 |
|
---|
341 | private void Save(string filename) {
|
---|
342 | try {
|
---|
343 | this.Cursor = Cursors.WaitCursor;
|
---|
344 | XmlGenerator.Serialize(this.dataProcessor, filename,9);
|
---|
345 | this.Cursor = Cursors.Default;
|
---|
346 | this.Text = "Data Importer - " + lastSavedFile;
|
---|
347 | this.lastSavedCommand = this.dataProcessor.CommandChain.LastExecutedCommand;
|
---|
348 | }
|
---|
349 | finally {
|
---|
350 | this.Cursor = Cursors.Default;
|
---|
351 | }
|
---|
352 | }
|
---|
353 |
|
---|
354 | private void SaveAs() {
|
---|
355 | SaveFileDialog saveFileDialog = new SaveFileDialog();
|
---|
356 | saveFileDialog.AddExtension = true;
|
---|
357 | saveFileDialog.RestoreDirectory = true;
|
---|
358 | saveFileDialog.DefaultExt = "dhl";
|
---|
359 | saveFileDialog.Filter = "DataImporter file (*.dhl)|*.dhl|All files (*.*)|*.*";
|
---|
360 |
|
---|
361 | if (saveFileDialog.ShowDialog() == DialogResult.OK) {
|
---|
362 | this.lastSavedFile = saveFileDialog.FileName;
|
---|
363 | this.Save(this.lastSavedFile);
|
---|
364 | }
|
---|
365 | }
|
---|
366 |
|
---|
367 | private void RecordMacro() {
|
---|
368 | if (dataProcessor.CommandChain.IsMacroRecording)
|
---|
369 | this.SaveCommandChain();
|
---|
370 | this.dataProcessor.CommandChain.ToggleMacroRecording();
|
---|
371 | }
|
---|
372 |
|
---|
373 | private void OpenCommandChain() {
|
---|
374 | OpenFileDialog dlg = new OpenFileDialog();
|
---|
375 | dlg.Filter = "DataImporter Command file (*.dhlcmd)|*.dhlcmd|All files (*.*)|*.*";
|
---|
376 | dlg.RestoreDirectory = true;
|
---|
377 | if (dlg.ShowDialog() == DialogResult.OK) {
|
---|
378 | this.dataSetView.Dispose();
|
---|
379 | this.Cursor = Cursors.WaitCursor;
|
---|
380 | this.Enabled = false;
|
---|
381 | try {
|
---|
382 | CommandChain temp = (CommandChain)XmlParser.Deserialize(dlg.FileName);
|
---|
383 | progressDlg = new ProgressDialog();
|
---|
384 | progressDlg.DesktopLocation = new Point(this.Location.X + this.Width / 2 - progressDlg.Width / 2, this.Location.Y + this.Height / 2 - progressDlg.Height / 2);
|
---|
385 | backgroundWorker.RunWorkerAsync(temp);
|
---|
386 | progressDlg.ShowDialog();
|
---|
387 | this.Refresh();
|
---|
388 | }
|
---|
389 | finally {
|
---|
390 | this.Enabled = true;
|
---|
391 | this.Cursor = Cursors.Default;
|
---|
392 | }
|
---|
393 | }
|
---|
394 | }
|
---|
395 |
|
---|
396 | private void SaveCommandChain() {
|
---|
397 | SaveFileDialog saveFileDialog = new SaveFileDialog();
|
---|
398 | saveFileDialog.AddExtension = true;
|
---|
399 | saveFileDialog.RestoreDirectory = true;
|
---|
400 | saveFileDialog.DefaultExt = "dhlcmd";
|
---|
401 | saveFileDialog.Filter = "DataImporter Command file (*.dhlcmd)|*.dhlcmd|All files (*.*)|*.*";
|
---|
402 |
|
---|
403 | if (saveFileDialog.ShowDialog() == DialogResult.OK) {
|
---|
404 | try {
|
---|
405 | this.Cursor = Cursors.WaitCursor;
|
---|
406 | XmlGenerator.Serialize(this.dataProcessor.CommandChain, saveFileDialog.FileName,9);
|
---|
407 | }
|
---|
408 | finally {
|
---|
409 | this.Cursor = Cursors.Default;
|
---|
410 | }
|
---|
411 | }
|
---|
412 | }
|
---|
413 |
|
---|
414 | private void Export() {
|
---|
415 | ExportDialog exportDlg = new ExportDialog(this.dataProcessor.DataSet);
|
---|
416 | exportDlg.StartPosition = FormStartPosition.CenterParent;
|
---|
417 | exportDlg.ShowDialog(this);
|
---|
418 | }
|
---|
419 |
|
---|
420 | private void Import() {
|
---|
421 | ImportDialog importDlg = new ImportDialog(this.dataProcessor.DataSet, this.dataProcessor.CommandChain);
|
---|
422 | importDlg.StartPosition = FormStartPosition.CenterParent;
|
---|
423 | importDlg.ShowDialog(this);
|
---|
424 | }
|
---|
425 |
|
---|
426 | private void Undo() {
|
---|
427 | this.dataProcessor.CommandChain.Undo();
|
---|
428 | this.Focus();
|
---|
429 | }
|
---|
430 |
|
---|
431 | private void Redo() {
|
---|
432 | this.dataProcessor.CommandChain.Redo();
|
---|
433 | this.Focus();
|
---|
434 | }
|
---|
435 |
|
---|
436 | private void AddTables() {
|
---|
437 | if (dataProcessor.DatabaseExplorer == null || !dataProcessor.DatabaseExplorer.IsConnected) {
|
---|
438 | MessageBox.Show("Not connected to database!");
|
---|
439 | return;
|
---|
440 | }
|
---|
441 | DbTablesView tablesForm = new DbTablesView();
|
---|
442 | tablesForm.DbExplorer = dataProcessor.DatabaseExplorer;
|
---|
443 | tablesForm.SetTables(dataProcessor.DatabaseExplorer.AllTables);
|
---|
444 | tablesForm.StartPosition = FormStartPosition.CenterParent;
|
---|
445 | if (tablesForm.ShowDialog(this) == DialogResult.OK) {
|
---|
446 | progressDlg = new ProgressDialog();
|
---|
447 | progressDlg.Label.Text = "Loading data from database";
|
---|
448 | progressDlg.Show(this);
|
---|
449 | progressDlg.DesktopLocation = new Point(this.Location.X + this.Width / 2 - progressDlg.Width / 2, this.Location.Y + this.Height / 2 - progressDlg.Height / 2);
|
---|
450 | this.Refresh();
|
---|
451 | this.dataProcessor.CommandChain.Add(new LoadColumnGroupsFromDBCommand(this.dataProcessor.DataSet, this.dataProcessor.DatabaseExplorer,
|
---|
452 | tablesForm.SelectedTables));
|
---|
453 | progressDlg.Close();
|
---|
454 | }
|
---|
455 | }
|
---|
456 |
|
---|
457 | private void DatabaseExplorer_NewRowLoaded(object sender, ProgressChangedEventArgs e) {
|
---|
458 | progressDlg.ProgressBar.Value = e.ProgressPercentage;
|
---|
459 | progressDlg.Label.Text = (string)e.UserState;
|
---|
460 | progressDlg.Refresh();
|
---|
461 | }
|
---|
462 |
|
---|
463 | private void AddTablesWithSQLCommand() {
|
---|
464 | CommandViewDialog dlg = new CommandViewDialog();
|
---|
465 | dlg.StartPosition = FormStartPosition.CenterParent;
|
---|
466 | SqlCommandView cmdView = new SqlCommandView();
|
---|
467 | dlg.Panel.Controls.Add(cmdView);
|
---|
468 | dlg.Panel.Size = cmdView.Size;
|
---|
469 | dlg.ShowDialog(this);
|
---|
470 | if (dlg.DialogResult == DialogResult.OK) {
|
---|
471 | this.dataProcessor.CommandChain.Add(new LoadColumnGroupWithSqlStringFromDBCommand(this.dataProcessor.DataSet, this.dataProcessor.DatabaseExplorer, cmdView.SqlCommand));
|
---|
472 | }
|
---|
473 | }
|
---|
474 |
|
---|
475 | private void SetDbConnection() {
|
---|
476 | dataProcessor.DatabaseExplorer.ShowDbConnectionWizard();
|
---|
477 | if (dataProcessor.DatabaseExplorer.IsConnected) {
|
---|
478 | this.lblConnectionStatus.Text = "Successfully connected to database!";
|
---|
479 | this.lblConnectionStatus.BackColor = Color.LightGreen;
|
---|
480 | } else {
|
---|
481 | this.lblConnectionStatus.Text = "Not connected to database!";
|
---|
482 | this.lblConnectionStatus.BackColor = Color.FromArgb(255, 128, 128); //light red
|
---|
483 | }
|
---|
484 | }
|
---|
485 | #endregion
|
---|
486 |
|
---|
487 | #region GUI ClickEvents - menuitems, toolbarbuttons
|
---|
488 |
|
---|
489 | private void DataProcessorView_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
490 | if (!CheckUnsavedChanges())
|
---|
491 | e.Cancel = true;
|
---|
492 | }
|
---|
493 |
|
---|
494 | #region MenuItems
|
---|
495 | private void newToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
496 | this.NewFile();
|
---|
497 | }
|
---|
498 |
|
---|
499 | private void openToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
500 | this.Open();
|
---|
501 | }
|
---|
502 |
|
---|
503 | private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
504 | this.Save();
|
---|
505 | }
|
---|
506 |
|
---|
507 | private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
508 | this.SaveAs();
|
---|
509 | }
|
---|
510 |
|
---|
511 | private void importToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
512 | this.Import();
|
---|
513 | }
|
---|
514 |
|
---|
515 | private void exportToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
516 | this.Export();
|
---|
517 | }
|
---|
518 |
|
---|
519 | private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
520 | this.Close();
|
---|
521 | }
|
---|
522 |
|
---|
523 | private void undoToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
524 | this.Undo();
|
---|
525 | }
|
---|
526 |
|
---|
527 | private void redoToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
528 | this.Redo();
|
---|
529 | }
|
---|
530 |
|
---|
531 | private void addTablesToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
532 | this.AddTables();
|
---|
533 | }
|
---|
534 |
|
---|
535 | private void addTablesWithSqlStringToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
536 | this.AddTablesWithSQLCommand();
|
---|
537 | }
|
---|
538 |
|
---|
539 | private void setGenericDBConnectionToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
540 | this.dataProcessor.DatabaseExplorer = (IDbExplorer)((ToolStripMenuItem)sender).Tag;
|
---|
541 | this.dataProcessor.DatabaseExplorer.NewRowLoaded += new ProgressChangedEventHandler(DatabaseExplorer_NewRowLoaded);
|
---|
542 | this.SetDbConnection();
|
---|
543 | }
|
---|
544 | #endregion
|
---|
545 |
|
---|
546 | #region ToolbarButtons
|
---|
547 | private void newToolStripButton_Click(object sender, EventArgs e) {
|
---|
548 | this.NewFile();
|
---|
549 | }
|
---|
550 |
|
---|
551 | private void openToolStripButton_Click(object sender, EventArgs e) {
|
---|
552 | this.Open();
|
---|
553 | }
|
---|
554 |
|
---|
555 | private void saveToolStripButton_Click(object sender, EventArgs e) {
|
---|
556 | this.Save();
|
---|
557 | }
|
---|
558 |
|
---|
559 | private void recordMacroToolStripButton_Click(object sender, EventArgs e) {
|
---|
560 | this.RecordMacro();
|
---|
561 | }
|
---|
562 |
|
---|
563 | private void openCommandChainToolStripButton_Click(object sender, EventArgs e) {
|
---|
564 | this.OpenCommandChain();
|
---|
565 | }
|
---|
566 |
|
---|
567 | private void saveCommandChaingToolStripButton_Click(object sender, EventArgs e) {
|
---|
568 | this.SaveCommandChain();
|
---|
569 | }
|
---|
570 |
|
---|
571 | private void undoToolStripButton_Click(object sender, EventArgs e) {
|
---|
572 | this.Undo();
|
---|
573 | }
|
---|
574 |
|
---|
575 | private void redoToolStripButton_Click(object sender, EventArgs e) {
|
---|
576 | this.Redo();
|
---|
577 | }
|
---|
578 | #endregion
|
---|
579 | #endregion
|
---|
580 |
|
---|
581 | private class AttributeComparer : IComparer<ViewableCommandInfoAttribute> {
|
---|
582 | public int Compare(ViewableCommandInfoAttribute x, ViewableCommandInfoAttribute y) {
|
---|
583 | int cmpResult = x.GroupName.CompareTo(y.GroupName);
|
---|
584 | if (cmpResult != 0)
|
---|
585 | return cmpResult;
|
---|
586 | cmpResult = x.Position.CompareTo(y.Position);
|
---|
587 | if (cmpResult != 0)
|
---|
588 | return cmpResult;
|
---|
589 | return x.Name.CompareTo(y.Name);
|
---|
590 | }
|
---|
591 | }
|
---|
592 | }
|
---|
593 | }
|
---|