Skip to content

Commit

Permalink
Added #35 & #36, Fixed #28 & #37
Browse files Browse the repository at this point in the history
  • Loading branch information
MERZAK-X committed May 19, 2020
1 parent 1715c16 commit 94eeb7d
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 333 deletions.
3 changes: 3 additions & 0 deletions XML-GUI/XML-GUI.Designer.cs

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

20 changes: 11 additions & 9 deletions XML-GUI/XML-GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void loadXmlFile(Stream xmlDoc)
: XmlUtils.getSpreadSheetData(openedDocument as FileStream).Tables[0]; // else if (xlsx|xls|csv)
enableCtrl(true);
// TODO: implement by Excel Sheets full support.
//currentOpenXmlPath = openFileDialog.FileName; // Set the currentOpenPath variable to be used later for saving
currentOpenXmlPath = (Path.GetExtension(openFileDialog.FileName)?.ToLower() == ".xml") ? openFileDialog.FileName : String.Empty;
this.Text = Resources.XmlGUI_title_ + '[' + openFileDialog.SafeFileName +']'; // Change the Forms title to currentOpenDoc #10
}
catch (Exception)
Expand All @@ -95,7 +95,7 @@ private void loadXmlFile(Stream xmlDoc)
}

} else {
MessageBox.Show(Resources.XmlGUI_DragDrop_wrongExt_msg, Resources.XMLGUI__fail, MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show(Resources.XmlGUI_OpenDoc_fail_msg, Resources.XMLGUI__fail, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
Expand Down Expand Up @@ -404,25 +404,27 @@ private void xmlDataGrid_DragDrop(object sender, DragEventArgs e)
{
var droppedDocumentPath = (string[]) e.Data.GetData(DataFormats.FileDrop, false);
if (droppedDocumentPath.Length > 1) MessageBox.Show(Resources.XmlGUI_DragDrop_many_msg, Resources.XMLGUI__warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
if(Path.GetExtension(droppedDocumentPath[0]).ToLower() == ".xml"){
Stream xmlDoc = null;
if(Regex.IsMatch(Path.GetExtension(droppedDocumentPath[0])?.ToLower(), @"^.*\.(xml|xlsx|xls|csv)$")){
FileStream droppedDocument = null;
try
{
// Load the contents of the file into xmlDataGrid
xmlDoc = new FileStream(droppedDocumentPath[0], FileMode.Open, FileAccess.Read); // [0] => the first selected file
loadXmlFile(xmlDoc);
droppedDocument = new FileStream(droppedDocumentPath[0], FileMode.Open, FileAccess.Read); // [0] => the first selected file
xmlDataGrid.DataSource = (Path.GetExtension(droppedDocumentPath[0])?.ToLower() == ".xml")
? XmlUtils.getXmlData(droppedDocument).Tables[0] // if it's an xml document
: XmlUtils.getSpreadSheetData(droppedDocument).Tables[0]; // else if (xlsx|xls|csv)
enableCtrl(true);
currentOpenXmlPath = droppedDocumentPath[0]; // Set the currentOpenPath variable to be used later for saving
currentOpenXmlPath = (Path.GetExtension(droppedDocumentPath[0])?.ToLower() == ".xml") ? droppedDocumentPath[0] : String.Empty; // Set the currentOpenPath variable to be used later for saving
this.Text = Resources.XmlGUI_title_ + '[' + Path.GetFileName(droppedDocumentPath[0]) +']'; // Change the Forms title to currentOpenDoc #10
}
catch (Exception)
{
MessageBox.Show(Resources.XmlGUI_OpenXmlDoc_fail_msg, Resources.XMLGUI__fail, MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(Resources.XmlGUI_OpenDoc_fail_msg, Resources.XMLGUI__fail, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
// Fixes #29 file lock issue
xmlDoc?.Close();
droppedDocument?.Close();
}
} else {
MessageBox.Show(Resources.XmlGUI_DragDrop_wrongExt_msg, Resources.XMLGUI__warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
Expand Down
Binary file modified XML-GUI/bin/Release/XML_GUI.exe
Binary file not shown.
Binary file modified XML-GUI/bin/Release/XML_GUI.pdb
Binary file not shown.
Binary file modified XML-GUI/obj/Release/XML_GUI.exe
Binary file not shown.
Binary file modified XML-GUI/obj/Release/XML_GUI.pdb
Binary file not shown.
Loading

0 comments on commit 94eeb7d

Please sign in to comment.