Skip to content

Commit

Permalink
Chart Manager : Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
MscrmTools committed Jul 29, 2015
1 parent e1bddd0 commit 2d6bb10
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 398 deletions.
28 changes: 25 additions & 3 deletions Plugins/MsCrmTools.ChartManager/Forms/CustomFolderBrowserDialog.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using System;
using System.IO;
using System.Runtime.Serialization.Formatters;
using System.Windows.Forms;

namespace MsCrmTools.ChartManager.Forms
{
public partial class CustomFolderBrowserDialog : Form
{
public CustomFolderBrowserDialog()
private readonly bool isForLoad;

public CustomFolderBrowserDialog(bool isForLoad)
{
InitializeComponent();

this.isForLoad = isForLoad;
}

public string FolderPath { get; set; }
Expand All @@ -22,8 +27,25 @@ private void btnOk_Click(object sender, EventArgs e)
{
if (!Directory.Exists(txtFolderPath.Text))
{
MessageBox.Show(this, "Invalid folder specified!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
if (!isForLoad && MessageBox.Show(this, "This folder does not exist. Would you like to create it?", "Warning",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
== DialogResult.Yes)
{
try
{
Directory.CreateDirectory(txtFolderPath.Text);
}
catch (Exception error)
{
MessageBox.Show(this, error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show(this, "Folder does not exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;
}
}

FolderPath = txtFolderPath.Text;
Expand Down
5 changes: 2 additions & 3 deletions Plugins/MsCrmTools.ChartManager/MainControl.Designer.cs

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

26 changes: 14 additions & 12 deletions Plugins/MsCrmTools.ChartManager/MainControl.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Metadata;
using MsCrmTools.ChartManager.Forms;
using MsCrmTools.ChartManager.Helpers;
using XrmToolBox;
using XrmToolBox.Extensibility;
using XrmToolBox.Extensibility.Interfaces;

namespace MsCrmTools.ChartManager
{
public partial class MainControl : PluginControlBase, IHelpPlugin
{
private List<EntityMetadata> entitiesCache;
private ListViewItem[] listViewItemsCache;
private string currentFolder;

Expand Down Expand Up @@ -62,7 +59,6 @@ public void LoadEntities()
}
else
{
entitiesCache = (List<EntityMetadata>) e.Result;
lvEntities.Items.Clear();
var list = new List<ListViewItem>();
foreach (EntityMetadata emd in (List<EntityMetadata>)e.Result)
Expand All @@ -72,13 +68,14 @@ public void LoadEntities()
list.Add(item);
}
this.listViewItemsCache = list.ToArray();
listViewItemsCache = list.ToArray();
lvEntities.Items.AddRange(listViewItemsCache);
gbEntities.Enabled = true;
tsbImportCharts.Enabled = true;
tsbExportCharts.Enabled = true;
tsbEditChart.Enabled = true;
txtSearchEntity.Focus();
}
});
}
Expand Down Expand Up @@ -172,7 +169,7 @@ private void tsbExportCharts_Click(object sender, EventArgs e)
{
try
{
var cfbDialog = new CustomFolderBrowserDialog { FolderPath = currentFolder };
var cfbDialog = new CustomFolderBrowserDialog(false) { FolderPath = currentFolder };
if (cfbDialog.ShowDialog(ParentForm) == DialogResult.OK)
{
currentFolder = cfbDialog.FolderPath;
Expand All @@ -192,6 +189,12 @@ private void tsbExportCharts_Click(object sender, EventArgs e)

doc.Save(Path.Combine(cfbDialog.FolderPath, chart.GetAttributeValue<string>("name") + ".xml"));
}

if (MessageBox.Show(ParentForm, "Would you like to open destination folder?", "Question",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Process.Start(cfbDialog.FolderPath);
}
}
}
catch (Exception error)
Expand All @@ -207,12 +210,12 @@ private void importChartsFromFileToolStripMenuItem_Click(object sender, EventArg
{
if (ofd.ShowDialog(ParentForm) == DialogResult.OK)
{
ProcessFiles(new List<string> {ofd.FileName});
ExecuteMethod(ProcessFiles, new List<string> {ofd.FileName});
}
}
}

private void ProcessFiles(List<string> files)
public void ProcessFiles(List<string> files)
{
WorkAsync("Analyzing file(s)...",
evt =>
Expand Down Expand Up @@ -278,12 +281,11 @@ private void ProcessFiles(List<string> files)

private void importChartsFromFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
var cfbDialog = new CustomFolderBrowserDialog {FolderPath = currentFolder};
var cfbDialog = new CustomFolderBrowserDialog(true) {FolderPath = currentFolder};
if (cfbDialog.ShowDialog(ParentForm) == DialogResult.OK)
{
currentFolder = cfbDialog.FolderPath;

ProcessFiles(new DirectoryInfo(currentFolder).GetFiles("*.xml").Select(f=>f.FullName).ToList());
ExecuteMethod(ProcessFiles, new DirectoryInfo(currentFolder).GetFiles("*.xml").Select(f => f.FullName).ToList());
}
}

Expand Down
Loading

0 comments on commit 2d6bb10

Please sign in to comment.