2021-01-17 20:57:00 -05: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 ;
2021-01-20 19:11:26 -05:00
using GreatHomeChildcare.Models ;
2021-01-17 20:57:00 -05:00
2021-01-20 22:45:18 -05:00
/ * Refs :
* https : //stackoverflow.com/questions/10063770/how-to-add-a-new-row-to-datagridview-programmatically
* https : //stackoverflow.com/questions/3370236/changing-the-row-height-of-a-datagridview
* /
2021-01-17 20:57:00 -05:00
namespace GreatHomeChildcare
{
public partial class frmAdminForm : Form
{
2021-01-20 19:11:26 -05:00
//globals for cheap access.
SqliteDataAccess SqliteDataAccess = new SqliteDataAccess ( ) ;
2021-01-22 01:58:52 -05:00
public static int child_id = 0 ;
2021-01-20 19:11:26 -05:00
2021-01-17 20:57:00 -05:00
public frmAdminForm ( )
{
InitializeComponent ( ) ;
}
2021-01-20 22:45:18 -05:00
// Load the datagridview of children when this form opens.
2021-01-17 20:57:00 -05:00
private void frmAdminForm_Load ( object sender , EventArgs e )
2021-01-20 22:45:18 -05:00
{
RefreshAdminView ( ) ;
}
/ * Load the admin form with a datagridview of
* all the children in the sql database .
* the ' id ' field is present in the datagridview for easy access
* but is hidden in the UI .
* INPUT : List of all children
* OUTPUT : Datagridview .
* /
private void RefreshAdminView ( )
2021-01-17 20:57:00 -05:00
{
2021-01-22 01:58:52 -05:00
dgvChildren . Rows . Clear ( ) ;
2021-01-20 19:11:26 -05:00
List < Child > children = new List < Child > ( ) ;
children = SqliteDataAccess . GetAllChildren ( ) ;
2021-01-20 22:45:18 -05:00
foreach ( Child c in children )
2021-01-20 19:11:26 -05:00
{
Image photo = ( c . photo ! = null ) ? ImageWrangler . ByteArrayToImage ( c . photo ) : Properties . Resources . child ;
dgvChildren . Rows . Add ( c . id , photo , c . DisplayName ) ;
}
2021-01-17 20:57:00 -05:00
}
2021-01-20 22:45:18 -05:00
//Close this screen, we're all done here.
private void btnClose_Click ( object sender , EventArgs e )
{
Close ( ) ;
}
//TODO: new form to generate reports
private void btnReports_Click ( object sender , EventArgs e )
{
MessageBox . Show ( "Reports button clicked." ) ;
}
2021-01-25 01:49:52 -05:00
/ * Pop - open a new form for crud operations for children
* and their guardians . Be sure you set the child_id
* to - 1 here just to be on the super - safe side .
* /
2021-01-20 22:45:18 -05:00
private void btnAdd_Click ( object sender , EventArgs e )
{
2021-01-22 01:58:52 -05:00
child_id = - 1 ; //ENSURE!!!!
ShowChildCrudForm ( ) ;
2021-01-20 22:45:18 -05:00
}
2021-01-25 01:49:52 -05:00
/ * Call the same crud form for adding a new child
* but store the child_id so the crud form
* can pick it up on form load .
* /
2021-01-20 22:45:18 -05:00
private void btnUpdate_Click ( object sender , EventArgs e )
{
2021-01-22 23:33:01 -05:00
/ * Get the child ' s database ID which is secretly hidden
* in the datagrid view at column 0. Since value is an
* Object , cast it to Int because that ' s what we know it is .
* /
child_id = ( int ) dgvChildren . CurrentRow . Cells [ 0 ] . Value ;
2021-01-22 01:58:52 -05:00
ShowChildCrudForm ( ) ;
}
2021-01-25 01:49:52 -05:00
/ * Seperate function to show the crud form
* because both the add and the update buttons
* will show the crud form .
* INPUT : void
* OUTPUT : void
* /
2021-01-22 01:58:52 -05:00
private void ShowChildCrudForm ( )
{
Form frmCrud = new frmChildCrud ( ) ;
frmCrud . FormClosed + = new FormClosedEventHandler ( CrudFormClosed ) ;
frmCrud . Show ( ) ;
Hide ( ) ;
}
//Show this admin screen after the child crud form is closed.
private void CrudFormClosed ( object sender , FormClosedEventArgs e )
{
RefreshAdminView ( ) ;
Show ( ) ;
2021-01-20 22:45:18 -05:00
}
2021-01-25 01:49:52 -05:00
/ * Allow the admin to quit the program as a normal login
* will not be able to exit the attendence program
* from the main pin screen on the shared tablet .
* /
2021-01-20 22:45:18 -05:00
private void btnQuit_Click ( object sender , EventArgs e )
{
MessageBox . Show ( "Thank you for using the program! Your data has been saved. Good bye!" , "Great Home Childcare" , MessageBoxButtons . OK , MessageBoxIcon . None ) ;
Environment . Exit ( 0 ) ;
}
2021-01-17 20:57:00 -05:00
}
}