Beispiel #1
0
        private void btnMisAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMisDesc.Text.Length == 0) throw new Exception("Voer aub een beschrijving in.");
                if(lstMisEmpChosen.Items.Count == 0) throw new Exception("Kies aub crew members");

                Mission thisMission;
                string beschrijving = txtMisDesc.Text;
                int lat = (int) numMisLat.Value;
                int lng = (int) numMisLng.Value;

                List<Employee> employees = (from object t in lstMisEmpChosen.Items
                                            select Convert.ToInt32(admin.GetSubstringByString("(", ")", Convert.ToString(t)))
                                                into id
                                                select admin.FindEmployee(id)).ToList();

                int captainCount = employees.Count(emp => emp.Type == EmployeeType.Kapitein);
                int policeCount = employees.Count(emp => emp.Type == EmployeeType.Politie);
                int bioCount = employees.Count(emp => emp.Type == EmployeeType.Bioloog);
                int techCount = employees.Count(emp => emp.Type == EmployeeType.Technicus);

                if(captainCount == 0) throw new Exception("Selecteer aub een kapitein");

                if (radMisHope.Checked)
                {
                    DateTime start = datMisStart.Value;
                    DateTime end = datMisEnd.Value;

                    if (comMisBoat.SelectedItem == null) throw new Exception("Kies aub een boot.");

                    Boat boat =
                        admin.FindBoat(
                            Convert.ToInt32(admin.GetSubstringByString("(", ")", comMisBoat.SelectedItem.ToString())));

                    thisMission = new Hope(0, beschrijving, lat, lng, boat, null, false, start, end, employees);

                }
                else
                {
                    int numPolice = (int) numMisPolice.Value;
                    if(policeCount != numPolice) throw new Exception("Please select " + numPolice + " police officers");

                    Boat boat = admin.GetClosestBoat(lat, lng, numPolice, datSinDate.Value);

                    thisMission = new Sin(0, beschrijving, lat, lng, boat, null, numPolice, datSinDate.Value, employees);
                }

                if (thisMission.Register())
                {
                    ClearMissionForm();
                    MessageBox.Show("De missie is toegevoegd aan het systeem.", "OK", MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Er is iets fout gegaan bij het toevoegen van de missie.", "Uh oh!",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Uh oh!",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        public List<Mission> GetMissions()
        {
            OracleCommand cmd = new OracleCommand("SELECT * FROM MISSIE");

            List<Dictionary<string, object>> missions = ExecuteQuery(cmd);

            List<Mission> returned = new List<Mission>();

            foreach (Dictionary<string, object> mission in missions)
            {
                string type = Convert.ToString(mission["TYPE"]);
                Mission thisMission;

                int id = Convert.ToInt32(mission["MISSIEID"]);
                string desc = Convert.ToString(mission["BESCHRIJVING"]);

                int lat = Convert.ToInt32(mission["LATITUDE"]);
                int lng = Convert.ToInt32(mission["LONGITUDE"]);

                if (type.ToUpper() == "HOPE")
                {
                    DateTime start = new SimpleDate(Convert.ToString(mission["STARTTIJD"])).RealDate;
                    DateTime end = new SimpleDate(Convert.ToString(mission["EINDTIJD"])).RealDate;
                    bool approved = (Convert.ToInt32(mission["APPROVED"]) == 1);

                    thisMission = new Hope(id, desc, lat, lng, null, null, approved, start, end, null);
                }
                else
                {
                    DateTime date = new SimpleDate(Convert.ToString(mission["STARTTIJD"])).RealDate;
                    int policeCount = Convert.ToInt32(mission["AANTALPOLITIE"]);

                    thisMission = new Sin(id, desc, lat, lng, null, null, policeCount, date, null);
                }

                returned.Add(thisMission);
            }
            return returned;
        }