1 // ByteFX.Data data access components for .Net
2 // Copyright (C) 2002-2003 ByteFX, Inc.
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 using System
.Collections
;
20 using System
.ComponentModel
;
23 using System
.Windows
.Forms
;
26 namespace ByteFX
.Data
.MySqlClient
.Designers
30 /// Summary description for EditConnectionString.
32 public class EditConnectionString
: System
.Windows
.Forms
.Form
34 private System
.Windows
.Forms
.Button buttonOK
;
35 private System
.Windows
.Forms
.Button buttonCancel
;
36 private System
.Windows
.Forms
.Label label1
;
37 private System
.Windows
.Forms
.TextBox textServer
;
38 private System
.Windows
.Forms
.TextBox textUser
;
39 private System
.Windows
.Forms
.Label label2
;
40 private System
.Windows
.Forms
.TextBox textPassword
;
41 private System
.Windows
.Forms
.Label label3
;
42 private System
.Windows
.Forms
.ComboBox comboDatabase
;
43 private System
.Windows
.Forms
.Label label4
;
44 private System
.Windows
.Forms
.Label label5
;
45 private System
.Windows
.Forms
.TextBox textPort
;
46 private System
.Windows
.Forms
.CheckBox useCompression
;
48 /// Required designer variable.
50 private System
.ComponentModel
.Container components
= null;
52 public EditConnectionString()
55 // Required for Windows Form Designer support
57 InitializeComponent();
60 // TODO: Add any constructor code after InitializeComponent call
64 public string ConnectionString
;
67 /// Clean up any resources being used.
69 protected override void Dispose( bool disposing
)
73 if(components
!= null)
78 base.Dispose( disposing
);
81 #region Windows Form Designer generated code
83 /// Required method for Designer support - do not modify
84 /// the contents of this method with the code editor.
86 private void InitializeComponent()
88 this.buttonOK
= new System
.Windows
.Forms
.Button();
89 this.buttonCancel
= new System
.Windows
.Forms
.Button();
90 this.label1
= new System
.Windows
.Forms
.Label();
91 this.textServer
= new System
.Windows
.Forms
.TextBox();
92 this.textUser
= new System
.Windows
.Forms
.TextBox();
93 this.label2
= new System
.Windows
.Forms
.Label();
94 this.textPassword
= new System
.Windows
.Forms
.TextBox();
95 this.label3
= new System
.Windows
.Forms
.Label();
96 this.comboDatabase
= new System
.Windows
.Forms
.ComboBox();
97 this.label4
= new System
.Windows
.Forms
.Label();
98 this.label5
= new System
.Windows
.Forms
.Label();
99 this.textPort
= new System
.Windows
.Forms
.TextBox();
100 this.useCompression
= new System
.Windows
.Forms
.CheckBox();
101 this.SuspendLayout();
105 this.buttonOK
.Location
= new System
.Drawing
.Point(67, 200);
106 this.buttonOK
.Name
= "buttonOK";
107 this.buttonOK
.TabIndex
= 0;
108 this.buttonOK
.Text
= "&OK";
109 this.buttonOK
.Click
+= new System
.EventHandler(this.buttonOK_Click
);
113 this.buttonCancel
.DialogResult
= System
.Windows
.Forms
.DialogResult
.Cancel
;
114 this.buttonCancel
.Location
= new System
.Drawing
.Point(187, 200);
115 this.buttonCancel
.Name
= "buttonCancel";
116 this.buttonCancel
.TabIndex
= 0;
117 this.buttonCancel
.Text
= "&Cancel";
121 this.label1
.Location
= new System
.Drawing
.Point(12, 24);
122 this.label1
.Name
= "label1";
123 this.label1
.Size
= new System
.Drawing
.Size(104, 16);
124 this.label1
.TabIndex
= 1;
125 this.label1
.Text
= "Mysql server name:";
126 this.label1
.TextAlign
= System
.Drawing
.ContentAlignment
.MiddleRight
;
130 this.textServer
.Location
= new System
.Drawing
.Point(112, 20);
131 this.textServer
.Name
= "textServer";
132 this.textServer
.Size
= new System
.Drawing
.Size(168, 20);
133 this.textServer
.TabIndex
= 2;
134 this.textServer
.Text
= "";
138 this.textUser
.Location
= new System
.Drawing
.Point(112, 76);
139 this.textUser
.Name
= "textUser";
140 this.textUser
.Size
= new System
.Drawing
.Size(168, 20);
141 this.textUser
.TabIndex
= 2;
142 this.textUser
.Text
= "";
146 this.label2
.Location
= new System
.Drawing
.Point(68, 76);
147 this.label2
.Name
= "label2";
148 this.label2
.Size
= new System
.Drawing
.Size(40, 16);
149 this.label2
.TabIndex
= 1;
150 this.label2
.Text
= "User:";
151 this.label2
.TextAlign
= System
.Drawing
.ContentAlignment
.MiddleRight
;
155 this.textPassword
.Location
= new System
.Drawing
.Point(112, 108);
156 this.textPassword
.Name
= "textPassword";
157 this.textPassword
.PasswordChar
= '*';
158 this.textPassword
.Size
= new System
.Drawing
.Size(168, 20);
159 this.textPassword
.TabIndex
= 2;
160 this.textPassword
.Text
= "";
164 this.label3
.Location
= new System
.Drawing
.Point(44, 108);
165 this.label3
.Name
= "label3";
166 this.label3
.Size
= new System
.Drawing
.Size(64, 16);
167 this.label3
.TabIndex
= 1;
168 this.label3
.Text
= "Password:";
169 this.label3
.TextAlign
= System
.Drawing
.ContentAlignment
.MiddleRight
;
173 this.comboDatabase
.Location
= new System
.Drawing
.Point(112, 160);
174 this.comboDatabase
.Name
= "comboDatabase";
175 this.comboDatabase
.Size
= new System
.Drawing
.Size(168, 21);
176 this.comboDatabase
.TabIndex
= 3;
177 this.comboDatabase
.DropDown
+= new System
.EventHandler(this.comboDatabase_DropDown
);
181 this.label4
.Location
= new System
.Drawing
.Point(4, 164);
182 this.label4
.Name
= "label4";
183 this.label4
.Size
= new System
.Drawing
.Size(104, 16);
184 this.label4
.TabIndex
= 1;
185 this.label4
.Text
= "Select a database:";
186 this.label4
.TextAlign
= System
.Drawing
.ContentAlignment
.MiddleRight
;
190 this.label5
.Location
= new System
.Drawing
.Point(72, 52);
191 this.label5
.Name
= "label5";
192 this.label5
.Size
= new System
.Drawing
.Size(36, 16);
193 this.label5
.TabIndex
= 1;
194 this.label5
.Text
= "Port:";
195 this.label5
.TextAlign
= System
.Drawing
.ContentAlignment
.MiddleRight
;
199 this.textPort
.Location
= new System
.Drawing
.Point(112, 48);
200 this.textPort
.Name
= "textPort";
201 this.textPort
.Size
= new System
.Drawing
.Size(168, 20);
202 this.textPort
.TabIndex
= 2;
203 this.textPort
.Text
= "";
207 this.useCompression
.Location
= new System
.Drawing
.Point(10, 132);
208 this.useCompression
.Name
= "useCompression";
209 this.useCompression
.RightToLeft
= System
.Windows
.Forms
.RightToLeft
.Yes
;
210 this.useCompression
.Size
= new System
.Drawing
.Size(116, 24);
211 this.useCompression
.TabIndex
= 4;
212 this.useCompression
.Text
= "Use compression";
213 this.useCompression
.TextAlign
= System
.Drawing
.ContentAlignment
.MiddleRight
;
215 // EditConnectionString
217 this.AcceptButton
= this.buttonOK
;
218 this.AutoScaleBaseSize
= new System
.Drawing
.Size(5, 13);
219 this.CancelButton
= this.buttonCancel
;
220 this.ClientSize
= new System
.Drawing
.Size(298, 239);
221 this.Controls
.AddRange(new System
.Windows
.Forms
.Control
[] {
235 this.FormBorderStyle
= System
.Windows
.Forms
.FormBorderStyle
.FixedDialog
;
236 this.MaximizeBox
= false;
237 this.MinimizeBox
= false;
238 this.Name
= "EditConnectionString";
239 this.ShowInTaskbar
= false;
240 this.StartPosition
= System
.Windows
.Forms
.FormStartPosition
.CenterParent
;
241 this.Text
= "Edit Connection String";
242 this.Load
+= new System
.EventHandler(this.EditConnectionString_Load
);
243 this.ResumeLayout(false);
248 MySqlConnection conn
;
250 private void EditConnectionString_Load(object sender
, System
.EventArgs e
)
252 conn
= new MySqlConnection(ConnectionString
);
253 textServer
.Text
= conn
.DataSource
;
254 textUser
.Text
= conn
.User
;
255 textPassword
.Text
= conn
.Password
;
256 textPort
.Text
= conn
.Port
.ToString();
262 System
.Text
.StringBuilder s
;
263 s
= new System
.Text
.StringBuilder();
264 s
.Append("server=" + textServer
.Text
);
265 s
.Append(";port=" + textPort
.Text
);
266 s
.Append(";uid=" + textUser
.Text
);
267 s
.Append(";pwd=" + textPassword
.Text
);
268 if (useCompression
.Checked
)
270 s
.Append(";Use compression=true");
272 if (comboDatabase
.SelectedIndex
!= -1)
273 s
.Append(";Initial Catalog=" + comboDatabase
.SelectedItem
.ToString());
275 s
.Append(";Initial Catalog=" + comboDatabase
.Text
);
279 private void comboDatabase_DropDown(object sender
, System
.EventArgs e
)
281 comboDatabase
.Items
.Clear();
282 comboDatabase
.SelectedIndex
= -1;
286 conn
= new MySqlConnection(GetString());
288 MySqlCommand comm
= new MySqlCommand("show databases",conn
);
289 MySqlDataReader r
= (MySqlDataReader
)comm
.ExecuteReader();
292 comboDatabase
.Items
.Add(r
[0]);
297 catch(MySqlException
)
302 private void buttonOK_Click(object sender
, System
.EventArgs e
)
304 ConnectionString
= GetString();
305 DialogResult
= DialogResult
.OK
;