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);
            }
        }
Ejemplo n.º 3
0
        private string DetermineRemoteGeomType(FeatureLayer layer)
        {
            MapInfo.Data.Table   t     = layer.Table;
            MapInfo.Styles.Style style = null;

            MIConnection con = null;
            MICommand    cmd = null;
            MIDataReader dr  = null;

            try {
                con = new MIConnection();
                con.Open();
                cmd             = con.CreateCommand();
                cmd.CommandText = "select mi_style from \"" + t.Alias + "\"";
                cmd.CommandType = System.Data.CommandType.Text;
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    if (!dr.IsDBNull(0))
                    {
                        style = dr.GetStyle(0);
                        break;
                    }
                }
            }
            catch (MIException) {
                // e.g. if there is no mi_style column
            }
            finally {
                if (cmd != null)
                {
                    cmd.Dispose();
                    cmd = null;
                }
                if (dr != null)
                {
                    dr.Close();
                }
                if (con != null)
                {
                    con.Close();
                    con = null;
                }
            }

            if (style != null)
            {
                if (style is SimpleLineStyle)
                {
                    return("lclayerline.bmp");
                }
                else if (style is SimpleInterior || style is AreaStyle)
                {
                    return("lclayerregion.bmp");
                }
                else if (style is BasePointStyle)
                {
                    return("lclayerpoint.bmp");
                }
                else
                {
                    return("lclayer.bmp");
                }
            }
            else
            {
                return(null);
            }
        }