2021-01-12 01:34:14 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
2021-01-14 19:20:41 -05:00
|
|
|
|
using GreatHomeChildcare.Models;
|
2021-01-12 01:34:14 -05:00
|
|
|
|
|
2021-02-03 00:12:18 -05:00
|
|
|
|
//Refs
|
|
|
|
|
// https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form.shown?redirectedfrom=MSDN&view=net-5.0
|
2021-01-12 01:34:14 -05:00
|
|
|
|
namespace GreatHomeChildcare
|
|
|
|
|
{
|
|
|
|
|
public partial class frmPinEntry : Form
|
|
|
|
|
{
|
|
|
|
|
//Global instance of the SqliteDataAccess object.
|
2021-01-13 01:23:43 -05:00
|
|
|
|
SqliteDataAccess SqliteDataAccess = new SqliteDataAccess();
|
2021-01-12 01:34:14 -05:00
|
|
|
|
|
2021-01-13 23:13:31 -05:00
|
|
|
|
public static string strPin = String.Empty;
|
2021-01-12 01:34:14 -05:00
|
|
|
|
|
|
|
|
|
public frmPinEntry()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 20:57:46 -05:00
|
|
|
|
/* Event delegate to handle all the numerical buttons on the page.
|
|
|
|
|
* INPUT object sender, eventargs e
|
|
|
|
|
* OUTPUT: Stores pin in hidden variable strPin, while displaying * in the text box.
|
|
|
|
|
*/
|
2021-01-12 01:34:14 -05:00
|
|
|
|
private void btnNumButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Don't allow a PIN length longer than 4 digits.
|
|
|
|
|
if (strPin.Length >= 4)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//to the passed in sender source and cast it to a Button
|
|
|
|
|
Button button = (Button)sender;
|
|
|
|
|
strPin += button.Text;
|
|
|
|
|
tbPinNumber.Text += button.Text;
|
|
|
|
|
|
|
|
|
|
if (strPin.Length == 4)
|
|
|
|
|
btnLogin.Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 20:57:46 -05:00
|
|
|
|
//Prevents typing in the pin number box.
|
2021-01-12 01:34:14 -05:00
|
|
|
|
private void tbPinNumber_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Don't allow typing in the control.
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 20:57:46 -05:00
|
|
|
|
/*Clears the pin entry completely,
|
|
|
|
|
* resetting the hidden variable strPin,
|
|
|
|
|
* clearing the text box,
|
|
|
|
|
* and disabling the login button.
|
|
|
|
|
*/
|
2021-01-12 01:34:14 -05:00
|
|
|
|
private void btnCE_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
strPin = String.Empty;
|
|
|
|
|
tbPinNumber.Text = String.Empty;
|
|
|
|
|
btnLogin.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 20:57:46 -05:00
|
|
|
|
// Deletes the last number entered into the pinpad.
|
2021-01-12 01:34:14 -05:00
|
|
|
|
private void btnBack_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//If there is nothing in the display, do not attempt
|
|
|
|
|
//to remove any digits, or the program will crash.
|
|
|
|
|
if (strPin.Length == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//Assign the text in the display using a substring
|
|
|
|
|
//of whatever the text is, subtracting the length by 1.
|
|
|
|
|
//This effectively 'strips' the last digit from the display string.
|
|
|
|
|
tbPinNumber.Text = tbPinNumber.Text.Substring(0, tbPinNumber.Text.Length - 1);
|
|
|
|
|
strPin = strPin.Substring(0, strPin.Length - 1);
|
|
|
|
|
|
|
|
|
|
//disable login button
|
|
|
|
|
btnLogin.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 20:57:46 -05:00
|
|
|
|
/* Implements login functionality. If the pin # is valid (present in Guardian table)
|
|
|
|
|
* then it will instantiate a new object of Form2, and attach a form closed delegate to it.
|
|
|
|
|
* Then, the program shows the new form. strPin is public global so the new form can grab it.
|
|
|
|
|
* The program will then hide the pinpad form and clear the entry/pin value from memory.
|
|
|
|
|
*/
|
2021-01-12 01:34:14 -05:00
|
|
|
|
private void btnLogin_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Form frm2 = new frmMainForm();
|
|
|
|
|
frm2.FormClosed += new FormClosedEventHandler(MainFormClosed);
|
|
|
|
|
|
2021-01-13 01:23:43 -05:00
|
|
|
|
if(IsValidLogin(strPin))
|
|
|
|
|
{
|
|
|
|
|
frm2.Show();
|
|
|
|
|
Hide();
|
2021-01-13 23:13:31 -05:00
|
|
|
|
btnCE_Click(this, EventArgs.Empty);
|
2021-01-13 01:23:43 -05:00
|
|
|
|
}
|
2021-01-12 01:34:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-14 19:20:41 -05:00
|
|
|
|
/* valid login check to see if pin# exists in the db.
|
|
|
|
|
* INPUT integer pin number
|
|
|
|
|
* OUTPUT boolean true/false
|
|
|
|
|
*/
|
2021-01-13 01:23:43 -05:00
|
|
|
|
private bool IsValidLogin(string pin_in)
|
2021-01-12 01:34:14 -05:00
|
|
|
|
{
|
2021-01-13 01:23:43 -05:00
|
|
|
|
return true;
|
2021-01-14 19:20:41 -05:00
|
|
|
|
//TODO: Remove above return statement and implement after code testing.
|
|
|
|
|
//Could possibly move guardian to global and pass guardian to frmMainForm.
|
|
|
|
|
Guardian guardian = new Guardian();
|
|
|
|
|
|
|
|
|
|
guardian = SqliteDataAccess.GetGuardianByPin(Int32.Parse(pin_in));
|
|
|
|
|
|
|
|
|
|
if(guardian == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Sorry, that is an invalid login.", "Great Home Childcare", MessageBoxButtons.OK, MessageBoxIcon.None);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2021-01-13 01:23:43 -05:00
|
|
|
|
}
|
2021-01-12 01:34:14 -05:00
|
|
|
|
|
2021-01-13 01:23:43 -05:00
|
|
|
|
//Show the pin login screen after the main student login/out form is closed.
|
|
|
|
|
private void MainFormClosed(object sender, FormClosedEventArgs e)
|
|
|
|
|
{
|
2021-01-12 01:34:14 -05:00
|
|
|
|
Show();
|
2021-01-13 01:23:43 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Checks to see if this is the first-ever time the application has
|
|
|
|
|
* run by querying number of rows in Guardian table.
|
|
|
|
|
* If number of rows <= 0, we must setup an admin user in the guardian table.
|
2021-02-03 00:12:18 -05:00
|
|
|
|
* The Shown event is only raised the first time a form is displayed; subsequently
|
|
|
|
|
* minimizing, maximizing, restoring, hiding, showing, or invalidating and repainting
|
|
|
|
|
* will not raise this event. Ref: Microsoft
|
2021-01-13 01:23:43 -05:00
|
|
|
|
*/
|
2021-02-03 00:12:18 -05:00
|
|
|
|
private void frmPinEntry_Shown(object sender, EventArgs e)
|
2021-01-13 01:23:43 -05:00
|
|
|
|
{
|
2021-02-03 00:12:18 -05:00
|
|
|
|
Hide();
|
|
|
|
|
|
2021-01-30 01:12:05 -05:00
|
|
|
|
int num_admins = 0;
|
2021-01-13 01:23:43 -05:00
|
|
|
|
DialogResult dr;
|
|
|
|
|
|
2021-01-30 01:12:05 -05:00
|
|
|
|
num_admins = SqliteDataAccess.GetNumAdmins();
|
2021-01-13 01:23:43 -05:00
|
|
|
|
|
2021-02-03 00:12:18 -05:00
|
|
|
|
if (num_admins <= 0)
|
2021-01-13 01:23:43 -05:00
|
|
|
|
{
|
|
|
|
|
dr = MessageBox.Show("Program not setup yet. Setup now?", "Great Home Childcare", MessageBoxButtons.YesNo, MessageBoxIcon.None);
|
|
|
|
|
|
2021-01-27 17:56:59 -05:00
|
|
|
|
// Open the form to add a new guardian.
|
2021-01-13 01:23:43 -05:00
|
|
|
|
if (dr == DialogResult.Yes)
|
2021-01-27 17:56:59 -05:00
|
|
|
|
{
|
|
|
|
|
Form frm2 = new frmGuardianCrud();
|
|
|
|
|
frm2.FormClosed += new FormClosedEventHandler(MainFormClosed);
|
|
|
|
|
frm2.Show();
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
2021-01-13 01:23:43 -05:00
|
|
|
|
else //Show a message and close the application.
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Come back when you are ready to setup the program!", "Great Home Childcare", MessageBoxButtons.OK, MessageBoxIcon.None);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-03 00:12:18 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Show();
|
|
|
|
|
}
|
2021-01-12 01:34:14 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|