Implement GetSchoolByName for school editor

Bugfix .single() to .SingleOrDefault()
Move school stuff to a new region.
This commit is contained in:
kougyokugentou 2020-05-19 21:42:44 -07:00
parent ea3947eaf2
commit 06e167a75f

View File

@ -64,7 +64,7 @@ namespace DBWizard
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{ {
string strQuery = "SELECT * FROM students WHERE id=@id"; string strQuery = "SELECT * FROM students WHERE id=@id";
Student stu_out = cnn.Query<Student>(strQuery, new { id = dbid_in }).Single(); Student stu_out = cnn.Query<Student>(strQuery, new { id = dbid_in }).SingleOrDefault();
return stu_out; return stu_out;
} }
@ -155,7 +155,7 @@ namespace DBWizard
string strQuery = "INSERT INTO PARENTS (FirstName,LastName,PhoneNumber,EmailAddress)" + string strQuery = "INSERT INTO PARENTS (FirstName,LastName,PhoneNumber,EmailAddress)" +
"VALUES (@FirstName,@LastName,@PhoneNumber,@EmailAddress);" + "VALUES (@FirstName,@LastName,@PhoneNumber,@EmailAddress);" +
"SELECT MAX(parent_id) as parent_id from parents;"; "SELECT MAX(parent_id) as parent_id from parents;";
int parent_id_out = cnn.Query<int>(strQuery, par).Single(); int parent_id_out = cnn.Query<int>(strQuery, par).SingleOrDefault();
return parent_id_out; return parent_id_out;
} }
} }
@ -222,6 +222,55 @@ namespace DBWizard
#endregion #endregion
#region school
// ***************** Create *****************
/* Inserts a new school to the SQL database.
* INPUT: School
* OUTPUT: new row to SQL database, null to program.
*/
internal void InsertNewSchool(School sch)
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
string strQuery = "INSERT INTO SCHOOLS (name) VALUES (@name)";
cnn.Execute(strQuery, sch);
}
}
// ***************** Read *****************
/* Returns the list of available schools from the DB to fill the Schools drop-down.
* INPUT: no args
* OUTPUT: List<School>
*/
internal List<School> GetSchools()
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
string strQuery = "SELECT name FROM schools;";
var output = cnn.Query<School>(strQuery, new DynamicParameters());
return output.ToList();
}
}
/* Returns the a single School from the DB by name.
* Needed for the school editor.
* INPUT: string school_name_in
* OUTPUT: School
*/
internal School GetSchoolByName(string school_name_in)
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
string strQuery = "SELECT name FROM Schools WHERE name = @school_name;";
School output = cnn.Query<School>(strQuery, new { school_name = school_name_in }).SingleOrDefault();
return output;
}
}
#endregion
#region Misc #region Misc
/* Returns the list of available programs from the DB to fill the Programs drop-down. /* Returns the list of available programs from the DB to fill the Programs drop-down.
* INPUT: no args * INPUT: no args
@ -238,20 +287,6 @@ namespace DBWizard
} }
} }
/* Returns the list of available schools from the DB to fill the Schools drop-down.
* INPUT: no args
* OUTPUT: List<School>
*/
internal List<School> GetSchools()
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
string strQuery = "SELECT name FROM schools;";
var output = cnn.Query<School>(strQuery, new DynamicParameters());
return output.ToList();
}
}
#endregion #endregion
#region reports #region reports