public void Initialize()
 {
     specie = new Specie("Ab", "Ab", DateTime.MinValue, DateTime.MaxValue, 5);
     observation = new Observation(1, 1, specie, ObservationType.BirdPresent, 5, 5, 5);
     observation2 = new Observation(1, 1, specie, ObservationType.TerritoryIndicating, 5, 5, 5);
     observation3 = new Observation(1, 1, specie, ObservationType.NestIndicating, 5, 5, 5);
     visit = new Visit(1, 1, DateTime.MinValue, DateTime.MaxValue, null);
     area = new Area(1, 1, "Test", "Image", null);
     project = new Project(1, "Project", DateTime.MinValue, DateTime.MaxValue, null);
     visits = new Visits();
     observations = new Observations();
     speciePoint = new SpeciePoint("Sp", 5, 6);
     projectRepo = new ProjectRepository(new ProjectOracleContext());
     visitRepo = new VisitRepository(new VisitOracleContext());
     visitForm = new VisitForm(visit);
     observationForm = new ObservationForm(observation);
     observationForm2 = new ObservationForm(5, 5, 5, 5);
 }
        /// <summary>
        /// This method will edit an observation
        /// </summary>
        /// <param name="observation">Observation type observation parameter</param>
        /// <returns>A boolean which is true when observation is edited</returns>
        public bool EditObservation(Observation observation)
        {
            using (var connection = Database.Connection)
            using (var command = connection.CreateCommand())
            {
                command.CommandText = "UPDATE OBSERVATION " +
                                      "SET SPECIECODE=:specieCode, " +
                                      "OBSTYPE=:obsType, " +
                                      "AMOUNT=:amount " +
                                      "WHERE OBSID=:obsId ";

                command.Parameters.AddWithValue("specieCode", observation.Specie.SpecieCode);

                switch (observation.ObsType)
                {
                    case ObservationType.BirdPresent:
                        command.Parameters.AddWithValue("obsType", "BIRDPRESENT");
                        break;
                    case ObservationType.TerritoryIndicating:
                        command.Parameters.AddWithValue("obsType", "TERRITORYINDICATING");
                        break;
                    case ObservationType.NestIndicating:
                        command.Parameters.AddWithValue("obsType", "NESTINDICATING");
                        break;
                }
                
                command.Parameters.AddWithValue("amount", observation.Amount);
                command.Parameters.AddWithValue("obsId", observation.ObsId);

                try
                {
                    command.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
        /// <summary>
        /// This method will create an observation
        /// </summary>
        /// <param name="observation">Observation type observation parameter</param>
        /// <returns>A boolean which is true when observation is created</returns>
        public bool CreateObservation(Observation observation)
        {
            using (var connection = Database.Connection)
            using (var command = connection.CreateCommand())
            {
                command.CommandText = "INSERT INTO OBSERVATION (OBSID, VISITID, SPECIECODE, " +
                                      "OBSTYPE, AMOUNT, XCOR, YCOR) VALUES " +
                                      "(:obsId, :visitId, :specieCode, :obsType, :amount, :xCor, :yCor) ";

                command.Parameters.AddWithValue("obsId", observation.ObsId);
                command.Parameters.AddWithValue("visitId", observation.VisitId);
                command.Parameters.AddWithValue("specieCode", observation.Specie.SpecieCode);
                
                switch (observation.ObsType)
                {
                    case ObservationType.BirdPresent:
                        command.Parameters.AddWithValue("obsType", "BIRDPRESENT");
                        break;
                    case ObservationType.TerritoryIndicating:
                        command.Parameters.AddWithValue("obsType", "TERRITORYINDICATING");
                        break;
                    case ObservationType.NestIndicating:
                        command.Parameters.AddWithValue("obsType", "NESTINDICATING");
                        break;
                }
                
                command.Parameters.AddWithValue("amount", observation.Amount);
                command.Parameters.AddWithValue("xCor", observation.XCor);
                command.Parameters.AddWithValue("yCor", observation.YCor);

                try
                {
                    command.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the ObservationForm class.
        /// </summary>
        /// <param name="observation">Observation type observation parameter</param>
        public ObservationForm(Observation observation)
        {
            InitializeComponent();

            projectRepo = new ProjectRepository(new ProjectOracleContext());

            foreach (var s in projectRepo.LoadAllSpecies())
            {
                cbSpecies.Items.Add(s);
            }

            cbSpecies.Text = observation.Specie.Name;

            cbObservationType.Items.Add("Vogel aanwezig");
            cbObservationType.Items.Add("Territorium indicerend");
            cbObservationType.Items.Add("Nest indicerend");

            switch (observation.ObsType)
            {
                case ObservationType.BirdPresent:
                    cbObservationType.Text = "Vogel aanwezig";
                    break;
                case ObservationType.TerritoryIndicating:
                    cbObservationType.Text = "Territorium indicerend";
                    break;
                case ObservationType.NestIndicating:
                    cbObservationType.Text = "Nest indicerend";
                    break;
            }

            nudAmount.Value = observation.Amount;

            btnPlaceObservation.Visible = false;
            btnEditObservation.Visible = true;
        }
        private void btnPlaceObservation_Click(object sender, EventArgs e)
        {
            switch (cbObservationType.Text)
            {
                case "Vogel aanwezig":
                    observation = new Observation(obsId, visitId, specie, ObservationType.BirdPresent, Convert.ToInt32(nudAmount.Value), xcor, ycor);
                    break;
                case "Territorium indicerend":
                    observation = new Observation(obsId, visitId, specie, ObservationType.TerritoryIndicating, Convert.ToInt32(nudAmount.Value), xcor, ycor);
                    break;
                case "Nest indicerend":
                    observation = new Observation(obsId, visitId, specie, ObservationType.NestIndicating, Convert.ToInt32(nudAmount.Value), xcor, ycor);
                    break;
            }

            DialogResult = DialogResult.OK;
        }
 /// <summary>
 /// This method will edit an observation
 /// </summary>
 /// <param name="observation">Observation type observation parameter</param>
 /// <returns>A boolean which is true when observation is eidted</returns>
 public bool EditObservation(Observation observation)
 {
     return context.EditObservation(observation);
 }
 /// <summary>
 /// This method will create an observation
 /// </summary>
 /// <param name="observation">Observation type observation parameter</param>
 /// <returns>A boolean which is true when observation is created</returns>
 public bool CreateObservation(Observation observation)
 {
     return context.CreateObservation(observation);
 }
        private void panelMap_MouseClick(object sender, MouseEventArgs e)
        {
            x = e.X;
            y = e.Y;

            var observationForm = new ObservationForm(x, y, visit.VisitId, visitRepository.GetSequenceNextValObservation()) { Text = "Nieuwe waarneming" };

            DialogResult dr = new DialogResult();
            dr = observationForm.ShowDialog();

            if (dr == DialogResult.OK)
            {
                observation = ObservationForm.ReturnObservation();

                try
                {
                    observations.Add(observation);
                    Panel panel = new Panel();
                    panel.Height = 35;
                    panel.Width = 35;
                    panel.Location = new Point(x, y);
                    panel.MouseClick += p_Click;

                    switch (observation.ObsType)
                    {
                        case ObservationType.BirdPresent:
                            panel.BackgroundImage = images.Images[0];
                            break;
                        case ObservationType.TerritoryIndicating:
                            panel.BackgroundImage = images.Images[1];
                            break;
                        case ObservationType.NestIndicating:
                            panel.BackgroundImage = images.Images[2];
                            break;
                    }

                    panelMap.Controls.Add(panel);
                }
                catch (Exception)
                {
                    MessageBox.Show("Waarneming kon niet worden toegevoegd, probeer het nog eens.", "Error");
                }
            }
        }
        private void p_Click(object sender, MouseEventArgs e)
        {
            foreach (var o in observations)
            {
                Rectangle rect = new Rectangle(new Point(o.XCor, o.YCor), new Size(35, 35));

                if (rect.Contains(e.X + x, e.Y + y))
                {
                    selectedObservation = o;
                }
            }

            var observationForm = new ObservationForm(selectedObservation) { Text = "Waarneming aanpassen" };
            observationForm.ShowDialog();
            observation = ObservationForm.ReturnObservation();

            try
            {
                observations.Remove(selectedObservation);
                observations.Add(observation);
                Panel panel = new Panel();
                panel.Height = 35;
                panel.Width = 35;
                panel.Location = new Point(x, y);
                panel.MouseClick += p_Click;

                switch (observation.ObsType)
                {
                    case ObservationType.BirdPresent:
                        panel.BackgroundImage = images.Images[0];
                        break;
                    case ObservationType.TerritoryIndicating:
                        panel.BackgroundImage = images.Images[1];
                        break;
                    case ObservationType.NestIndicating:
                        panel.BackgroundImage = images.Images[2];
                        break;
                }

                panelMap.Controls.Add(panel);
                panel.BringToFront();
                selectedObservation = null;   
            }
            catch (Exception)
            {
                MessageBox.Show("Waarneming kon niet worden aangepast, probeer het nog eens.", "Error");
            }
        }