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