**** Merged from MCS ****
[mono-project.git] / mcs / tools / SqlSharp / gui / gtk-sharp / LoginDialog.cs
blobe74c07ad7d53e0656614dc29ae58817ec6ed64af
1 // LoginDialog.cs
2 //
3 // Author:
4 // Daniel Morgan <danielmorgan@verizon.net>
5 //
6 // (C)Copyright 2002-2003 by Daniel Morgan
7 //
8 // To be included with Mono as a SQL query tool licensed under the GPL license.
9 //
11 namespace Mono.Data.SqlSharp.Gui.GtkSharp
13 using System;
14 using System.Collections;
15 using System.Data;
16 using System.Drawing;
17 using System.Text;
18 using System.IO;
19 using Gtk;
20 using GtkSharp;
21 using SqlEditorSharp;
22 using System.Reflection;
23 using System.Runtime.Remoting;
24 using System.Diagnostics;
26 public class LoginDialog
28 Dialog dialog;
29 Entry connection_entry;
30 Entry provider_entry;
31 SqlSharpGtk sqlSharp;
32 OptionMenu providerOptionMenu;
33 int providerSelected = 0;
35 public LoginDialog(SqlSharpGtk sqlSharpGtk)
37 sqlSharp = sqlSharpGtk;
38 CreateGui();
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);
53 hbox.BorderWidth = 5;
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;
59 table.RowSpacing = 4;
60 Label label = null;
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);
72 frame.Add (hbox);
74 dialog.VBox.PackStart (frame, true, true, 0);
76 Button button = null;
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);
86 dialog.Modal = true;
88 dialog.ShowAll ();
91 public OptionMenu CreateProviderOptionMenu()
93 OptionMenu optionMenu = new OptionMenu();
95 Menu providerMenu = new Menu ();
96 MenuItem menuItem;
98 if (sqlSharp.dbProvider == null)
99 providerSelected = 0;
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);
115 return optionMenu;
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)
126 try {
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.");
140 dialog.Destroy ();
141 dialog = null;
144 void Dialog_Cancel (object o, EventArgs args)
146 dialog.Destroy ();
147 dialog = null;