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:
parent
b677ba02c6
commit
3af94d7f92
|
@ -9,14 +9,24 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GreatHomeChildcare.Models;
|
using GreatHomeChildcare.Models;
|
||||||
|
|
||||||
|
/* REFERENCES:
|
||||||
|
https://stackoverflow.com/questions/16436485/sqlite-selecting-the-maximum-corresponding-value
|
||||||
|
*/
|
||||||
|
|
||||||
namespace GreatHomeChildcare
|
namespace GreatHomeChildcare
|
||||||
{
|
{
|
||||||
class SqliteDataAccess
|
class SqliteDataAccess
|
||||||
{
|
{
|
||||||
#region student
|
#region student
|
||||||
|
// ***************** Create *****************
|
||||||
|
// ***************** Read *******************
|
||||||
|
// ***************** Update *****************
|
||||||
|
// ***************** Delete *****************
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region guardian
|
#region guardian
|
||||||
|
// ***************** Create *****************
|
||||||
|
|
||||||
// ***************** Read *****************
|
// ***************** Read *****************
|
||||||
|
|
||||||
/* Gets a Guardian by a distinct pin number. Distinctness enforced elsewhere.
|
/* Gets a Guardian by a distinct pin number. Distinctness enforced elsewhere.
|
||||||
|
@ -32,9 +42,13 @@ namespace GreatHomeChildcare
|
||||||
return guardian;
|
return guardian;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ***************** Update *****************
|
||||||
|
// ***************** Delete *****************
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region authorized_guardians
|
#region authorized_guardians
|
||||||
|
// ***************** Create *****************
|
||||||
|
|
||||||
// ***************** Read *****************
|
// ***************** Read *****************
|
||||||
|
|
||||||
/* Gets a list of all children per a specific guardian.
|
/* Gets a list of all children per a specific guardian.
|
||||||
|
@ -68,14 +82,63 @@ WHERE Guardians.id = @id
|
||||||
return output.ToList();
|
return output.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ***************** Update *****************
|
||||||
|
// ***************** Delete *****************
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region attendance
|
#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
|
#endregion
|
||||||
|
|
||||||
#region misc
|
#region misc
|
||||||
#endregion
|
// ***************** Create *****************
|
||||||
|
// ***************** Read *******************
|
||||||
|
|
||||||
/* Checks to see if this is the first time the application has run.
|
/* Checks to see if this is the first time the application has run.
|
||||||
* by counting the number of guardians in the guardian table.
|
* by counting the number of guardians in the guardian table.
|
||||||
|
@ -93,8 +156,15 @@ WHERE Guardians.id = @id
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ***************** Update *****************
|
||||||
|
// ***************** Delete *****************
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region reports
|
#region reports
|
||||||
|
// ***************** Create *****************
|
||||||
|
// ***************** Read *******************
|
||||||
|
// ***************** Update *****************
|
||||||
|
// ***************** Delete *****************
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private static string LoadConnectionString(string id = "Default")
|
private static string LoadConnectionString(string id = "Default")
|
||||||
|
|
Loading…
Reference in New Issue