Mercurial > postarc > postarc
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1aca3d413885 |
---|---|
1 /* | |
2 * Postarc | |
3 * | |
4 * Author: | |
5 * Christian Lins <christian.lins@intevation.de> | |
6 * | |
7 * Copyright: | |
8 * Copyright (C) 2012 Intevation GmbH <http://www.intevation.de/> | |
9 * | |
10 * This program is free software: you can redistribute it and/or modify | |
11 * it under the terms of the GNU Lesser General Public License as published by | |
12 * the Free Software Foundation, either version 3 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU Lesser General Public License | |
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
22 */ | |
23 | |
24 using System; | |
25 using System.Collections.Generic; | |
26 using System.ComponentModel; | |
27 using System.Data; | |
28 using System.Drawing; | |
29 using System.IO; | |
30 using System.Linq; | |
31 using System.Runtime.Serialization.Formatters.Binary; | |
32 using System.Text; | |
33 using System.Windows.Forms; | |
34 using Npgsql; | |
35 | |
36 namespace Postarc.GUI | |
37 { | |
38 public partial class FormConnectionProperties : Form | |
39 { | |
40 private PostGISConnection conn; | |
41 | |
42 public FormConnectionProperties(PostGISConnection conn) | |
43 { | |
44 InitializeComponent(); | |
45 this.conn = conn; | |
46 | |
47 this.txtConnectionName.Text = conn.Name; | |
48 this.txtHost.Text = conn.Host; | |
49 this.txtUser.Text = conn.User; | |
50 this.txtPassword.Text = conn.Password; | |
51 this.cmbDbNames.SelectedItem = conn.Database; | |
52 this.numPort.Value = conn.Port; | |
53 } | |
54 | |
55 private void groupBoxAuthentication_Enter(object sender, EventArgs e) | |
56 { | |
57 | |
58 } | |
59 | |
60 private void btnSave_Click(object sender, EventArgs e) | |
61 { | |
62 UpdateConnectionObject(); | |
63 | |
64 // Write to application data | |
65 Directory.CreateDirectory(Application.UserAppDataPath + "\\postarc\\"); | |
66 FileStream fs = new FileStream( | |
67 Application.UserAppDataPath + "\\postarc\\" + txtConnectionName.Text + ".connprof", | |
68 FileMode.OpenOrCreate); | |
69 BinaryFormatter formatter = new BinaryFormatter(); | |
70 formatter.Serialize(fs, this.conn); | |
71 fs.Close(); | |
72 | |
73 MessageBox.Show( | |
74 "Connection profile saved!", "Save success", | |
75 MessageBoxButtons.OK, MessageBoxIcon.Information); | |
76 } | |
77 | |
78 private void btnTestConnection_Click(object sender, EventArgs e) | |
79 { | |
80 UpdateConnectionObject(); | |
81 try | |
82 { | |
83 NpgsqlConnection conn = this.conn.Open(); | |
84 conn.Close(); | |
85 } | |
86 catch (Exception ex) | |
87 { | |
88 MessageBox.Show(ex.Message); | |
89 return; | |
90 } | |
91 | |
92 MessageBox.Show("Connection succeeded."); | |
93 } | |
94 | |
95 private void UpdateConnectionObject() | |
96 { | |
97 this.conn.Database = this.cmbDbNames.SelectedValue != null ? this.cmbDbNames.SelectedValue.ToString() : ""; | |
98 this.conn.Host = this.txtHost.Text; | |
99 this.conn.Name = this.txtConnectionName.Text; | |
100 this.conn.Password = this.txtPassword.Text; | |
101 this.conn.Port = Convert.ToInt16(this.numPort.Value); | |
102 this.conn.User = this.txtUser.Text; | |
103 } | |
104 | |
105 private void btnCancel_Click(object sender, EventArgs e) | |
106 { | |
107 Close(); | |
108 } | |
109 } | |
110 } |