Esempio n. 1
0
        /// <summary>
        /// btnSetSiteGPS Click event.
        /// Makes an async call to the CurrentGPS.CurrentLocation function.
        /// On success it sets the User's current location, on fail it does not.
        /// In either situation the User will be notified.
        /// Note: This is the second most important function in collNotes, as the GPS coordinates serve a purpose later on.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        public async void btnSetSiteGPS_Clicked(object sender, EventArgs e)
        {
            lblStatusMessage.IsVisible = true;
            lblStatusMessage.TextColor = Color.Orange;
            lblStatusMessage.Text      = "Getting Location...";

            Plugin.Geolocator.Abstractions.Position currentPosition;
            currentPosition = await CurrentGPS.CurrentLocation();

            if (currentPosition is null)
            {
                lblStatusMessage.TextColor = Color.Red;
                lblStatusMessage.Text      = "Failed to get location";
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("collNotes requires Location permission, and Location must be enabled!");
            }
            else
            {
                // 0 - 20    good
                if (currentPosition.Accuracy >= 0 && currentPosition.Accuracy <= 20)
                {
                    lblStatusMessage.TextColor = Color.Green;
                }
                // 21 - 30   ok
                else if (currentPosition.Accuracy >= 21 && currentPosition.Accuracy <= 30)
                {
                    lblStatusMessage.TextColor = Color.Yellow;
                }
                // 31 - ...  poor
                else
                {
                    lblStatusMessage.TextColor = Color.Orange;
                }

                lblStatusMessage.Text = "Location Received";
                siteGPS = currentPosition.Latitude.ToString() + "," + currentPosition.Longitude.ToString() + "," + currentPosition.Accuracy.ToString() + "," + currentPosition.Altitude.ToString();
            }
        }
Esempio n. 2
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);
            }
        }