prep for admin loading in one student file

This commit is contained in:
Tim Young 2017-08-12 16:05:54 -05:00
parent cff1dada9c
commit 392c8c8b35
3 changed files with 88 additions and 45 deletions

View File

@ -1751,6 +1751,8 @@ namespace EduNetworkBuilder
MessageBox.Show(NB.Translate("NB_LogOutFirst")); MessageBox.Show(NB.Translate("NB_LogOutFirst"));
return; return;
} }
if (CurrentUser == null)
{ //Load a starting, or a new user
int counter = 0; int counter = 0;
PersonClass tUser = null; PersonClass tUser = null;
while (counter < 3) while (counter < 3)
@ -1780,6 +1782,15 @@ namespace EduNetworkBuilder
CurrentUser = PPF.Edit(); //This does the form as dialog. When we come back, update the menu. CurrentUser = PPF.Edit(); //This does the form as dialog. When we come back, update the menu.
UpdateMenu(); UpdateMenu();
} }
else if(CurrentUser != null && CurrentUser.isAdmin)
{
//We want to import the student information for this one student
//Dig up the corresponding user.
//Use the alt password for that user to load the file
//import their settings
//messagebox to show what we are doing
}
}
else if (extension == ".enbh") else if (extension == ".enbh")
{ {
if(NB.GetUser() == null || CurrentUser == null) if(NB.GetUser() == null || CurrentUser == null)

View File

@ -573,5 +573,52 @@ namespace EduNetworkBuilder
return Top; return Top;
} }
/// <summary>
/// Return the student with the specified UserName
/// </summary>
/// <param name="UserName">The user name to find</param>
/// <returns>The specified person, or null if no such person exists.</returns>
public PersonClass StudentWithTheUserName(string UserName)
{
if (!isAdmin) return null; //Students do not store other student records
foreach(PersonClass PC in Students)
{
if (PC.UserName == UserName) return PC;
}
return null;
}
/// <summary>
/// Import the settings from a student record
/// </summary>
/// <param name="ImportedStudent">the student we are importing from</param>
/// <returns>The count of homeworks we added. -1 if there is an error</returns>
public int TeacherImportStudentHomework(PersonClass ImportedStudent)
{
if (!isAdmin) return -1;
PersonClass StoredStudent = StudentWithTheUserName(ImportedStudent.UserName);
if (StoredStudent == null) return -1;
int NumSubmitted = 0;
//Retrieve all the stored settings, in case we need to re-write their file
StoredStudent.UserSettings = ImportedStudent.UserSettings;
//Pull out their password, in case we want to retrieve it. (sigh)
StoredStudent.Password = ImportedStudent.Password;
// loop through all networks
foreach (SchoolworkClass SWC in ImportedStudent.Projects)
{
// Find any that are submitted, which are not in the admin file
if (StoredStudent.RegisterNewlySubmittedHW(SWC))
{
// copy them into the admin file
NumSubmitted++;
}
}
return NumSubmitted;
}
} }
} }

View File

@ -919,24 +919,9 @@ namespace EduNetworkBuilder
continue; //Do not try to load in the data continue; //Do not try to load in the data
} }
//Retrieve all the stored settings, in case we need to re-write their file int tCountSubmitted = CurrentUser.TeacherImportStudentHomework(tempStudent);
storedStudent.UserSettings = tempStudent.UserSettings; NumSubmitted += tCountSubmitted;
if (tCountSubmitted >0)
//Pull out their password, in case we want to retrieve it. (sigh)
storedStudent.Password = tempStudent.Password;
// loop through all networks
foreach (SchoolworkClass SWC in tempStudent.Projects)
{
// Find any that are submitted, which are not in the admin file
if(storedStudent.RegisterNewlySubmittedHW(SWC))
{
// copy them into the admin file
NumSubmitted++;
HadASubmission = true;
}
}
if (!HadASubmission)
NumStudentsNoSubmissions++; NumStudentsNoSubmissions++;
} }
else else