4 // Daniel Morgan <danielmorgan@verizon.net>
6 // (C)Copyright 2002-2003 by Daniel Morgan
8 // To be included with Mono as a SQL query tool licensed under the GPL license.
11 namespace Mono
.Data
.SqlSharp
.Gui
.GtkSharp
14 using System
.Collections
;
22 using System
.Reflection
;
23 using System
.Runtime
.Remoting
;
24 using System
.Diagnostics
;
26 public class LoginDialog
29 Entry connection_entry
;
32 OptionMenu providerOptionMenu
;
33 int providerSelected
= 0;
35 public LoginDialog(SqlSharpGtk sqlSharpGtk
)
37 sqlSharp
= sqlSharpGtk
;
41 public void CreateGui()
43 dialog
= new Dialog ();
44 dialog
.Title
= "Login";
45 dialog
.BorderWidth
= 3;
46 dialog
.VBox
.BorderWidth
= 5;
47 dialog
.HasSeparator
= false;
49 Frame frame
= new Frame ("Connection");
50 string image
= Stock
.DialogInfo
;
52 HBox hbox
= new HBox (false, 2);
54 hbox
.PackStart (new Gtk
.Image (image
, IconSize
.Dialog
), true, true, 0);
56 Table table
= new Table (2, 3, false);
57 hbox
.PackStart (table
);
58 table
.ColumnSpacing
= 4;
62 label
= Label
.NewWithMnemonic ("_Provider");
63 table
.Attach (label
, 0, 1, 0, 1);
64 providerOptionMenu
= CreateProviderOptionMenu();
65 table
.Attach (providerOptionMenu
, 1, 2, 0, 1);
67 label
= Label
.NewWithMnemonic ("_Connection String");
68 table
.Attach (label
, 0, 1, 1, 2);
69 connection_entry
= new Entry ();
70 table
.Attach (connection_entry
, 1, 2, 1, 2);
74 dialog
.VBox
.PackStart (frame
, true, true, 0);
77 button
= new Button(Stock
.Ok
);
78 button
.Clicked
+= new EventHandler (Connect_Action
);
79 button
.CanDefault
= true;
80 dialog
.ActionArea
.PackStart (button
, true, true, 0);
81 button
.GrabDefault ();
83 button
= new Button(Stock
.Cancel
);
84 button
.Clicked
+= new EventHandler (Dialog_Cancel
);
85 dialog
.ActionArea
.PackStart (button
, true, true, 0);
91 public OptionMenu
CreateProviderOptionMenu()
93 OptionMenu optionMenu
= new OptionMenu();
95 Menu providerMenu
= new Menu ();
98 if (sqlSharp
.dbProvider
== null)
101 for(int i
= 0; i
< sqlSharp
.providerList
.Count
; i
++) {
102 DbProvider p
= sqlSharp
.providerList
[i
];
103 menuItem
= new MenuItem(p
.Name
);
104 providerMenu
.Append (menuItem
);
105 if (sqlSharp
.dbProvider
!= null)
106 if (sqlSharp
.dbProvider
.Name
.Equals(p
.Name
))
107 providerSelected
= i
;
110 optionMenu
.Menu
= providerMenu
;
111 optionMenu
.Changed
+= new EventHandler (provider_changed_cb
);
113 optionMenu
.SetHistory ((uint) providerSelected
);
118 void provider_changed_cb (object o
, EventArgs args
)
120 if(providerOptionMenu
!= null)
121 providerSelected
= providerOptionMenu
.History
;
124 void Connect_Action (object o
, EventArgs args
)
127 sqlSharp
.dbProvider
= null;
128 sqlSharp
.dbProvider
= sqlSharp
.providerList
[providerSelected
];
129 string connection
= "";
131 connection
= connection_entry
.Text
;
133 sqlSharp
.connectionString
= connection
;
134 sqlSharp
.OpenDataSource();
136 } catch (Exception e
) {
137 sqlSharp
.AppendText(sqlSharp
.buf
,
138 "Error: Unable to connect.");
144 void Dialog_Cancel (object o
, EventArgs args
)