Exemplo n.º 1
0
 public AddOfficerForm()
 {
     InitializeComponent();
     using (StaffMemberContext dc = new StaffMemberContext())
     {
         var      ambulances = from k in dc.Ambulances select k;
         String[] ambulance  = new String[ambulances.Count()];
         int      count      = 0;
         foreach (Ambulance a in ambulances)
         {
             ambulance[count] = a.AmbulanceID;
             count           += 1;
         }
         String[] skills = { "Basic", "Intermediate", "Advanced" };
         for (int h = 0; h < skills.Length; h++)
         {
             skillComboBox.Items.Add(skills[h]);
         }
         for (int i = 0; i < ambulance.Length; i++)
         {
             ambComboBox.Items.Add(ambulance[i]);
         }
         skillComboBox.SelectedIndex = 0;
         ambComboBox.SelectedIndex   = 0;
         validateFirst();
         validateSur();
         validateSkill();
         validateAmbulance();
         validateID();
     }
     fnTextBox.Focus();
 }
 public AmbulanceOfficerForm()
 {
     InitializeComponent(); try
     {
         using (StaffMemberContext db = new StaffMemberContext())
         {
             var    rowSelect   = from h in db.StaffMembers select h;
             String ambulanceID = "";
             foreach (StaffMember officer in rowSelect)
             {
                 if (officer.AmbulanceID == null)
                 {
                     ambulanceID = "None";
                 }
                 else
                 {
                     ambulanceID = officer.AmbulanceID;
                 }
                 amboffcrtable.Rows.Add(officer.ID, officer.GivenNames + " " + officer.Surname, officer.SkillLevel, ambulanceID);
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.StackTrace);
         Environment.Exit(0);
     }
 }
Exemplo n.º 3
0
        private void ambulanceTable_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            String oldID      = "";
            String oldStation = "";
            int    count      = 0;//Counter for crew loop.

            foreach (DataGridViewRow row in ambulanceTable.SelectedRows)
            {
                oldID      += row.Cells[0].Value.ToString();
                oldStation += row.Cells[1].Value.ToString();
            }
            using (StaffMemberContext dj = new StaffMemberContext())
            {
                var      crewCheck = from r in dj.StaffMembers where r.AmbulanceID == oldID select r;
                String[] crewList  = new String[crewCheck.Count()];
                foreach (StaffMember crew in crewCheck)
                {
                    crewList[count] = crew.GivenNames + " " + crew.Surname;
                    count++;
                }
                AddAmbulanceForm editForm = new AddAmbulanceForm(oldID, oldStation, crewList);
                editForm.Visible = true;
                Visible          = false;
            }
        }
Exemplo n.º 4
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;
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
        public RosterForm()
        {
            InitializeComponent();
            using (StaffMemberContext dl = new StaffMemberContext())
            {
                var ambCount = from d in dl.Ambulances select d;
                foreach (Ambulance a in ambCount)
                {
                    String  idA       = a.AmbulanceID;
                    TextBox rosterBox = new TextBox();
                    rosterBox.Location   = new Point(x, y);
                    rosterBox.Width      = width;
                    rosterBox.Height     = height;
                    rosterBox.Multiline  = true;
                    rosterBox.ReadOnly   = true;
                    rosterBox.ScrollBars = ScrollBars.Vertical;
                    y = y + height + 22;//Gap between two buttons.
                    using (StaffMemberContext dp = new StaffMemberContext())
                    {
                        var      crewCount = from w in dp.StaffMembers where w.AmbulanceID == idA select w;
                        string[] crewList  = new string[crewCount.Count()];
                        int      count     = 0;
                        foreach (StaffMember staff in crewCount)
                        {
                            crewList[count] = staff.ID + " (" + staff.SkillLevel + ")";
                            count++;
                        }
                        rosterBox.Text = a.AmbulanceID + Environment.NewLine + string.Join(Environment.NewLine, crewList);
                        switch (paintSwatch)
                        {
                        case 0:
                            rosterBox.BackColor = Color.Crimson;
                            paintSwatch++;
                            break;

                        case 1:
                            rosterBox.BackColor = Color.GhostWhite;
                            paintSwatch--;
                            break;
                        }
                    }
                    rosterPanel.Controls.Add(rosterBox);
                }
            }
        }
Exemplo n.º 6
0
        public AddOfficerForm(String givenNames, String surname, String ID, String skill, String AmbulanceID)
        {
            InitializeComponent();
            int counterA = 0; // count of Skill Combo Box Index.
            int counterS = 0; //counter of Ambulance Combo Box.

            using (StaffMemberContext dc = new StaffMemberContext())
            {
                var      ambulances = from k in dc.Ambulances select k;
                String[] ambulance  = new String[ambulances.Count() + 1];
                ambulance[0] = "None";
                int count = 1;
                foreach (Ambulance a in ambulances)
                {
                    ambulance[count] = a.AmbulanceID;
                    count           += 1;
                }
                String[] skills = { "Basic", "Intermediate", "Advanced" };
                for (int h = 0; h < skills.Length; h++)
                {
                    skillComboBox.Items.Add(skills[h]);
                    if (skills[h].Equals(skill))
                    {
                        counterS = h;
                    }
                }
                for (int i = 0; i < ambulance.Length; i++)
                {
                    ambComboBox.Items.Add(ambulance[i]);
                    if (ambulance[i].Equals(AmbulanceID))
                    {
                        counterA = i;
                    }
                }
            }
            titlelbl.Text               = "Ambulance Officer: " + givenNames + surname;
            fnTextBox.Text              = givenNames;
            lnTexBox.Text               = surname;
            idTextBox.Text              = ID;
            idTextBox.ReadOnly          = true;
            skillComboBox.SelectedIndex = counterS;
            ambComboBox.SelectedIndex   = counterA;
            fnTextBox.Focus();
        }
Exemplo n.º 7
0
 public AmbulanceForm()
 {
     InitializeComponent();
     try
     {
         using (StaffMemberContext db = new StaffMemberContext())
         {
             var rowSelect = from h in db.Ambulances select h;
             foreach (Ambulance ambulance in rowSelect)
             {
                 ambulanceTable.Rows.Add(ambulance.AmbulanceID, ambulance.Station);
             }
         }
     }catch (Exception e)
     {
         Console.WriteLine(e.StackTrace);
         Environment.Exit(0);
     }
 }
Exemplo n.º 8
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();
             }
         }
     }
 }