Finish importing students, saving, and reporting on the process.
This commit is contained in:
parent
5654cba0d9
commit
8cd1f22e7f
@ -42,6 +42,8 @@ namespace EduNetworkBuilder
|
||||
|
||||
public List<SchoolworkClass> Projects = new List<SchoolworkClass>();
|
||||
|
||||
public List<PersonClass> Students = new List<PersonClass>(); //only teachers (admins) will have students.
|
||||
|
||||
public NBSettings UserSettings = new NBSettings();
|
||||
|
||||
public bool ChangePassAtFirstLogin = true;
|
||||
@ -59,6 +61,11 @@ namespace EduNetworkBuilder
|
||||
{
|
||||
Load(Filename);
|
||||
}
|
||||
public PersonClass(XmlNode reader)
|
||||
{
|
||||
Load(reader);
|
||||
}
|
||||
|
||||
|
||||
public string Password(int index = 0)
|
||||
{
|
||||
@ -86,11 +93,11 @@ namespace EduNetworkBuilder
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
xmlDoc.Load(filename);
|
||||
Load(xmlDoc, filename);
|
||||
Load(xmlDoc);
|
||||
}
|
||||
}
|
||||
|
||||
public void Load(XmlNode TheNode, string Name)
|
||||
public void Load(XmlNode TheNode)
|
||||
{
|
||||
foreach (XmlNode Individual in TheNode.ChildNodes)
|
||||
{
|
||||
@ -102,7 +109,7 @@ namespace EduNetworkBuilder
|
||||
case "edunetworkbuilderuser":
|
||||
case "edunetworkbuilder":
|
||||
case "user":
|
||||
Load(Individual, Name);
|
||||
Load(Individual);
|
||||
break;
|
||||
case "username":
|
||||
_UserName = Individual.InnerText;
|
||||
@ -137,6 +144,10 @@ namespace EduNetworkBuilder
|
||||
SchoolworkClass SWC = new SchoolworkClass(Individual);
|
||||
Projects.Add(SWC);
|
||||
break;
|
||||
case "student":
|
||||
PersonClass PC = new PersonClass(Individual);
|
||||
Students.Add(PC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -168,12 +179,14 @@ namespace EduNetworkBuilder
|
||||
}
|
||||
|
||||
|
||||
public void Save(XmlWriter writer)
|
||||
public void Save(XmlWriter writer, bool AsStudent=false)
|
||||
{
|
||||
//Save the language name
|
||||
//save the number of items
|
||||
//Save all the items
|
||||
writer.WriteStartElement("User");
|
||||
string Element = "User";
|
||||
if (AsStudent) Element = "Student";
|
||||
writer.WriteStartElement(Element);
|
||||
writer.WriteElementString("UserName", UserName);
|
||||
writer.WriteElementString("FullName", FullName);
|
||||
writer.WriteElementString("PasswordHint", PasswordHint);
|
||||
@ -185,6 +198,8 @@ namespace EduNetworkBuilder
|
||||
|
||||
foreach(string One in Passwords)
|
||||
writer.WriteElementString("Password", One);
|
||||
foreach (PersonClass PC in Students)
|
||||
PC.Save(writer, true); //Save as a student entry
|
||||
//Save all the devices
|
||||
foreach (SchoolworkClass One in Projects)
|
||||
{
|
||||
|
@ -31,7 +31,6 @@ namespace EduNetworkBuilder
|
||||
public string Name = "";
|
||||
public string Password = "";
|
||||
public string FullName = "";
|
||||
public bool ForceToChangePass = true;
|
||||
}
|
||||
|
||||
|
||||
@ -408,6 +407,9 @@ namespace EduNetworkBuilder
|
||||
//Get a csv file
|
||||
//try to read it in
|
||||
//Import them all
|
||||
Random myRandom = NB.GetRandom();
|
||||
bool AutoCreatePWs = true;
|
||||
bool ForcePWChange = true;
|
||||
OpenFileDialog mydialog = new OpenFileDialog();
|
||||
mydialog.AddExtension = true;
|
||||
string filter = "Comma Separated List (*.csv)|*.csv";
|
||||
@ -425,12 +427,15 @@ namespace EduNetworkBuilder
|
||||
List<string> InvalidFullName = new List<string>();
|
||||
List<string> InvalidPasswords = new List<string>();
|
||||
|
||||
|
||||
//Now we have a csv file. Try to parse it
|
||||
bool HadError = false;
|
||||
try
|
||||
{
|
||||
using (TextFieldParser parser = new TextFieldParser(mydialog.FileName))
|
||||
{
|
||||
StudentHolder TStudent = new StudentHolder();
|
||||
|
||||
parser.TextFieldType = FieldType.Delimited;
|
||||
parser.SetDelimiters(",");
|
||||
while (!parser.EndOfData)
|
||||
@ -438,12 +443,12 @@ namespace EduNetworkBuilder
|
||||
//Process row
|
||||
int index = 0;
|
||||
string[] fields = parser.ReadFields();
|
||||
StudentHolder TStudent = new StudentHolder();
|
||||
foreach (string field in fields)
|
||||
{
|
||||
//TODO: Process field
|
||||
if (index == 0)
|
||||
{
|
||||
TStudent = new StudentHolder();
|
||||
TStudent.Name = field;
|
||||
if (!NB.ValidateUsername(field))
|
||||
{
|
||||
@ -472,6 +477,8 @@ namespace EduNetworkBuilder
|
||||
}
|
||||
index++; //Track which field we are in.
|
||||
}
|
||||
if (AutoCreatePWs && TStudent.Password == "")
|
||||
TStudent.Password = TrippleDESDocumentEncryption.GenUserPW(myRandom);
|
||||
tList.Add(TStudent);
|
||||
}
|
||||
}
|
||||
@ -480,12 +487,47 @@ namespace EduNetworkBuilder
|
||||
ShowInvalid("Username", InvalidUsers);
|
||||
ShowInvalid("Full Name", InvalidFullName);
|
||||
ShowInvalid("Password", InvalidPasswords);
|
||||
return; //Break out without adding them
|
||||
}
|
||||
}
|
||||
catch (Exception except)
|
||||
{
|
||||
MessageBox.Show(except.ToString());
|
||||
return; //Break out without trying to add something
|
||||
}
|
||||
//If we get here, we are ready to add students.
|
||||
int dup_students = 0;
|
||||
int new_students = 0;
|
||||
|
||||
//Loop through them all and add ones that do not already exist.
|
||||
foreach(StudentHolder SH in tList)
|
||||
{
|
||||
//find if they already exist
|
||||
if(StudentFromUsername(SH.Name) == null)
|
||||
{
|
||||
new_students++;
|
||||
PersonClass tPC = new PersonClass(SH.Name,false); //Make a new account that is not an admin
|
||||
tPC.FullName = SH.FullName;
|
||||
tPC.ChangePassword(SH.Password);
|
||||
tPC.ChangePassAtFirstLogin = ForcePWChange;
|
||||
CurrentUser.Students.Add(tPC);
|
||||
}
|
||||
else
|
||||
{
|
||||
dup_students++;
|
||||
}
|
||||
}
|
||||
MessageBox.Show(string.Format(NB.Translate("PPF_ImportSummary"),"\n\t" + new_students,"\n\t" + dup_students));
|
||||
}
|
||||
|
||||
PersonClass StudentFromUsername(string Username)
|
||||
{
|
||||
foreach(PersonClass pc in CurrentUser.Students)
|
||||
{
|
||||
if (pc.UserName == Username)
|
||||
return pc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ShowInvalid(string What, List<string> BadUsers)
|
||||
|
@ -1777,6 +1777,10 @@
|
||||
<value>Import Students</value>
|
||||
<comment>PPF_ImportStudents = Import Students</comment>
|
||||
</data>
|
||||
<data name="PPF_ImportSummary" xml:space="preserve">
|
||||
<value>Result: {0} New Students: {1} Duplicates (not added)</value>
|
||||
<comment>PPF_ImportSummary = Result: {0} New Students: {1} Duplicates (not added)</comment>
|
||||
</data>
|
||||
<data name="PPF_ImportToolTip" xml:space="preserve">
|
||||
<value>Import from comma-deliminated file. User, Full Name, password. With full name and password being optional.</value>
|
||||
<comment>PPF_ImportToolTip = Import from comma-deliminated file. User, Full Name, password. With full name and password being optional.</comment>
|
||||
|
Loading…
Reference in New Issue
Block a user