Add: Basic functionality for the child crud form.
This commit is contained in:
parent
4166541b39
commit
f4b54e8c6f
@ -20,7 +20,7 @@ namespace GreatHomeChildcare
|
||||
{
|
||||
//globals for cheap access.
|
||||
SqliteDataAccess SqliteDataAccess = new SqliteDataAccess();
|
||||
int child_id = 0;
|
||||
public static int child_id = 0;
|
||||
|
||||
public frmAdminForm()
|
||||
{
|
||||
@ -42,6 +42,8 @@ namespace GreatHomeChildcare
|
||||
*/
|
||||
private void RefreshAdminView()
|
||||
{
|
||||
dgvChildren.Rows.Clear();
|
||||
|
||||
List<Child> children = new List<Child>();
|
||||
children = SqliteDataAccess.GetAllChildren();
|
||||
|
||||
@ -67,14 +69,37 @@ namespace GreatHomeChildcare
|
||||
//TODO: new form to add a new child and their guardian(s)
|
||||
private void btnAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("Add button clicked.");
|
||||
child_id = -1; //ENSURE!!!!
|
||||
|
||||
ShowChildCrudForm();
|
||||
}
|
||||
|
||||
//TODO: new form(or same form as adding) for updating children
|
||||
//PB&J: get currently selected row from dgv, then pass to GetChildByID() to get Child object.
|
||||
private void btnUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("Update button clicked.");
|
||||
child_id = dgvChildren.CurrentRow.Index;
|
||||
|
||||
//child_id must be incremented as the index starts at 0.
|
||||
//TODO: FIX BUG!!
|
||||
child_id++;
|
||||
|
||||
ShowChildCrudForm();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private void btnQuit_Click(object sender, EventArgs e)
|
||||
|
@ -7,14 +7,76 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using GreatHomeChildcare.Models;
|
||||
|
||||
namespace GreatHomeChildcare
|
||||
{
|
||||
public partial class frmChildCrud : Form
|
||||
{
|
||||
const string DEFAULT_PIC_TAG = "DefaultPic";
|
||||
const string CUSTOM_PIC_TAG = "dickpic";
|
||||
|
||||
//Global instance of the SqliteDataAccess object.
|
||||
SqliteDataAccess SqliteDataAccess = new SqliteDataAccess();
|
||||
|
||||
enum Gender
|
||||
{
|
||||
Female = 0,
|
||||
Male = 1
|
||||
}
|
||||
|
||||
public frmChildCrud()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/* Event handler on form load.
|
||||
* Reads the child_id from the admin form if the update button
|
||||
* was selected on the admin form.
|
||||
* INPUTS: child_id from the admin form
|
||||
* OUTPUTS: void
|
||||
*/
|
||||
private void frmChildCrud_Load(object sender, EventArgs e)
|
||||
{
|
||||
int child_id = frmAdminForm.child_id;
|
||||
|
||||
//If the update button was selected.
|
||||
if (child_id > 0)
|
||||
{
|
||||
LoadChild(child_id);
|
||||
}
|
||||
}
|
||||
|
||||
/* Load an existing child onto the form for update/delete operations.
|
||||
* INPUT: integer child_id
|
||||
* OUTPUT: data to screen
|
||||
*/
|
||||
private void LoadChild(int child_id_in)
|
||||
{
|
||||
Child child = SqliteDataAccess.GetChildByID(child_id_in);
|
||||
|
||||
// sanity check, though it shouldn't be needed...
|
||||
if (child == null)
|
||||
return;
|
||||
|
||||
//Load the child data into the form.
|
||||
idNumericUpDown.Value = child.id;
|
||||
firstNameTextBox.Text = child.FirstName;
|
||||
lastNameTextBox.Text = child.LastName;
|
||||
//TODO: Gender via enum
|
||||
addressTextBox.Text = child.address;
|
||||
photoPictureBox.Image = (child.photo != null) ? ImageWrangler.ByteArrayToImage(child.photo) : Properties.Resources.child;
|
||||
LoadGuardiansForChild(child);
|
||||
}
|
||||
|
||||
private void LoadGuardiansForChild(Child child_in)
|
||||
{
|
||||
List<Guardian> guardians = SqliteDataAccess.GetGuardiansByChild(child_in);
|
||||
|
||||
foreach (Guardian g in guardians)
|
||||
{
|
||||
dgvGuardians.Rows.Add(g.id, g.LastName, g.FirstName, g.PhoneNumber, g.EmailAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user