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.
This commit is contained in:
kougyokugentou 2021-01-14 21:38:58 -08:00
parent b677ba02c6
commit 3af94d7f92
1 changed files with 72 additions and 2 deletions

View File

@ -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<string>(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")