public async void btnSaveTrip_Clicked(object sender, EventArgs e) { if (editing) // editing should only require all existing information to be changed { if (!entryAdditionalCollectors.Text.Equals("") && !entryAdditionalCollectors.Text.Equals("")) { trip.AdditionalCollectors = entryAdditionalCollectors.Text; trip.CollectionDate = dpCollectionDate.Date; int updateResult = ORM.GetConnection().Update(trip, typeof(Trip)); if (updateResult == 1) // what is result of above call? { DependencyService.Get <ICrossPlatformToast>().ShortAlert(trip.TripName + " save succeeded."); return; } else { DependencyService.Get <ICrossPlatformToast>().ShortAlert(trip.TripName + " save failed."); return; } } } trip.ProjectName = projectName; bool defaultData = false; // check to make sure name is present if (entryTripName.Text is null || entryAdditionalCollectors.Text is null) { trip.TripName = entryTripName.Text; // only trip name is required // add default date trip.CollectionDate = DateTime.Today; defaultData = true; } if (!defaultData) { trip.TripName = entryTripName.Text; trip.AdditionalCollectors = entryAdditionalCollectors.Text; trip.CollectionDate = dpCollectionDate.Date; } // check for duplicate names before saving if (ORM.CheckExists(trip)) { DependencyService.Get <ICrossPlatformToast>().ShortAlert("You already have a trip with the same name!"); return; } // save trip to database int autoKeyResult = ORM.GetConnection().Insert(trip); Debug.WriteLine("inserted trip, recordno is: " + autoKeyResult.ToString()); DependencyService.Get <ICrossPlatformToast>().ShortAlert("Saved Trip " + trip.TripName); // automatically navigate to Site page after saving Trip await Navigation.PushAsync(new SitePage(trip)); }
// SaveProject button event // - checks for required data on click // - writes Project to the local database private async void btnSaveProject_Clicked(object sender, EventArgs e) { if (editing) { if (!(entryPrimaryCollectorProject.Text is null) || !entryPrimaryCollectorProject.Text.Equals("")) { project.PrimaryCollector = entryPrimaryCollectorProject.Text; project.CreatedDate = dpCreatedDate.Date; int updateResult = ORM.GetConnection().Update(project, typeof(Project)); if (updateResult == 1) { DependencyService.Get <ICrossPlatformToast>().ShortAlert(project.ProjectName + " update succeeded."); return; } else { DependencyService.Get <ICrossPlatformToast>().ShortAlert(project.ProjectName + " update failed."); return; } } else { DependencyService.Get <ICrossPlatformToast>().ShortAlert("Update requires some info to be changed."); return; } }
protected override void OnStart() { // Handle when your app starts // load app variables from file bool result = AppVarsFile.ReadAppVars(); // create tables for ORM, if not already created ORM.GetConnection().CreateTable <Project>(); ORM.GetConnection().CreateTable <Trip>(); ORM.GetConnection().CreateTable <Site>(); ORM.GetConnection().CreateTable <Specimen>(); }
public void btnSaveSite_Clicked(object sender, EventArgs e) { if (editing) // editing should only require all existing information to be changed { if (!entryHabitat.Text.Equals("") && !entryLocality.Text.Equals("") && !entryAssocTaxa.Text.Equals("") && entryLocationNotes.Text.Equals("") && !(entryHabitat.Text is null) && !(entryLocality.Text is null) && !(entryAssocTaxa.Text is null) && !(entryLocationNotes.Text is null)) { site.AssociatedTaxa = entryAssocTaxa.Text; site.GPSCoordinates = (siteGPS.Equals("")) ? site.GPSCoordinates : siteGPS; site.Habitat = entryHabitat.Text; site.Locality = entryLocality.Text; site.LocationNotes = entryLocationNotes.Text; int updateResult = ORM.GetConnection().Update(site, typeof(Site)); if (updateResult == 1) { DependencyService.Get <ICrossPlatformToast>().ShortAlert(site.SiteName + " save succeeded."); return; } else { DependencyService.Get <ICrossPlatformToast>().ShortAlert(site.SiteName + " save failed."); return; } } else { DependencyService.Get <ICrossPlatformToast>().ShortAlert("Need all info to save Site!"); return; } } site.GPSCoordinates = siteGPS; site.TripName = 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; } 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 existingSites = ORM.GetSites(site.TripName); foreach (Site s in existingSites) { if (s.SiteName.Equals(site.SiteName)) { DependencyService.Get <ICrossPlatformToast>().ShortAlert("You already have a site with the same name!"); return; } } // save site to database int autoKeyResult = ORM.GetConnection().Insert(site); DependencyService.Get <ICrossPlatformToast>().ShortAlert("Site " + site.SiteName + " saved!"); Debug.WriteLine("inserted site, recordno is: " + autoKeyResult.ToString()); }
public void btnSaveSpecimen_Clicked(object sender, EventArgs e) { if (editing) { if (!entrySubstrate.Text.Equals("") && !entryIndivCount.Text.Equals("") && !entryOccurrenceNotes.Text.Equals("") && !(pickerLifeStage.SelectedItem is null) && !(entrySubstrate.Text is null) && !(entryIndivCount.Text is null) && !(entryOccurrenceNotes.Text is null)) { specimen.Substrate = entrySubstrate.Text; specimen.IndividualCount = entryIndivCount.Text; specimen.Cultivated = switchCultivated.IsToggled; specimen.OccurrenceNotes = entryOccurrenceNotes.Text; specimen.LifeStage = pickerLifeStage.SelectedItem.ToString(); specimen.GPSCoordinates = (specimenGPS.Equals("")) ? specimen.GPSCoordinates : specimenGPS; int updateResult = ORM.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; } } else { DependencyService.Get <ICrossPlatformToast>().ShortAlert("Need all info to save Specimen!"); return; } } specimen.SiteName = site.SiteName; specimen.GPSCoordinates = specimenGPS; specimen.OccurrenceNotes = entryOccurrenceNotes.Text is null ? "" : entryOccurrenceNotes.Text; specimen.Substrate = entrySubstrate.Text is null ? "" : entrySubstrate.Text; specimen.IndividualCount = entryIndivCount.Text is null ? "" : entryIndivCount.Text; AppVariables.CollectionCount = AppVariables.CollectionCount > 0 ? AppVariables.CollectionCount : 0; specimen.SpecimenNumber = AppVariables.CollectionCount + 1; specimen.FieldIdentification = entryFieldID.Text is null ? "Specimen" + specimen.SpecimenNumber.ToString() : entryFieldID.Text; specimen.SpecimenName = "Specimen" + specimen.SpecimenNumber; if (entryOtherLifeStage.IsVisible && !entryOtherLifeStage.Text.Equals("")) { specimen.LifeStage = entryOtherLifeStage.Text; } else if (entryOtherLifeStage.IsVisible) { DependencyService.Get <ICrossPlatformToast>().ShortAlert("Fill in \"Other\" Life Stage!"); return; } else { specimen.LifeStage = pickerLifeStage.SelectedItem is null ? "" : pickerLifeStage.SelectedItem.ToString(); } specimen.Cultivated = switchCultivated.IsToggled; // save Specimen to database int autoKeyResult = ORM.GetConnection().Insert(specimen); Debug.WriteLine("inserted specimen, recordno is: " + autoKeyResult.ToString()); // update CollectionCount AppVariables.CollectionCount = specimen.SpecimenNumber; DependencyService.Get <ICrossPlatformToast>().ShortAlert("Saved specimen " + specimen.FieldIdentification); }