public object PropertyPanel(IFeatureLayerJoin join, Framework.UI.IMapDocument mapDocument) { if (join is FeatureLayerJoin) { _join = (FeatureLayerJoin)join; foreach (IDatasetElement element in mapDocument.FocusMap.MapElements) { if (/*element == layer ||*/ !(element.Class is ITableClass)) { continue; } ITOCElement tocElement = mapDocument.FocusMap.TOC.GetTOCElement(element as ILayer); string alias = tocElement != null ? tocElement.Name : element.Title; cmbJoinedLayer.Items.Add(new DatasetElementItem(element, alias)); if (_join.FeatureLayer != null && element.ID == _join.FeatureLayer.ID) { cmbJoinedLayer.SelectedIndex = cmbJoinedLayer.Items.Count - 1; } } cmbJoinedFeatureLayerJoinField.SelectedItem = _join.JoinField; } return(this); }
private void btnEdit_Click(object sender, EventArgs e) { if (!(lstJoins.SelectedItem is FeatureLayerJoinItem)) { return; } IFeatureLayerJoin join = ((FeatureLayerJoinItem)lstJoins.SelectedItem).FeatureLayerJoin; AddJoinDialog dlg = new AddJoinDialog(_mapDocument, _layer); dlg.FeatureLayerJoin = join; if (dlg.ShowDialog() == DialogResult.OK) { IFeatureLayerJoin newJoin = dlg.FeatureLayerJoin; if (newJoin != null) { _layer.Joins.Remove(join); _layer.Joins.Add(newJoin); _layer.FirePropertyChanged(); FillList(); } } }
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 object PropertyPanel(IFeatureLayerJoin join, Framework.UI.IMapDocument mapDocument) { if (join is FeatureLayerDatabaseJoin) { _join = (FeatureLayerDatabaseJoin)join; if (!String.IsNullOrEmpty(_join.JoinConnectionString)) { gView.Framework.Db.DbConnectionString connStr = new Framework.Db.DbConnectionString(); connStr.UseProviderInConnectionString = true; connStr.FromString(_join.JoinConnectionString); this.JoinDbConnectionString = connStr; } this.JoinTableName = _join.JoinTable; this.JoinTableField = _join.JoinField; this.JoinTableFields = _join.JoinFields; } return(this); }
private void cmbJoinMode_SelectedIndexChanged(object sender, EventArgs e) { panelJoinTypeUI.Controls.Clear(); if (!(cmbJoinClasses.SelectedItem is FeatureLayerJoinItem)) { return; } IFeatureLayerJoin join = ((FeatureLayerJoinItem)cmbJoinClasses.SelectedItem).FeatureLayerJoin; if (join is IPropertyPage) { object ctrl = ((IPropertyPage)join).PropertyPage(_mapDocument); if (ctrl is Control) { ((Control)ctrl).Dock = DockStyle.Fill; panelJoinTypeUI.Controls.Add((Control)ctrl); } } }
private void btnRemove_Click(object sender, EventArgs e) { if (!(lstJoins.SelectedItem is FeatureLayerJoinItem)) { return; } IFeatureLayerJoin join = ((FeatureLayerJoinItem)lstJoins.SelectedItem).FeatureLayerJoin; if (join != null && _layer.Joins != null) { _layer.Joins.Remove(join); if (_layer.Joins.Count == 0) { _layer.Joins = null; } _layer.FirePropertyChanged(); } FillList(); }
private void btnAdd_Click(object sender, EventArgs e) { AddJoinDialog dlg = new AddJoinDialog(_mapDocument, _layer); if (dlg.ShowDialog() == DialogResult.OK) { IFeatureLayerJoin join = dlg.FeatureLayerJoin; if (join != null) { if (_layer.Joins == null) { _layer.Joins = new Framework.Data.FeatureLayerJoins(); } _layer.Joins.Add(join); _layer.FirePropertyChanged(); FillList(); } } }
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); } }
private void Join() { if (_fieldNames == null || _joins == null) { return; } #region Collect values & perform cache query foreach (string joinName in _fieldNames.Keys) { if (String.IsNullOrEmpty(joinName)) { continue; } IFeatureLayerJoin join = _joins[joinName]; if (join == null) { continue; } List <string> vals = new List <string>(); foreach (IFeature feature in _features) { object joinVal = feature[join.Field]; if (joinVal == null) { continue; } if (!vals.Contains(joinVal.ToString())) { vals.Add(joinVal.ToString()); } } join.PerformCacheQuery(vals.ToArray()); } #endregion List <IFeature> removeFeatures = new List <IFeature>(); foreach (IFeature feature in _features) { if (_fieldNames != null && _joins != null) { foreach (string joinName in _fieldNames.Keys) { if (String.IsNullOrEmpty(joinName)) { continue; } IFeatureLayerJoin join = _joins[joinName]; if (join == null) { continue; } object joinVal = feature[join.Field]; if (joinVal == null) { continue; } IRow row = join.GetJoinedRow(joinVal.ToString()); if (row == null) { if (join.JoinType == joinType.LeftInnerJoin) { removeFeatures.Add(feature); break; } continue; } foreach (string fieldName in _fieldNames[joinName]) { if (fieldName == "*" && join.JoinFields != null) { foreach (IField f in join.JoinFields.ToEnumerable()) { object v = row[f.name]; feature.Fields.Add(new FieldValue(joinName + ":" + f.name, v)); } break; } object val = row[fieldName]; feature.Fields.Add(new FieldValue(joinName + ":" + fieldName, val)); } } } } foreach (IFeature feature in removeFeatures) { _features.Remove(feature); } }