More progress on loading / saving user

This commit is contained in:
Tim Young 2017-07-29 11:46:39 -05:00
parent 4415ca5944
commit 8d5ccdb159
4 changed files with 63 additions and 18 deletions

View File

@ -1372,13 +1372,14 @@ namespace EduNetworkBuilder
{ {
OpenFileDialog mydialog = new OpenFileDialog(); OpenFileDialog mydialog = new OpenFileDialog();
mydialog.AddExtension = true; mydialog.AddExtension = true;
mydialog.Filter = "EduNet File (*.enbx)|*.enbx"; mydialog.Filter = "EduNet File (*.enbx, *enbu)|*.enbx; *.enbu";
mydialog.Multiselect = false; mydialog.Multiselect = false;
mydialog.ShowHelp = true; mydialog.ShowHelp = true;
if (LastPath != null && LastPath != "") mydialog.FileName = LastPath; if (LastPath != null && LastPath != "") mydialog.FileName = LastPath;
DialogResult result = mydialog.ShowDialog(); DialogResult result = mydialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel) return; if (result == System.Windows.Forms.DialogResult.Cancel) return;
if(!Regex.IsMatch(mydialog.FileName,@"^.*.enbx$")) string extension = Path.GetExtension(mydialog.FileName).ToString();
if(extension != ".enbx" && extension != ".enbu")
{ {
MessageBox.Show(NB.Translate("_LoadErr")); MessageBox.Show(NB.Translate("_LoadErr"));
return; return;
@ -1386,10 +1387,7 @@ namespace EduNetworkBuilder
LastPath = mydialog.FileName; LastPath = mydialog.FileName;
if (!File.Exists(mydialog.FileName)) return; if (!File.Exists(mydialog.FileName)) return;
PrepForLoad(); LoadInitialFile(mydialog.FileName);
myNetwork.Load(mydialog.FileName);
UpdateMenu();
UpdateForm();
} }
private void reloadToolStripMenuItem_Click(object sender, EventArgs e) private void reloadToolStripMenuItem_Click(object sender, EventArgs e)
@ -1644,6 +1642,34 @@ namespace EduNetworkBuilder
UpdateForm(); UpdateForm();
} }
private void LoadInitialFile(string filename)
{
if (filename == "")
{
MessageBox.Show(NB.Translate("NB_InvalidFile"));
Close();
}
//If it is a network file
string extension = Path.GetExtension(filename).ToLower();
//MessageBox.Show(filename + " " +extension);
if (extension == ".enbx")
{
PrepForLoad();
myNetwork.Load(filename);
UpdateMenu();
UpdateForm();
} else if(extension == ".enbu")
{
CurrentUser = new PersonClass(filename);
UpdateMenu();
}
else
{
MessageBox.Show(NB.Translate("NB_InvalidFile"));
Close();
}
}
private void BuilderWindow_Load(object sender, EventArgs e) private void BuilderWindow_Load(object sender, EventArgs e)
{ {
if (OurSettings.MainWindowX != -1 && OurSettings.MainWindowY != -1) if (OurSettings.MainWindowX != -1 && OurSettings.MainWindowY != -1)
@ -1669,20 +1695,14 @@ namespace EduNetworkBuilder
if (uri.IsFile) if (uri.IsFile)
{ {
PrepForLoad(); LoadInitialFile(uri.LocalPath);
myNetwork.Load(uri.LocalPath);
UpdateMenu();
UpdateForm();
} }
} }
if (InitialFileLoad != "") //This is set when we are installed by msi and we click a file if (InitialFileLoad != "") //This is set when we are installed by msi and we click a file
{ {
if (File.Exists(InitialFileLoad)) if (File.Exists(InitialFileLoad))
{ {
PrepForLoad(); LoadInitialFile(InitialFileLoad);
myNetwork.Load(InitialFileLoad);
UpdateMenu();
UpdateForm();
} }
} }
else else

View File

@ -54,7 +54,7 @@ namespace EduNetworkBuilder
public PersonClass(string Filename) public PersonClass(string Filename)
{ {
Load(Filename);
} }
public string Password(int index = 0) public string Password(int index = 0)
@ -96,6 +96,11 @@ namespace EduNetworkBuilder
{ {
switch (Individual.Name.ToLower()) switch (Individual.Name.ToLower())
{ {
case "edunetworkbuilderuser":
case "edunetworkbuilder":
case "user":
Load(Individual, Name);
break;
case "username": case "username":
_UserName = Individual.InnerText; _UserName = Individual.InnerText;
break; break;
@ -126,7 +131,7 @@ namespace EduNetworkBuilder
public void Save() public void Save()
{ {
//Save to our pre-existing / pre-defined file //Save to our pre-existing / pre-defined file
string filename = Path.Combine(filepath, FileName); string filename = Path.Combine(filepath, FileName);
Save(filename); Save(filename);
} }
@ -139,7 +144,7 @@ namespace EduNetworkBuilder
//Now we write the file: //Now we write the file:
writer.WriteStartDocument(); writer.WriteStartDocument();
writer.WriteStartElement("EduNetworkBuilder"); writer.WriteStartElement("EduNetworkBuilderUser");
writer.WriteComment("This is a user file for EduNetworkBuilder."); writer.WriteComment("This is a user file for EduNetworkBuilder.");
Save(writer); Save(writer);
writer.WriteEndElement(); writer.WriteEndElement();

View File

@ -1745,4 +1745,8 @@
<value>Re-Enter that same password</value> <value>Re-Enter that same password</value>
<comment>PPF_VerifyPass = Re-Enter that same password</comment> <comment>PPF_VerifyPass = Re-Enter that same password</comment>
</data> </data>
<data name="NB_InvalidFile" xml:space="preserve">
<value>Cannot load invalid file.</value>
<comment>NB_InvalidFile = Cannot load invalid file.</comment>
</data>
</root> </root>

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
using System.IO;
namespace EduNetworkBuilder namespace EduNetworkBuilder
{ {
@ -43,6 +44,16 @@ namespace EduNetworkBuilder
#region Load and Save #region Load and Save
//Load and save functions //Load and save functions
public void Load(string filename)
{
XmlDocument xmlDoc = new XmlDocument();
if (File.Exists(filename))
{
xmlDoc.Load(filename);
Load(xmlDoc);
}
}
public void Load(XmlNode TheNode) public void Load(XmlNode TheNode)
{ {
foreach (XmlNode Individual in TheNode.ChildNodes) foreach (XmlNode Individual in TheNode.ChildNodes)
@ -82,13 +93,18 @@ namespace EduNetworkBuilder
} }
} }
public void Save(string filename)
{
//Save to our pre-existing / pre-defined file
Save(filename);
}
public void Save(XmlWriter writer) public void Save(XmlWriter writer)
{ {
//Save the language name //Save the language name
//save the number of items //save the number of items
//Save all the items //Save all the items
writer.WriteStartElement("project"); writer.WriteStartElement("schoolwork");
writer.WriteElementString("Name", Name); writer.WriteElementString("Name", Name);
writer.WriteElementString("Description", Description); writer.WriteElementString("Description", Description);
writer.WriteElementString("Class", Class); writer.WriteElementString("Class", Class);