From 95baba1ee124209f15b38ddc291edeb32a196185 Mon Sep 17 00:00:00 2001 From: kougyokugentou <41278462+kougyokugentou@users.noreply.github.com> Date: Wed, 20 Jan 2021 19:45:18 -0800 Subject: [PATCH] SHELL: Buttons for crud operations Move loading/refreshing datagridview into separate function so I can call it later on form add/update close. Add color commentary. --- frmAdminForm.cs | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/frmAdminForm.cs b/frmAdminForm.cs index 07c830e..fe88281 100644 --- a/frmAdminForm.cs +++ b/frmAdminForm.cs @@ -9,6 +9,11 @@ using System.Threading.Tasks; using System.Windows.Forms; using GreatHomeChildcare.Models; +/* 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 + */ + namespace GreatHomeChildcare { public partial class frmAdminForm : Form @@ -21,17 +26,60 @@ namespace GreatHomeChildcare InitializeComponent(); } + // Load the datagridview of children when this form opens. private void frmAdminForm_Load(object sender, EventArgs e) + { + 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() { List children = new List(); children = SqliteDataAccess.GetAllChildren(); - foreach(Child c in children) + foreach (Child c in children) { Image photo = (c.photo != null) ? ImageWrangler.ByteArrayToImage(c.photo) : Properties.Resources.child; - dgvChildren.Rows.Add(c.id, photo, c.DisplayName); } } + + //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."); + } + + //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."); + } + + //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."); + } + + 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); + } } }