diff Postarc/Postarc/GUI/FormNewPostGISFeatClass.cs @ 0:1aca3d413885 tip

Initial import of Postarc
author Christian Lins <christian.lins@intevation.de>
date Fri, 05 Oct 2012 23:55:06 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Postarc/Postarc/GUI/FormNewPostGISFeatClass.cs	Fri Oct 05 23:55:06 2012 +0200
@@ -0,0 +1,154 @@
+/*
+ * Postarc
+ *
+ * Author:
+ * Christian Lins <christian.lins@intevation.de>
+ *
+ * Copyright:
+ * Copyright (C) 2012 Intevation GmbH <http://www.intevation.de/>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using ESRI.ArcGIS.Carto;
+using ESRI.ArcGIS.Geodatabase;
+using ESRI.ArcGIS.Geometry;
+using Postarc.Feature;
+
+namespace Postarc.GUI
+{
+    public partial class FormNewPostGISFeatClass : Form
+    {
+        public FormNewPostGISFeatClass()
+        {
+            InitializeComponent();
+            this.cmbGeometryType.SelectedIndex = 0;
+        }
+
+        private void btnCreate_Click(object sender, EventArgs e)
+        {
+            if (cmbGeometryType.SelectedItem == null)
+            {
+                MessageBox.Show("Please choose the Shape type of the new FeatureClass!", "Shape type", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                return;
+            }
+            if (txtLayerName.Text == null || txtLayerName.Text.Equals(""))
+            {
+                MessageBox.Show("Please enter a name for the new layer!", "Layer name", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                return;
+            }
+            if (txtFCName.Text == null || txtFCName.Text.Equals(""))
+            {
+                MessageBox.Show("Please enter a name for the FeatureClass!", "FeatureClass name", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                return;
+            }
+
+            esriGeometryType shapeType = esriGeometryType.esriGeometryNull;
+            if (cmbGeometryType.SelectedItem.Equals("POINT"))
+            {
+                shapeType = esriGeometryType.esriGeometryPoint;
+            }
+            else if (cmbGeometryType.SelectedItem.Equals("POLYGON"))
+            {
+                shapeType = esriGeometryType.esriGeometryPolygon;
+            }
+            else if (cmbGeometryType.SelectedItem.Equals("POLYLINE"))
+            {
+                shapeType = esriGeometryType.esriGeometryPolyline;
+            }
+
+            //PostarcClassDescription.Register();
+
+            IFeatureClass featClass;
+            //if (cmbGeometryTable.SelectedText!= null)
+            {
+                featClass = new Postarc.Feature.FeatureClass(
+                    this.cmbDatabaseConnections.SelectedItem as PostGISConnection,
+                    this.cmbGeometryTable.SelectedItem as string);
+            }
+            //else
+            //{
+              //  featClass = new PostGISFeatureClass(shapeType);
+            //}
+
+            // Load field definitions from geometry table
+
+            Visible = false;
+            Application.DoEvents();
+
+            // Create FeatureLayer that encapsulates our FeatureClass
+            IFeatureLayer featLayer = new Postarc.Feature.FeatureLayer();
+            featLayer.FeatureClass = featClass;
+            featLayer.Name = txtLayerName.Text;
+
+            // Add FeatureLayer to active map document
+            ArcMap.Document.FocusMap.AddLayer(featLayer);
+        }
+
+        private void btnEditConnections_Click(object sender, EventArgs e)
+        {
+            PostGISConnection conn = this.cmbDatabaseConnections.SelectedItem as PostGISConnection;
+            if (conn != null)
+            {
+                FormConnectionProperties connProp = new FormConnectionProperties(conn);
+                connProp.ShowDialog();
+            }
+            else
+            {
+                MessageBox.Show("Please select a connection profile first!");
+            }
+        }
+
+        private void FormNewPostGISFeatClass_Shown(object sender, EventArgs e)
+        {
+            int selIndex;
+            
+            // Fill the database connections to the combo box and preselect one
+            selIndex = this.cmbDatabaseConnections.SelectedIndex;
+            this.cmbDatabaseConnections.Items.Clear();
+            this.cmbDatabaseConnections.Items.AddRange(Settings.LoadSavedProfiles().ToArray());
+            this.cmbDatabaseConnections.Items.Add(new PostGISConnection());
+            this.cmbDatabaseConnections.SelectedIndex = 0;
+            if (selIndex >= 0)
+            {
+                this.cmbDatabaseConnections.SelectedIndex = selIndex;
+            }
+        }
+
+        private void FormNewPostGISFeatClass_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            e.Cancel = true;
+            Visible = false;
+        }
+
+        private void cmbDatabaseConnections_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            if (cmbDatabaseConnections.SelectedIndex >= 0)
+            {
+                PostGISConnection conn = cmbDatabaseConnections.SelectedItem as PostGISConnection;
+                this.cmbGeometryTable.Items.Clear();
+                this.cmbGeometryTable.Items.AddRange(conn.QueryTables().ToArray());
+                this.cmbGeometryTable.SelectedIndex = 0;
+            }
+        }
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)