void btnSaveSettings_Clicked(object sender, EventArgs e) { if (!entryStartingRecordNumber.Text.Equals("")) { int currentSpecimenCount = DataFunctions.GetSpecimenCount(); if (currentSpecimenCount > 0) { int userEntered = int.Parse(entryStartingRecordNumber.Text); if (userEntered < currentSpecimenCount) // the user should not be able to set the collection count to a value lower than the current total { DependencyService.Get <ICrossPlatformToast>().ShortAlert("You cannot set the Specimen Count lower than the current total."); return; } else { AppVariables.CollectionCount = userEntered; } } } if (!entryCollectorName.Text.Equals("")) { AppVariables.CollectorName = entryCollectorName.Text; } if (pickerExportFormat.SelectedIndex != -1) { AppVariables.DataExportFormat = pickerExportFormat.SelectedItem.ToString(); } AppVarsFile.WriteAppVars(); DependencyService.Get <ICrossPlatformToast>().ShortAlert("Saved settings"); // automatically go back to main page after save Navigation.PopAsync(); }
/// <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); }
protected override void OnSleep() { // Handle when your app sleeps AppVarsFile.WriteAppVars(); }
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); } }