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,34 +1751,45 @@ namespace EduNetworkBuilder
MessageBox.Show(NB.Translate("NB_LogOutFirst"));
return;
}
int counter = 0;
PersonClass tUser = null;
while (counter < 3)
{
string tPass = NB.TextPromptBox("Enter a password", Properties.Resources.NBIco, true);
string tUserName = Path.GetFileNameWithoutExtension(filename);
string PasToUse = tUserName + tPass;
tUser = PersonClass.TryLoad(filename, PasToUse);
if (tUser != null) break;
counter++;
}
if(tUser == null)
{
//failed to load.
MessageBox.Show("Too many password failures. Exiting.");
return;
}
CurrentUser = tUser;
CurrentUser.filepath = Path.GetDirectoryName(filename); //store the directory
OurSettings = NB.GetSettings(); //Grab the new settings from the user
if (CurrentUser.ChangePassAtFirstLogin)
CurrentUser.ChangePassword(); //change the password
UpdateMenu();
if (CurrentUser == null)
{ //Load a starting, or a new user
int counter = 0;
PersonClass tUser = null;
while (counter < 3)
{
string tPass = NB.TextPromptBox("Enter a password", Properties.Resources.NBIco, true);
string tUserName = Path.GetFileNameWithoutExtension(filename);
string PasToUse = tUserName + tPass;
tUser = PersonClass.TryLoad(filename, PasToUse);
if (tUser != null) break;
counter++;
}
if (tUser == null)
{
//failed to load.
MessageBox.Show("Too many password failures. Exiting.");
return;
}
CurrentUser = tUser;
CurrentUser.filepath = Path.GetDirectoryName(filename); //store the directory
OurSettings = NB.GetSettings(); //Grab the new settings from the user
if (CurrentUser.ChangePassAtFirstLogin)
CurrentUser.ChangePassword(); //change the password
UpdateMenu();
//Now, open a new window to edit them.
PersonProfileForm PPF = new PersonProfileForm(CurrentUser);
CurrentUser = PPF.Edit(); //This does the form as dialog. When we come back, update the menu.
UpdateMenu();
//Now, open a new window to edit them.
PersonProfileForm PPF = new PersonProfileForm(CurrentUser);
CurrentUser = PPF.Edit(); //This does the form as dialog. When we come back, update the menu.
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")
{

View File

@ -573,5 +573,52 @@ namespace EduNetworkBuilder
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
}
//Retrieve all the stored settings, in case we need to re-write their file
storedStudent.UserSettings = tempStudent.UserSettings;
//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)
int tCountSubmitted = CurrentUser.TeacherImportStudentHomework(tempStudent);
NumSubmitted += tCountSubmitted;
if (tCountSubmitted >0)
NumStudentsNoSubmissions++;
}
else