1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.ActiveRecord
.Generator
.Dialogs
19 using System
.Collections
;
20 using System
.ComponentModel
;
21 using System
.Windows
.Forms
;
24 /// Summary description for DatabaseConnectionDialog.
26 public class DatabaseConnectionDialog
: System
.Windows
.Forms
.Form
28 private System
.Windows
.Forms
.Button button1
;
29 private System
.Windows
.Forms
.Button button2
;
30 private System
.Windows
.Forms
.Label label1
;
31 private System
.Windows
.Forms
.TextBox textBox1
;
32 private System
.Windows
.Forms
.Label label2
;
33 private System
.Windows
.Forms
.Button button3
;
34 private System
.Windows
.Forms
.TextBox connectionString
;
36 /// Required designer variable.
38 private System
.ComponentModel
.Container components
= null;
40 public DatabaseConnectionDialog()
43 // Required for Windows Form Designer support
45 InitializeComponent();
48 // TODO: Add any constructor code after InitializeComponent call
52 // textBox1.Text = "MyAlias";
53 // connectionString.Text = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=.";
58 /// Clean up any resources being used.
60 protected override void Dispose( bool disposing
)
64 if(components
!= null)
69 base.Dispose( disposing
);
72 #region Windows Form Designer generated code
74 /// Required method for Designer support - do not modify
75 /// the contents of this method with the code editor.
77 private void InitializeComponent()
79 this.button1
= new System
.Windows
.Forms
.Button();
80 this.button2
= new System
.Windows
.Forms
.Button();
81 this.label1
= new System
.Windows
.Forms
.Label();
82 this.textBox1
= new System
.Windows
.Forms
.TextBox();
83 this.connectionString
= new System
.Windows
.Forms
.TextBox();
84 this.label2
= new System
.Windows
.Forms
.Label();
85 this.button3
= new System
.Windows
.Forms
.Button();
90 this.button1
.Location
= new System
.Drawing
.Point(360, 160);
91 this.button1
.Name
= "button1";
92 this.button1
.TabIndex
= 4;
93 this.button1
.Text
= "OK";
94 this.button1
.Click
+= new System
.EventHandler(this.button1_Click
);
98 this.button2
.Location
= new System
.Drawing
.Point(272, 160);
99 this.button2
.Name
= "button2";
100 this.button2
.TabIndex
= 1;
101 this.button2
.Text
= "Cancel";
102 this.button2
.Click
+= new System
.EventHandler(this.button2_Click
);
106 this.label1
.Location
= new System
.Drawing
.Point(16, 24);
107 this.label1
.Name
= "label1";
108 this.label1
.TabIndex
= 0;
109 this.label1
.Text
= "Alias:";
110 this.label1
.TextAlign
= System
.Drawing
.ContentAlignment
.MiddleLeft
;
114 this.textBox1
.Location
= new System
.Drawing
.Point(128, 24);
115 this.textBox1
.Name
= "textBox1";
116 this.textBox1
.Size
= new System
.Drawing
.Size(160, 21);
117 this.textBox1
.TabIndex
= 1;
118 this.textBox1
.Text
= "";
122 this.connectionString
.Location
= new System
.Drawing
.Point(128, 64);
123 this.connectionString
.Name
= "connectionString";
124 this.connectionString
.Size
= new System
.Drawing
.Size(272, 21);
125 this.connectionString
.TabIndex
= 3;
126 this.connectionString
.Text
= "";
130 this.label2
.Location
= new System
.Drawing
.Point(16, 64);
131 this.label2
.Name
= "label2";
132 this.label2
.TabIndex
= 2;
133 this.label2
.Text
= "Connection String:";
134 this.label2
.TextAlign
= System
.Drawing
.ContentAlignment
.MiddleLeft
;
138 this.button3
.Location
= new System
.Drawing
.Point(408, 64);
139 this.button3
.Name
= "button3";
140 this.button3
.Size
= new System
.Drawing
.Size(24, 23);
141 this.button3
.TabIndex
= 6;
142 this.button3
.Text
= "...";
143 this.button3
.Click
+= new System
.EventHandler(this.button3_Click
);
145 // DatabaseConnectionDialog
147 this.AutoScaleBaseSize
= new System
.Drawing
.Size(5, 14);
148 this.ClientSize
= new System
.Drawing
.Size(448, 194);
149 this.Controls
.Add(this.button3
);
150 this.Controls
.Add(this.connectionString
);
151 this.Controls
.Add(this.textBox1
);
152 this.Controls
.Add(this.label2
);
153 this.Controls
.Add(this.label1
);
154 this.Controls
.Add(this.button2
);
155 this.Controls
.Add(this.button1
);
156 this.Font
= new System
.Drawing
.Font("Tahoma", 8.25F
, System
.Drawing
.FontStyle
.Regular
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
157 this.FormBorderStyle
= System
.Windows
.Forms
.FormBorderStyle
.FixedDialog
;
158 this.MaximizeBox
= false;
159 this.Name
= "DatabaseConnectionDialog";
160 this.StartPosition
= System
.Windows
.Forms
.FormStartPosition
.CenterScreen
;
161 this.Text
= "Add Database Connection";
162 this.ResumeLayout(false);
167 private void button3_Click(object sender
, System
.EventArgs e
)
169 MSDASC
.DataLinks dataLinks
= new MSDASC
.DataLinksClass();
170 ADODB
._Connection connection
;
172 if (connectionString
.Text
== String
.Empty
)
176 connection
= (ADODB
._Connection
) dataLinks
.PromptNew();
178 connectionString
.Text
= connection
.ConnectionString
.ToString();
182 MessageBox
.Show(ex
.ToString());
187 connection
= new ADODB
.ConnectionClass();
188 connection
.ConnectionString
= connectionString
.Text
;
190 object oConnection
= connection
;
194 if (dataLinks
.PromptEdit(ref oConnection
))
196 connectionString
.Text
= connection
.ConnectionString
;
201 MessageBox
.Show(ex
.ToString());
206 private void button2_Click(object sender
, System
.EventArgs e
)
208 DialogResult
= DialogResult
.Cancel
;
212 private void button1_Click(object sender
, System
.EventArgs e
)
214 // TODO: Validate fields
216 DialogResult
= DialogResult
.OK
;
222 get { return textBox1.Text; }
225 public String ConnectionString
227 get { return connectionString.Text; }