private void officerbutton_Click(object sender, EventArgs e) { this.Hide(); officerform a = new officerform(); a.Closed += (s, args) => this.Close(); a.ShowDialog(); }
private void addeditofficersavebutton_Click(object sender, EventArgs e) { //START VALIDATING ALL THE VALUES int offidvalue; StaffMember stafftosave = new StaffMember(); List <string> validofficers = new List <string>(); //vaidate first name if (firstnametextbox.Text.Length == 0) { MessageBox.Show("'First Names' is a required field"); } else if (surnametextbox.Text.Length == 0) { MessageBox.Show("'Surname' is a required field"); } else if (!int.TryParse(officeridtextbox.Text, out offidvalue) && (officeridtextbox.Text.Length == 6)) { MessageBox.Show("Officer ID must be a six digit number"); } else if (skillcombobox.SelectedItem == null) { MessageBox.Show("A skill level must be selected"); } else if (ambulancecombobox.SelectedItem == null) { MessageBox.Show("An ambulance must be selected"); } else { using (TableContext db = new TableContext()) { foreach (var record in db.StaffTable) { if (record.officer_id == offidvalue) { stafftosave = record; } } if (stafftosave == null) { //Add a new record StaffMember a = new StaffMember { officer_id = offidvalue, first_names = firstnametextbox.Text, surname = surnametextbox.Text, skill_level = skillcombobox.SelectedItem.ToString(), ambulance_id = ambulancecombobox.SelectedItem.ToString() }; db.StaffTable.Add(a); } else { //Update a record stafftosave.officer_id = offidvalue; stafftosave.first_names = firstnametextbox.Text; stafftosave.surname = surnametextbox.Text; stafftosave.skill_level = skillcombobox.SelectedItem.ToString(); stafftosave.ambulance_id = ambulancecombobox.SelectedItem.ToString(); } db.SaveChanges(); this.Hide(); officerform form = new officerform(); form.Closed += (s, args) => this.Close(); form.ShowDialog(); } } }