Ejemplo n.º 1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            IndividualSighting s = new IndividualSighting();

            s.TroopVisit = DailyData.Current.TroopVisit;
            s.Individual = (Individual)comboBoxIndividuals.SelectedValue;
            s.Comments   = textBoxNewComments.Text;
            s.Sighting   = seen;

            foreach (IndividualSighting x in currentNotSeen)
            {
                if (x.Individual.ID == s.Individual.ID)
                {
                    MessageBox.Show("This " + s.Individual.Name + " already has an entry in the list. " +
                                    "Update the individuals detail with the 'Update' control.");
                    return;
                }
            }

            // Add to top of the list
            this.currentNotSeen.Insert(0, s);
            // Check the box
            SetCheckBox(0, true);

            CheckComplete();
            this.dataGridViewNotSeen_SelectionChanged(this, null);
        }
        private void buttonDone_Click(object sender, EventArgs e)
        {
            IndividualSighting currentIS = (IndividualSighting)dataGridViewNotSeen.SelectedRows[0].DataBoundItem;
            IndividualSighting newIS     = new IndividualSighting();

            newIS.TroopVisit = DailyData.Current.TroopVisit;
            newIS.Individual = currentIS.Individual;
            newIS.Sighting   = (radioButtonSeen.Checked ? seen : notSeen);
            newIS.Comments   = textBoxComments.Text;

            int index = dataGridViewNotSeen.SelectedRows[0].Index;

            // Replace the entry
            currentNotSeen[index] = newIS;

            // Set that we have updated this
            ((DataGridViewCheckBoxCell)dataGridViewNotSeen.Rows[index].Cells["sightedCheckBoxColumn"]).Value = sightedCheckBoxColumn.TrueValue;

            if (dataGridViewNotSeen.Rows.Count > index + 1)
            {
                dataGridViewNotSeen.Rows[index + 1].Selected = true;
            }

            CheckComplete();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Needs to be called after the form is created to populate
        /// the datagridview and add context menus etc.
        /// </summary>
        public override void LoadData()
        {
            // Get all the individuals then find their current states
            IList <Individual> individuals = Session
                                             .CreateQuery("from Individual as i " +
                                                          "join fetch i.SightingHistory as tc " +
                                                          "join fetch tc.TroopVisit as tv " +
                                                          "left join fetch i.ReproductiveStateHistory " +
                                                          "join fetch tc.Sighting ")
                                             .SetResultTransformer(new DistinctRootEntityResultTransformer())
                                             .List <Individual>();

            // Create a list for the current states
            currentStates = new SortableBindingList <IndividualSighting>();
            // Add each individuals current sighting
            foreach (Individual i in individuals)
            {
                IndividualSighting tc = i.CurrentSighting(troopVisit.Date);
                if (tc != null &&
                    tc.TroopVisit.Troop.TroopID == troop.TroopID)
                {
                    currentStates.Add(tc);
                }
            }

            this.bindingSource.DataSource = currentStates;
            this.DataGridView.DataSource  = bindingSource;
            this.DataGridView.Columns["Id"].DisplayIndex         = 0;
            this.DataGridView.Columns["Individual"].DisplayIndex = 1;
            this.DataGridView.Columns["Sighting"].DisplayIndex   = 2;
        }
        private void buttonAdd_Click_1(object sender, EventArgs e)
        {
            // Do some final checks and create a new individual and
            // add it to the list.
            Individual newIndividual = new Individual();

            newIndividual.Name = textBoxName.Text;
            newIndividual.Sex  = (Individual.SexEnum)comboBoxSex.SelectedItem;
            if (dateTimePickerActualDOB.Checked)
            {
                newIndividual.ActualDOB = dateTimePickerActualDOB.Value.Date;
            }
            if (dateTimePickerFieldDOB.Checked)
            {
                newIndividual.FieldEstimatedDOB = dateTimePickerFieldDOB.Value.Date;
            }
            newIndividual.Comment = textBoxComments.Text;
            newIndividual.IDNote  = textBoxIDNotes.Text;
            if (!checkBoxMotherUnknown.Checked)
            {
                newIndividual.Mother = (Individual)comboBoxMother.SelectedItem;
            }

            // We need to check the IDs of both the current and new individuals
            // to generate and id so create a new list with all the indiviudals
            List <Individual> newAndCurrent = new List <Individual>(individualList);

            newAndCurrent.AddRange(this.newIndividuals);
            newIndividual.ID = Individual.GenerateNewId(newAndCurrent,
                                                        DailyData.Current.TroopVisit, newIndividual.Sex);

            // We need to create initial individual sighting and ageclass entries
            IndividualSighting s = new IndividualSighting();

            s.Individual = newIndividual;
            s.Comments   = this.textBoxComments.Text;
            s.Sighting   = (Sighting)this.comboBoxSighting.SelectedValue;
            s.TroopVisit = DailyData.Current.TroopVisit;
            newIndividual.SightingHistory.Add(s);

            IndividualAgeClass a = new IndividualAgeClass();

            a.AgeClass   = (AgeClass)this.comboBoxAgeClass.SelectedValue;
            a.TroopVisit = DailyData.Current.TroopVisit;
            a.Individual = newIndividual;
            a.Comments   = textBoxComments.Text;
            newIndividual.AgeClassHistory.Add(a);

            // Add to binding list
            this.newIndividuals.Add(newIndividual);

            // Also add to list of Individuals for
            // id code updating
            this.individualList.Add(newIndividual);
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            IndividualSighting s = new IndividualSighting();

            s.TroopVisit = DailyData.Current.TroopVisit;
            s.Individual = (Individual)comboBoxIndividuals.SelectedValue;
            s.Comments   = textBoxNewComments.Text;
            s.Sighting   = seen;

            this.currentNotSeen.Add(s);
            int index = currentNotSeen.Count - 1;

            // Check the box
            ((DataGridViewCheckBoxCell)this.dataGridViewNotSeen["sightedCheckBoxColumn", index])
            .Value = sightedCheckBoxColumn.TrueValue;
        }
Ejemplo n.º 6
0
        void notSeenButton_Click(object sender, System.EventArgs e)
        {
            // Create a new entry for the selectded individual with the current troop visit
            // and set to not seen.
            Individual         individual = currentStates[DataGridView.CurrentRow.Index].Individual;
            IndividualSighting notSeen    = new IndividualSighting();

            notSeen.TroopVisit = troopVisit;
            notSeen.Individual = individual;
            notSeen.Sighting   = Session.Get <Sighting>("NS");

            individual.SightingHistory.Add(notSeen);
            IndividualSighting current = individual.CurrentSighting(troopVisit.Date);

            //this.AddNewEntry(notSeen, DataGridView.CurrentRow);
            RefreshRow(DataGridView.CurrentRow);
        }
Ejemplo n.º 7
0
        protected override void RowAction(DataGridViewRow row)
        {
            Individual individual = currentStates[row.Index].Individual;

            IndividualSighting tc = null;

            // We are making an entry for a specific date
            if (troopVisit != null)
            {
                tc            = new IndividualSighting();
                tc.Individual = individual;
                tc.TroopVisit = troopVisit;
            }

            SightingEditor tce = new SightingEditor(Session, individual, tc);

            if (tce.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                individual.SightingHistory.Add(tce.State);
                RefreshRow(row);
            }
        }
Ejemplo n.º 8
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            // We need to do some final checks here, namely the free form
            // text fields.

            // Check that the ID is valid
            //if (!this.checkIDValidity(individuals, this.troopVisitFirstObserved,
            //  (Individual.SexEnum)this.comboBoxSex.SelectedItem,
            //this.textBoxTrappingID.Text))
            //{
            //  MessageBox.Show("The trapping ID that has been enter is not valid. It must a 4 digit code of the form:\r" +
            //    "Troop ID of first observation + Sex + Digit + Digit"
            //  , "Invalid Trapping ID"
            //  , MessageBoxButtons.OK
            //  , MessageBoxIcon.Error);
            //return;
            //}

            // Check that the name is valid
            if (this.textBoxName.Text.Length < 1 || this.textBoxName.Text.Length > 45)
            {
                MessageBox.Show("The Name that has been enter is too long. It must be less than 44 digits long"
                                , "Invalid Name"
                                , MessageBoxButtons.OK
                                , MessageBoxIcon.Error);
                return;
            }

            // Check the IDNote is valid
            if (this.textBoxIDNotes.Text.Length > 200)
            {
                MessageBox.Show("The ID Note that has been enter is too long. It must be less than 200 digits long"
                                , "Invalid ID Note"
                                , MessageBoxButtons.OK
                                , MessageBoxIcon.Error);
                return;
            }

            // Check the Comment is valid
            if (this.textBoxIDNotes.Text.Length > 200)
            {
                MessageBox.Show("The Comment that has been enter is too long. It must be less than 200 digits long"
                                , "Invalid Comment"
                                , MessageBoxButtons.OK
                                , MessageBoxIcon.Error);
                return;
            }

            // Assign the values that were not bound
            individual.Sex        = (Individual.SexEnum) this.comboBoxSex.SelectedItem;
            individual.TrappingID = this.textBoxTrappingID.Text;
            individual.Name       = textBoxName.Text;
            //Session.SaveOrUpdate();

            if (isNew)
            {
                // We need to create initial individual sighting and ageclass entries
                IndividualSighting s = new IndividualSighting();
                s.Individual = this.individual;
                s.Comments   = this.textBoxComments.Text;
                s.Sighting   = (Sighting)this.comboBoxSighting.SelectedValue;
                s.TroopVisit = this.troopVisitFirstObserved;
                this.individual.SightingHistory.Add(s);

                IndividualAgeClass a = new IndividualAgeClass();
                a.AgeClass   = (AgeClass)this.comboBoxAgeClass.SelectedValue;
                a.TroopVisit = this.troopVisitFirstObserved;
                a.Individual = this.individual;
                a.Comments   = textBoxComments.Text;
                this.individual.AgeClassHistory.Add(a);
            }
            Session.SaveOrUpdate(individual);


            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
Ejemplo n.º 9
0
        public void LoadData()
        {
            this.currentNotSeen.Clear();

            // Should never happen but...
            if (DailyData.Current.TroopVisit == null)
            {
                MessageBox.Show("There is no current troop visit, cannot load data.");
                return;
            }

            session = NHibernateHelper.OpenNewSession();
            tx      = session.BeginTransaction();

            // Cache these values for later
            notSeen    = session.Get <Sighting>("NS");
            seen       = session.Get <Sighting>("S");
            absent     = session.Get <Sighting>("A");
            immigrated = session.Get <Sighting>("IM");

            // Get the last 5 (maxUncertainSightings) troop visits before this date
            lastTroopVisits = new List <TroopVisit>(session
                                                    .CreateQuery("select tv from TroopVisit as tv " +
                                                                 "left join fetch tv.Troop as t " +
                                                                 "where t.TroopID = :troopID and " +
                                                                 "tv.Date < :date " +
                                                                 "order by tv.Date desc")
                                                    .SetParameter <string>("troopID", DailyData.Current.TroopVisit.Troop.TroopID)
                                                    .SetParameter <DateTime>("date", DailyData.Current.TroopVisit.Date.Date)
                                                    .SetMaxResults(maxUncertainSightings)
                                                    .List <TroopVisit>());

            // Note the mostRecentTroopVisit prior to this one
            if (lastTroopVisits.Count > 0)
            {
                mostRecentTroopVisit = lastTroopVisits[0];
            }

            // Get all the individuals
            individuals = Individual.LoadAll(session);

            // We want all individual sightings for this troop visit and the last
            // if possible
            List <IndividualSighting> currentIndividualSightings = null;

            if (mostRecentTroopVisit != null && DailyData.Current.RetrievedData)
            {
                currentIndividualSightings = new List <IndividualSighting>(
                    session.CreateQuery("select s from IndividualSighting as s " +
                                        "where s.TroopVisit = :troopVisit or " +
                                        "s.TroopVisit = :troopVisit2")
                    .SetParameter <TroopVisit>("troopVisit", mostRecentTroopVisit)
                    .SetParameter <TroopVisit>("troopVisit2", DailyData.Current.TroopVisit)
                    //.SetMaxResults(maxUncertainSightings)
                    .List <IndividualSighting>());
            }
            else if (mostRecentTroopVisit != null)
            {
                TroopVisit tv = DailyData.Current.RetrievedData ? DailyData.Current.TroopVisit : mostRecentTroopVisit;
                currentIndividualSightings = new List <IndividualSighting>(
                    session.CreateQuery("select s from IndividualSighting as s " +
                                        "where s.TroopVisit = :troopVisit ")
                    .SetParameter <TroopVisit>("troopVisit", tv)
                    //.SetMaxResults(maxUncertainSightings)
                    .List <IndividualSighting>());
            }

            tx.Commit();

            // A list for sorting
            List <IndividualSighting> sightings = new List <IndividualSighting>();

            // List an entry for each individual
            foreach (Individual i in individuals)
            {
                // Find any sightings for this troop visit or the last troop visit
                // for this individual
                List <IndividualSighting> individualSightingCandidates = new List <IndividualSighting>();
                if (currentIndividualSightings != null)
                {
                    individualSightingCandidates = currentIndividualSightings.FindAll(x => x.Individual.ID == i.ID);
                }

                if (individualSightingCandidates.Count > 0) // Does this individual have an uncertain entry to list?
                {
                    // we want the most recent one to be displayed
                    IndividualSighting mostRecent = null;
                    foreach (IndividualSighting s in individualSightingCandidates)
                    {
                        if (mostRecent == null || s.TroopVisit.Date > mostRecent.TroopVisit.Date)
                        {
                            mostRecent = s;
                        }
                    }
                    sightings.Add(mostRecent);
                }
                else // if not add the current certain sighting that is an inclusion
                {
                    IndividualSighting s = i.CurrentSighting(DailyData.Current.TroopVisit,
                                                             true);
                    if (s != null && s.State.Inclusion)
                    {
                        sightings.Add(s);
                    }
                }
            }

            // Sort reverse date order
            sightings.Sort((x, y) => - 1 * x.TroopVisit.Date.CompareTo(y.TroopVisit.Date));

            // Add to the datagridview
            currentNotSeen = new BindingList <IndividualSighting>(sightings);
            this.individualSightingBindingSource.DataSource = currentNotSeen;

            // Filter individuals not from this troop only, either current troop == null
            // or current troop is differnet
            individuals = individuals.FindAll(new Predicate <Individual>(x =>
                                                                         x.CurrentTroop(DailyData.Current.TroopVisit.Date) == null || (
                                                                             x.CurrentTroop(DailyData.Current.TroopVisit.Date) != null &&
                                                                             (x.CurrentTroop(DailyData.Current.TroopVisit.Date).TroopID != DailyData.Current.TroopVisit.Troop.TroopID))));

            // Add to combo box
            this.comboBoxIndividuals.DataSource = individuals;

            CheckComplete();
            this.FinishedLoading(this, null);
        }
Ejemplo n.º 10
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            // The index of the selected row
            int index = dataGridViewNotSeen.SelectedRows[0].Index;
            IndividualSighting sighting = currentNotSeen[index];

            // What has the user selected for this individual
            Sighting selection = seen;

            if (radioButtonNotSeen.Checked)
            {
                selection = notSeen;
            }

            // What is the current state of the individual?
            // If we are updating a seen individual it is foreign
            if (sighting.Sighting.ID == seen.ID)
            {
                // If they have been seen again we need to add another entry for the individual
                if (selection.ID == seen.ID)
                {
                    IndividualSighting newIS = new IndividualSighting();
                    newIS.TroopVisit = DailyData.Current.TroopVisit;
                    newIS.Individual = sighting.Individual;
                    newIS.Sighting   = selection;
                    newIS.Comments   = textBoxComments.Text;

                    // Replace the entry
                    currentNotSeen[index] = newIS;

                    // Set that we have updated this
                    SetCheckBox(index, true);

                    // Move to next entry
                    if (dataGridViewNotSeen.Rows.Count > index + 1)
                    {
                        dataGridViewNotSeen.Rows[index + 1].Selected = true;
                    }
                }
                else // Remove them from the list, we do not need
                // to make any new entries
                {
                    currentNotSeen.RemoveAt(index);

                    // Move to next entry
                    if (dataGridViewNotSeen.Rows.Count > index)
                    {
                        dataGridViewNotSeen.Rows[index].Selected = true;
                    }
                }
            }
            else // the individual is not foreign
            {
                // Are we marking them as not seen?
                // If so we need to add a new entry
                if (selection.ID == notSeen.ID)
                {
                    IndividualSighting newIS = new IndividualSighting();
                    newIS.TroopVisit = DailyData.Current.TroopVisit;
                    newIS.Individual = sighting.Individual;
                    newIS.Sighting   = selection;
                    newIS.Comments   = textBoxComments.Text;

                    // Replace the entry
                    currentNotSeen[index] = newIS;

                    // Set that we have updated this
                    SetCheckBox(index, true);

                    // Move to next entry
                    if (dataGridViewNotSeen.Rows.Count > index + 1)
                    {
                        dataGridViewNotSeen.Rows[index + 1].Selected = true;
                    }
                }
                else // We need to show the last certain sighting
                     // and check as done
                {
                    currentNotSeen[index] = sighting.Individual.CurrentSighting(DailyData.Current.TroopVisit, true);

                    // Set that we have updated this
                    SetCheckBox(index, true);

                    // Move to next entry
                    if (dataGridViewNotSeen.Rows.Count > index + 1)
                    {
                        dataGridViewNotSeen.Rows[index + 1].Selected = true;
                    }
                }
            }

            // Is this page complete?
            CheckComplete();
        }
Ejemplo n.º 11
0
        public bool Finish()
        {
            // New version, we just need to add the values in currentNotSeen
            // and currentSeen to the database, as they should all have been
            // replaced
            foreach (IndividualSighting newIS in currentNotSeen)
            {
                // Check if this individual has reached the threshold for a change in certain
                // troop membership

                // First find all uncertain sightings that match with our last troop visits list
                List <IndividualSighting> matches = new List <IndividualSighting>(newIS.Individual.SightingHistory)
                                                    .FindAll(x =>
                                                             x.State.Certain == false &&
                                                             lastTroopVisits.Contains(x.TroopVisit));

                if (matches.Count >= maxUncertainSightings)
                {
                    int      threshold      = maxUncertainSightings + 1;
                    Sighting uncertainValue = null;
                    Sighting certainValue   = null;
                    if (matches[0].Sighting.ID == seen.ID)
                    {
                        uncertainValue = seen;
                        certainValue   = immigrated;
                    }
                    else
                    {
                        uncertainValue = notSeen;
                        certainValue   = absent;
                    }

                    IndividualSighting certainSighting = new IndividualSighting();
                    certainSighting.Individual = newIS.Individual;
                    certainSighting.TroopVisit = lastTroopVisits[lastTroopVisits.Count - 1];
                    certainSighting.Sighting   = certainValue;
                    certainSighting.Comments   = "AUTOMATICALLY GENERATED ENTRY :- Troop membership updated after " + threshold +
                                                 " " + uncertainValue.ID + " sightings";

                    // Ask if we want to change the troop membership for this individual
                    if (MessageBox.Show(newIS.Individual.Name + " " + uncertainValue.Description.ToLower() +
                                        " for the last " + threshold + " troop visits. These entries will be removed " +
                                        " and the individual will be marked as '" + certainSighting.Sighting.Description +
                                        "' on troop visit " + certainSighting.TroopVisit.ToString() + ". Do you want to make this change?",
                                        "Troop membership changed for " + newIS.Individual.Name,
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question,
                                        MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        // Add the new entry
                        DailyData.Current.NewSightings.Add(certainSighting);
                        // Delete the old entries
                        DailyData.Current.SightingsToDelete.AddRange(matches);

                        // We also want to remove reproductive states for females so..
                        List <IndividualReproductiveState> reproductiveStates =
                            new List <IndividualReproductiveState>(newIS.Individual.ReproductiveStateHistory)
                            .FindAll(x => lastTroopVisits.Contains(x.TroopVisit));

                        DailyData.Current.ReproductiveStatesToDelete.AddRange(reproductiveStates);
                        DailyData.Current.MigratedToday.Add(newIS.Individual);
                    }
                    else
                    {
                        if (newIS.State.ID == "NS")
                        {
                            DailyData.Current.MissingToday.Add(newIS.Individual);
                        }
                        if (newIS.ID == 0)
                        {
                            DailyData.Current.NewSightings.Add(newIS);
                        }
                    }
                }
                else // Not a migration so
                {
                    // Add those whose id is new
                    if (newIS.ID == 0)
                    {
                        DailyData.Current.NewSightings.Add(newIS);
                    }

                    if (newIS.State.ID == "NS")
                    {
                        DailyData.Current.MissingToday.Add(newIS.Individual);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 12
0
 private void AddNewEntry(IndividualSighting tc, DataGridViewRow row)
 {
     this.currentStates[row.Index] = tc;
     this.DataGridView.Rows[row.Index].DefaultCellStyle.BackColor = Color.Yellow;
 }