diff Postarc/Postarc/GUI/FormConnectionProperties.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/FormConnectionProperties.cs	Fri Oct 05 23:55:06 2012 +0200
@@ -0,0 +1,110 @@
+/*
+ * 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.IO;
+using System.Linq;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Text;
+using System.Windows.Forms;
+using Npgsql;
+
+namespace Postarc.GUI
+{
+    public partial class FormConnectionProperties : Form
+    {
+        private PostGISConnection conn;
+
+        public FormConnectionProperties(PostGISConnection conn)
+        {
+            InitializeComponent();
+            this.conn = conn;
+
+            this.txtConnectionName.Text = conn.Name;
+            this.txtHost.Text = conn.Host;
+            this.txtUser.Text = conn.User;
+            this.txtPassword.Text = conn.Password;
+            this.cmbDbNames.SelectedItem = conn.Database;
+			this.numPort.Value = conn.Port;
+        }
+
+        private void groupBoxAuthentication_Enter(object sender, EventArgs e)
+        {
+
+        }
+
+        private void btnSave_Click(object sender, EventArgs e)
+        {
+            UpdateConnectionObject();
+
+            // Write to application data
+            Directory.CreateDirectory(Application.UserAppDataPath + "\\postarc\\");
+            FileStream fs = new FileStream(
+                Application.UserAppDataPath + "\\postarc\\" + txtConnectionName.Text + ".connprof", 
+                FileMode.OpenOrCreate);
+            BinaryFormatter formatter = new BinaryFormatter();
+            formatter.Serialize(fs, this.conn);
+            fs.Close();
+
+            MessageBox.Show(
+                "Connection profile saved!", "Save success", 
+                MessageBoxButtons.OK, MessageBoxIcon.Information);
+        }
+
+        private void btnTestConnection_Click(object sender, EventArgs e)
+        {
+            UpdateConnectionObject();
+            try
+            {
+                NpgsqlConnection conn = this.conn.Open();
+                conn.Close();
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message);
+                return;
+            }
+
+            MessageBox.Show("Connection succeeded.");
+        }
+
+        private void UpdateConnectionObject()
+        {
+            this.conn.Database = this.cmbDbNames.SelectedValue != null ? this.cmbDbNames.SelectedValue.ToString() : "";
+            this.conn.Host = this.txtHost.Text;
+            this.conn.Name = this.txtConnectionName.Text;
+            this.conn.Password = this.txtPassword.Text;
+            this.conn.Port = Convert.ToInt16(this.numPort.Value);
+            this.conn.User = this.txtUser.Text;
+        }
+
+        private void btnCancel_Click(object sender, EventArgs e)
+        {
+            Close();
+        }
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)