Example #1
0
        private void ambulancebtn_Click(object sender, EventArgs e)
        {
            AmbulanceForm ambulance = new AmbulanceForm();

            ambulance.Visible = true;
            Visible           = false;
        }
Example #2
0
        private void cancelButton_Click(object sender, EventArgs e)
        {
            AmbulanceForm back = new AmbulanceForm();

            back.Visible = true;
            Visible      = false;
        }
Example #3
0
 private void SaveButton_Click(object sender, EventArgs e)
 {
     using (StaffMemberContext db = new StaffMemberContext())
     {
         String aID     = AIDTextBox.Text;
         String station = StationTextBox.Text;
         string isA     = aID.Substring(0, 1);
         int    x;
         if (aID.Length > 4)
         {
             MessageBox.Show("Ambulance ID must be at least length 4.");
             AIDTextBox.Clear();
             AIDTextBox.Focus();
         }
         if (!(isA.Equals("A")))
         {
             MessageBox.Show("Ambulance ID must start with 'A'.");
             AIDTextBox.Clear();
             AIDTextBox.Focus();
         }
         else
         {
             String intCheck = aID.Substring(1);
             if (int.TryParse(intCheck, out x))
             {
                 if (AIDTextBox.BackColor.Equals(Color.AliceBlue))
                 {
                     using (StaffMemberContext dp = new StaffMemberContext())
                     {
                         var amb         = from s in dp.Ambulances where s.AmbulanceID == aIDb select s;
                         var updateStaff = from t in dp.StaffMembers where t.AmbulanceID == aIDb select t;
                         foreach (StaffMember s in updateStaff)
                         {
                             s.AmbulanceID = aID;
                         }
                         String istasyon = amb.First().Station;
                         dp.Ambulances.RemoveRange(amb);
                         var updatedAmb = new Ambulance {
                             AmbulanceID = aID, Station = istasyon
                         };
                         dp.Ambulances.Add(updatedAmb);
                         dp.SaveChanges();
                         AmbulanceForm returnForm = new AmbulanceForm();
                         returnForm.Visible = true;
                         Visible            = false;
                     }
                 }
                 else
                 {
                     var idCheck = from g in db.Ambulances where g.AmbulanceID == aID select g;
                     if (idCheck.Count() == 0)
                     {
                         var newAmb = new Ambulance {
                             AmbulanceID = aID, Station = station
                         };
                         db.Ambulances.Add(newAmb);
                         db.SaveChanges();
                         AmbulanceForm returnForm = new AmbulanceForm();
                         returnForm.Visible = true;
                         Visible            = false;
                     }
                     else
                     {
                         MessageBox.Show("Ambulance ID must be unique.");
                         AIDTextBox.Clear();
                         AIDTextBox.Focus();
                     }
                 }
             }
             else
             {
                 MessageBox.Show("The sequence following 'A' must be an integer.");
                 AIDTextBox.Clear();
                 AIDTextBox.Focus();
             }
         }
     }
 }