diff --git a/EduNetworkBuilder/PersonClass.cs b/EduNetworkBuilder/PersonClass.cs index e6186a0..6329cba 100644 --- a/EduNetworkBuilder/PersonClass.cs +++ b/EduNetworkBuilder/PersonClass.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml; +using System.IO; namespace EduNetworkBuilder { @@ -32,7 +34,7 @@ namespace EduNetworkBuilder /// /// Used to determine if the user we are working with is the admin account. /// - public bool isAdmin { get; private set; } + public bool isAdmin { get; protected set; } /// /// EverCompletedPuzzles is a list of puzzles that they have completed once. /// @@ -40,12 +42,20 @@ namespace EduNetworkBuilder List Projects = new List(); + private PersonClass() + { } + public PersonClass(String User, bool MakeAdmin) { _UserName = User; isAdmin = MakeAdmin; } + public PersonClass(string Filename) + { + + } + public string Password(int index = 0) { if (Passwords.Count == 0) return ""; @@ -63,5 +73,105 @@ namespace EduNetworkBuilder for (int a = Passwords.Count - 1; a >= maxPWs; a--) Passwords.RemoveAt(a); //Remove all but the one password } + + #region Load and Save + //Load and save functions + public void Load() + { + Load(@"C:\Users\tyoung\Desktop\Test.enbx"); + } + + public void Load(string filename) + { + XmlDocument xmlDoc = new XmlDocument(); + if (File.Exists(filename)) + { + xmlDoc.Load(filename); + Load(xmlDoc, filename); + } + } + + public void Load(XmlNode TheNode, string Name) + { + foreach (XmlNode Individual in TheNode.ChildNodes) + { + XmlNodeType myNodetype = Individual.NodeType; + if (myNodetype == XmlNodeType.Element) + { + switch (Individual.Name.ToLower()) + { + case "username": + _UserName = Individual.InnerText; + break; + case "fullname": + FullName = Individual.InnerText; + break; + case "passwordhint": + PasswordHint = Individual.InnerText; + break; + case "altpassword": + AltPassword = Individual.InnerText; + break; + case "isadmin": + bool isadmin = false; + bool.TryParse(Individual.InnerText, out isadmin); + isAdmin = isadmin; + break; + case "password": + Passwords.Add(Individual.InnerText); + break; + case "project": + break; + } + } + } + } + + + public void Save() + { + Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.enbx")); + } + + public void Save(string filename) + { + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Indent = true; + settings.NewLineOnAttributes = true; + XmlWriter writer = XmlWriter.Create(filename, settings); + + //Now we write the file: + writer.WriteStartDocument(); + writer.WriteStartElement("EduNetworkBuilder"); + writer.WriteComment("This is a network file for EduNetworkBuilder."); + Save(writer); + writer.WriteEndElement(); + writer.WriteEndDocument(); + writer.Flush(); + writer.Close(); + } + + + public void Save(XmlWriter writer) + { + //Save the language name + //save the number of items + //Save all the items + writer.WriteStartElement("User"); + writer.WriteElementString("UserName", UserName); + writer.WriteElementString("FullName", FullName); + writer.WriteElementString("PasswordHint", PasswordHint); + writer.WriteElementString("AltPassword", AltPassword); + writer.WriteElementString("IsAdmin", isAdmin.ToString()); + foreach(string One in Passwords) + writer.WriteElementString("Password", One); + //Save all the devices + foreach (SchoolworkClass One in Projects) + { + //One.Save(writer); + } + writer.WriteEndElement(); + } + #endregion } } diff --git a/EduNetworkBuilder/PersonProfileForm.cs b/EduNetworkBuilder/PersonProfileForm.cs index aada252..ceefb71 100644 --- a/EduNetworkBuilder/PersonProfileForm.cs +++ b/EduNetworkBuilder/PersonProfileForm.cs @@ -63,10 +63,27 @@ namespace EduNetworkBuilder if (Dest[0] != '_') Dest = "_Teacher_" + Dest; //Make sure it begins with _ //Find a directory for it. CurrentUser = new PersonClass(Dest, true); //Make an admin person class + //Choose an initial folder for the file: + OpenFileDialog OFD = new OpenFileDialog(); + OFD.ValidateNames = false; + OFD.CheckFileExists = false; + OFD.CheckPathExists = true; + OFD.FileName = NB.Translate("PPF_SelectThisFolder"); + OFD.ShowDialog(); + Console.WriteLine(Path.GetDirectoryName(OFD.FileName)); } else if (CurrentUser == null) { //Try to load the file. Close form & give error if it fails + try + { + //Load in from the file + } + catch(Exception e) + { + CurrentUser = null; + Close(); //we did not succeed. Exit out + } } //Make sure we update any profile settings they change diff --git a/EduNetworkBuilder/Resources/languages/edustrings.resx b/EduNetworkBuilder/Resources/languages/edustrings.resx index 90e49b6..aab1836 100644 --- a/EduNetworkBuilder/Resources/languages/edustrings.resx +++ b/EduNetworkBuilder/Resources/languages/edustrings.resx @@ -1725,6 +1725,10 @@ Passwords did not match. Please try again. PPF_PassValidateMismatch = Passwords did not match. Please try again. + + Select This Folder + PPF_SelectThisFolder = Select This Folder + Classwork PPF_TabClasswork = Classwork