functions to make student csv file

This commit is contained in:
Tim Young 2017-08-10 16:07:33 -05:00
parent ed48b943aa
commit 50a04dbef0
3 changed files with 36 additions and 1 deletions

View File

@ -1101,5 +1101,17 @@ namespace EduNetworkBuilder
MessageBox.Show(Translate("NB_NotImplimented"));
}
public static string CSVSafeString(string source)
{
string dest = source;
char[] chars = { '\t', '\r', '\n', '\"', ',' };
if (dest.IndexOfAny(chars) >= 0)
{
dest = '\"' + dest.Replace("\"", "\"\"") + '\"'; //quotes around outside, replace " with ""
}
return dest;
}
}
}

View File

@ -2055,5 +2055,28 @@ namespace EduNetworkBuilder
PPF.Edit();
UpdateMenu();
}
private void WriteStudentCSVFile(string path)
{
try
{
using (var w = new StreamWriter(path))
{
foreach (PersonClass pc in CurrentUser.Students)
{
string UName = NB.CSVSafeString(pc.UserName);
string FName = NB.CSVSafeString(pc.FullName);
string Pass = NB.CSVSafeString(pc.Password);
var line = string.Format("{0},{1},{2}", UName, FName, Pass);
w.WriteLine(line);
w.Flush();
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
}