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<SchoolworkClass> Projects = new List<SchoolworkClass>();
|
||||||
|
|
||||||
|
public List<PersonClass> Students = new List<PersonClass>(); //only teachers (admins) will have students.
|
||||||
|
|
||||||
public NBSettings UserSettings = new NBSettings();
|
public NBSettings UserSettings = new NBSettings();
|
||||||
|
|
||||||
public bool ChangePassAtFirstLogin = true;
|
public bool ChangePassAtFirstLogin = true;
|
||||||
@ -59,6 +61,11 @@ namespace EduNetworkBuilder
|
|||||||
{
|
{
|
||||||
Load(Filename);
|
Load(Filename);
|
||||||
}
|
}
|
||||||
|
public PersonClass(XmlNode reader)
|
||||||
|
{
|
||||||
|
Load(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public string Password(int index = 0)
|
public string Password(int index = 0)
|
||||||
{
|
{
|
||||||
@ -86,11 +93,11 @@ namespace EduNetworkBuilder
|
|||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
xmlDoc.Load(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)
|
foreach (XmlNode Individual in TheNode.ChildNodes)
|
||||||
{
|
{
|
||||||
@ -102,7 +109,7 @@ namespace EduNetworkBuilder
|
|||||||
case "edunetworkbuilderuser":
|
case "edunetworkbuilderuser":
|
||||||
case "edunetworkbuilder":
|
case "edunetworkbuilder":
|
||||||
case "user":
|
case "user":
|
||||||
Load(Individual, Name);
|
Load(Individual);
|
||||||
break;
|
break;
|
||||||
case "username":
|
case "username":
|
||||||
_UserName = Individual.InnerText;
|
_UserName = Individual.InnerText;
|
||||||
@ -137,6 +144,10 @@ namespace EduNetworkBuilder
|
|||||||
SchoolworkClass SWC = new SchoolworkClass(Individual);
|
SchoolworkClass SWC = new SchoolworkClass(Individual);
|
||||||
Projects.Add(SWC);
|
Projects.Add(SWC);
|
||||||
break;
|
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 language name
|
||||||
//save the number of items
|
//save the number of items
|
||||||
//Save all the items
|
//Save all the items
|
||||||
writer.WriteStartElement("User");
|
string Element = "User";
|
||||||
|
if (AsStudent) Element = "Student";
|
||||||
|
writer.WriteStartElement(Element);
|
||||||
writer.WriteElementString("UserName", UserName);
|
writer.WriteElementString("UserName", UserName);
|
||||||
writer.WriteElementString("FullName", FullName);
|
writer.WriteElementString("FullName", FullName);
|
||||||
writer.WriteElementString("PasswordHint", PasswordHint);
|
writer.WriteElementString("PasswordHint", PasswordHint);
|
||||||
@ -185,6 +198,8 @@ namespace EduNetworkBuilder
|
|||||||
|
|
||||||
foreach(string One in Passwords)
|
foreach(string One in Passwords)
|
||||||
writer.WriteElementString("Password", One);
|
writer.WriteElementString("Password", One);
|
||||||
|
foreach (PersonClass PC in Students)
|
||||||
|
PC.Save(writer, true); //Save as a student entry
|
||||||
//Save all the devices
|
//Save all the devices
|
||||||
foreach (SchoolworkClass One in Projects)
|
foreach (SchoolworkClass One in Projects)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,6 @@ namespace EduNetworkBuilder
|
|||||||
public string Name = "";
|
public string Name = "";
|
||||||
public string Password = "";
|
public string Password = "";
|
||||||
public string FullName = "";
|
public string FullName = "";
|
||||||
public bool ForceToChangePass = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -408,6 +407,9 @@ namespace EduNetworkBuilder
|
|||||||
//Get a csv file
|
//Get a csv file
|
||||||
//try to read it in
|
//try to read it in
|
||||||
//Import them all
|
//Import them all
|
||||||
|
Random myRandom = NB.GetRandom();
|
||||||
|
bool AutoCreatePWs = true;
|
||||||
|
bool ForcePWChange = true;
|
||||||
OpenFileDialog mydialog = new OpenFileDialog();
|
OpenFileDialog mydialog = new OpenFileDialog();
|
||||||
mydialog.AddExtension = true;
|
mydialog.AddExtension = true;
|
||||||
string filter = "Comma Separated List (*.csv)|*.csv";
|
string filter = "Comma Separated List (*.csv)|*.csv";
|
||||||
@ -425,12 +427,15 @@ namespace EduNetworkBuilder
|
|||||||
List<string> InvalidFullName = new List<string>();
|
List<string> InvalidFullName = new List<string>();
|
||||||
List<string> InvalidPasswords = new List<string>();
|
List<string> InvalidPasswords = new List<string>();
|
||||||
|
|
||||||
|
|
||||||
//Now we have a csv file. Try to parse it
|
//Now we have a csv file. Try to parse it
|
||||||
bool HadError = false;
|
bool HadError = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (TextFieldParser parser = new TextFieldParser(mydialog.FileName))
|
using (TextFieldParser parser = new TextFieldParser(mydialog.FileName))
|
||||||
{
|
{
|
||||||
|
StudentHolder TStudent = new StudentHolder();
|
||||||
|
|
||||||
parser.TextFieldType = FieldType.Delimited;
|
parser.TextFieldType = FieldType.Delimited;
|
||||||
parser.SetDelimiters(",");
|
parser.SetDelimiters(",");
|
||||||
while (!parser.EndOfData)
|
while (!parser.EndOfData)
|
||||||
@ -438,12 +443,12 @@ namespace EduNetworkBuilder
|
|||||||
//Process row
|
//Process row
|
||||||
int index = 0;
|
int index = 0;
|
||||||
string[] fields = parser.ReadFields();
|
string[] fields = parser.ReadFields();
|
||||||
StudentHolder TStudent = new StudentHolder();
|
|
||||||
foreach (string field in fields)
|
foreach (string field in fields)
|
||||||
{
|
{
|
||||||
//TODO: Process field
|
//TODO: Process field
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
{
|
{
|
||||||
|
TStudent = new StudentHolder();
|
||||||
TStudent.Name = field;
|
TStudent.Name = field;
|
||||||
if (!NB.ValidateUsername(field))
|
if (!NB.ValidateUsername(field))
|
||||||
{
|
{
|
||||||
@ -472,6 +477,8 @@ namespace EduNetworkBuilder
|
|||||||
}
|
}
|
||||||
index++; //Track which field we are in.
|
index++; //Track which field we are in.
|
||||||
}
|
}
|
||||||
|
if (AutoCreatePWs && TStudent.Password == "")
|
||||||
|
TStudent.Password = TrippleDESDocumentEncryption.GenUserPW(myRandom);
|
||||||
tList.Add(TStudent);
|
tList.Add(TStudent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -480,12 +487,47 @@ namespace EduNetworkBuilder
|
|||||||
ShowInvalid("Username", InvalidUsers);
|
ShowInvalid("Username", InvalidUsers);
|
||||||
ShowInvalid("Full Name", InvalidFullName);
|
ShowInvalid("Full Name", InvalidFullName);
|
||||||
ShowInvalid("Password", InvalidPasswords);
|
ShowInvalid("Password", InvalidPasswords);
|
||||||
|
return; //Break out without adding them
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception except)
|
catch (Exception except)
|
||||||
{
|
{
|
||||||
MessageBox.Show(except.ToString());
|
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)
|
private void ShowInvalid(string What, List<string> BadUsers)
|
||||||
|
@ -1777,6 +1777,10 @@
|
|||||||
<value>Import Students</value>
|
<value>Import Students</value>
|
||||||
<comment>PPF_ImportStudents = Import Students</comment>
|
<comment>PPF_ImportStudents = Import Students</comment>
|
||||||
</data>
|
</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">
|
<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>
|
<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>
|
<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