diff --git a/frmMainForm.Designer.cs b/frmMainForm.Designer.cs index 88f62fc..d20fcb5 100644 --- a/frmMainForm.Designer.cs +++ b/frmMainForm.Designer.cs @@ -173,6 +173,7 @@ namespace GreatHomeChildcare this.btnChild2.TabIndex = 1; this.btnChild2.Text = "Child 2"; this.btnChild2.UseVisualStyleBackColor = true; + this.btnChild2.Click += new System.EventHandler(this.btnChild_Click); // // picturebox_child2 // @@ -205,6 +206,7 @@ namespace GreatHomeChildcare this.btnChild3.TabIndex = 1; this.btnChild3.Text = "Child 3"; this.btnChild3.UseVisualStyleBackColor = true; + this.btnChild3.Click += new System.EventHandler(this.btnChild_Click); // // picturebox_child3 // @@ -249,6 +251,7 @@ namespace GreatHomeChildcare this.btnChild4.TabIndex = 1; this.btnChild4.Text = "Child 4"; this.btnChild4.UseVisualStyleBackColor = true; + this.btnChild4.Click += new System.EventHandler(this.btnChild_Click); // // picturebox_child4 // @@ -281,6 +284,7 @@ namespace GreatHomeChildcare this.btnChild5.TabIndex = 1; this.btnChild5.Text = "Child 5"; this.btnChild5.UseVisualStyleBackColor = true; + this.btnChild5.Click += new System.EventHandler(this.btnChild_Click); // // picturebox_child5 // @@ -313,6 +317,7 @@ namespace GreatHomeChildcare this.btnChild6.TabIndex = 1; this.btnChild6.Text = "Child 6"; this.btnChild6.UseVisualStyleBackColor = true; + this.btnChild6.Click += new System.EventHandler(this.btnChild_Click); // // picturebox_child6 // @@ -345,6 +350,7 @@ namespace GreatHomeChildcare this.btnChild7.TabIndex = 1; this.btnChild7.Text = "Child 7"; this.btnChild7.UseVisualStyleBackColor = true; + this.btnChild7.Click += new System.EventHandler(this.btnChild_Click); // // picturebox_child7 // @@ -409,6 +415,7 @@ namespace GreatHomeChildcare this.btnChild9.TabIndex = 1; this.btnChild9.Text = "Child 9"; this.btnChild9.UseVisualStyleBackColor = true; + this.btnChild9.Click += new System.EventHandler(this.btnChild_Click); // // picturebox_child9 // diff --git a/frmMainForm.cs b/frmMainForm.cs index c0c919b..85462e5 100644 --- a/frmMainForm.cs +++ b/frmMainForm.cs @@ -55,8 +55,7 @@ namespace GreatHomeChildcare foreach(Child child in children) { //Make sure we don't break the program. - //Keep it in your pants, man!! - if (i >= 10) + if (i >= 10) //Keep it in your pants, man!! { MessageBox.Show("Sorry, the program only supports 9 children per guardian.", "Great Home Childcare", MessageBoxButtons.OK, MessageBoxIcon.None); break; @@ -83,15 +82,16 @@ namespace GreatHomeChildcare if (c is Button) { Button btn = (Button)c; + string strStudentStatus = SqliteDataAccess.GetChildSignInOut(child_in); + string btnText = child_in.DisplayName + " ("+ child_in.gender + ")\n\r" + + "DOB: " + child_in.DOB + "\n\r" + + "The student is checked " + strStudentStatus + "\n\r" + + "Press this button to sign " + (strStudentStatus == "in" ? "out" : "in"); - string btnText = child_in.DisplayName + "\n\r" - + child_in.gender + "\n\r" - + child_in.DOB + "\n\r" - + "CHECKOUT STATUS"; - - //TODO: Find a way to bind the child_in data to the button to reuse it when the button is clicked. - //btn.DataBindings.Add("childdata", child_in,); - Console.WriteLine("blaaaha"); + //shove the child into the Tag property which is a type of 'object' for later retrieval. + //see also: cheap hax + btn.Text = btnText; + btn.Tag = child_in; } } //foreach control } @@ -108,7 +108,25 @@ namespace GreatHomeChildcare private void btnChild_Click(object sender, EventArgs e) { + //to the passed in sender source and cast it to a Button + Button button = (Button)sender; + //here comes that cast we talked about. + //also: cheap hax + Child selectedChild = (Child)button.Tag; + + //Sign the student in or out. Logic handled in function. + SqliteDataAccess.SignChildInOut(selectedChild, guardian); + + //Re-grok the student's status. + string strStudentStatus = SqliteDataAccess.GetChildSignInOut(selectedChild); + + //Update the button text. + string btnText = selectedChild.DisplayName + " (" + selectedChild.gender + ")\n\r" + + "DOB: " + selectedChild.DOB + "\n\r" + + "The student is checked " + strStudentStatus + "\n\r" + + "Press this button to sign " + (strStudentStatus == "in" ? "out" : "in"); + button.Text = btnText; } } }