Work on treeview and adding unique ID to each schoolwork item

This commit is contained in:
Tim Young 2017-07-31 11:27:25 -05:00
parent 3bed5e7210
commit 258e7a5a6c
4 changed files with 60 additions and 4 deletions

View File

@ -292,7 +292,7 @@ namespace EduNetworkBuilder
}
class NB
static class NB
{
public static string BroadcastMACString = "FF:FF:FF:FF:FF:FF"; //The broadcast MAC address
@ -877,5 +877,25 @@ namespace EduNetworkBuilder
return randomizedList;
}
public static List<TreeNode> GetAllNodes(this TreeView _self)
{
List<TreeNode> result = new List<TreeNode>();
foreach (TreeNode child in _self.Nodes)
{
result.AddRange(child.GetAllNodes());
}
return result;
}
public static List<TreeNode> GetAllNodes(this TreeNode _self)
{
List<TreeNode> result = new List<TreeNode>();
result.Add(_self);
foreach (TreeNode child in _self.Nodes)
{
result.AddRange(child.GetAllNodes());
}
return result;
}
}
}

View File

@ -28,6 +28,7 @@ namespace EduNetworkBuilder
public int MainWindowWidth = -1;
public int MainWindowHeight = -1;
public string ProcessingLevel = "none";
protected UInt32 NextID = 100;
public NBSettings()
{
@ -140,6 +141,11 @@ namespace EduNetworkBuilder
Save(NB.IsRunningOnMono());
}
public UInt64 IssueID()
{
//return the id and increment it.
return NextID++;
}
public void Save(bool UsingMono)
{
if(UsingMono)

View File

@ -124,10 +124,30 @@ namespace EduNetworkBuilder
{
if (CurrentUser == null) return CurrentUser;
BuilderWindow BW = NB.GetBuilderWin();
SchoolworkClass NewWork = new SchoolworkClass(ToAdd);
SchoolworkClass NewWork = new SchoolworkClass(ToAdd, CurrentUser);
CurrentUser.Projects.Add(NewWork);
UpdateFormFromUser(); //make sure we list the right homeworks.
ChangeTreeDataTab(TreeDataTab.homeworktab);
tvClasswork.ExpandAll();
tvClasswork.Update();
//Now we want to select the item.
foreach(TreeNode TN in tvClasswork.GetAllNodes())
{
TN.ExpandAll(); //Expand everything until we get to what we need.
if(TN.Tag is SchoolworkClass)
{
SchoolworkClass Check = (SchoolworkClass)TN.Tag;
if(Check == NewWork)
{
tvClasswork.SelectedNode = TN;
break;
}
}
}
if (BW != null)
{
BW.Hide();
@ -297,5 +317,6 @@ namespace EduNetworkBuilder
if (ViewedSchoolwork.DueDate < dtpHWDue.MinDate) ViewedSchoolwork.DueDate = dtpHWDue.MinDate;
dtpHWDue.Value = ViewedSchoolwork.DueDate;
}
}
}

View File

@ -36,14 +36,17 @@ namespace EduNetworkBuilder
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)
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;
@ -72,6 +75,11 @@ namespace EduNetworkBuilder
{
switch (Individual.Name.ToLower())
{
case "id":
UInt64 tID;
UInt64.TryParse(Individual.InnerText, out tID);
ThisID = tID;
break;
case "name":
Name = Individual.InnerText;
break;
@ -114,6 +122,7 @@ namespace EduNetworkBuilder
//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);