示例#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>
        /// 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);
        }
示例#3
0
        /// <summary>
        /// btnNewSpecimen Click event.
        /// Clears the Page for a new Specimen.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        public void btnNewSpecimen_Clicked(object sender, EventArgs e)
        {
            specimen = new Specimen();

            entryFieldID.Text            = "";
            entryOccurrenceNotes.Text    = "";
            entrySubstrate.Text          = "";
            pickerLifeStage.SelectedItem = null;
            switchCultivated.IsToggled   = false;
            entryIndivCount.Text         = "";

            lblStatusMessage.IsVisible = false;
            lblStatusMessage.Text      = "";

            specimen.SiteName = site.SiteName;

            if (DataFunctions.CheckExists(specimen, site.RecordNo.ToString() + "-" + AppVariables.CollectionCount.ToString()))
            {
                Title = site.RecordNo.ToString() + "-" + (AppVariables.CollectionCount + 1).ToString();
            }
            else
            {
                Title = site.RecordNo.ToString() + "-" + AppVariables.CollectionCount.ToString();
            }
        }
示例#4
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);
        }
示例#5
0
        public async void Collect_OnClick(object sender, EventArgs e)
        {
            try
            {
                List <Project> projectList = DataFunctions.GetProjects();

                string[] projects = new string[projectList.Count + 1];
                for (int i = 0; i < projects.Length - 1; i++)
                {
                    projects[i] = projectList[i].ProjectName;
                }

                // default 'today' project
                Project todayProject = new Project
                {
                    ProjectName      = string.Format("Project-{0}", DateTime.Now.ToString("MM-dd-yyyy")),
                    PrimaryCollector = (AppVariables.CollectorName is null) ? "" : AppVariables.CollectorName,
                    CreatedDate      = DateTime.Now
                };

                bool dayPExists = false;

                foreach (var p in projectList)
                {
                    if (p.ProjectName.Equals(todayProject.ProjectName))
                    {
                        dayPExists = true;
                        break;
                    }
                }

                if (!dayPExists)
                {
                    projectList.Add(todayProject);
                    projects[projects.Length - 1] = string.Format("Project-{0}", DateTime.Now.ToString("MM-dd-yyyy"));
                }
                else
                {
                    projects = (from p in projectList
                                select p.ProjectName).ToArray();
                }

                var action = await DisplayActionSheet("Choose a project", "Cancel", null, projects);

                foreach (Project p in projectList)
                {
                    if (p.ProjectName.Equals(action))
                    {
                        if (action.Equals(string.Format("Project-{0}", DateTime.Now.ToString("MM-dd-yyyy"))))
                        { // add today project to database if it is selected
                            if (!DataFunctions.CheckExists(p, p.ProjectName))
                            {
                                int autoKeyResult = DataFunctions.InsertObject(p);
                                await Navigation.PushAsync(new CollectingPage(p));

                                break;
                            }
                            else
                            {
                                await Navigation.PushAsync(new CollectingPage(p));

                                break;
                            }
                        }
                        else
                        {
                            await Navigation.PushAsync(new CollectingPage(p));

                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("Can't start collecting until you've created a project!");
            }
        }
示例#6
0
        public async void btnAddSpecimen_Clicked(object sender, EventArgs e)
        {
            try
            {
                // get all sites for current Project
                List <Trip> tripList = DataFunctions.GetTrips(project.ProjectName);

                List <Site> allSites = new List <Site>();

                foreach (Trip trip in tripList)
                {
                    List <Site> tripSiteList = DataFunctions.GetSites(trip.TripName);
                    foreach (Site site in tripSiteList)
                    {
                        allSites.Add(site);
                    }
                }

                string[] sites = new string[allSites.Count + 1];
                for (int i = 0; i < sites.Length - 1; i++)
                {
                    sites[i] = allSites[i].SiteName;
                }

                sites[allSites.Count] = "Specimen-" + (AppVariables.CollectionCount + 1).ToString();

                var action = await DisplayActionSheet("Choose a Site, or add default Specimen", "Cancel", null, sites);

                Debug.WriteLine("Action chosen: " + action);

                if (action.Equals("Cancel"))
                {
                    return;
                }

                if (action.Contains("Specimen"))
                {
                    // if trip-today exists, add to it
                    // else add trip-today, add to it
                    Trip trip = new Trip
                    {
                        ProjectName    = project.ProjectName,
                        TripName       = "Trip-" + DateTime.Now.ToString("MM-dd-yyyy"),
                        CollectionDate = DateTime.Now
                    };
                    if (!DataFunctions.CheckExists(new Trip(), "Trip-" + DateTime.Now.ToString("MM-dd-yyyy")))
                    {
                        DataFunctions.InsertObject(trip);
                    }
                    // if site-today exists, add to it
                    // else add site-today, add to it
                    Site site = new Site
                    {
                        SiteName = "Site-" + DateTime.Now.ToString("MM-dd-yyyy"),
                        TripName = trip.TripName
                    };
                    if (!DataFunctions.CheckExists(site, site.SiteName))
                    {
                        Plugin.Geolocator.Abstractions.Position position = await CurrentGPS.CurrentLocation();

                        if (!(position is null))
                        {
                            site.GPSCoordinates = position.Latitude.ToString() + "," + position.Longitude.ToString() + "," + position.Accuracy.ToString() + "," + position.Altitude.ToString();
                        }
                        DataFunctions.InsertObject(site);
                    }
                    // add this specimen to the specimen database
                    // message user that specimen was added
                    Specimen specimen = new Specimen
                    {
                        SiteName       = site.SiteName,
                        SpecimenName   = action,
                        SpecimenNumber = AppVariables.CollectionCount,
                        GPSCoordinates = site.GPSCoordinates
                    };

                    DataFunctions.InsertObject(specimen);
                    AppVariables.CollectionCount += 1;

                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(action + " saved!");

                    // anytime we add a specimen we need to write back the CollectionCount
                    AppVarsFile.WriteAppVars();
                }
                else
                {
                    await Navigation.PushAsync(new SpecimenPage(DataFunctions.GetSiteByName(action)));
                }
            }
            catch (Exception ex)
            {
                // no Sites have been saved, no Site table to query against
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("Create Site first!");
                Debug.WriteLine(ex.Message);
            }
        }