Esempio n. 1
0
 private void officerform_Load(object sender, EventArgs e)
 {
     officerdatagridview.Columns.Add("Officer ID", "ID");
     officerdatagridview.Columns.Add("Officer Name", "Name");
     officerdatagridview.Columns.Add("Officer Skill Level", "Skill");
     officerdatagridview.Columns.Add("Ambulance ID", "Ambulance");
     using (TableContext db = new TableContext())
     {
         foreach (var record in db.StaffTable)
         {
             officerdatagridview.Rows.Add(record.officer_id, record.first_names + " " + record.surname, record.skill_level, record.ambulance_id ?? "None");
         }
     }
 }
Esempio n. 2
0
        //Constructor for a row click add edit officer form
        public addeditofficerform(int officerid, string firstname, string surname, string skill, string ambulanceid)
        {
            InitializeComponent();

            this.officerid   = officerid;
            this.firstname   = firstname;
            this.surname     = surname;
            this.skill       = skill;
            this.ambulanceid = ambulanceid;
            if (ambulanceid == null)
            {
                ambulanceid = "None";
            }


            //add valid ambulances to combo box
            List <string> ambucomboitems = new List <string>();

            using (TableContext db = new TableContext())
            {
                foreach (var record in db.AmbulanceTable)
                {
                    ambucomboitems.Add(record.ambulance_id);
                }
            }
            foreach (var item in ambucomboitems)
            {
                if (item != null)
                {
                    ambulancecombobox.Items.Add(item);
                }
            }

            //declaring strings and int for data to be put as default values
            firstnametextbox.Text          = firstname;
            surnametextbox.Text            = surname;
            officeridtextbox.Text          = officerid.ToString();
            skillcombobox.SelectedItem     = skill;
            ambulancecombobox.SelectedItem = ambulanceid;
        }
Esempio n. 3
0
        public addeditofficerform()
        {
            InitializeComponent();

            //add valid ambulances to combo box
            List <string> ambucomboitems = new List <string>();

            using (TableContext db = new TableContext())
            {
                foreach (var record in db.AmbulanceTable)
                {
                    ambucomboitems.Add(record.ambulance_id);
                }
            }
            foreach (var item in ambucomboitems)
            {
                if (item != null)
                {
                    ambulancecombobox.Items.Add(item);
                }
            }
        }
Esempio n. 4
0
        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();
                }
            }
        }