2017-07-27 22:20:32 +02:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
2017-07-28 00:02:52 +02:00
using System.IO ;
2017-08-01 21:30:07 +02:00
using Microsoft.VisualBasic.FileIO ; //for CSV parsing
2017-07-27 22:20:32 +02:00
namespace EduNetworkBuilder
{
2017-08-01 21:30:07 +02:00
//A temporary holding structure when loading in students from CSV for validation.
//Once loaded and parsed, we then make actual students from them.
2017-07-27 22:20:32 +02:00
public partial class PersonProfileForm : Form
{
2017-07-31 01:18:41 +02:00
enum TopTab { profiletab = 0 , classworktab = 1 }
2017-08-02 03:52:07 +02:00
enum TreeDataTab { classtab = 0 , homeworktab = 1 , studentstab = 2 , studenttab = 3 }
2017-07-27 22:20:32 +02:00
PersonClass CurrentUser = null ;
string FileName = "" ;
2017-07-31 01:18:41 +02:00
PersonClass ViewedUser = null ;
SchoolworkClass ViewedSchoolwork = null ;
2017-07-27 22:20:32 +02:00
2017-08-02 00:14:21 +02:00
ToolTip myTooltip = new ToolTip ( ) ;
2017-08-02 00:04:02 +02:00
class StudentHolder
{
public string Name = "" ;
public string Password = "" ;
public string FullName = "" ;
}
2017-07-27 22:20:32 +02:00
public PersonProfileForm ( string filename = "" )
{
InitializeComponent ( ) ;
FileName = filename ;
//We do LocalSetup at load time. This saves us some grief.
}
2017-07-28 00:02:52 +02:00
public PersonProfileForm ( PersonClass User )
{
InitializeComponent ( ) ;
CurrentUser = User ;
if ( CurrentUser ! = null )
{
FileName = Path . Combine ( CurrentUser . filepath , CurrentUser . UserName ) ;
}
//We do LocalSetup at load time. This saves us some grief.
}
2017-07-27 22:20:32 +02:00
private void PersonProfileForm_Load ( object sender , EventArgs e )
{
LocalSetup ( ) ;
2017-07-28 00:02:52 +02:00
UpdateFormFromUser ( ) ;
2017-07-27 22:20:32 +02:00
}
private void LanguagifyComponents ( )
{
lblFullName . Text = NB . Translate ( "PPF_FullName" ) ;
lblUsername . Text = NB . Translate ( "PPF_UserName" ) ;
TabClasswork . Text = NB . Translate ( "PPF_TabClasswork" ) ;
TabProfile . Text = NB . Translate ( "PPF_TabProfile" ) ;
btnExit . Text = NB . Translate ( "NB_exitToolStripMenuItem" ) ;
2017-07-31 23:44:41 +02:00
btnChangePassword . Text = NB . Translate ( "PPF_ChangePassword" ) ;
btnHWDelete . Text = NB . Translate ( "_Delete" ) ;
btnImportStudents . Text = NB . Translate ( "PPF_ImportStudents" ) ;
btnLaunch . Text = NB . Translate ( "PPF_Launch" ) ;
2017-08-02 18:10:34 +02:00
btnGenerateStudentFiles . Text = NB . Translate ( "PPF_GenerateFiles" ) ;
2017-08-02 19:03:35 +02:00
btnHWGive . Text = NB . Translate ( "PPF_HWGive" ) ;
btnHWSave . Text = NB . Translate ( "_Save" ) ;
2017-08-14 17:29:37 +02:00
cbTeacherAutoDHCP . Text = NB . Translate ( "PPF_AutoDHCP" ) ;
2017-07-27 22:20:32 +02:00
}
private void LocalSetup ( )
{
2017-07-28 00:02:52 +02:00
Icon = Properties . Resources . NBIco ;
LanguagifyComponents ( ) ;
2017-08-02 17:16:10 +02:00
HideAllTabs ( ) ;
2017-07-28 00:02:52 +02:00
2017-08-02 00:14:21 +02:00
myTooltip . AutoPopDelay = 5000 ;
myTooltip . InitialDelay = 1000 ;
myTooltip . ReshowDelay = 500 ;
// Force the ToolTip text to be displayed whether or not the form is active.
myTooltip . ShowAlways = true ;
myTooltip . SetToolTip ( btnImportStudents , NB . Translate ( "PPF_ImportToolTip" ) ) ;
2017-08-02 19:46:11 +02:00
myTooltip . SetToolTip ( btnHWGive , NB . Translate ( "PPF_HWGiveToolTip" ) ) ;
myTooltip . SetToolTip ( btnHWSave , NB . Translate ( "PPF_HWSaveToolTip" ) ) ;
2017-08-02 22:35:43 +02:00
myTooltip . SetToolTip ( btnAllHomeworkToStudents , "Take all currently defined homework and put it into the student accounts. Do at the beginning of a class and before you generate the student files for the first time." ) ;
2017-08-05 23:56:25 +02:00
myTooltip . SetToolTip ( btnExportHomework , "Export all the homework into a single homework file. Use this file to set up for another class." ) ;
2017-08-02 00:14:21 +02:00
2017-08-17 17:29:37 +02:00
tvClasswork . ShowNodeToolTips = true ;
2017-07-28 00:02:52 +02:00
if ( CurrentUser = = null & & FileName = = "" )
2017-07-27 22:20:32 +02:00
{
//Prompt for a username
2017-07-31 23:36:07 +02:00
NBSettings oldsettings = NB . GetSettings ( ) ; //Grab the old settings.
2017-07-28 00:02:52 +02:00
String Dest = NB . TextPromptBox ( NB . Translate ( "PPF_EnterUserName" ) ) ;
2017-07-30 01:31:19 +02:00
if ( Dest = = "" ) { Close ( ) ; return ; } //No name given or canceled.
if ( Dest = = null ) { Close ( ) ; return ; }
2017-07-28 00:02:52 +02:00
if ( Dest [ 0 ] ! = '_' ) Dest = "_Teacher_" + Dest ; //Make sure it begins with _
2017-07-27 22:20:32 +02:00
//Find a directory for it.
2017-07-28 00:02:52 +02:00
CurrentUser = new PersonClass ( Dest , true ) ; //Make an admin person class
2017-07-28 20:00:07 +02:00
//Choose an initial folder for the file:
2017-08-02 18:25:26 +02:00
OpenFileDialog OFD = NB . SelectDirectoryDialog ( NB . Translate ( "PPF_UserDirectory" ) , CurrentUser . filepath ) ;
if ( OFD . FileName = = "" ) return ; //we cancel out
2017-07-29 16:26:25 +02:00
CurrentUser . filepath = Path . GetDirectoryName ( OFD . FileName ) ;
2017-07-31 23:36:07 +02:00
CurrentUser . UserSettings . AutoStartPuzzles = false ;
CurrentUser . UserSettings . ChosenLanguage = oldsettings . ChosenLanguage ;
CurrentUser . UserSettings . LanguageHasBeenChosen = true ;
2017-08-16 00:22:55 +02:00
CurrentUser . ChangePassAtFirstLogin = true ;
CurrentUser . ChangePassword ( true ) ; //If they do not set a password now, they will do it next time
2017-08-01 00:17:17 +02:00
2017-07-27 22:20:32 +02:00
}
2017-07-28 00:02:52 +02:00
else if ( CurrentUser = = null )
2017-07-27 22:20:32 +02:00
{
//Try to load the file. Close form & give error if it fails
2017-07-28 20:00:07 +02:00
try
{
//Load in from the file
}
catch ( Exception e )
{
2017-08-02 19:17:20 +02:00
MessageBox . Show ( e . ToString ( ) ) ;
2017-07-28 20:00:07 +02:00
CurrentUser = null ;
Close ( ) ; //we did not succeed. Exit out
}
2017-07-27 22:20:32 +02:00
}
2017-07-28 00:02:52 +02:00
2017-07-31 01:18:41 +02:00
tvClasswork . AfterSelect + = tvClasswork_Click ;
tbHWClass . LostFocus + = SaveSchoolworkDataFromForm ;
tbHWDescription . LostFocus + = SaveSchoolworkDataFromForm ;
tbHWName . LostFocus + = SaveSchoolworkDataFromForm ;
tbHWSubmitted . LostFocus + = SaveSchoolworkDataFromForm ;
dtpHWDue . LostFocus + = SaveSchoolworkDataFromForm ;
2017-08-01 00:17:17 +02:00
tcTabControl . SelectedIndexChanged + = UpdateFormFromSchoolwork ;
2017-07-28 00:02:52 +02:00
//Make sure we update any profile settings they change
tbFullName . LostFocus + = SaveUserInfoFromForm ;
2017-08-02 03:52:07 +02:00
tbStudentFullName . LostFocus + = SaveStudentDataFromForm ;
2017-08-09 02:01:42 +02:00
tvClasswork . DoubleClick + = btnLaunch_Click ;
2017-07-27 22:20:32 +02:00
}
2017-07-31 01:18:41 +02:00
private void DtpHWDue_LostFocus ( object sender , EventArgs e )
{
2017-08-10 23:32:45 +02:00
2017-07-31 01:18:41 +02:00
}
2017-07-28 00:02:52 +02:00
public PersonClass Edit ( )
{
2017-08-01 02:26:04 +02:00
CloseAllRTFWindows ( ) ;
2017-07-28 00:02:52 +02:00
BuilderWindow BW = NB . GetBuilderWin ( ) ;
if ( BW ! = null )
{
BW . Hide ( ) ;
this . ShowDialog ( ) ;
BW . Show ( ) ;
}
return CurrentUser ;
2017-07-30 01:31:19 +02:00
}
2017-08-01 02:26:04 +02:00
private void CloseAllRTFWindows ( )
{
for ( int i = Application . OpenForms . Count - 1 ; i > = 0 ; i - - )
{
if ( Application . OpenForms [ i ] is RTFWindow )
Application . OpenForms [ i ] . Close ( ) ;
}
}
2017-07-30 01:31:19 +02:00
public PersonClass AddSchoolwork ( Network ToAdd )
{
if ( CurrentUser = = null ) return CurrentUser ;
2017-08-01 02:26:04 +02:00
CloseAllRTFWindows ( ) ;
2017-07-30 01:31:19 +02:00
BuilderWindow BW = NB . GetBuilderWin ( ) ;
2017-07-31 18:27:25 +02:00
SchoolworkClass NewWork = new SchoolworkClass ( ToAdd , CurrentUser ) ;
2017-07-30 01:31:19 +02:00
CurrentUser . Projects . Add ( NewWork ) ;
UpdateFormFromUser ( ) ; //make sure we list the right homeworks.
2017-07-31 18:27:25 +02:00
ChangeTreeDataTab ( TreeDataTab . homeworktab ) ;
tvClasswork . ExpandAll ( ) ;
tvClasswork . Update ( ) ;
//Now we want to select the item.
foreach ( TreeNode TN in tvClasswork . GetAllNodes ( ) )
{
TN . ExpandAll ( ) ; //Expand everything until we get to what we need.
if ( TN . Tag is SchoolworkClass )
{
SchoolworkClass Check = ( SchoolworkClass ) TN . Tag ;
if ( Check = = NewWork )
{
tvClasswork . SelectedNode = TN ;
break ;
}
}
}
2017-07-30 01:31:19 +02:00
if ( BW ! = null )
{
BW . Hide ( ) ;
this . tcTabControl . SelectedIndex = 1 ; //Jump to the items tab
this . ShowDialog ( ) ;
BW . Show ( ) ;
}
return CurrentUser ;
}
2017-07-28 00:02:52 +02:00
2017-08-02 21:54:50 +02:00
public PersonClass SubmitSchoolwork ( Network ToAdd )
{
if ( CurrentUser = = null ) return CurrentUser ;
if ( ToAdd . WhatFrom = = null ) return CurrentUser ; //we have it
CloseAllRTFWindows ( ) ;
BuilderWindow BW = NB . GetBuilderWin ( ) ;
SchoolworkClass NewWork = ToAdd . WhatFrom . Clone ( ) ;
NewWork . isMaster = false ;
NewWork . IsSumbitted = true ;
NewWork . SaveDate = DateTime . Now ;
2017-08-03 21:33:06 +02:00
NewWork . theProject = ToAdd ; //Save the changed version of the homework
2017-08-02 21:54:50 +02:00
CurrentUser . Projects . Add ( NewWork ) ;
UpdateFormFromUser ( ) ; //make sure we list the right homeworks.
ChangeTreeDataTab ( TreeDataTab . homeworktab ) ;
tvClasswork . ExpandAll ( ) ;
tvClasswork . Update ( ) ;
//Now we want to select the item.
foreach ( TreeNode TN in tvClasswork . GetAllNodes ( ) )
{
TN . ExpandAll ( ) ; //Expand everything until we get to what we need.
if ( TN . Tag is SchoolworkClass )
{
SchoolworkClass Check = ( SchoolworkClass ) TN . Tag ;
if ( Check = = NewWork )
{
tvClasswork . SelectedNode = TN ;
break ;
}
}
}
if ( BW ! = null )
{
BW . Hide ( ) ;
this . tcTabControl . SelectedIndex = 1 ; //Jump to the items tab
this . ShowDialog ( ) ;
BW . Show ( ) ;
}
return CurrentUser ;
}
2017-07-28 00:02:52 +02:00
private void UpdateFormFromUser ( )
{
if ( CurrentUser = = null ) return ;
tbFullName . Text = CurrentUser . FullName ;
tbUsername . Text = CurrentUser . UserName ;
if ( CurrentUser . isAdmin ) this . Text = "Admin: " + CurrentUser . UserName ;
else this . Text = "Student: " + CurrentUser . UserName ;
2017-07-30 01:31:19 +02:00
2017-08-14 17:28:03 +02:00
cbTeacherAutoDHCP . Checked = CurrentUser . UserSettings . AutoDHCPAllMachinesAtNetworkLoad ;
2017-07-30 01:31:19 +02:00
tvClasswork . Nodes . Clear ( ) ;
if ( CurrentUser . isAdmin )
{
2017-08-14 17:28:03 +02:00
cbTeacherAutoDHCP . Visible = true ;
2017-08-02 19:38:10 +02:00
UpdateAdminFormFromUser ( ) ;
}
else
2017-08-14 17:28:03 +02:00
{
cbTeacherAutoDHCP . Visible = false ;
2017-08-02 19:38:10 +02:00
UpdateStudentFormFromUser ( ) ;
2017-08-14 17:28:03 +02:00
}
2017-08-02 19:38:10 +02:00
}
2017-08-02 03:30:43 +02:00
2017-08-02 19:38:10 +02:00
private void UpdateAdminFormFromUser ( )
{
2017-08-02 21:39:37 +02:00
btnGenerateStudentFiles . Visible = true ;
btnImportStudents . Visible = true ;
2017-08-02 22:28:02 +02:00
dtpHWDue . Enabled = true ;
2017-08-02 21:39:37 +02:00
2017-08-02 19:38:10 +02:00
TreeNode Node ;
//We have a class tree
Node = new TreeNode ( NB . Translate ( "PPF_Class" ) ) ;
Node . Tag = "Class" ; //Do not translate this
TreeNode Top = Node ;
tvClasswork . Nodes . Add ( Node ) ;
2017-08-11 22:01:09 +02:00
//This is sorted reverse from what happens in PersonClass.WorkTree.
//In PersonClass.WorkTree, we traverse it backwards.
CurrentUser . Projects . Sort ( ( p , q ) = > p . Compare ( q ) ) ;
2017-08-02 19:38:10 +02:00
foreach ( SchoolworkClass SWC in CurrentUser . Projects )
{
Node = new TreeNode ( SWC . Name ) ;
2017-08-09 02:01:42 +02:00
Node . Tag = SWC ; //Store the schoolwork record in with the node
2017-08-02 19:38:10 +02:00
Top . Nodes . Add ( Node ) ;
}
//we have a students tree. Use top again so we can populate it
Top = new TreeNode ( NB . Translate ( "PPF_Students" ) ) ;
Top . Tag = "Students" ; //Do not translate this
tvClasswork . Nodes . Add ( Top ) ;
//Create nodes for each student
foreach ( PersonClass PC in CurrentUser . Students )
{
Node = new TreeNode ( PC . UserName ) ;
Node . Tag = PC ;
2017-08-09 16:32:32 +02:00
PC . WorkTree ( Node , true ) ;
2017-08-02 19:38:10 +02:00
Top . Nodes . Add ( Node ) ;
}
}
private void UpdateStudentFormFromUser ( )
{
2017-08-02 21:37:18 +02:00
if ( CurrentUser = = null ) return ;
2017-08-02 21:39:37 +02:00
btnGenerateStudentFiles . Visible = false ;
btnImportStudents . Visible = false ;
2017-08-16 00:24:57 +02:00
btnExportStudentPasswords . Visible = false ;
2017-08-02 22:28:02 +02:00
dtpHWDue . Enabled = false ;
2017-08-02 21:37:18 +02:00
TreeNode Top = CurrentUser . WorkTree ( ) ;
if ( Top ! = null )
tvClasswork . Nodes . Add ( Top ) ;
2017-07-28 00:02:52 +02:00
}
private void SaveUserInfoFromForm ( )
{
CurrentUser . FullName = tbFullName . Text ;
}
private void SaveUserInfoFromForm ( object sender , EventArgs e )
{
SaveUserInfoFromForm ( ) ;
}
private void btnExit_Click ( object sender , EventArgs e )
{
//Save during closing
Close ( ) ;
}
private void btnChangePassword_Click ( object sender , EventArgs e )
{
2017-08-11 21:34:35 +02:00
CurrentUser . ChangePassword ( true ) ; //Try to change it once.
2017-07-28 00:02:52 +02:00
}
2017-07-31 01:18:41 +02:00
2017-08-09 16:32:32 +02:00
public Font GetFont ( )
{
if ( tvClasswork . Font ! = null ) return tvClasswork . Font ;
if ( Font ! = null ) return Font ;
BuilderWindow BW = NB . GetBuilderWin ( ) ;
if ( BW ! = null ) return BW . GetFont ( ) ;
return new Font ( FontFamily . GenericSansSerif , 10.0F , FontStyle . Bold ) ;
}
2017-07-31 01:18:41 +02:00
private void ChangeTreeDataTab ( TreeDataTab WhatTo )
{
2017-08-02 04:09:05 +02:00
foreach ( TreeDataTab one in Enum . GetValues ( typeof ( TreeDataTab ) ) )
{
if ( one = = WhatTo ) ShowTabPage ( one ) ;
else HideTabPage ( one ) ;
}
2017-07-31 01:18:41 +02:00
tcTabControl . SelectedIndex = ( int ) TopTab . classworktab ;
2017-08-02 04:09:05 +02:00
//Now there is just one tab. Select it
//tcTreeData.SelectedIndex = (int)WhatTo;
tcTreeData . SelectedIndex = 0 ;
}
2017-08-02 17:16:10 +02:00
private void HideAllTabs ( )
{
foreach ( TreeDataTab one in Enum . GetValues ( typeof ( TreeDataTab ) ) )
HideTabPage ( one ) ;
}
2017-08-02 04:09:05 +02:00
private void HideTabPage ( TreeDataTab What )
{
TabPage Tab = null ;
switch ( What )
{
case TreeDataTab . classtab :
Tab = tabClass ;
break ;
case TreeDataTab . homeworktab :
Tab = TabHomework ;
break ;
case TreeDataTab . studentstab :
Tab = TabStudents ;
break ;
case TreeDataTab . studenttab :
Tab = TabStudent ;
break ;
}
if ( tcTreeData . TabPages . Contains ( Tab ) )
tcTreeData . TabPages . Remove ( Tab ) ;
}
private void ShowTabPage ( TreeDataTab What )
{
TabPage Tab = null ;
switch ( What )
{
case TreeDataTab . classtab :
Tab = tabClass ;
break ;
case TreeDataTab . homeworktab :
Tab = TabHomework ;
break ;
case TreeDataTab . studentstab :
Tab = TabStudents ;
break ;
case TreeDataTab . studenttab :
Tab = TabStudent ;
break ;
}
if ( ! tcTreeData . TabPages . Contains ( Tab ) )
tcTreeData . TabPages . Add ( Tab ) ;
2017-07-31 01:18:41 +02:00
}
private void tvClasswork_Click ( object sender , EventArgs e )
{
if ( tvClasswork . SelectedNode = = null ) return ;
TreeNode Node = tvClasswork . SelectedNode ;
2017-08-10 22:35:56 +02:00
if ( Node = = null ) return ; //Break out to avoid exploding
2017-07-31 01:18:41 +02:00
if ( Node . Tag is SchoolworkClass )
{
SchoolworkClass SWC = ( SchoolworkClass ) Node . Tag ;
//It is a homework. Select the homework tab and fill it
ChangeTreeDataTab ( TreeDataTab . homeworktab ) ;
UpdateFormFromSchoolwork ( SWC ) ;
}
2017-08-02 03:35:41 +02:00
if ( Node . Tag is PersonClass )
{
2017-08-02 03:52:07 +02:00
PersonClass PC = ( PersonClass ) Node . Tag ;
2017-08-02 03:35:41 +02:00
//It is an individual student
ChangeTreeDataTab ( TreeDataTab . studenttab ) ;
2017-08-02 03:52:07 +02:00
UpdateFormFromStudent ( PC ) ;
2017-08-02 03:35:41 +02:00
}
2017-07-31 01:22:55 +02:00
if ( Node . Tag is string )
{
string Selected = ( string ) Node . Tag ;
if ( Selected = = "Class" ) //Do not translate this
ChangeTreeDataTab ( TreeDataTab . classtab ) ;
if ( Selected = = "Students" ) //Do not translate this
2017-08-02 03:35:41 +02:00
ChangeTreeDataTab ( TreeDataTab . studentstab ) ;
2017-07-31 01:22:55 +02:00
}
2017-07-31 01:18:41 +02:00
}
void SaveSchoolworkDataFromForm ( object sender , EventArgs e )
{
SaveSchoolworkDataFromForm ( ) ;
}
private void SaveSchoolworkDataFromForm ( )
{
if ( ViewedSchoolwork = = null ) return ;
ViewedSchoolwork . Class = tbHWClass . Text ;
ViewedSchoolwork . Description = tbHWDescription . Text ;
ViewedSchoolwork . Name = tbHWName . Text ;
ViewedSchoolwork . DueDate = dtpHWDue . Value ;
}
2017-08-01 00:17:17 +02:00
private void UpdateFormFromSchoolwork ( object sender , EventArgs e )
{
UpdateFormFromSchoolwork ( ) ;
}
2017-07-31 01:18:41 +02:00
private void UpdateFormFromSchoolwork ( SchoolworkClass What )
{
ViewedSchoolwork = What ;
UpdateFormFromSchoolwork ( ) ;
}
private void UpdateFormFromSchoolwork ( )
{
2017-08-10 22:42:41 +02:00
bool OnStudentTree = false ;
TreeNode Node = tvClasswork . SelectedNode ;
if ( Node ! = null & & Node . FullPath . StartsWith ( "Student" ) )
OnStudentTree = true ;
2017-07-31 01:18:41 +02:00
if ( ViewedSchoolwork = = null )
{
tbHWClass . Text = "" ;
tbHWDescription . Text = "" ;
tbHWName . Text = "" ;
tbHWSubmitted . Visible = false ;
dtpHWDue . Visible = false ;
lblHWDue . Visible = false ;
2017-07-31 18:44:42 +02:00
btnHWDelete . Visible = false ;
2017-08-01 00:01:03 +02:00
btnLaunch . Visible = false ;
2017-08-02 19:38:10 +02:00
btnHWGive . Visible = false ;
btnHWSave . Visible = false ;
2017-07-31 01:18:41 +02:00
return ;
}
2017-08-11 22:05:22 +02:00
2017-07-31 01:18:41 +02:00
tbHWClass . Text = ViewedSchoolwork . Class ;
tbHWDescription . Text = ViewedSchoolwork . Description ;
tbHWName . Text = ViewedSchoolwork . Name ;
2017-08-11 22:05:22 +02:00
myTooltip . SetToolTip ( tbHWClass , tbHWClass . Text ) ;
myTooltip . SetToolTip ( tbHWDescription , tbHWDescription . Text ) ;
myTooltip . SetToolTip ( tbHWName , tbHWName . Text ) ;
2017-07-31 01:18:41 +02:00
dtpHWDue . Visible = true ;
lblHWDue . Visible = true ;
if ( ViewedSchoolwork . IsSumbitted )
{
tbHWSubmitted . Visible = true ;
lblHWDue . Visible = true ;
2017-08-09 17:11:55 +02:00
lblHWSubmitted . Visible = true ;
2017-07-31 01:18:41 +02:00
tbHWSubmitted . Text = ViewedSchoolwork . SaveDate . ToString ( ) ;
}
else
{
2017-08-01 00:17:17 +02:00
tbHWSubmitted . Visible = false ;
lblHWSubmitted . Visible = false ;
2017-07-31 01:18:41 +02:00
}
if ( ViewedSchoolwork . DueDate < dtpHWDue . MinDate ) ViewedSchoolwork . DueDate = dtpHWDue . MinDate ;
dtpHWDue . Value = ViewedSchoolwork . DueDate ;
2017-08-02 19:38:10 +02:00
if ( CurrentUser ! = null & & CurrentUser . isAdmin )
{
2017-07-31 18:44:42 +02:00
btnHWDelete . Visible = true ; //Only the teacher can delete the homework
2017-08-02 19:38:10 +02:00
btnHWGive . Visible = true ;
btnHWSave . Visible = true ;
}
2017-08-03 19:01:38 +02:00
else
{
btnHWDelete . Visible = false ; //Only the teacher can delete the homework
btnHWGive . Visible = false ;
2017-08-10 23:07:33 +02:00
btnHWSave . Visible = false ;
2017-08-03 19:01:38 +02:00
}
2017-08-10 22:42:41 +02:00
if ( OnStudentTree )
{ //We cannot give or delete submitted stuff
btnHWDelete . Visible = false ;
btnHWGive . Visible = false ;
}
2017-08-01 00:01:03 +02:00
btnLaunch . Visible = true ;
2017-07-31 18:44:42 +02:00
}
2017-07-31 18:27:25 +02:00
2017-08-02 03:52:07 +02:00
void UpdateFormFromStudent ( PersonClass Student )
{
ViewedUser = Student ;
UpdateFormFromStudent ( ) ;
}
void UpdateFormFromStudent ( )
{
if ( ViewedUser = = null )
{
btnStudentChangePassword . Visible = false ;
btnStudentUpdateFile . Visible = false ;
return ;
}
tbStudentFullName . Text = ViewedUser . FullName ;
tbStudentUsername . Text = ViewedUser . UserName ;
btnStudentChangePassword . Visible = true ;
btnStudentUpdateFile . Visible = true ;
}
void SaveStudentDataFromForm ( object sender , EventArgs e )
{
SaveStudentDataFromForm ( ) ;
}
void SaveStudentDataFromForm ( )
{
if ( ViewedUser = = null ) return ;
ViewedUser . FullName = tbStudentFullName . Text ;
}
2017-07-31 18:44:42 +02:00
private void btnHWDelete_Click ( object sender , EventArgs e )
{
if ( ViewedSchoolwork = = null ) return ;
if ( CurrentUser ! = null & & CurrentUser . isAdmin ) //Only the teacher can delete the homework
{
DialogResult Sure = MessageBox . Show ( NB . Translate ( "PPF_ConfirmHWDelete" ) , "" , MessageBoxButtons . YesNoCancel ) ;
if ( Sure = = DialogResult . Yes )
{
CurrentUser . Projects . Remove ( ViewedSchoolwork ) ;
ViewedSchoolwork = null ;
UpdateFormFromUser ( ) ;
UpdateFormFromSchoolwork ( ) ;
}
}
}
2017-07-31 23:44:41 +02:00
2017-08-02 16:36:39 +02:00
private void btnLaunch_Click ( object sender , EventArgs e )
2017-07-31 23:44:41 +02:00
{
2017-08-01 00:01:03 +02:00
BuilderWindow BW = NB . GetBuilderWin ( ) ;
2017-08-09 02:01:42 +02:00
if ( tvClasswork . SelectedNode ! = null & & tvClasswork . SelectedNode . Tag is string ) return ;
if ( tvClasswork . SelectedNode ! = null & & tvClasswork . SelectedNode . Tag is PersonClass ) return ;
if ( BW ! = null & & ViewedSchoolwork ! = null & & ViewedSchoolwork . theProject ! = null )
2017-08-01 00:01:03 +02:00
{
ViewedSchoolwork . theProject . WhatFrom = ViewedSchoolwork ; //Store the homework info. Used for pushing it back
2017-08-02 16:35:29 +02:00
BW . LoadNetworkFromNetwork ( ViewedSchoolwork . theProject ) ;
2017-08-01 00:01:03 +02:00
Close ( ) ; //Exit out of the profile
}
2017-07-31 23:44:41 +02:00
}
2017-08-01 21:30:07 +02:00
private void btnImportStudents_Click ( object sender , EventArgs e )
{
//Get a csv file
//try to read it in
//Import them all
2017-08-02 02:04:35 +02:00
Random myRandom = NB . GetRandom ( ) ;
bool AutoCreatePWs = true ;
bool ForcePWChange = true ;
2017-08-01 21:30:07 +02:00
OpenFileDialog mydialog = new OpenFileDialog ( ) ;
mydialog . AddExtension = true ;
string filter = "Comma Separated List (*.csv)|*.csv" ;
mydialog . Filter = filter ;
mydialog . Multiselect = false ;
mydialog . CheckFileExists = true ;
mydialog . ShowHelp = true ;
if ( CurrentUser . UserSettings . LastPath ! = null & & CurrentUser . UserSettings . LastPath ! = "" )
mydialog . FileName = CurrentUser . UserSettings . LastPath ;
DialogResult result = mydialog . ShowDialog ( ) ;
if ( result = = System . Windows . Forms . DialogResult . Cancel ) return ;
2017-08-02 16:01:14 +02:00
//Prompt for import settings.
Dictionary < string , bool > Checks = new Dictionary < string , bool > ( ) ;
Checks . Add ( NB . Translate ( "PPF_AutoGenPW" ) , AutoCreatePWs ) ;
Checks . Add ( NB . Translate ( "PPF_ForcePWChange" ) , ForcePWChange ) ;
Dictionary < string , bool > Response = NB . CheckPromptBox ( Checks , NB . Translate ( "PPF_ImportSettings" ) , Properties . Resources . NBIco ) ;
if ( Response = = null ) return ; //We canceled out
if ( Response . ContainsKey ( NB . Translate ( "PPF_AutoGenPW" ) ) ) AutoCreatePWs = Response [ NB . Translate ( "PPF_AutoGenPW" ) ] ;
if ( Response . ContainsKey ( NB . Translate ( "PPF_ForcePWChange" ) ) ) ForcePWChange = Response [ NB . Translate ( "PPF_ForcePWChange" ) ] ;
2017-08-01 21:30:07 +02:00
List < StudentHolder > tList = new List < StudentHolder > ( ) ;
2017-08-01 21:43:55 +02:00
List < string > InvalidUsers = new List < string > ( ) ;
List < string > InvalidFullName = new List < string > ( ) ;
List < string > InvalidPasswords = new List < string > ( ) ;
2017-08-01 21:30:07 +02:00
//Now we have a csv file. Try to parse it
2017-08-01 21:43:55 +02:00
bool HadError = false ;
2017-08-01 21:45:38 +02:00
try
2017-08-01 21:30:07 +02:00
{
2017-08-01 21:45:38 +02:00
using ( TextFieldParser parser = new TextFieldParser ( mydialog . FileName ) )
2017-08-01 21:30:07 +02:00
{
2017-08-02 02:04:35 +02:00
StudentHolder TStudent = new StudentHolder ( ) ;
2017-08-01 21:45:38 +02:00
parser . TextFieldType = FieldType . Delimited ;
parser . SetDelimiters ( "," ) ;
while ( ! parser . EndOfData )
2017-08-01 21:30:07 +02:00
{
2017-08-01 21:45:38 +02:00
//Process row
int index = 0 ;
string [ ] fields = parser . ReadFields ( ) ;
foreach ( string field in fields )
2017-08-01 21:43:55 +02:00
{
2017-08-01 21:45:38 +02:00
//TODO: Process field
if ( index = = 0 )
2017-08-01 21:43:55 +02:00
{
2017-08-02 02:04:35 +02:00
TStudent = new StudentHolder ( ) ;
2017-08-01 21:45:38 +02:00
TStudent . Name = field ;
if ( ! NB . ValidateUsername ( field ) )
{
HadError = true ;
InvalidUsers . Add ( TStudent . Name ) ;
}
2017-08-01 21:43:55 +02:00
2017-08-01 21:45:38 +02:00
}
if ( index = = 1 )
2017-08-01 21:43:55 +02:00
{
2017-08-01 21:45:38 +02:00
TStudent . FullName = field ;
if ( ! NB . ValidateFullName ( field ) )
{
HadError = true ;
InvalidFullName . Add ( TStudent . Name ) ;
}
2017-08-01 21:43:55 +02:00
}
2017-08-01 21:45:38 +02:00
if ( index = = 2 )
2017-08-01 21:43:55 +02:00
{
2017-08-01 21:45:38 +02:00
TStudent . Password = field ;
if ( ! NB . ValidatePassword ( field ) )
{
HadError = true ;
InvalidPasswords . Add ( TStudent . Name ) ;
}
2017-08-01 21:43:55 +02:00
}
2017-08-01 21:45:38 +02:00
index + + ; //Track which field we are in.
2017-08-01 21:43:55 +02:00
}
2017-08-02 02:04:35 +02:00
if ( AutoCreatePWs & & TStudent . Password = = "" )
TStudent . Password = TrippleDESDocumentEncryption . GenUserPW ( myRandom ) ;
2017-08-01 21:45:38 +02:00
tList . Add ( TStudent ) ;
2017-08-01 21:30:07 +02:00
}
2017-08-01 21:45:38 +02:00
}
if ( HadError )
{
ShowInvalid ( "Username" , InvalidUsers ) ;
ShowInvalid ( "Full Name" , InvalidFullName ) ;
ShowInvalid ( "Password" , InvalidPasswords ) ;
2017-08-02 02:04:35 +02:00
return ; //Break out without adding them
2017-08-01 21:30:07 +02:00
}
}
2017-08-01 21:45:38 +02:00
catch ( Exception except )
2017-08-01 21:43:55 +02:00
{
2017-08-01 21:45:38 +02:00
MessageBox . Show ( except . ToString ( ) ) ;
2017-08-02 02:04:35 +02:00
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 ;
2017-08-02 18:42:33 +02:00
tPC . UserSettings . AutoStartPuzzles = false ; //They will start with homework
tPC . UserSettings . ChosenLanguage = CurrentUser . UserSettings . ChosenLanguage ;
tPC . UserSettings . LanguageHasBeenChosen = true ; //No need to start by prompting.
2017-08-02 02:04:35 +02:00
CurrentUser . Students . Add ( tPC ) ;
}
else
{
dup_students + + ;
}
}
2017-08-03 18:46:04 +02:00
UpdateFormFromUser ( ) ;
2017-08-02 02:04:35 +02:00
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 ;
2017-08-01 21:43:55 +02:00
}
2017-08-02 02:04:35 +02:00
return null ;
2017-08-01 21:43:55 +02:00
}
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 ) ;
2017-08-01 21:30:07 +02:00
}
2017-08-02 18:10:34 +02:00
2017-08-02 18:25:26 +02:00
/// <summary>
/// Generate The student files for all the students.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2017-08-02 18:10:34 +02:00
private void btnGenerateStudentFiles_Click ( object sender , EventArgs e )
{
2017-08-02 18:25:26 +02:00
//Verify (choose) student file directory
//Loop through all the students
//Calculate the filename for the student file
//See if the file exists. If not, gen a new file
//Keep track of total # students, # new files, # skipped because they existed
2017-08-02 18:34:53 +02:00
int NumStudent = 0 ;
int NumMade = 0 ;
int NumSkipped = 0 ;
2017-08-02 18:25:26 +02:00
OpenFileDialog OFD = NB . SelectDirectoryDialog ( NB . Translate ( "PPF_SelectStudentDir" ) , CurrentUser . StudentFilePath ) ;
if ( OFD . FileName = = "" ) return ; //we cancel out
CurrentUser . StudentFilePath = Path . GetDirectoryName ( OFD . FileName ) ;
2017-08-02 18:34:53 +02:00
foreach ( PersonClass PC in CurrentUser . Students )
{
NumStudent + + ;
string FileName = Path . Combine ( CurrentUser . StudentFilePath , PC . FileName ) ;
if ( File . Exists ( FileName ) ) NumSkipped + + ;
else
{
2017-08-02 18:42:33 +02:00
PC . filepath = CurrentUser . StudentFilePath ; //For now. This changes, but it helps for now.
2017-08-02 18:34:53 +02:00
NumMade + + ;
PC . Save ( FileName ) ;
}
}
2017-08-02 18:10:34 +02:00
2017-08-02 18:34:53 +02:00
//Now, print the stats
MessageBox . Show ( string . Format ( NB . Translate ( "PPF_StudentWriteStats" ) , "\n\t" + NumStudent , "\n\t" + NumMade , "\n\t" + NumSkipped ) ) ;
2017-08-02 18:10:34 +02:00
}
2017-08-02 18:59:42 +02:00
private void btnHWGive_Click ( object sender , EventArgs e )
{
2017-08-02 19:17:20 +02:00
int NumStudents = 0 ;
int NumGiven = 0 ;
int NumAlready = 0 ;
//Create a new homework class for each student, containing this homework
if ( ViewedSchoolwork = = null ) return ; //We do not have homework selected
foreach ( PersonClass PC in CurrentUser . Students )
{
NumStudents + + ;
SchoolworkClass SWC = ViewedSchoolwork . Clone ( ) ;
SWC . isMaster = true ; //It is homework
SWC . IsSumbitted = false ; //It has not yet been submitted
bool didit = PC . AddHomework ( SWC ) ;
if ( didit ) NumGiven + + ;
else NumAlready + + ;
}
MessageBox . Show ( string . Format ( NB . Translate ( "PPF_GiveHWStats" ) , "\n\t" + NumStudents , "\n\t" + NumGiven , "\n\t" + NumAlready ) ) ;
2017-08-02 18:59:42 +02:00
}
private void btnHWSave_Click ( object sender , EventArgs e )
{
2017-08-02 20:03:14 +02:00
if ( ViewedSchoolwork = = null ) return ;
2017-08-02 19:50:25 +02:00
//Prompt for the filename where to save it
//Save the Schoolwork file
2017-08-02 20:03:14 +02:00
SaveFileDialog SFD = new SaveFileDialog ( ) ;
SFD . InitialDirectory = CurrentUser . filepath ; //Save wherever the teacher file is stored
SFD . OverwritePrompt = true ;
SFD . FileName = ViewedSchoolwork . FileName ;
SFD . AddExtension = true ;
SFD . Filter = "EduNetworkBuilder Homework File (*.eduh)|*.eduh" ;
DialogResult Answer = SFD . ShowDialog ( ) ;
if ( Answer = = DialogResult . Cancel ) return ;
//If we are here, we are ready to save it
ViewedSchoolwork . Save ( SFD . FileName ) ;
2017-08-02 18:59:42 +02:00
}
2017-08-02 23:57:50 +02:00
private void btnAllHomeworkToStudents_Click ( object sender , EventArgs e )
{
NB . NotImplimentedMessage ( ) ;
}
2017-08-05 23:56:25 +02:00
private void btnExportHomework_Click ( object sender , EventArgs e )
2017-08-02 23:57:50 +02:00
{
2017-08-06 00:01:37 +02:00
//Generate a list of homework, so we can make a check-box for it...
Dictionary < string , bool > HWList = new Dictionary < string , bool > ( ) ;
foreach ( SchoolworkClass sc in CurrentUser . Projects )
{
string one = sc . DueDate . ToShortDateString ( ) + " - " + sc . Name ;
HWList . Add ( one , false ) ;
}
//Now, make a prompt box for it.
Dictionary < string , bool > Response = NB . CheckPromptBox ( HWList , "Homework to include" , Properties . Resources . NBIco ) ;
2017-08-06 00:11:55 +02:00
if ( Response = = null ) return ; //if we canceled out
//Add each homework to a list
List < SchoolworkClass > HWClassList = new List < SchoolworkClass > ( ) ;
int index = 0 ;
foreach ( string one in HWList . Keys )
{
if ( index < CurrentUser . Projects . Count )
{
if ( Response [ one ] )
HWClassList . Add ( CurrentUser . Projects [ index ] ) ;
}
index + + ;
}
2017-08-06 04:39:57 +02:00
if ( HWClassList . Count = = 0 ) return ; //none selected.
2017-08-06 00:11:55 +02:00
2017-08-06 02:22:36 +02:00
OpenFileDialog mydialog = new OpenFileDialog ( ) ;
//If we have a user loaded, we can open homework files
string filter = "EduNetworkBuilder Homework File (*.enbh)|*.enbh;" ;
mydialog . Filter = filter ;
mydialog . Multiselect = false ;
mydialog . ShowHelp = true ;
2017-08-08 02:31:36 +02:00
mydialog . CheckFileExists = false ;
2017-08-06 02:22:36 +02:00
mydialog . CheckPathExists = true ;
2017-08-06 04:39:57 +02:00
mydialog . AddExtension = true ;
2017-08-06 02:22:36 +02:00
DialogResult result = mydialog . ShowDialog ( ) ;
if ( result = = System . Windows . Forms . DialogResult . Cancel ) return ; //Choose a file
2017-08-06 04:39:57 +02:00
2017-08-06 00:11:55 +02:00
//save that list in that file
2017-08-06 04:39:57 +02:00
SchoolworkClass . Save ( HWClassList , mydialog . FileName ) ;
2017-08-02 23:57:50 +02:00
}
2017-08-03 00:31:12 +02:00
private void btnReadAllStudentHomework_Click ( object sender , EventArgs e )
{
//Ask for a directory
//Loop through all students
//Read in the file for that student
// make temp person record
// loop through all networks
// Find any that are submitted, which are not in the admin file
// copy them into the admin file
//Track
// Num submitted homeworks.
// Num students
// Num of students with no submissions
bool HadASubmission = false ;
int NumStudent = 0 ;
int NumSubmitted = 0 ;
int NumStudentsNoSubmissions = 0 ;
int NumErrorFiles = 0 ;
int NumStudentsNoFiles = 0 ;
//Ask for a directory
OpenFileDialog OFD = NB . SelectDirectoryDialog ( NB . Translate ( "PPF_SelectStudentDir" ) , CurrentUser . StudentFilePath ) ;
if ( OFD . FileName = = "" ) return ; //we cancel out
CurrentUser . StudentFilePath = Path . GetDirectoryName ( OFD . FileName ) ;
//Loop through all students
foreach ( PersonClass storedStudent in CurrentUser . Students )
{
NumStudent + + ;
HadASubmission = false ;
string FullName = Path . Combine ( CurrentUser . StudentFilePath , storedStudent . FileName ) ;
//Read in the file for that student
try
{
if ( File . Exists ( FullName ) )
{
// make temp person record
2017-08-10 00:01:30 +02:00
PersonClass tempStudent = PersonClass . TryLoad ( FullName , storedStudent . AltPassword ) ;
2017-08-11 17:16:49 +02:00
if ( tempStudent = = null )
{
NumErrorFiles + + ;
continue ; //Do not try to load in the data
}
2017-08-12 23:05:54 +02:00
int tCountSubmitted = CurrentUser . TeacherImportStudentHomework ( tempStudent ) ;
NumSubmitted + = tCountSubmitted ;
if ( tCountSubmitted > 0 )
2017-08-03 00:31:12 +02:00
NumStudentsNoSubmissions + + ;
}
else
{
NumStudentsNoFiles + + ;
}
}
catch
{
NumErrorFiles + + ;
}
}
2017-08-17 02:04:21 +02:00
UpdateFormFromUser ( ) ;
2017-08-03 00:31:12 +02:00
MessageBox . Show ( string . Format ( NB . Translate ( "PPF_BringInHWSummary" ) ,
"\n\t" + NumStudent , "\n\t" + NumSubmitted ,
"\n\t" + NumStudentsNoSubmissions , "\n\t" + NumStudentsNoFiles ,
"\n\t" + NumErrorFiles ) ) ;
}
2017-08-10 23:32:45 +02:00
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 ( ) ) ;
}
}
private void btnExportStudentPasswords_Click ( object sender , EventArgs e )
{
SaveFileDialog mydialog = new SaveFileDialog ( ) ;
mydialog . AddExtension = true ;
string filter = "Comma Separated List (*.csv)|*.csv" ;
mydialog . Filter = filter ;
mydialog . CheckFileExists = false ;
mydialog . ShowHelp = true ;
if ( CurrentUser . UserSettings . LastPath ! = null & & CurrentUser . UserSettings . LastPath ! = "" )
mydialog . FileName = CurrentUser . UserSettings . LastPath ;
DialogResult result = mydialog . ShowDialog ( ) ;
if ( result = = System . Windows . Forms . DialogResult . Cancel ) return ;
WriteStudentCSVFile ( mydialog . FileName ) ;
}
2017-08-14 17:28:03 +02:00
private void cbTeacherAutoDHCP_CheckedChanged ( object sender , EventArgs e )
{
CurrentUser . UserSettings . AutoDHCPAllMachinesAtNetworkLoad = cbTeacherAutoDHCP . Checked ;
}
2017-08-14 23:13:17 +02:00
private void bthAutoTestStudentHomework_Click ( object sender , EventArgs e )
{
if ( CurrentUser = = null ) return ;
//Test all student's homework that is ungraded.
foreach ( PersonClass student in CurrentUser . Students )
{
foreach ( SchoolworkClass homework in student . Projects )
{
2017-08-15 00:21:24 +02:00
if ( homework . IsSumbitted & & ! homework . IsGraded & & homework . HomeworkStatus = = HomeworkSolvedStatus . NeverChecked )
2017-08-14 23:13:17 +02:00
{
//We only need to test homework that is submitted and not graded.
2017-08-15 00:21:24 +02:00
homework . CheckThatHomeworkIsSolved ( ) ; //Process it
2017-08-14 23:13:17 +02:00
}
}
}
2017-08-17 17:43:17 +02:00
UpdateFormFromUser ( ) ; //rebuild the tree.
2017-08-14 23:13:17 +02:00
}
2017-07-27 22:20:32 +02:00
}
}