コード例 #1
0
 public string[] prepareData(FeatureLayer data)
 {
     try
     {
         string[] columns = null;
         if (data != null)
         {
             Task t = QueuedTask.Run(() =>
             {
                 Table table      = data.GetTable();
                 RowCursor cursor = table.Search();
                 cursor.MoveNext();
                 var fields = cursor.GetFields();
                 columns    = new string[fields.Count];
                 int i      = 0;
                 foreach (Field field in fields)
                 {
                     columns[i] = field.Name;
                     i++;
                 }
             });
             t.Wait();
         }
         return(columns);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
コード例 #2
0
        private async void ReadRows()
        {
            if (_executeQuery)
            {
                return;
            }
            if (_gdbPath.IsEmpty())
            {
                return;
            }
            if (SelectedTableName.IsEmpty())
            {
                return;
            }

            _executeQuery = true;
            _columns.Clear();
            _timer.Start();
            OnPropertyChanged("IsExecutingQuery");

            string tableName = SelectedTableName.Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries)[1].Trim();

            var data = new ObservableCollection <DynamicDataRow>();

            try {
                //Note, we have to return something
                await TaskUtils.StartSTATask <int>(() => {
                    using (Geodatabase gdb = new Geodatabase(
                               new FileGeodatabaseConnectionPath(new Uri(_gdbPath, UriKind.Absolute))))
                    {
                        var table = gdb.OpenDataset <Table>(tableName);

                        RowCursor cursor           = table.Search();
                        IReadOnlyList <Field> flds = cursor.GetFields();
                        foreach (var fld in flds)
                        {
                            _columns.Add(new ColumnData()
                            {
                                AliasName = fld.AliasName ?? fld.Name,
                                Name      = fld.Name,
                                FieldType = fld.FieldType
                            });
                        }

                        while (cursor.MoveNext())
                        {
                            var row = new DynamicDataRow();

                            for (int v = 0; v < flds.Count; v++)
                            {
                                row[GetName(flds[v])] = GetValue(cursor.Current, v);
                            }
                            data.Add(row);
                        }
                    }
                    return(0);
                });
            }
            finally {
                ExtendListView.Columns = _columns;
                _timer.Stop();

                lock (_theLock) {
                    _rows.Clear();
                    _rows = null;
                    _rows = data;
                }
                if (_rows.Count > 0)
                {
                    TableHasNoRows = "";
                }
                else
                {
                    TableHasNoRows = "No rows returned";
                }
                _executeQuery = false;
                OnPropertyChanged("Rows");
                OnPropertyChanged("IsExecutingQuery");
            }
        }
コード例 #3
0
        private async Task QueryRows(object query)
        {
            string where = "";
            if (query != null)
            {
                where = query.ToString();
            }
            IsLoading = true;
            lock (_theLock)
            {
                ListOfRows.Clear();
            }
            if (_layerSource == null)
            {
                _layerSource = await _selectedLayer.getFeatureClass();
            }
            if (_layerSource != null)
            {
                var data = new List <DynamicDataRow>();
                await QueuedTask.Run(() =>
                {
                    var queryFilter = new ArcGIS.Core.Data.QueryFilter
                    {
                        WhereClause = where
                    };
                    int maxcols = 6;

                    RowCursor cursor = null;

                    // Use try catch to catch invalid SQL statements in queryFilter
                    try
                    {
                        cursor = _layerSource.Search(queryFilter);
                    }
                    catch (GeodatabaseGeneralException gdbEx)
                    {
                        System.Windows.MessageBox.Show("Error searching data. " + gdbEx.Message, "Search Error",
                                                       System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
                        return;
                    }

                    if (cursor.MoveNext())
                    {
                        ExtendListView.Columns = new List <ArcGIS.Core.Data.Field>();
                        maxcols = cursor.Current.GetFields().Count() > 6 ? 6 : cursor.Current.GetFields().Count();

                        for (int c = 0; c < maxcols; c++)
                        {
                            ExtendListView.Columns.Add(cursor.Current.GetFields()[c]);
                        }
                        do
                        {
                            var row = new DynamicDataRow();
                            for (int v = 0; v < maxcols; v++)
                            {
                                if (cursor.Current[v] != null)
                                {
                                    row[GetName(cursor.GetFields()[v])] = cursor.Current[v].ToString();
                                }
                            }
                            data.Add(row);
                        } while (cursor.MoveNext());
                    }
                });

                lock (_theLock)
                {
                    ListOfRows = null;
                    ListOfRows = data;
                }
            }
            RaisePropertyChanged("ListOfRows");
            Status    = string.Format("{0} rows loaded", ListOfRows.Count());
            IsLoading = false;
        }