private void listBoxSearchResult_DoubleClick(object sender, System.EventArgs e) { // get the selected object string selectedCloseMatch = (string)this.listBoxSearchResult.SelectedItem; // get the selected object index in the list as well since multiple matches // may have the same name - we can't just compare close match names. int selectedIndex = this.listBoxSearchResult.SelectedIndex; int currentIndex = 0; // create a close match object FindCloseMatch closeMatch = null; // create an enumerator from the results FindCloseMatchEnumerator enumerator = _result.GetCloseMatchEnumerator(); while (enumerator.MoveNext()) { // if the selected name equals the enumerated name... if (currentIndex == selectedIndex && selectedCloseMatch.Equals(enumerator.Current.Name)) { // set the close match object closeMatch = enumerator.Current; // break out of the loop break; } // else keep looking currentIndex++; } if (closeMatch != null) { // create the command string string command = "select obj from " + _searchTable.Alias + " where MI_Key = \'" + closeMatch.Key + "\'"; // create the command object MICommand cmd = _miConnection.CreateCommand(); cmd.CommandText = command; // create the reader by executing the command MIDataReader rdr = cmd.ExecuteReader(); // read a row rdr.Read(); // get the point MapInfo.Geometry.DPoint point = rdr.GetFeatureGeometry(0).Centroid; // Close the reader and dispose of the command. rdr.Close(); cmd.Cancel(); cmd.Dispose(); // show point on a map showPointOnSearchTableMap(point.x, point.y); } }
private void buttonFind_Click(object sender, EventArgs e) { listBoxSearchResult.Items.Clear(); listBoxSearchResult.Visible = false; Find find = null; Column searchColumn = _searchTable.TableInfo.Columns[comboBoxSearchColumn.SelectedItem.ToString()]; if (_refiningTable != null && _refiningTable.IsOpen) { if (comboBoxRefiningColumn.Items.Count > 0) { Column refiningColumn = _refiningTable.TableInfo.Columns[comboBoxRefiningColumn.SelectedItem.ToString()]; find = new Find(_searchTable, searchColumn, _refiningTable, refiningColumn); } else { MessageBox.Show(String.Format("No indexed columns in " + _refiningTable + ".")); return; } } else { find = new Find(_searchTable, searchColumn); } if (checkBoxUseCloseMatches.Checked) { find.UseCloseMatches = true; find.CloseMatchesMax = int.Parse(textBoxMaxCloseMatches.Text); } if (checkBoxAddressNumAfterStreet.Checked) { find.AddressNumberAfterStreet = true; } // Do the actual search. if (_refiningTable != null && _refiningTable.IsOpen) { if (_bSearchIntersection) { _result = find.SearchIntersection(textBoxSearchString.Text, textBoxIntersection.Text, textBoxRefiningString.Text); } else { _result = find.Search(textBoxSearchString.Text, textBoxRefiningString.Text); } } else { if (_bSearchIntersection) { _result = find.SearchIntersection(textBoxSearchString.Text, textBoxIntersection.Text); } else { _result = find.Search(textBoxSearchString.Text); } } // display label that tells us when multiple matches were found labelMultipleMatchesFound.Visible = _result.MultipleMatches; if (_result.ExactMatch && _result.NameResultCode.Equals(FindNameCode.ExactMatch) && _result.FoundPoint != null) { labelSearchResult.Text = "Exact Match"; showPointOnSearchTableMap(_result.FoundPoint.X, _result.FoundPoint.Y); } else if (_result.NameResultCode.Equals(FindNameCode.ExactMatch) && _result.AddressResultCode.Equals(FindAddressCode.AddressNumNotSpecified)) { labelSearchResult.Text = _result.AddressResultCode.ToString(); FindAddressRangeEnumerator _enum = _result.GetAddressRangeEnumerator(); FindAddressRange _findAddressRange; listBoxSearchResult.Visible = true; while (_enum.MoveNext()) { _findAddressRange = _enum.Current; listBoxSearchResult.Items.Add( String.Format("Address range: [{0} - {1}]", _findAddressRange.BeginRange, _findAddressRange.EndRange)); } } else if (_result.NameResultCode.Equals(FindNameCode.ExactMatch) && _result.MultipleMatches) { labelSearchResult.Text = _result.NameResultCode.ToString(); listBoxSearchResult.Visible = true; FindCloseMatchEnumerator enumerator = _result.GetCloseMatchEnumerator(); while (enumerator.MoveNext()) { listBoxSearchResult.Items.Add(enumerator.Current.Name); } } else { labelSearchResult.Text = _result.NameResultCode.ToString(); if (find.UseCloseMatches) { listBoxSearchResult.Visible = true; FindCloseMatchEnumerator enumerator = _result.GetCloseMatchEnumerator(); while (enumerator.MoveNext()) { listBoxSearchResult.Items.Add(enumerator.Current.Name); } } } find.Dispose(); }