LoginDialog.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // LoginDialog.cs
  2. //
  3. // Author:
  4. // Daniel Morgan <[email protected]>
  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. //
  10. namespace Mono.Data.SqlSharp.Gui.GtkSharp
  11. {
  12. using System;
  13. using System.Collections;
  14. using System.Data;
  15. using System.Drawing;
  16. using System.Text;
  17. using System.IO;
  18. using Gtk;
  19. using GtkSharp;
  20. using SqlEditorSharp;
  21. using System.Reflection;
  22. using System.Runtime.Remoting;
  23. using System.Diagnostics;
  24. public class LoginDialog
  25. {
  26. Dialog dialog;
  27. Entry connection_entry;
  28. Entry provider_entry;
  29. SqlSharpGtk sqlSharp;
  30. OptionMenu providerOptionMenu;
  31. int providerSelected = 0;
  32. public LoginDialog(SqlSharpGtk sqlSharpGtk)
  33. {
  34. sqlSharp = sqlSharpGtk;
  35. CreateGui();
  36. }
  37. public void CreateGui()
  38. {
  39. dialog = new Dialog ();
  40. dialog.Title = "Login";
  41. dialog.BorderWidth = 3;
  42. dialog.VBox.BorderWidth = 5;
  43. dialog.HasSeparator = false;
  44. Frame frame = new Frame ("Connection");
  45. string image = Stock.DialogInfo;
  46. HBox hbox = new HBox (false, 2);
  47. hbox.BorderWidth = 5;
  48. hbox.PackStart (new Gtk.Image (image, IconSize.Dialog), true, true, 0);
  49. Table table = new Table (2, 3, false);
  50. hbox.PackStart (table);
  51. table.ColumnSpacing = 4;
  52. table.RowSpacing = 4;
  53. Label label = null;
  54. label = Label.NewWithMnemonic ("_Provider");
  55. table.Attach (label, 0, 1, 0, 1);
  56. providerOptionMenu = CreateProviderOptionMenu();
  57. table.Attach (providerOptionMenu, 1, 2, 0, 1);
  58. label = Label.NewWithMnemonic ("_Connection String");
  59. table.Attach (label, 0, 1, 1, 2);
  60. connection_entry = new Entry ();
  61. table.Attach (connection_entry, 1, 2, 1, 2);
  62. frame.Add (hbox);
  63. dialog.VBox.PackStart (frame, true, true, 0);
  64. Button button = null;
  65. button = new Button(Stock.Ok);
  66. button.Clicked += new EventHandler (Connect_Action);
  67. button.CanDefault = true;
  68. dialog.ActionArea.PackStart (button, true, true, 0);
  69. button.GrabDefault ();
  70. button = new Button(Stock.Cancel);
  71. button.Clicked += new EventHandler (Dialog_Cancel);
  72. dialog.ActionArea.PackStart (button, true, true, 0);
  73. dialog.Modal = true;
  74. dialog.ShowAll ();
  75. }
  76. public OptionMenu CreateProviderOptionMenu()
  77. {
  78. OptionMenu optionMenu = new OptionMenu();
  79. Menu providerMenu = new Menu ();
  80. MenuItem menuItem;
  81. if (sqlSharp.dbProvider == null)
  82. providerSelected = 0;
  83. for(int i = 0; i < sqlSharp.providerList.Count; i++) {
  84. DbProvider p = sqlSharp.providerList[i];
  85. menuItem = new MenuItem(p.Name);
  86. providerMenu.Append (menuItem);
  87. if (sqlSharp.dbProvider != null)
  88. if (sqlSharp.dbProvider.Name.Equals(p.Name))
  89. providerSelected = i;
  90. }
  91. optionMenu.Menu = providerMenu;
  92. optionMenu.Changed += new EventHandler (provider_changed_cb);
  93. optionMenu.SetHistory ((uint) providerSelected);
  94. return optionMenu;
  95. }
  96. void provider_changed_cb (object o, EventArgs args)
  97. {
  98. if(providerOptionMenu != null)
  99. providerSelected = providerOptionMenu.History;
  100. }
  101. void Connect_Action (object o, EventArgs args)
  102. {
  103. try {
  104. sqlSharp.dbProvider = null;
  105. sqlSharp.dbProvider = sqlSharp.providerList[providerSelected];
  106. string connection = "";
  107. connection = connection_entry.Text;
  108. sqlSharp.connectionString = connection;
  109. sqlSharp.OpenDataSource();
  110. } catch (Exception e) {
  111. sqlSharp.AppendText(sqlSharp.buf,
  112. "Error: Unable to connect.");
  113. }
  114. dialog.Destroy ();
  115. dialog = null;
  116. }
  117. void Dialog_Cancel (object o, EventArgs args)
  118. {
  119. dialog.Destroy ();
  120. dialog = null;
  121. }
  122. }
  123. }