Move guardian_id to global for the guardian crud form.
Add a found guardian combobox to add existing guardians to a child. ADD: Code to add an existing guardian to a child ADD: Code to pluck the guardian_id out of the currently selected combobox bound list of guardians Wrap FileOK in try/catch.
This commit is contained in:
parent
93968ac789
commit
1916c27af6
|
@ -21,6 +21,7 @@ namespace GreatHomeChildcare
|
||||||
//Global instance of the SqliteDataAccess object.
|
//Global instance of the SqliteDataAccess object.
|
||||||
SqliteDataAccess SqliteDataAccess = new SqliteDataAccess();
|
SqliteDataAccess SqliteDataAccess = new SqliteDataAccess();
|
||||||
Child child;
|
Child child;
|
||||||
|
int guardian_id;
|
||||||
|
|
||||||
enum Gender
|
enum Gender
|
||||||
{
|
{
|
||||||
|
@ -42,6 +43,7 @@ namespace GreatHomeChildcare
|
||||||
private void frmChildCrud_Load(object sender, EventArgs e)
|
private void frmChildCrud_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
FillGenderComboBox();
|
FillGenderComboBox();
|
||||||
|
FillGuardiansComboBox();
|
||||||
|
|
||||||
int child_id = frmAdminForm.child_id;
|
int child_id = frmAdminForm.child_id;
|
||||||
|
|
||||||
|
@ -52,12 +54,31 @@ namespace GreatHomeChildcare
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Populate the gender combo box with our enum.
|
||||||
private void FillGenderComboBox()
|
private void FillGenderComboBox()
|
||||||
{
|
{
|
||||||
genderComboBox.Items.Add(Gender.Female);
|
genderComboBox.Items.Add(Gender.Female);
|
||||||
genderComboBox.Items.Add(Gender.Male);
|
genderComboBox.Items.Add(Gender.Male);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Populate the existing guardian combobox
|
||||||
|
* with a listing of all guardians in the DB
|
||||||
|
* sorted by last name. Bind the guardian object
|
||||||
|
* to the drop-down so it can be easily referenced upon click
|
||||||
|
* of "add existing guardian".
|
||||||
|
* INPUTS: void from program
|
||||||
|
* OUTPUT: list of guardians from SQL db
|
||||||
|
*/
|
||||||
|
private void FillGuardiansComboBox()
|
||||||
|
{
|
||||||
|
List<Guardian> guardians = new List<Guardian>();
|
||||||
|
guardians = SqliteDataAccess.GetAllGuardians();
|
||||||
|
|
||||||
|
cbExistingGuardians.DataSource = guardians;
|
||||||
|
cbExistingGuardians.DisplayMember = "DisplayName";
|
||||||
|
cbExistingGuardians.Text = "Choose a guardian to add to this child";
|
||||||
|
}
|
||||||
|
|
||||||
/* Load an existing child onto the form for update/delete operations.
|
/* Load an existing child onto the form for update/delete operations.
|
||||||
* INPUT: integer child_id
|
* INPUT: integer child_id
|
||||||
* OUTPUT: data to screen
|
* OUTPUT: data to screen
|
||||||
|
@ -153,16 +174,63 @@ namespace GreatHomeChildcare
|
||||||
|
|
||||||
private void btnAddGuardian_Click(object sender, EventArgs e)
|
private void btnAddGuardian_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Add guardian");
|
int iOctomomCheck;
|
||||||
|
|
||||||
|
if(cbExistingGuardians.Text == "Choose a guardian to add to this child")
|
||||||
|
{
|
||||||
|
MessageBox.Show("Please select an existing guardian.", "Great Home Childcare", MessageBoxButtons.OK, MessageBoxIcon.None);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Guardian newGuardian = (Guardian)cbExistingGuardians.SelectedItem;
|
||||||
|
//Check to see if newGuardian is already a guardian of this child.
|
||||||
|
foreach(DataGridViewRow row in dgvGuardians.Rows)
|
||||||
|
{
|
||||||
|
if((int)row.Cells[0].Value == newGuardian.id)
|
||||||
|
{
|
||||||
|
MessageBox.Show("That guardian is already assigned to this child.", "Great Home Childcare", MessageBoxButtons.OK, MessageBoxIcon.None);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for octomom.
|
||||||
|
iOctomomCheck = SqliteDataAccess.CheckForOctomom(newGuardian);
|
||||||
|
if(iOctomomCheck > 9) // SERIOUSLY, KEEP IT IN YOUR PANTS
|
||||||
|
{
|
||||||
|
MessageBox.Show("Sorry, a single guardian can't have more than 9 children.", "Great Home Childcare", MessageBoxButtons.OK, MessageBoxIcon.None);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We are clear to add this guardian.
|
||||||
|
SqliteDataAccess.AddNewGuardianToChild(child, newGuardian);
|
||||||
|
LoadGuardiansForChild(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnNewGuardian_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
guardian_id = -1;
|
||||||
|
MessageBox.Show("Add (create) New guardian");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnEditGuardian_Click(object sender, EventArgs e)
|
private void btnEditGuardian_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
/* Get the guardian's database ID which is secretly hidden
|
||||||
|
* in the datagrid view at column 0. Since value is an
|
||||||
|
* Object, cast it to Int because that's what we know it is.
|
||||||
|
*/
|
||||||
|
guardian_id = (int)dgvGuardians.CurrentRow.Cells[0].Value;
|
||||||
|
|
||||||
MessageBox.Show("Edit Guardian");
|
MessageBox.Show("Edit Guardian");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnDeleteGuardian_Click(object sender, EventArgs e)
|
private void btnDeleteGuardian_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
/* Get the guardian's database ID which is secretly hidden
|
||||||
|
* in the datagrid view at column 0. Since value is an
|
||||||
|
* Object, cast it to Int because that's what we know it is.
|
||||||
|
*/
|
||||||
|
guardian_id = (int)dgvGuardians.CurrentRow.Cells[0].Value;
|
||||||
|
|
||||||
MessageBox.Show("Delete Guardian");
|
MessageBox.Show("Delete Guardian");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,6 +279,8 @@ namespace GreatHomeChildcare
|
||||||
{
|
{
|
||||||
byte[] dickpic;
|
byte[] dickpic;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
//Chunk file into bytes.
|
//Chunk file into bytes.
|
||||||
//If file > MAX_PIC_SIZE bytes long, reject file.
|
//If file > MAX_PIC_SIZE bytes long, reject file.
|
||||||
dickpic = File.ReadAllBytes(pic_openFileDialog.FileName);
|
dickpic = File.ReadAllBytes(pic_openFileDialog.FileName);
|
||||||
|
@ -220,5 +290,12 @@ namespace GreatHomeChildcare
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
MessageBox.Show("Unable to read selected file, try again.", "Great Home Childcare", MessageBoxButtons.OK, MessageBoxIcon.None);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user