Exemplo 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();
        }
Exemplo n.º 2
0
        public FormFindSample()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            //
            // Create a connection object and open it.
            //
            this._miConnection = new MIConnection();
            _miConnection.Open();

            //
            // Create a command object to hold parameters and last command executed
            //
            this._miCommand = _miConnection.CreateCommand();

            buttonFind.Enabled = false;
            checkBoxUseCloseMatches.Checked = true;
            listBoxSearchResult.Visible     = false;
            textBoxMaxCloseMatches.Text     = "5";
        }
Exemplo n.º 3
0
 private void SetDataGrid(DataGrid dataGrid, string commandText, bool bShowSchema)
 {
     MapInfo.Data.MIConnection miConnection = new MIConnection();
     miConnection.Open();
     MapInfo.Data.MICommand miCommand = miConnection.CreateCommand();
     miCommand.CommandText = commandText;
     MapInfo.Data.MIDataReader miReader = null;
     try
     {
         miReader = miCommand.ExecuteReader();
         if (bShowSchema)
         {
             dataGrid.DataSource = miReader.GetSchemaTable();
         }
         else
         {
             DataTable dt = new DataTable("Data");
             for (int index = 0; index < miReader.FieldCount; index++)
             {
                 DataColumn dc = dt.Columns.Add(miReader.GetName(index));
             }
             while (miReader.Read())
             {
                 DataRow dr = dt.NewRow();
                 for (int index = 0; index < miReader.FieldCount; index++)
                 {
                     dr[index] = miReader.GetValue(index);
                 }
                 dt.Rows.Add(dr);
             }
             dataGrid.DataSource = dt;
         }
     }
     catch (Exception)
     {
         SelectClauseTextBox.Text += " ***Wrong select clause, try it.***";
     }
     finally
     {
         if (miReader != null)
         {
             miReader.Close();
         }
     }
 }
Exemplo n.º 4
0
 private void SetDataGrid(DataGrid dataGrid, string commandText, bool bShowSchema)
 {
     MapInfo.Data.MIConnection miConnection = new MIConnection();
     miConnection.Open();
     MapInfo.Data.MICommand miCommand = miConnection.CreateCommand();
     miCommand.CommandText = commandText;
     MapInfo.Data.MIDataReader miReader = null;
     try
     {
         miReader = miCommand.ExecuteReader();
         if (bShowSchema)
         {
             dataGrid.DataSource = miReader.GetSchemaTable();
         }
         else
         {
             DataTable dt = new DataTable("Data");
             for (int index = 0; index < miReader.FieldCount; index++)
             {
                 DataColumn dc = dt.Columns.Add(miReader.GetName(index));
             }
             while (miReader.Read())
             {
                 DataRow dr = dt.NewRow();
                 for (int index = 0; index < miReader.FieldCount; index++)
                 {
                     dr[index] = miReader.GetValue(index);
                 }
                 dt.Rows.Add(dr);
             }
             dataGrid.DataSource = dt;
         }
     }
     catch(Exception)
     {
         SelectClauseTextBox.Text +=  " ***Wrong select clause, try it.***";
     }
     finally
     {
         if(miReader != null)
         {
             miReader.Close();
         }
     }
 }
Exemplo n.º 5
0
        private void showPointOnSearchTableMap(double x, double y)
        {
            MapInfo.Mapping.Map          map         = Session.Current.MapFactory.CreateEmptyMap(System.IntPtr.Zero, new Size(10, 10));
            MapInfo.Mapping.FeatureLayer searchLayer = new MapInfo.Mapping.FeatureLayer(_searchTable);
            map.Layers.Add(searchLayer);

            MapForm1 mapForm    = new MapForm1(map);
            Form     parentForm = this;

            // create a temp table and add a featurelayer for it (use map alias as table alias)
            // make the table hidden (maybe)
            MapInfo.Geometry.CoordSys coordSys = map.GetDisplayCoordSys();
            TableInfoMemTable         ti       = new TableInfoMemTable("temp");

            ti.Temporary = true;

            // add object column
            Column col;

            col          = new GeometryColumn(coordSys); // specify coordsys for object column
            col.Alias    = "obj";
            col.DataType = MIDbType.FeatureGeometry;
            ti.Columns.Add(col);

            // add style column
            col          = new Column();
            col.Alias    = "MI_Style";
            col.DataType = MIDbType.Style;
            ti.Columns.Add(col);

            Table pointTable = Session.Current.Catalog.CreateTable(ti);

            // I am using a Point example here. You can create a rectangle instead
            MapInfo.Geometry.FeatureGeometry      g  = new MapInfo.Geometry.Point(coordSys, x, y);
            MapInfo.Styles.SimpleVectorPointStyle vs = new MapInfo.Styles.SimpleVectorPointStyle(37, System.Drawing.Color.Red, 14);
            MapInfo.Styles.CompositeStyle         cs = new MapInfo.Styles.CompositeStyle(vs);

            MICommand cmd = _miConnection.CreateCommand();

            cmd.Parameters.Add("geometry", MIDbType.FeatureGeometry);
            cmd.Parameters.Add("style", MIDbType.Style);
            cmd.CommandText = "Insert Into temp (obj,MI_Style) values (geometry,style)";
            cmd.Prepare();
            cmd.Parameters[0].Value = g;
            cmd.Parameters[1].Value = cs;
            int nchanged = cmd.ExecuteNonQuery();

            cmd.Dispose();

            map.Layers.Add(new MapInfo.Mapping.FeatureLayer(pointTable));
            // another way: Map.Load(new MapTableLoader(table));

            // make the map encompass the entire search layer
            map.SetView(searchLayer);

            // size the map form
            mapForm.Size = new Size(500, 500);

            //Show the form like a dialog (modal)
            mapForm.ShowDialog(parentForm);

            pointTable.Close();
        }
Exemplo n.º 6
0
        public FormFindSample()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            //
            // Create a connection object and open it.
            //
            this._miConnection = new MIConnection();
            _miConnection.Open();

            //
            // Create a command object to hold parameters and last command executed
            //
            this._miCommand = _miConnection.CreateCommand();

            buttonFind.Enabled = false;
            checkBoxUseCloseMatches.Checked = true;
            listBoxSearchResult.Visible = false;
            textBoxMaxCloseMatches.Text = "5";
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
        public MainForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            ToolBarSetup();

            //
            // Create a connection object and open it.
            //
            miConnection = new MIConnection();
            miConnection.Open();

            //
            // Create a command object to hold parameters and last command executed
            //
            miCommand = miConnection.CreateCommand();

            // Add a few default parameters
            CoordSysFactory CSysFactory = Session.Current.CoordSysFactory;
            CoordSys Robinson = CSysFactory.CreateFromPrjString("12, 62, 7, 0");
            CoordSys LatLong = CSysFactory.CreateFromPrjString("1, 0");
            CoordSys NAD83 = CSysFactory.CreateFromPrjString("1, 74");
            miCommand.Parameters.Add("RobinsonCSys", Robinson);
            miCommand.Parameters.Add("LatLongCSys", LatLong);
            miCommand.Parameters.Add("NAD83CSys", NAD83);

            // Set table search path to value sampledatasearch registry key
            // if not found, then use the sampledatasearchpath
            // if that is not found, then just use the app's current directory
            Microsoft.Win32.RegistryKey keyApp = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\MapInfo\MIDataExplorer");

            string s = (string)keyApp.GetValue("TableSearchPath");
            if (s == null || s.Length == 0)
            {
                Microsoft.Win32.RegistryKey keySamp = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MapInfo\MapXtreme\6.6");
                s = (string)keySamp.GetValue("SampleDataSearchPath");
                if (s != null && s.Length > 0)
                {
                    if (s.EndsWith("\\")==false)
                    {
                        s += "\\";
                    }
                }
                else
                {
                    s = Environment.CurrentDirectory;
                }
                keySamp.Close();
            }
            keyApp.Close();

            Session.Current.TableSearchPath.Path = s;

            ProcessCommand("help"); // show commands

            // For sample app purposes, open states.tab
            if (Session.Current.TableSearchPath.FileExists("usa.tab"))
            {
                ProcessCommand("open usa.tab");
                // For sample app purposes, load states.sql if we can find it.
                string sFound;
                if (Session.Current.TableSearchPath.FileExists("sample.sql", out sFound))
                {
                    rtCommand.LoadFile(sFound, RichTextBoxStreamType.PlainText);
                }
                else
                {
                    // could not open a command file, but we want to show something
                    ProcessCommand("select * from usa");
                }
            }
        }
Exemplo n.º 10
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;
            }
        }