From 2e501e513354d32f0a16d4ac2c230f9fa4afdf47 Mon Sep 17 00:00:00 2001 From: kougyokugentou <41278462+kougyokugentou@users.noreply.github.com> Date: Fri, 22 Jan 2021 23:18:39 -0800 Subject: [PATCH] Pop child object up to global. Add DOB picker to form Add some starter code to save/update and create a new child. Update should be done since it doesn't touch guardians. --- frmChildCrud.cs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/frmChildCrud.cs b/frmChildCrud.cs index 15c53b9..1f15d21 100644 --- a/frmChildCrud.cs +++ b/frmChildCrud.cs @@ -18,6 +18,7 @@ namespace GreatHomeChildcare //Global instance of the SqliteDataAccess object. SqliteDataAccess SqliteDataAccess = new SqliteDataAccess(); + Child child; enum Gender { @@ -61,7 +62,7 @@ namespace GreatHomeChildcare */ private void LoadChild(int child_id_in) { - Child child = SqliteDataAccess.GetChildByID(child_id_in); + child = SqliteDataAccess.GetChildByID(child_id_in); Gender genderOut; // sanity check, though it shouldn't be needed... @@ -79,6 +80,7 @@ namespace GreatHomeChildcare Enum.TryParse(child.gender, out genderOut); genderComboBox.SelectedItem = genderOut; + dOBMonthCalendar.SelectionStart = DateTime.Parse(child.DOB); addressTextBox.Text = child.address; photoPictureBox.Image = (child.photo != null) ? ImageWrangler.ByteArrayToImage(child.photo) : Properties.Resources.child; LoadGuardiansForChild(child); @@ -130,6 +132,38 @@ namespace GreatHomeChildcare private void btnSave_Click(object sender, EventArgs e) { MessageBox.Show("Save and close"); + return; + + //collect form and save to child object. + child.id = (int)idNumericUpDown.Value; + child.address = addressTextBox.Text; + child.DOB = dOBMonthCalendar.SelectionStart.ToShortDateString(); + child.FirstName = firstNameTextBox.Text; + child.gender = genderComboBox.Text; + child.LastName = lastNameTextBox.Text; + child.race = raceTextBox.Text; + + if (photoPictureBox.Tag.ToString() == DEFAULT_PIC_TAG) + child.photo = null; + else + child.photo = ImageWrangler.ImageToByteArray(photoPictureBox.Image); + + if(child.id > 0) //Should be all that's needed..... + { + SqliteDataAccess.UpdateChild(child); + MessageBox.Show("Child updated successfully! Data saved!"); + } + else + { + //TODO: write code to add child. >> bee-gee's "Stayin' alive" plays << + /* PB&J + * Pop new window to add at least one guardian to the child, either existing or new. + * Validate guardian exist in db upon return to this form. + * if valid, then populate guardian table and update authorized_guardians + * LAST THING: InsertNewStudent(child); + */ + } + Close(); } } }