Exemplo n.º 1
0
        /// <summary>
        /// Temporary
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnColumns_Click(object sender, EventArgs e)
        {
            IDataProvider provider = DbUtilities.GetDataProvider(this.txtFilename.Text);

            if (provider != null)
            {
                DbConnection connection = provider.CreateConnection(this.txtFilename.Text);
                connection.Open();
                try
                {
                    System.Diagnostics.Debug.Print("List of tables:");
                    List <string> list = DbUtilities.GetTablesByField(connection, "Geometry", "blob");
                    foreach (string s in list)
                    {
                        System.Diagnostics.Debug.Print(s);
                    }

                    //if (listView1.SelectedIndices.Count > 0)
                    //{
                    //    bool exists = DbUtilities.ColumnExists(connection, listView1.SelectedItems[0].Text, "Geometry");
                    //    MessageBox.Show("Geometry field exists: " +  exists.ToString());
                    //}
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Exports the selected layers
        /// </summary>
        private void btnOk_Click(object sender, EventArgs e)
        {
            IDataProvider provider = DbUtilities.GetDataProvider(this.txtFilename.Text);

            if (provider == null)
            {
                return;
            }

            IEnumerable <ListViewItem> items = this.listView1.Items.Cast <ListViewItem>().Where(item => item.Checked);

            if (items.Count() == 0)
            {
                MessageBox.Show("No layers are selected.", m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                ShapefileDataClient client = new ShapefileDataClient(provider, this.txtFilename.Text, InitStringType.DatabaseName);
                client.Callback = m_mapWin.Layers as MapWinGIS.ICallback;
                if (client.OpenConnection())
                {
                    int percent, count, i;
                    percent = count = i = 0;

                    foreach (ListViewItem item in items)
                    {
                        if (items.Count() > 1)
                        {
                            int newPercent = Convert.ToInt32((double)i / (double)(items.Count() - 1) * 100.0);
                            if (newPercent != percent)
                            {
                                (m_mapWin.Layers as MapWinGIS.ICallback).Progress("", newPercent, "Importing shapefiles...");
                                percent = newPercent;
                            }
                        }

                        MapWinGIS.Shapefile sf = client.LoadShapefile(item.Text, CommandType.TableDirect);
                        if (sf != null)
                        {
                            m_mapWin.Layers.StartAddingSession();
                            m_mapWin.Layers.Add(ref sf);
                            m_mapWin.Layers.StopAddingSession();
                            count++;
                            // TODO: log errors
                        }
                        i++;
                    }

                    // cleaning progress
                    if (items.Count() > 1)
                    {
                        (m_mapWin.Layers as MapWinGIS.ICallback).Progress("", 100, "");
                    }

                    MessageBox.Show("Shapefiles imported: " + count.ToString(), m_mapWin.ApplicationInfo.ApplicationName,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of the DataConverter class based on database name
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="databaseName"></param>
        public ShapefileDataClient(string databaseName)
        {
            m_provider = DbUtilities.GetDataProvider(databaseName);
            if (m_provider == null)
            {
                throw new DataException("Invalid database name. Coundn't find data provider.");
            }

            m_connectionString = m_provider.CreateConnectionString(databaseName);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Tests connection to the selected database
        /// </summary>
        public static bool TestConnection(string dbName, bool silentMode)
        {
            IDataProvider provider = DbUtilities.GetDataProvider(dbName);

            if (provider == null)
            {
                return(false);
            }

            bool         result = false;
            DbConnection conn   = provider.CreateConnection(dbName);

            try
            {
                conn.Open();
                Application.DoEvents();

                if (conn.State == ConnectionState.Open)
                {
                    if (!silentMode)
                    {
                        MessageBox.Show("Connection is successful.", "MapWinGIS",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    result = true;
                }
                else
                {
                    if (!silentMode)
                    {
                        MessageBox.Show("Connection failed.", "MapWinGIS",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            finally
            {
                conn.Close();
            }
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Refresh tables list in the selected database
        /// </summary>
        private void RefreshTables()
        {
            this.listView1.Items.Clear();

            IDataProvider provider = DbUtilities.GetDataProvider(this.txtFilename.Text);

            if (provider != null)
            {
                DbConnection connection = provider.CreateConnection(this.txtFilename.Text);
                connection.Open();
                try
                {
                    List <TableInfo> list = DbUtilities.GetTableList(connection);
                    foreach (TableInfo tbl in list)
                    {
                        this.listView1.Items.Add(tbl.Name);
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
        }