Пример #1
0
        /// <summary>
        /// Saves the current trip.
        /// </summary>
        /// <returns><c>true</c>, if current trip was saved, <c>false</c> otherwise.</returns>
        private bool SaveCurrentTrip()
        {
            // check to make sure name is present
            if (entryTripName.Text is null || entryTripName.Text.Equals(""))
            {
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("Trip name is required.");
                return(false);
            }

            trip.ProjectName          = project.ProjectName;
            trip.TripName             = entryTripName.Text;
            trip.AdditionalCollectors = (entryAdditionalCollectors.Text is null) ? "" : entryAdditionalCollectors.Text;
            trip.CollectionDate       = dpCollectionDate.Date;

            // check for duplicate names before saving
            if (DataFunctions.CheckExists(trip, trip.TripName))
            {
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("You already have a trip with the same name!");
                return(false);
            }

            // save trip to database
            int autoKeyResult = DatabaseFile.GetConnection().Insert(trip);

            Debug.WriteLine("inserted trip, recordno is: " + autoKeyResult.ToString());

            return(true);
        }
Пример #2
0
        /// <summary>
        /// btnSaveTrip Click event.
        /// Handles the Saving, or Updating, of the current Trip.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        public async void btnSaveTrip_Clicked(object sender, EventArgs e)
        {
            if (userIsEditing)
            {
                trip.AdditionalCollectors = (entryAdditionalCollectors.Text is null) ? "" : entryAdditionalCollectors.Text;
                trip.CollectionDate       = dateChanged ? dpCollectionDate.Date : trip.CollectionDate;

                int updateResult = DatabaseFile.GetConnection().Update(trip, typeof(Trip));
                if (updateResult == 1)
                {
                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(trip.TripName + " update succeeded.");
                    editWasSaved = true;
                    return;
                }
                else
                {
                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(trip.TripName + " update failed.");
                    return;
                }
            }

            SaveCurrentTrip();

            // automatically navigate to Site page after saving Trip
            await Navigation.PushAsync(new SitePage(trip));

            Navigation.RemovePage(this);
        }
Пример #3
0
        /// <summary>
        /// Saves the current project.
        /// </summary>
        /// <returns><c>true</c>, if current project was saved, <c>false</c> otherwise.</returns>
        private bool SaveCurrentProject()
        {
            // check to make sure name is present
            if (entryProjectName.Text is null || entryProjectName.Text.Equals(""))
            {
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("Project name is required.");
                return(false);
            }

            project.ProjectName      = entryProjectName.Text;
            project.PrimaryCollector = entryPrimaryCollectorProject.Text;
            project.CreatedDate      = dpCreatedDate.Date;

            // check for duplicate names first
            if (DataFunctions.CheckExists(project, project.ProjectName))
            {
                DependencyService.Get <ICrossPlatformToast>().ShortAlert($"'{project.ProjectName}' already exists...");
                return(false);
            }

            // save project to database
            int autoKeyResult = DatabaseFile.GetConnection().Insert(project);

            Debug.WriteLine("inserted project, recordno is: " + autoKeyResult.ToString());

            return(true);
        }
Пример #4
0
        /// <summary>
        /// btnSaveProject Click event.
        /// Handles the Saving, or Updating, of the current Project.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        private async void btnSaveProject_Clicked(object sender, EventArgs e)
        {
            if (userIsEditing)
            {
                project.PrimaryCollector = (entryPrimaryCollectorProject.Text is null) ? "" : entryPrimaryCollectorProject.Text;
                project.CreatedDate      = dateChanged ? dpCreatedDate.Date : project.CreatedDate;

                int updateResult = DatabaseFile.GetConnection().Update(project, typeof(Project));
                if (updateResult == 1)
                {
                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(project.ProjectName + " update succeeded.");
                    editWasSaved = true;
                    return;
                }
                else
                {
                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(project.ProjectName + " update failed.");
                    return;
                }
            }

            SaveCurrentProject();

            // automatically navigate to the collecting page after saving the project
            await Navigation.PushAsync(new CollectingPage(project));

            Navigation.RemovePage(this);
        }
Пример #5
0
        /// <summary>
        /// btnSaveSite Click event.
        /// Handles Save/Update of the current Site.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        public async void btnSaveSite_Clicked(object sender, EventArgs e)
        {
            if (userIsEditing)
            {
                site.AssociatedTaxa = (entryAssocTaxa.Text is null) ? "" : entryAssocTaxa.Text;
                site.GPSCoordinates = siteGPS.Equals("") ? site.GPSCoordinates : siteGPS;
                site.Habitat        = (entryHabitat.Text is null) ? "" : entryHabitat.Text;
                site.Locality       = (entryLocality.Text is null) ? "" : entryLocality.Text;
                site.LocationNotes  = (entryLocationNotes.Text is null) ? "" : entryLocationNotes.Text;

                int updateResult = DatabaseFile.GetConnection().Update(site, typeof(Site));
                if (updateResult == 1)
                {
                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(site.SiteName + " update succeeded.");
                    return;
                }
                else
                {
                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(site.SiteName + " update failed.");
                    return;
                }
            }

            SaveCurrentSite();

            // automatically navigate to the specimen page after creating the site
            await Navigation.PushAsync(new SpecimenPage(site));

            Navigation.RemovePage(this);
        }
Пример #6
0
        /// <summary>
        /// Saves the current specimen.
        /// </summary>
        /// <returns><c>true</c>, if current specimen was saved, <c>false</c> otherwise.</returns>
        private bool SaveCurrentSpecimen()
        {
            specimen.SiteName        = site.SiteName;
            specimen.GPSCoordinates  = site.GPSCoordinates;
            specimen.OccurrenceNotes = entryOccurrenceNotes.Text is null ? "" : entryOccurrenceNotes.Text;
            specimen.Substrate       = entrySubstrate.Text is null ? "" : entrySubstrate.Text;
            specimen.IndividualCount = entryIndivCount.Text is null ? "" : entryIndivCount.Text;
            specimen.Cultivated      = switchCultivated.IsToggled;

            AppVariables.CollectionCount = AppVariables.CollectionCount > 0 ? AppVariables.CollectionCount + 1 : 1;

            specimen.SpecimenNumber = AppVariables.CollectionCount;

            specimen.FieldIdentification = entryFieldID.Text is null ? "" : entryFieldID.Text;

            specimen.SpecimenName = "Specimen-" + specimen.SpecimenNumber;

            specimen.LifeStage = pickerLifeStage.SelectedItem is null ? "" : pickerLifeStage.SelectedItem.ToString();

            int autoKeyResult = DatabaseFile.GetConnection().Insert(specimen);

            Debug.WriteLine("inserted specimen, recordno is: " + autoKeyResult.ToString());

            // anytime we add a specimen we need to write back the CollectionCount
            AppVarsFile.WriteAppVars();

            return(true);
        }
Пример #7
0
        /// <summary>
        /// btnSaveSpecimen Click event.
        /// Saves or Updates the current Specimen.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        public void btnSaveSpecimen_Clicked(object sender, EventArgs e)
        {
            if (userIsEditing)
            {
                specimen.Substrate       = entrySubstrate.Text;
                specimen.IndividualCount = entryIndivCount.Text;
                specimen.Cultivated      = switchCultivated.IsToggled;
                specimen.OccurrenceNotes = entryOccurrenceNotes.Text;
                specimen.LifeStage       = pickerLifeStage.SelectedItem.ToString();
                specimen.GPSCoordinates  = site.GPSCoordinates;

                int updateResult = DatabaseFile.GetConnection().Update(specimen, typeof(Specimen));
                if (updateResult == 1)
                {
                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(specimen.SpecimenName + " save succeeded.");
                    return;
                }
                else
                {
                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(specimen.SpecimenName + " save failed");
                    return;
                }
            }

            SaveCurrentSpecimen();

            DependencyService.Get <ICrossPlatformToast>().ShortAlert("Saved " + specimen.SpecimenName);
            btnNewSpecimen_Clicked(this, e); // we could continue here or force the user to go back to the CollectingPage, need more user input...
        }
Пример #8
0
        protected override void OnStart()
        {
            // Handle when your app starts
            // load app variables from file
            bool result = AppVarsFile.ReadAppVars();

            if (!result)
            {
                AppVariables.CollectionCount = DataFunctions.GetSpecimenCount();
            }

            // create tables for ORM, if not already created
            DatabaseFile.GetConnection().CreateTable <Project>();
            DatabaseFile.GetConnection().CreateTable <Trip>();
            DatabaseFile.GetConnection().CreateTable <Site>();
            DatabaseFile.GetConnection().CreateTable <Specimen>();
        }
Пример #9
0
        /// <summary>
        /// Saves the current site.
        /// </summary>
        /// <returns><c>true</c>, if current site was saved, <c>false</c> otherwise.</returns>
        private bool SaveCurrentSite()
        {
            if (siteGPS.Equals(""))
            {
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("Record the Site GPS first!");
                return(false);
            }

            // saving new Site
            site.GPSCoordinates = siteGPS;
            site.TripName       = trip.TripName;

            // only require name to save Site
            if (entrySiteName.Text is null || entrySiteName.Text.Equals(""))
            {
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("Must enter a name for Site!");
                return(false);
            }

            site.SiteName = entrySiteName.Text;

            site.Locality       = entryLocality.Text is null ? "" : entryLocality.Text;
            site.Habitat        = entryHabitat.Text is null ? "" : entryHabitat.Text;
            site.AssociatedTaxa = entryAssocTaxa.Text is null ? "" : entryAssocTaxa.Text;
            site.LocationNotes  = entryLocationNotes.Text is null ? "" : entryLocationNotes.Text;

            // check for duplicate names before saving
            if (DataFunctions.CheckExists(site, site.SiteName))
            {
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("You already have a site with the same name!");
                return(false);
            }

            // save site to database
            int autoKeyResult = DatabaseFile.GetConnection().Insert(site);

            // DependencyService.Get<ICrossPlatformToast>().ShortAlert("Site " + site.SiteName + " saved!");
            Debug.WriteLine("inserted site, recordno is: " + autoKeyResult.ToString());

            return(true);
        }