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();
mydialog.AddExtension = true;
mydialog.Filter = "EduNet File (*.enbx)|*.enbx";
mydialog.Filter = "EduNet File (*.enbx, *enbu)|*.enbx; *.enbu";
mydialog.Multiselect = false;
mydialog.ShowHelp = true;
if (LastPath != null && LastPath != "") mydialog.FileName = LastPath;
DialogResult result = mydialog.ShowDialog();
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"));
return;
@ -1386,10 +1387,7 @@ namespace EduNetworkBuilder
LastPath = mydialog.FileName;
if (!File.Exists(mydialog.FileName)) return;
PrepForLoad();
myNetwork.Load(mydialog.FileName);
UpdateMenu();
UpdateForm();
LoadInitialFile(mydialog.FileName);
}
private void reloadToolStripMenuItem_Click(object sender, EventArgs e)
@ -1644,6 +1642,34 @@ namespace EduNetworkBuilder
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)
{
if (OurSettings.MainWindowX != -1 && OurSettings.MainWindowY != -1)
@ -1669,20 +1695,14 @@ namespace EduNetworkBuilder
if (uri.IsFile)
{
PrepForLoad();
myNetwork.Load(uri.LocalPath);
UpdateMenu();
UpdateForm();
LoadInitialFile(uri.LocalPath);
}
}
if (InitialFileLoad != "") //This is set when we are installed by msi and we click a file
{
if (File.Exists(InitialFileLoad))
{
PrepForLoad();
myNetwork.Load(InitialFileLoad);
UpdateMenu();
UpdateForm();
LoadInitialFile(InitialFileLoad);
}
}
else

View File

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

View File

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

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.IO;
namespace EduNetworkBuilder
{
@ -43,6 +44,16 @@ namespace EduNetworkBuilder
#region Load and Save
//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)
{
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)
{
//Save the language name
//save the number of items
//Save all the items
writer.WriteStartElement("project");
writer.WriteStartElement("schoolwork");
writer.WriteElementString("Name", Name);
writer.WriteElementString("Description", Description);
writer.WriteElementString("Class", Class);