Exemplo n.º 1
0
        public static int InsertObject(object obj)
        {
            int result = 0;

            if (obj.GetType() == typeof(Project))
            {
                Project objProject = (Project)obj;
                result = GetConnection().Insert(objProject);
            }
            else if (obj.GetType() == typeof(Trip))
            {
                Trip objTrip = (Trip)obj;
                result = GetConnection().Insert(objTrip);
            }
            else if (obj.GetType() == typeof(Site))
            {
                Site objSite = (Site)obj;
                result = GetConnection().Insert(objSite);
            }
            else if (obj.GetType() == typeof(Specimen))
            {
                Specimen objSpecimen = (Specimen)obj;
                result = GetConnection().Insert(objSpecimen);
            }

            return(result);
        }
Exemplo n.º 2
0
 // constructor takes Site as argument to record Specimen under
 public SpecimenPage(Site site)
 {
     specimen  = new Specimen();
     this.site = site;
     siteName  = site.SiteName;
     InitializeComponent();
     Title = siteName + "-Specimen" + (AppVariables.CollectionCount + 1).ToString();
 }
Exemplo n.º 3
0
        // constructor takes Specimen as argument - editing
        public SpecimenPage(Specimen specimen)
        {
            this.specimen = specimen;
            siteName      = specimen.SiteName;
            InitializeComponent();

            editing = true;

            Title                        = specimen.SiteName + "-" + specimen.SpecimenName;
            entryFieldID.Text            = specimen.FieldIdentification;
            entryFieldID.IsEnabled       = false;
            entryOccurrenceNotes.Text    = specimen.OccurrenceNotes;
            entrySubstrate.Text          = specimen.Substrate;
            pickerLifeStage.SelectedItem = specimen.LifeStage;
            switchCultivated.IsToggled   = specimen.Cultivated;
            entryIndivCount.Text         = specimen.IndividualCount;
            btnNewSpecimen.IsEnabled     = false;
        }
Exemplo n.º 4
0
        public void btnNewSpecimen_Clicked(object sender, EventArgs e)
        {
            specimen = new Specimen();

            specimenGPS = "";

            entryFieldID.Text            = "";
            entryOccurrenceNotes.Text    = "";
            entrySubstrate.Text          = "";
            pickerLifeStage.SelectedItem = null;
            switchCultivated.IsToggled   = false;
            entryIndivCount.Text         = "";

            lblOtherLifeStage.IsVisible   = false;
            entryOtherLifeStage.IsVisible = false;
            entryOtherLifeStage.Text      = "";

            lblStatusMessage.IsVisible = false;
            lblStatusMessage.Text      = "";

            DependencyService.Get <ICrossPlatformToast>().ShortAlert("Cleared for new Specimen");
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        public static bool CheckExists(object obj)
        {
            bool exists = false;

            if (obj.GetType() == typeof(Project))
            {
                Project objProject = (Project)obj;

                // check for duplicate names first
                List <Project> existingProjects = GetConnection().Query <Project>("select * from Project");

                foreach (Project p in existingProjects)
                {
                    if (p.ProjectName.Equals(objProject.ProjectName))
                    {
                        exists = true;
                        break;
                    }
                }
            }
            else if (obj.GetType() == typeof(Trip))
            {
                Trip objTrip = (Trip)obj;

                // check for duplicate names first
                List <Trip> existingTrips = GetConnection().Query <Trip>("select * from Trip");

                foreach (Trip p in existingTrips)
                {
                    if (p.TripName.Equals(objTrip.TripName))
                    {
                        exists = true;
                        break;
                    }
                }
            }
            else if (obj.GetType() == typeof(Site))
            {
                Site objSite = (Site)obj;

                // check for duplicate names first
                List <Site> existingSites = GetConnection().Query <Site>("select * from Site");

                foreach (Site p in existingSites)
                {
                    if (p.SiteName.Equals(objSite.SiteName))
                    {
                        exists = true;
                        break;
                    }
                }
            }
            else if (obj.GetType() == typeof(Specimen))
            {
                Specimen objSpecimen = (Specimen)obj;

                // check for duplicate names first
                List <Specimen> existingSpecimens = GetConnection().Query <Specimen>("select * from Specimen");

                foreach (Specimen p in existingSpecimens)
                {
                    if (p.SpecimenName.Equals(objSpecimen.SpecimenName))
                    {
                        exists = true;
                        break;
                    }
                }
            }

            return(exists);
        }