From 3af94d7f9274b64bd2f4f0f2cbaacbb97a1afff9 Mon Sep 17 00:00:00 2001 From: kougyokugentou <41278462+kougyokugentou@users.noreply.github.com> Date: Thu, 14 Jan 2021 21:38:58 -0800 Subject: [PATCH] Add comment (not region) for crud operations within each region. Add code to sign a student in or out. Add code to get a student sign in/out status. --- SqliteDataAccess.cs | 74 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/SqliteDataAccess.cs b/SqliteDataAccess.cs index d5f4636..a18da6f 100644 --- a/SqliteDataAccess.cs +++ b/SqliteDataAccess.cs @@ -9,14 +9,24 @@ using System.Text; using System.Threading.Tasks; using GreatHomeChildcare.Models; +/* REFERENCES: +https://stackoverflow.com/questions/16436485/sqlite-selecting-the-maximum-corresponding-value +*/ + namespace GreatHomeChildcare { class SqliteDataAccess { #region student + // ***************** Create ***************** + // ***************** Read ******************* + // ***************** Update ***************** + // ***************** Delete ***************** #endregion #region guardian + // ***************** Create ***************** + // ***************** Read ***************** /* Gets a Guardian by a distinct pin number. Distinctness enforced elsewhere. @@ -32,9 +42,13 @@ namespace GreatHomeChildcare return guardian; } } + // ***************** Update ***************** + // ***************** Delete ***************** #endregion #region authorized_guardians + // ***************** Create ***************** + // ***************** Read ***************** /* Gets a list of all children per a specific guardian. @@ -68,14 +82,63 @@ WHERE Guardians.id = @id return output.ToList(); } } - + // ***************** Update ***************** + // ***************** Delete ***************** #endregion #region attendance + // ***************** Create ***************** + + /* Creates a new entry in the attendence table each time + * a child is signed in our out of the system. + * Does --NOT-- need an Update function as the system + * is designed to keep track of --all-- times a child + * is signed in or out, and by which guardian. + * INPUTS: child, guardian + * OUTPUT: none to program, new row to sql db. + */ + internal void SignChildInOut(Child child_in, Guardian guardian_in) + { + string strStudentStatus = GetChildSignInOut(child_in); + + using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) + { + string strInOut = (strStudentStatus == "in" ? "out" : "in"); + string strQuery = "INSERT INTO Attendence(child_id, guardian_id,in_out) VALUES(@child_id, @guardian_id, @in_out)"; + cnn.Execute(strQuery, new + { + child_id = child_in.id, + guardian_id = guardian_in.id, + in_out = strInOut + }); + } + } + + // ***************** Read ***************** + + /* gets a single child in/out status. + * INPUT Child + * OUTPUT string "in" or "out". + */ + internal string GetChildSignInOut(Child child_in) + { + using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) + { + //Select only the latest attendence data for this student. + string strQuery = "SELECT in_out FROM Attendence WHERE child_id=@id AND id = (SELECT MAX(id) FROM Attendence WHERE child_id = @id)"; + + string output = cnn.Query(strQuery, child_in).SingleOrDefault(); + return output; + } + } + // ***************** Update ***************** + + // ***************** Delete ***************** #endregion #region misc - #endregion + // ***************** Create ***************** + // ***************** Read ******************* /* Checks to see if this is the first time the application has run. * by counting the number of guardians in the guardian table. @@ -93,8 +156,15 @@ WHERE Guardians.id = @id return true; } } + // ***************** Update ***************** + // ***************** Delete ***************** + #endregion #region reports + // ***************** Create ***************** + // ***************** Read ******************* + // ***************** Update ***************** + // ***************** Delete ***************** #endregion private static string LoadConnectionString(string id = "Default")