validate csv info

This commit is contained in:
Tim Young 2017-08-01 14:43:55 -05:00
parent 0911479d22
commit 405fe94953
3 changed files with 55 additions and 3 deletions

View File

@ -914,6 +914,10 @@ namespace EduNetworkBuilder
{
return ValidateString(password, AllowedUsernameCharacters);
}
public static bool ValidateFullName(string password)
{
return ValidateString(password, AllowedUsernameCharacters + " ");
}
}
}

View File

@ -408,8 +408,12 @@ namespace EduNetworkBuilder
if (result == System.Windows.Forms.DialogResult.Cancel) return;
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
bool HadError = false;
using (TextFieldParser parser = new TextFieldParser(mydialog.FileName))
{
parser.TextFieldType = FieldType.Delimited;
@ -423,14 +427,54 @@ namespace EduNetworkBuilder
foreach (string field in fields)
{
//TODO: Process field
if (index == 0) TStudent.Name = field;
if (index == 1) TStudent.FullName = field;
if (index == 2) TStudent.Password = field;
if (index == 0)
{
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.
}
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);
}
}
}

View File

@ -1781,4 +1781,8 @@
<value>Launch</value>
<comment>PPF_Launch = Launch</comment>
</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>