Ejemplo n.º 1
0
        private void FillDropDown(string tableName, string colName)
        {
            MapInfo.Mapping.Map map = null;

            // Get the map
            if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
                (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
            {
                return;
            }

            DropDownList1.Items.Clear();
            MapInfo.Mapping.FeatureLayer fl = (MapInfo.Mapping.FeatureLayer)map.Layers[tableName];
            MapInfo.Data.Table           t  = fl.Table;
            MIDataReader tr;
            MIConnection con = new MIConnection();
            MICommand    tc  = con.CreateCommand();

            tc.CommandText = "select " + colName + " from " + t.Alias;
            con.Open();
            tr = tc.ExecuteReader();
            while (tr.Read())
            {
                DropDownList1.Items.Add(tr.GetString(0));
            }
            tc.Cancel();
            tc.Dispose();
            tr.Close();
            con.Close();
            //t.Close();
        }
Ejemplo n.º 2
0
        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);
            }
        }