EduNetworkBuilder/EduNetworkBuilder/SchoolworkClass.cs

139 lines
5.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.IO;
namespace EduNetworkBuilder
{
/// <summary>
/// A class holding a project that needs to be done as either a test, quiz, or homework
/// </summary>
public class SchoolworkClass
{
public Network theProject = null;
/// <summary>
/// The name of the project. Homework3, Quiz 4, etc.
/// </summary>
public string Name = "";
/// <summary>
/// The short description of the project.
/// </summary>
public string Description = "";
/// <summary>
/// The class to which this project belongs. If the student is using this for multiple classes,
/// but more likely just for the teacher to organize things with.
/// </summary>
public string Class = "";
/// <summary>
/// The date / time that the project is due.
/// </summary>
public DateTime DueDate;
public bool isMaster = false; //Is this the original project? If so, we never replace it.
public bool IsSumbitted = false; //Is the student submitting this? If so, date-stamp it and lock it.
public DateTime SaveDate; //The date this file was saved.
public UInt64 ThisID { get; protected set; }
public SchoolworkClass(XmlNode TheNode)
{
Load(TheNode);
}
public SchoolworkClass(Network ToAdd, PersonClass WhoFor)
{
if(WhoFor != null && WhoFor.UserSettings != null)
ThisID = WhoFor.UserSettings.IssueID();
theProject = ToAdd.Clone();
Name = theProject.PuzzleName;
Description = theProject.PuzzleName;
isMaster = true;
}
#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)
{
XmlNodeType myNodetype = Individual.NodeType;
if (myNodetype == XmlNodeType.Element)
{
switch (Individual.Name.ToLower())
{
case "id":
UInt64 tID;
UInt64.TryParse(Individual.InnerText, out tID);
ThisID = tID;
break;
case "name":
Name = Individual.InnerText;
break;
case "description":
Description = Individual.InnerText;
break;
case "class":
Class = Individual.InnerText;
break;
case "duedate":
DateTime.TryParse(Individual.InnerText, out DueDate);
break;
case "savedate":
DateTime.TryParse(Individual.InnerText, out SaveDate);
break;
case "ismaster":
bool.TryParse(Individual.InnerText, out isMaster);
break;
case "issubmitted":
bool.TryParse(Individual.InnerText, out IsSumbitted);
break;
case "network":
theProject = new Network();
theProject.Load(Individual, "",false,true);
break;
}
}
}
}
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("schoolwork");
writer.WriteElementString("ID", ThisID.ToString());
writer.WriteElementString("Name", Name);
writer.WriteElementString("Description", Description);
writer.WriteElementString("Class", Class);
writer.WriteElementString("DueDate", DueDate.ToString());
writer.WriteElementString("SaveDate", SaveDate.ToString());
writer.WriteElementString("IsMaster", isMaster.ToString());
writer.WriteElementString("IsSubmitted", IsSumbitted.ToString());
if (theProject != null) theProject.Save(writer);
writer.WriteEndElement();
}
#endregion
}
}