public FeatureCursor(IFeatureCursor cursor, FeatureLayerJoins joins, Dictionary <string, UniqueList <string> > fieldNames) { _cursor = cursor; _joins = joins; _fieldNames = fieldNames; if (_fieldNames != null) { foreach (string joinName in _fieldNames.Keys) { IFeatureLayerJoin join = _joins[joinName]; if (join != null) { join.Init(_fieldNames[joinName].ToString(',')); } } } }
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); } }