functions to make student csv file
This commit is contained in:
parent
ed48b943aa
commit
50a04dbef0
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user