コード例 #1
0
        // edit trip button event
        // bring up selection of trips for projecg
        // pass selected to TripPage for editing
        public async void btnEditTrip_Clicked(object sender, EventArgs e)
        {
            try
            {
                List <Trip> tripList = ORM.GetTrips(project.ProjectName);

                string[] trips = new string[tripList.Count];
                for (int i = 0; i < trips.Length; i++)
                {
                    trips[i] = tripList[i].TripName;
                }

                var action = await DisplayActionSheet("Choose a Trip", "Cancel", null, trips);

                foreach (Trip t in tripList)
                {
                    if (t.TripName == action)
                    {
                        await Navigation.PushAsync(new TripPage(t));

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("Are there any Trips for this Project?");
            }
        }
コード例 #2
0
        // constructor for collecting
        public TripPage(Project project)
        {
            this.project = project;
            projectName  = project.ProjectName;
            trip         = new Trip();

            InitializeComponent();

            List <Trip> trips = ORM.GetTrips(projectName);

            entryTripName.Text = projectName + " - Trip" + (trips.Count + 1).ToString();
        }
コード例 #3
0
        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?");
            }
        }
コード例 #4
0
        // AddSite button
        //  - prompts user with list of Trips to add a Site to
        //  - selected Trip is passed to the SitePage through SitePage's constructor
        public async void btnAddSite_Clicked(object sender, EventArgs e)
        {
            try
            {
                List <Trip> tripList = ORM.GetTrips(project.ProjectName);

                if (tripList.Count == 0)
                {
                    DependencyService.Get <ICrossPlatformToast>().ShortAlert("Create Trip first!");
                    return;
                }

                string[] trips = new string[tripList.Count];
                for (int i = 0; i < trips.Length; i++)
                {
                    trips[i] = tripList[i].TripName;
                }

                var action = await DisplayActionSheet("Choose a Trip", "Cancel", null, trips);

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

                foreach (Trip t in tripList)
                {
                    if (t.TripName == action)
                    {
                        await Navigation.PushAsync(new SitePage(t));

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // no Trips created, so no Trip database to query
                DependencyService.Get <ICrossPlatformToast>().ShortAlert("Create Trip first!");
                Debug.WriteLine(ex.Message);
            }
        }
コード例 #5
0
        // 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);
            }
        }
コード例 #6
0
        // Add Specimen button
        //  - prompts user with a Site to add Specimen to
        //  - upon selecting a Site, the Site is passed to the SpecimenPage through SpecimenPage's constructor
        public async void btnAddSpecimen_Clicked(object sender, EventArgs e)
        {
            try
            {
                // get all sites for current Project
                List <Trip> tripList = ORM.GetTrips(project.ProjectName);

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

                foreach (Trip trip in tripList)
                {
                    List <Site> tripSiteList = ORM.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();
                AppVariables.CollectionCount += 1;

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

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

                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 (!ORM.CheckExists(trip))
                    {
                        ORM.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,
                        GPSCoordinates = await CurrentGPS.CurrentLocation()
                    };
                    if (!ORM.CheckExists(site))
                    {
                        ORM.InsertObject(site);
                    }
                    // add this specimen to the specimen database
                    // message user that specimen was added
                    Specimen specimen = new Specimen();
                    specimen.SiteName       = site.SiteName;
                    specimen.SpecimenName   = action;
                    specimen.SpecimenNumber = AppVariables.CollectionCount;
                    specimen.GPSCoordinates = await CurrentGPS.CurrentLocation();

                    ORM.InsertObject(specimen);

                    DependencyService.Get <ICrossPlatformToast>().ShortAlert(action + " saved!");
                }
                else
                {
                    await Navigation.PushAsync(new SpecimenPage(ORM.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);
            }
        }