import homework for students

This commit is contained in:
Tim Young 2017-08-08 14:19:56 -05:00
parent 0acb89c429
commit e1515c7a4f
3 changed files with 98 additions and 2 deletions

View File

@ -1755,12 +1755,13 @@ namespace EduNetworkBuilder
} }
else if (extension == ".enbh") else if (extension == ".enbh")
{ {
if(NB.GetUser() == null) if(NB.GetUser() == null || CurrentUser == null)
{ {
MessageBox.Show(NB.Translate("NB_LoadUserFirst")); MessageBox.Show(NB.Translate("NB_LoadUserFirst"));
return; return;
} }
//Here we would load a homework file //Here we would load a homework file
CurrentUser.LoadHomeworkFile(filename);
} }
else else
{ {

View File

@ -239,6 +239,19 @@ namespace EduNetworkBuilder
return true; 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) public bool RegisterNewlySubmittedHW(SchoolworkClass ToCheck)
{ {
//Check to see if we already exist //Check to see if we already exist
@ -255,6 +268,65 @@ namespace EduNetworkBuilder
return true; 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<SchoolworkClass> 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"));
}
}
}
/// <summary> /// <summary>
/// Organize the projects into a nice project tree. /// Organize the projects into a nice project tree.
/// </summary> /// </summary>

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
using System.IO; using System.IO;
using System.Windows.Forms;
namespace EduNetworkBuilder namespace EduNetworkBuilder
{ {
@ -94,13 +95,35 @@ namespace EduNetworkBuilder
public void Load(string filename) public void Load(string filename)
{ {
XmlDocument xmlDoc = new XmlDocument(); XmlDocument xmlDoc = new XmlDocument();
if (File.Exists(filename)) if (File.Exists(filename))
{ {
xmlDoc.Load(filename); xmlDoc.Load(filename);
Load(xmlDoc); List<SchoolworkClass> results = Load(xmlDoc);
if (results.Count > 0) Clone(results[0], this);
} }
} }
public static List<SchoolworkClass> LoadMultiple(string filename)
{
XmlDocument xmlDoc = new XmlDocument();
List<SchoolworkClass> results = new List<SchoolworkClass>();
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<SchoolworkClass> Load(XmlNode TheNode) public static List<SchoolworkClass> Load(XmlNode TheNode)
{ {
SchoolworkClass currentOne = new SchoolworkClass(); SchoolworkClass currentOne = new SchoolworkClass();