Esempio n. 1
0
 private void savebtn_Click(object sender, EventArgs e)
 {
     using (StaffMemberContext db = new StaffMemberContext())
     {
         String surname    = lnTexBox.Text;
         String firstNames = fnTextBox.Text;
         String ID         = idTextBox.Text;
         String skill      = skillComboBox.SelectedItem.ToString();
         String ambID      = ambComboBox.SelectedItem.ToString();
         int    x;
         if (idTextBox.ReadOnly)
         {
             var idCheck = from j in db.StaffMembers where j.ID == ID select j;
             idCheck.First().GivenNames  = firstNames.Replace(" ", "");
             idCheck.First().Surname     = surname;
             idCheck.First().SkillLevel  = skill;
             idCheck.First().AmbulanceID = ambID;
             db.SaveChanges();
             AmbulanceOfficerForm ambulance = new AmbulanceOfficerForm();
             ambulance.Visible = true;
             Visible           = false;
         }
         else
         {
             if (!(int.TryParse(ID, out x)) || ID.Length != 6)
             {
                 MessageBox.Show("ID must be a number.\n Or the ID length must be of length 6.");
                 idTextBox.Clear();
                 idTextBox.Focus();
             }
             else
             {
                 var idCheck = from j in db.StaffMembers where j.ID == ID select j;
                 if (idCheck.Count() != 0)
                 {
                     MessageBox.Show("ID must be unique.");
                     idTextBox.Clear();
                     idTextBox.Focus();
                 }
                 else
                 {
                     var newMem = new StaffMember {
                         GivenNames = firstNames, Surname = surname, ID = ID, SkillLevel = skill, AmbulanceID = ambID
                     };
                     db.StaffMembers.Add(newMem);
                     db.SaveChanges();
                     AmbulanceOfficerForm ambulance = new AmbulanceOfficerForm();
                     ambulance.Visible = true;
                     Visible           = false;
                 }
             }
         }
     }
 }
Esempio n. 2
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();
             }
         }
     }
 }