validate csv info
This commit is contained in:
parent
0911479d22
commit
405fe94953
@ -914,6 +914,10 @@ namespace EduNetworkBuilder
|
|||||||
{
|
{
|
||||||
return ValidateString(password, AllowedUsernameCharacters);
|
return ValidateString(password, AllowedUsernameCharacters);
|
||||||
}
|
}
|
||||||
|
public static bool ValidateFullName(string password)
|
||||||
|
{
|
||||||
|
return ValidateString(password, AllowedUsernameCharacters + " ");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -408,8 +408,12 @@ namespace EduNetworkBuilder
|
|||||||
if (result == System.Windows.Forms.DialogResult.Cancel) return;
|
if (result == System.Windows.Forms.DialogResult.Cancel) return;
|
||||||
|
|
||||||
List<StudentHolder> tList = new List<StudentHolder>();
|
List<StudentHolder> tList = new List<StudentHolder>();
|
||||||
|
List<string> InvalidUsers = new List<string>();
|
||||||
|
List<string> InvalidFullName = 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;
|
||||||
using (TextFieldParser parser = new TextFieldParser(mydialog.FileName))
|
using (TextFieldParser parser = new TextFieldParser(mydialog.FileName))
|
||||||
{
|
{
|
||||||
parser.TextFieldType = FieldType.Delimited;
|
parser.TextFieldType = FieldType.Delimited;
|
||||||
@ -423,14 +427,54 @@ namespace EduNetworkBuilder
|
|||||||
foreach (string field in fields)
|
foreach (string field in fields)
|
||||||
{
|
{
|
||||||
//TODO: Process field
|
//TODO: Process field
|
||||||
if (index == 0) TStudent.Name = field;
|
if (index == 0)
|
||||||
if (index == 1) TStudent.FullName = field;
|
{
|
||||||
if (index == 2) TStudent.Password = field;
|
TStudent.Name = field;
|
||||||
|
if (!NB.ValidateUsername(field))
|
||||||
|
{
|
||||||
|
HadError = true;
|
||||||
|
InvalidUsers.Add(TStudent.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (index == 1)
|
||||||
|
{
|
||||||
|
TStudent.FullName = field;
|
||||||
|
if (!NB.ValidateFullName(field))
|
||||||
|
{
|
||||||
|
HadError = true;
|
||||||
|
InvalidFullName.Add(TStudent.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index == 2)
|
||||||
|
{
|
||||||
|
TStudent.Password = field;
|
||||||
|
if (!NB.ValidatePassword(field))
|
||||||
|
{
|
||||||
|
HadError = true;
|
||||||
|
InvalidPasswords.Add(TStudent.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
index++; //Track which field we are in.
|
index++; //Track which field we are in.
|
||||||
}
|
}
|
||||||
tList.Add(TStudent);
|
tList.Add(TStudent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(HadError)
|
||||||
|
{
|
||||||
|
ShowInvalid("Username", InvalidUsers);
|
||||||
|
ShowInvalid("Full Name", InvalidFullName);
|
||||||
|
ShowInvalid("Password", InvalidPasswords);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowInvalid(string What, List<string> BadUsers)
|
||||||
|
{
|
||||||
|
if (BadUsers.Count < 1) return;
|
||||||
|
string message = NB.Translate("PPF_NoImportInvalid") + ": " + What;
|
||||||
|
foreach (string one in BadUsers)
|
||||||
|
message += "\n" + one;
|
||||||
|
MessageBox.Show(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1781,4 +1781,8 @@
|
|||||||
<value>Launch</value>
|
<value>Launch</value>
|
||||||
<comment>PPF_Launch = Launch</comment>
|
<comment>PPF_Launch = Launch</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="PPF_NoImportInvalid" xml:space="preserve">
|
||||||
|
<value>Error. Could not import students. List of invalid</value>
|
||||||
|
<comment>PPF_NoImportInvalid = Error. Could not import students. List of invalid</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
Loading…
Reference in New Issue
Block a user