Exemple #1
0
        private async void ExecuteStatisticsQuery(object sender, EventArgs e)
        {
            // Remove the placeholder "Add statistic" row (if it exists).
            StatisticDefinition placeholderRow = _statisticDefinitions.LastOrDefault();

            if (placeholderRow != null && placeholderRow.OutputAlias == "")
            {
                _statisticDefinitions.Remove(placeholderRow);
            }

            // Verify that there is at least one statistic definition.
            if (!_statisticDefinitions.Any())
            {
                ShowAlert("Statistical Query", "Please define at least one statistic for the query.");
                return;
            }

            // Create the statistics query parameters, pass in the list of statistic definitions.
            StatisticsQueryParameters statQueryParams = new StatisticsQueryParameters(_statisticDefinitions);

            // Specify the selected group fields (if any).
            if (_groupByFields != null)
            {
                foreach (KeyValuePair <string, bool> groupField in _groupByFields.Where(field => field.Value))
                {
                    statQueryParams.GroupByFieldNames.Add(groupField.Key);
                }
            }

            // Specify the fields to order by (if any).
            if (_orderByFields != null)
            {
                foreach (OrderFieldOption orderBy in _orderByFields)
                {
                    statQueryParams.OrderByFields.Add(orderBy.OrderInfo);
                }
            }

            // Ignore counties with missing data
            statQueryParams.WhereClause = "\"State\" IS NOT NULL";

            // Execute the statistical query with these parameters and await the results.
            try
            {
                StatisticsQueryResult statQueryResult = await _usStatesTable.QueryStatisticsAsync(statQueryParams);

                // Get results formatted as a dictionary (group names and their associated dictionary of results).
                Dictionary <string, IReadOnlyDictionary <string, object> > resultsLookup = statQueryResult.ToDictionary(result => string.Join(", ", result.Group.Values), result => result.Statistics);

                // Create an instance of a custom data source to display the results.
                StatisticQueryResultsDataSource statResultsDataSource = new StatisticQueryResultsDataSource(resultsLookup);

                // Create a new table with a grouped style for displaying rows.
                UITableViewController statResultsTable = new UITableViewController(UITableViewStyle.Grouped)
                {
                    // Set the table view data source.
                    TableView = { Source = statResultsDataSource }
                };

                // Show the table view.
                NavigationController.PushViewController(statResultsTable, true);
            }
            catch (ArcGISWebException exception)
            {
                ShowAlert("There was a problem performing the query.", exception.ToString());
            }
        }
Exemple #2
0
        private async void ExecuteStatisticsQuery(object sender, EventArgs e)
        {
            // Verify that there is at least one statistic definition
            if (!_statisticDefinitions.Any())
            {
                // Warn the user to define a statistic to query
                ShowMessage("Please define at least one statistic for the query.", "Statistical Query");
                return;
            }

            // Create the statistics query parameters, pass in the list of statistic definitions
            StatisticsQueryParameters statQueryParams = new StatisticsQueryParameters(_statisticDefinitions);

            // Specify the selected group fields (if any)
            if (_groupByFields != null)
            {
                // Find fields in the dictionary with a 'true' value and add them to the group by field names
                foreach (KeyValuePair <string, bool> groupField in _groupByFields.Where(field => field.Value))
                {
                    statQueryParams.GroupByFieldNames.Add(groupField.Key);
                }
            }

            // Specify the fields to order by (if any)
            if (_orderByFields != null)
            {
                foreach (OrderFieldOption orderBy in _orderByFields)
                {
                    statQueryParams.OrderByFields.Add(orderBy.OrderInfo);
                }
            }

            // Ignore counties with missing data
            statQueryParams.WhereClause = "\"State\" IS NOT NULL";

            try
            {
                // Execute the statistical query with these parameters and await the results
                StatisticsQueryResult statQueryResult = await _usStatesTable.QueryStatisticsAsync(statQueryParams);

                // Get results formatted as a dictionary (group names and their associated dictionary of results)
                Dictionary <string, IReadOnlyDictionary <string, object> > resultsLookup = statQueryResult.ToDictionary(r => string.Join(", ", r.Group.Values), r => r.Statistics);

                // Create an instance of a custom list adapter that has logic to show results as expandable groups
                ExpandableResultsListAdapter expandableListAdapter = new ExpandableResultsListAdapter(this, resultsLookup);

                // Create an expandable list view and assign the expandable adapter
                ExpandableListView expandableResultsListView = new ExpandableListView(this);
                expandableResultsListView.SetAdapter(expandableListAdapter);

                // Show the expandable list view in a dialog
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
                dialogBuilder.SetView(expandableResultsListView);
                dialogBuilder.Show();
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.ToString()).SetTitle("Error").Show();
            }
        }