From e1515c7a4f332d5eb57baaf970f36ad1df1d21ea Mon Sep 17 00:00:00 2001 From: Tim Young Date: Tue, 8 Aug 2017 14:19:56 -0500 Subject: [PATCH] import homework for students --- EduNetworkBuilder/NetworkBuilder.cs | 3 +- EduNetworkBuilder/PersonClass.cs | 72 ++++++++++++++++++++++++++++ EduNetworkBuilder/SchoolworkClass.cs | 25 +++++++++- 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index 836a5b2..0ebd1fc 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -1755,12 +1755,13 @@ namespace EduNetworkBuilder } else if (extension == ".enbh") { - if(NB.GetUser() == null) + if(NB.GetUser() == null || CurrentUser == null) { MessageBox.Show(NB.Translate("NB_LoadUserFirst")); return; } //Here we would load a homework file + CurrentUser.LoadHomeworkFile(filename); } else { diff --git a/EduNetworkBuilder/PersonClass.cs b/EduNetworkBuilder/PersonClass.cs index f4063a7..c3e275a 100644 --- a/EduNetworkBuilder/PersonClass.cs +++ b/EduNetworkBuilder/PersonClass.cs @@ -239,6 +239,19 @@ namespace EduNetworkBuilder return true; } + public bool HasHomework(SchoolworkClass ToCheck, bool compare_ID) + { + //Check to see if we already exist + foreach (SchoolworkClass one in Projects) + { + if (compare_ID && one.ThisID == ToCheck.ThisID) + return true; + else if (!compare_ID && one.Name.ToLower() == ToCheck.Name.ToLower()) + return true; + } + return false; + } + public bool RegisterNewlySubmittedHW(SchoolworkClass ToCheck) { //Check to see if we already exist @@ -255,6 +268,65 @@ namespace EduNetworkBuilder return true; } + public void LoadHomeworkFile(string HomeworkFile) + { + if (!File.Exists(HomeworkFile)) return; //The file does not exist + if (! (Path.GetExtension(HomeworkFile).ToLower() == ".enbh")) return; //It is not a homework file + List WhatWeRead = SchoolworkClass.LoadMultiple(HomeworkFile); + if(WhatWeRead.Count > 0) //We have something to import + { + bool IsOK = true; + //Verify that all the homeworks are OK to load + foreach(SchoolworkClass one in WhatWeRead) + { + //if one is already submitted, reject it + if(one.IsSumbitted || one.IsGraded) + { + IsOK = false; + } + } + //Load them + if(IsOK) + { + int totalHW =0; + int Skipped = 0; + int imported = 0; + int replaced = 0; + foreach (SchoolworkClass one in WhatWeRead) + { + totalHW++; + if(isAdmin) + { + //we want to prompt what to do. + //Ask for each (import, skip, replace) + //Ask only for duplicates + // Determine it is duplicate by comparing ID + // Determine if it is duplicate by comparing name + //Never ask + // Automatically replace duplicates + // Automatically skip duplicates + // Import records but make a new ID for each puzzle + } + else + { + if(AddHomework(one)) + { + imported++; + } + else + { + Skipped++; + } + } + } + } + else + { + MessageBox.Show(NB.Translate("PC_AlreadySubmittedOrGraded")); + } + } + } + /// /// Organize the projects into a nice project tree. /// diff --git a/EduNetworkBuilder/SchoolworkClass.cs b/EduNetworkBuilder/SchoolworkClass.cs index 2f25214..6bc2cd3 100644 --- a/EduNetworkBuilder/SchoolworkClass.cs +++ b/EduNetworkBuilder/SchoolworkClass.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Xml; using System.IO; +using System.Windows.Forms; namespace EduNetworkBuilder { @@ -94,13 +95,35 @@ namespace EduNetworkBuilder public void Load(string filename) { XmlDocument xmlDoc = new XmlDocument(); + if (File.Exists(filename)) { xmlDoc.Load(filename); - Load(xmlDoc); + List results = Load(xmlDoc); + if (results.Count > 0) Clone(results[0], this); } } + public static List LoadMultiple(string filename) + { + XmlDocument xmlDoc = new XmlDocument(); + List results = new List(); + if (File.Exists(filename)) + { + try + { + xmlDoc.Load(filename); + } + catch (Exception e) + { + MessageBox.Show(e.ToString()); + return results; //return an empty list + } + results.AddRange(Load(xmlDoc)); + } + return results; + } + public static List Load(XmlNode TheNode) { SchoolworkClass currentOne = new SchoolworkClass();