示例#1
0
        async private void btnCompleteList_Click(object sender, EventArgs e)
        {
            if (_tc == null || lstFields.SelectedItems == null)
            {
                return;
            }
            string fieldName = lstFields.SelectedItem.ToString().Replace("[", String.Empty).Replace("]", String.Empty); // Joined Fields [...]
            IField field     = _tc.FindField(fieldName);

            DistinctFilter filter = new DistinctFilter(field.name);

            lstUniqueValues.Items.Clear();

            this.Cursor = Cursors.WaitCursor;

            ICursor cursor = await _tc.Search(filter);

            if (cursor == null)
            {
                return;
            }

            _cancelTracker.Reset();
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork             += new DoWorkEventHandler(CompleteList_DoWork);
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompleteList_RunWorkerCompleted);
            bw.RunWorkerAsync(cursor);
        }
        public GeoJsonDistinctFeatureCursor(IEnumerable <IFeature> features, DistinctFilter filter)
        {
            _distinctField = filter.SubFields?.Trim().Replace(",", " ").Split(' ')[0];

            if (features != null && !String.IsNullOrEmpty(_distinctField))
            {
                foreach (var feature in features?.ToArray())
                {
                    var val = feature[_distinctField]?.ToString();
                    if (val != null && !_values.Contains(val))
                    {
                        _values.Add(val);
                    }
                }
            }

            _filter = filter;
        }
示例#3
0
        private void btnAllValues_Click(object sender, System.EventArgs e)
        {
            try
            {
                DistinctFilter filter = new DistinctFilter(cmbFields.SelectedItem.ToString());
                //QueryFilter filter=new QueryFilter();
                //filter.AddField("DISTINCT("+cmbFields.SelectedItem.ToString()+")");
                //filter.AddField(cmbFields.SelectedItem.ToString());
                filter.OrderBy = cmbFields.SelectedItem.ToString();

                Array array = Array.CreateInstance(typeof(string), _renderer.Keys.Count);
                _renderer.Keys.CopyTo(array, 0);
                foreach (string key in array)
                {
                    _renderer.RemoveSymbol(key);
                }

                IFeatureCursor cursor = (IFeatureCursor)_fc.Search(filter);

                string [] labels = new string[2];
                IFeature  feature;
                while ((feature = cursor.NextFeature) != null)
                {
                    labels[0] = ((FieldValue)feature.Fields[0]).Value.ToString();
                    if (_renderer[labels[0]] == null)
                    {
                        _renderer[labels[0]] = null;                        // neues Symbol erzeugen...
                    }
                    //symbolsListView1.addSymbol(_renderer[labels[0]],labels);
                    int i = 0;
                }

                BuildList();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#4
0
        void FillValueList()
        {
            lstValues.Items.Clear();

            if (_fc == null ||
                _merger == null ||
                _merger.Sources.Count != 1 ||
                ((FieldItem)cmbField.SelectedItem).Field == null)
            {
                return;
            }

            this.Cursor = Cursors.WaitCursor;
            IActivityData aData = _merger.Sources[0];

            if (aData.QueryMethod == QueryMethod.All ||
                aData.QueryMethod == QueryMethod.Filter)
            {
                DistinctFilter filter = new DistinctFilter(((FieldItem)cmbField.SelectedItem).Field.name);
                if (aData.QueryMethod == QueryMethod.Filter)
                {
                    filter.WhereClause = aData.FilterClause;
                }
                filter.OrderBy = ((FieldItem)cmbField.SelectedItem).Field.name;

                using (IFeatureCursor cursor = _fc.GetFeatures(filter))
                {
                    IFeature feature;
                    while ((feature = cursor.NextFeature) != null)
                    {
                        ListViewItem item = new ListViewItem(feature[0].ToString(), 0);
                        item.Checked = true;
                        lstValues.Items.Add(item);
                    }
                }
            }
            this.Cursor = Cursors.Default;
        }
示例#5
0
        public IFeatureCursor GetFeatures(IQueryFilter filter)
        {
            if (filter == null)
            {
                return(null);
            }

            if (filter is IBufferQueryFilter)
            {
                ISpatialFilter sFilter = BufferQueryFilter.ConvertToSpatialFilter(filter as IBufferQueryFilter);
                if (sFilter == null)
                {
                    return(null);
                }
                return(GetFeatures(sFilter));
            }

            #region IDistrictFilter ?
            if (filter is IDistinctFilter)
            {
                if (filter.SubFields.Contains(":"))
                {
                    string[] fn = filter.SubFields.Split(':');

                    IFeatureLayerJoin join = _joins[fn[0]];
                    if (join != null)
                    {
                        using (join = (IFeatureLayerJoin)join.Clone())
                        {
                            join.Init(String.Empty);
                            filter         = new DistinctFilter(fn[1]);
                            filter.OrderBy = fn[1];
                            return(new FeatureCursorWrapper(join.PerformQuery(filter)));
                        }
                    }
                    return(null);
                }
                else
                {
                    return(_fc.GetFeatures(filter));
                }
            }
            #endregion

            #region IFunctionFilter ?
            if (filter is IFunctionFilter)
            {
                if (filter.SubFields.Contains(":"))
                {
                    string[] fn = filter.SubFields.Split(':');

                    IFeatureLayerJoin join = _joins[fn[0]];
                    if (join != null)
                    {
                        using (join = (IFeatureLayerJoin)join.Clone())
                        {
                            join.Init(String.Empty);
                            filter = new FunctionFilter(((IFunctionFilter)filter).Function, fn[1], ((IFunctionFilter)filter).Alias);
                            return(new FeatureCursorWrapper(join.PerformQuery(filter)));
                        }
                    }
                    return(null);
                }
                else
                {
                    return(_fc.GetFeatures(filter));
                }
            }
            #endregion

            bool hasInnerJoin = false;
            if (_joins != null)
            {
                foreach (IFeatureLayerJoin join in _joins)
                {
                    if (join.JoinType == joinType.LeftInnerJoin)
                    {
                        hasInnerJoin = true;
                        break;
                    }
                }
            }
            if ((!filter.SubFields.Contains(":") && !filter.SubFields.Contains("*") && hasInnerJoin == false && !filter.WhereClause.Contains(":")) || _joins == null || _joins.Count == 0)
            {
                return(_fc.GetFeatures(filter));
            }

            Dictionary <string, UniqueList <string> > fieldNames = new Dictionary <string, UniqueList <string> >();
            fieldNames.Add(String.Empty, new UniqueList <string>());
            fieldNames[String.Empty].Add(this.IDFieldName);

            string[] names = filter.SubFields.Replace(" ", ",").Split(',');

            foreach (string fieldname in filter.SubFields.Replace(" ", ",").Split(','))
            {
                if (fieldname == "*")
                {
                    fieldNames[String.Empty] = new UniqueList <string>();
                    fieldNames[String.Empty].Add("*");
                    foreach (IFeatureLayerJoin join in _joins)
                    {
                        fieldNames[join.JoinName] = new UniqueList <string>();
                        fieldNames[join.JoinName].Add("*");
                    }
                    break;
                }
                if (fieldname.Contains(":"))
                {
                    string[] fn = fieldname.Split(':');

                    IFeatureLayerJoin join = _joins[fn[0]];
                    if (join != null)
                    {
                        fieldNames[String.Empty].Add(join.Field);

                        if (!fieldNames.ContainsKey(fn[0]))
                        {
                            fieldNames.Add(fn[0], new UniqueList <string>());
                        }
                        fieldNames[fn[0]].Add(fn[1].Trim());
                    }
                }
                else
                {
                    fieldNames[String.Empty].Add(fieldname.Trim());
                }
            }

            foreach (IFeatureLayerJoin join in _joins)
            {
                if (join.JoinType == joinType.LeftInnerJoin)
                {
                    if (!fieldNames.Keys.Contains(join.JoinName))
                    {
                        fieldNames.Add(join.JoinName, new UniqueList <string>()
                        {
                            join.JoinFields[0].name
                        });
                        fieldNames[String.Empty].Add(join.Field);
                    }
                }
            }

            filter           = (IQueryFilter)filter.Clone();
            filter.SubFields = fieldNames[String.Empty].ToString(',');

            #region CrossTable Where Clause ?
            if (!String.IsNullOrEmpty(filter.WhereClause) && filter.WhereClause.Contains(":"))
            {
                string where = filter.WhereClause.ToLower();
                bool isCrossTableQuery = false;
                foreach (IField field in this.Fields.ToEnumerable())
                {
                    if (field.name.Contains(":") && where.Contains("[" + field.name.ToLower() + "]"))
                    {
                        IFeatureLayerJoin join = _joins[field.name.Split(':')[0]];
                        if (join != null)
                        {
                            isCrossTableQuery = true;
                            if (!fieldNames.ContainsKey(join.JoinName))
                            {
                                fieldNames.Add(join.JoinName, new UniqueList <string>());
                            }
                            fieldNames[join.JoinName].Add(field.name.Split(':')[1].Trim());
                            filter.AddField(join.Field);
                            //filter.AddField(field.name);
                        }
                    }
                    else if (!field.name.Contains(":") && where.Contains(field.name.ToLower()))  // select all fields in the where clause (because you need them in table.Select(...)
                    {
                        filter.AddField(field.name);
                    }
                }
                if (isCrossTableQuery)
                {
                    where = filter.WhereClause;
                    filter.WhereClause = String.Empty;
                    IFeatureCursor cursor = new FeatureCursor(_fc.GetFeatures(filter), (FeatureLayerJoins)_joins.Clone(), fieldNames);

                    DataTable tab  = gView.Framework.Data.FeatureCursor.ToDataTable(cursor);
                    DataRow[] rows = null;
                    try
                    {
                        rows = tab.Select(where, filter.OrderBy);
                    }
                    catch
                    {
                    }
                    return(new gView.Framework.Data.FeatureCursor.DataRowCursor(rows));
                }
            }
            #endregion

            if (fieldNames.Keys.Count <= 1)
            {
                fieldNames = null;
            }

            try
            {
                return(new FeatureCursor(_fc.GetFeatures(filter), (FeatureLayerJoins)_joins.Clone(), fieldNames));
            }
            catch
            {
                return(null);
            }
        }
示例#6
0
        async private void btnApply_Click(object sender, EventArgs e)
        {
            if (!txtTemplate.Text.Contains("[VALUE]"))
            {
                txtTemplate.Text += "[VALUE]";
            }

            lstLayerNames.Items.Clear();
            string         fieldName = cmbFilterField.Text.Replace("[", String.Empty).Replace("]", String.Empty); // Joined fields [...]. Dont need brackets in Distinctfilter...
            DistinctFilter filter    = new DistinctFilter(fieldName);

            filter.OrderBy = fieldName;
            using (IFeatureCursor cursor = await((IFeatureClass)_layer.Class).Search(filter) as IFeatureCursor)
            {
                if (cursor == null)
                {
                    return;
                }

                IFeature feature;
                while ((feature = await cursor.NextFeature()) != null)
                {
                    object oobj;
                    object obj = oobj = feature[fieldName];
                    if (obj == null && fieldName.Contains(":"))
                    {
                        obj = oobj = feature[fieldName.Split(':')[1]];
                    }
                    if (obj == null || obj == DBNull.Value)
                    {
                        continue;
                    }

                    if (numOperator.Visible)
                    {
                        try
                        {
                            double d = Convert.ToDouble(obj);
                            switch (cmbOperator.Text)
                            {
                            case "+":
                                d += (double)numOperator.Value;
                                break;

                            case "-":
                                d -= (double)numOperator.Value;
                                break;

                            case "*":
                                d *= (double)numOperator.Value;
                                break;

                            case "/":
                                d /= (double)numOperator.Value;
                                break;
                            }

                            obj = d;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("ERROR: " + ex.Message);
                            return;
                        }
                    }

                    lstLayerNames.Items.Add(
                        new FilterExpessionItem(
                            txtTemplate.Text.Replace("[VALUE]", obj.ToString()),
                            cmbFilterField.Text + "=" + Quote(oobj.ToString())), true);
                }
            }
        }
        public async void InnerExecuteDistinct()
        {
            Owner.Executing = true;
            try
            {
                var results = await Owner.Service.DistinctAsync(Owner.Database, Owner.Collection, DistinctFieldName, DistinctFilter.Deserialize <BsonDocument>(Constants.DistinctFilterProperty), Owner.Cts.Token);

                Owner.Executing = false;
                Owner.ShowPager = false;

                Owner.RawResult         = results.ToJson(Options.JsonWriterSettings);
                Owner.SelectedViewIndex = 0;

                Owner.Root = new ResultsViewModel(results.Select(r => new BsonDocument(results.IndexOf(r).ToString(), r)).ToList(), Owner);
                GC.Collect();
            }
            catch (BsonExtensions.BsonParseException ex)
            {
                LoggerHelper.Logger.Error("Exception while executing Distinct command", ex);
                Owner.SelectedViewIndex = 1;
                Owner.RawResult         = ex.Message;
                Owner.Root = null;
                Messenger.Default.Send(new NotificationMessage <BsonExtensions.BsonParseException>(this, ex, Constants.DistinctParseException));
            }
            catch (Exception ex)
            {
                LoggerHelper.Logger.Error("Exception while executing Distinct command", ex);
                Owner.SelectedViewIndex = 1;
                Owner.RawResult         = ex.Message;
                Owner.Root = null;
            }
            finally
            {
                Owner.Executing = false;
            }
        }