public async void btnEditSpecimen_Clicked(object sender, EventArgs e) { try { List <Trip> tripList = ORM.GetTrips(project.ProjectName); List <Site> siteList = new List <Site>(); foreach (Trip trip in tripList) { siteList.AddRange(ORM.GetSites(trip.TripName)); } List <Specimen> specimenList = new List <Specimen>(); foreach (Site site in siteList) { specimenList.AddRange(ORM.GetSpecimens(site.SiteName)); } string[] specimens = new string[specimenList.Count]; for (int i = 0; i < specimens.Length; i++) { specimens[i] = specimenList[i].SpecimenName; } var action = await DisplayActionSheet("Choose a Specimen", "Cancel", null, specimens); foreach (Specimen s in specimenList) { if (s.SpecimenName.Equals(action)) { await Navigation.PushAsync(new SpecimenPage(s)); break; } } } catch (Exception ex) { Debug.WriteLine(ex.Message); DependencyService.Get <ICrossPlatformToast>().ShortAlert("Are there any Specimen for this Project?"); } }
// Export CSV button event // - creates the CSV for export of the selected Project public async void btnExportProjectCSV_Clicked(object sender, EventArgs e) { var result = await CheckExternalFilePermissions(); if (!result) { DependencyService.Get <ICrossPlatformToast>().ShortAlert("Storage permission required for data export!"); } try { if (selectedProject == null) { DependencyService.Get <ICrossPlatformToast>().ShortAlert("Select a Project first"); return; } // data from project recordedBy = selectedProject.PrimaryCollector; samplingEffort = selectedProject.ProjectName; // get Trips for selected Project List <Trip> selectedProjectTrips = ORM.GetTrips(selectedProject.ProjectName); // get Sites for each Trip Dictionary <string, List <Site> > sitesForTrips = new Dictionary <string, List <Site> >(); foreach (Trip trip in selectedProjectTrips) { List <Site> sites = ORM.GetSites(trip.TripName); sitesForTrips.Add(trip.TripName, sites); } if (sitesForTrips.Count == 0) { DependencyService.Get <ICrossPlatformToast>().ShortAlert("Missing data"); return; } // get Specimen for each Site Dictionary <string, List <Specimen> > specimenForSites = new Dictionary <string, List <Specimen> >(); foreach (var trip in sitesForTrips) // trip, list<site> { foreach (var site in trip.Value) // go through list<site> { List <Specimen> specimenList = ORM.GetSpecimens(site.SiteName); specimenForSites.Add(site.SiteName, specimenList); } } if (specimenForSites.Count == 0) { DependencyService.Get <ICrossPlatformToast>().ShortAlert("Missing data"); return; } // csv content string to write to file string csvContent = ""; switch (AppVariables.DataExportFormat) { case "Darwin Core": csvContent = CreateCSVForExport(DataExportType.DarwinCore, selectedProjectTrips, specimenForSites, sitesForTrips); break; default: csvContent = CreateCSVForExport(DataExportType.DarwinCore, selectedProjectTrips, specimenForSites, sitesForTrips); break; } string filePath = DependencyService.Get <ICrossPlatform_GetShareFolder>().GetShareFolder(); // save to local app data // to share in email must use temporary file, can't use internal storage string fileName = selectedProject.ProjectName.Trim() + "_" + DateTime.Now.ToString("MM-dd-yyyy") + ".csv"; string localFileLocation = Path.Combine(filePath, fileName); File.WriteAllText(localFileLocation, csvContent, System.Text.Encoding.UTF8); // create csvfile with utf8 encoding, in permanent local storage CrossShareFile.Current.ShareLocalFile(localFileLocation, "Share Specimen Export"); // working on Android, not showing all sharing options on iOS... https://github.com/nielscup/ShareFile } catch (Exception ex) { DependencyService.Get <ICrossPlatformToast>().ShortAlert("Error: " + ex.Message); } }