(CreateUnixSocketStream): Instead of hostList [0], which is a char,
[mono.git] / mcs / class / ByteFX.Data / Common / SqlCommandEditorDlg.cs
1 // ByteFX.Data data access components for .Net
2 // Copyright (C) 2002-2003  ByteFX, Inc.
3 //
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.
8 // 
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.
13 // 
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
17
18 using System;
19 using System.Windows.Forms;
20 using System.Data;
21 using ByteFX.Data.MySqlClient;
22
23 namespace ByteFX.Data.Common
24 {
25         /// <summary>
26         /// Summary description for SqlCommandEditorDlg.
27         /// </summary>
28         internal class SqlCommandEditorDlg : System.Windows.Forms.Form
29         {
30                 private System.Windows.Forms.TextBox            sqlText;
31                 private System.Windows.Forms.Button                     CancelBtn;
32                 private System.Windows.Forms.Button                     OKBtn;
33                 private System.Windows.Forms.Panel                      panel1;
34                 private System.Windows.Forms.Splitter           splitter1;
35                 private System.Windows.Forms.DataGrid           dataGrid;
36                 private System.Windows.Forms.ContextMenu        sqlMenu;
37                 private System.Windows.Forms.MenuItem           runMenuItem;
38                 private IDbCommand                                                      command;
39                 private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
40
41                 /// <summary>
42                 /// Required designer variable.
43                 /// </summary>
44                 private System.ComponentModel.Container components = null;
45
46                 public SqlCommandEditorDlg(object o)
47                 {
48                         command = (IDbCommand)o;
49
50                         InitializeComponent();
51                 }
52
53                 /// <summary>
54                 /// Clean up any resources being used.
55                 /// </summary>
56                 protected override void Dispose( bool disposing )
57                 {
58                         if( disposing )
59                         {
60                                 if(components != null)
61                                 {
62                                         components.Dispose();
63                                 }
64                         }
65                         base.Dispose( disposing );
66                 }
67
68                 public string SQL 
69                 {
70                         get { return sqlText.Text; }
71                         set { sqlText.Text = value; }
72                 }
73
74                 #region Windows Form Designer generated code
75                 /// <summary>
76                 /// Required method for Designer support - do not modify
77                 /// the contents of this method with the code editor.
78                 /// </summary>
79                 private void InitializeComponent()
80                 {
81                         this.sqlText = new System.Windows.Forms.TextBox();
82                         this.sqlMenu = new System.Windows.Forms.ContextMenu();
83                         this.runMenuItem = new System.Windows.Forms.MenuItem();
84                         this.CancelBtn = new System.Windows.Forms.Button();
85                         this.OKBtn = new System.Windows.Forms.Button();
86                         this.panel1 = new System.Windows.Forms.Panel();
87                         this.splitter1 = new System.Windows.Forms.Splitter();
88                         this.dataGrid = new System.Windows.Forms.DataGrid();
89                         this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
90                         this.panel1.SuspendLayout();
91                         ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).BeginInit();
92                         this.SuspendLayout();
93                         // 
94                         // sqlText
95                         // 
96                         this.sqlText.ContextMenu = this.sqlMenu;
97                         this.sqlText.Dock = System.Windows.Forms.DockStyle.Top;
98                         this.sqlText.Location = new System.Drawing.Point(10, 10);
99                         this.sqlText.Multiline = true;
100                         this.sqlText.Name = "sqlText";
101                         this.sqlText.Size = new System.Drawing.Size(462, 144);
102                         this.sqlText.TabIndex = 0;
103                         this.sqlText.Text = "";
104                         // 
105                         // sqlMenu
106                         // 
107                         this.sqlMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
108                                                                                                                                                                         this.runMenuItem});
109                         // 
110                         // runMenuItem
111                         // 
112                         this.runMenuItem.Index = 0;
113                         this.runMenuItem.Text = "Run";
114                         this.runMenuItem.Click += new System.EventHandler(this.runMenuItem_Click);
115                         // 
116                         // CancelBtn
117                         // 
118                         this.CancelBtn.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
119                         this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
120                         this.CancelBtn.Location = new System.Drawing.Point(400, 350);
121                         this.CancelBtn.Name = "CancelBtn";
122                         this.CancelBtn.TabIndex = 3;
123                         this.CancelBtn.Text = "Cancel";
124                         this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
125                         // 
126                         // OKBtn
127                         // 
128                         this.OKBtn.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
129                         this.OKBtn.DialogResult = System.Windows.Forms.DialogResult.OK;
130                         this.OKBtn.Location = new System.Drawing.Point(316, 350);
131                         this.OKBtn.Name = "OKBtn";
132                         this.OKBtn.TabIndex = 4;
133                         this.OKBtn.Text = "OK";
134                         this.OKBtn.Click += new System.EventHandler(this.OKBtn_Click);
135                         // 
136                         // panel1
137                         // 
138                         this.panel1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
139                                 | System.Windows.Forms.AnchorStyles.Left) 
140                                 | System.Windows.Forms.AnchorStyles.Right);
141                         this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
142                                                                                                                                                                  this.splitter1,
143                                                                                                                                                                  this.dataGrid,
144                                                                                                                                                                  this.sqlText});
145                         this.panel1.DockPadding.Bottom = 10;
146                         this.panel1.DockPadding.Left = 10;
147                         this.panel1.DockPadding.Right = 14;
148                         this.panel1.DockPadding.Top = 10;
149                         this.panel1.Location = new System.Drawing.Point(2, 2);
150                         this.panel1.Name = "panel1";
151                         this.panel1.Size = new System.Drawing.Size(486, 344);
152                         this.panel1.TabIndex = 5;
153                         // 
154                         // splitter1
155                         // 
156                         this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
157                         this.splitter1.Location = new System.Drawing.Point(10, 154);
158                         this.splitter1.Name = "splitter1";
159                         this.splitter1.Size = new System.Drawing.Size(462, 3);
160                         this.splitter1.TabIndex = 3;
161                         this.splitter1.TabStop = false;
162                         // 
163                         // dataGrid
164                         // 
165                         this.dataGrid.CaptionVisible = false;
166                         this.dataGrid.DataMember = "";
167                         this.dataGrid.Dock = System.Windows.Forms.DockStyle.Fill;
168                         this.dataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
169                         this.dataGrid.Location = new System.Drawing.Point(10, 154);
170                         this.dataGrid.Name = "dataGrid";
171                         this.dataGrid.Size = new System.Drawing.Size(462, 180);
172                         this.dataGrid.TabIndex = 2;
173                         this.dataGrid.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
174                                                                                                                                                                                                  this.dataGridTableStyle1});
175                         // 
176                         // dataGridTableStyle1
177                         // 
178                         this.dataGridTableStyle1.AllowSorting = false;
179                         this.dataGridTableStyle1.DataGrid = this.dataGrid;
180                         this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
181                         this.dataGridTableStyle1.MappingName = "";
182                         // 
183                         // SqlCommandEditorDlg
184                         // 
185                         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
186                         this.ClientSize = new System.Drawing.Size(486, 384);
187                         this.ControlBox = false;
188                         this.Controls.AddRange(new System.Windows.Forms.Control[] {
189                                                                                                                                                   this.panel1,
190                                                                                                                                                   this.OKBtn,
191                                                                                                                                                   this.CancelBtn});
192                         this.DockPadding.Bottom = 10;
193                         this.DockPadding.Left = 10;
194                         this.DockPadding.Right = 12;
195                         this.DockPadding.Top = 10;
196                         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
197                         this.Name = "SqlCommandEditorDlg";
198                         this.Text = "Query Builder";
199                         this.panel1.ResumeLayout(false);
200                         ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit();
201                         this.ResumeLayout(false);
202
203                 }
204                 #endregion
205
206                 private void CancelBtn_Click(object sender, System.EventArgs e)
207                 {
208                         this.Close();
209                 }
210
211                 private void OKBtn_Click(object sender, System.EventArgs e)
212                 {
213                         this.Close();
214                 }
215
216                 private void runMenuItem_Click(object sender, System.EventArgs e)
217                 {
218                         if (command is MySqlCommand)
219                         {
220                                 RunMySql(); 
221                         }
222                 }
223
224                 private void RunMySql() 
225                 {
226                         try 
227                         {
228                                 MySqlDataAdapter da = new MySqlDataAdapter((MySqlCommand)command);
229                                 command.CommandText = sqlText.Text;
230                                 command.Connection.Open();
231                                 DataTable dt = new DataTable();
232                                 da.Fill(dt);
233                                 dataGrid.DataSource = dt;
234                                 command.Connection.Close();
235                                 dataGrid.Expand(-1);
236                         }
237                         catch (Exception ex) 
238                         {
239                                 MessageBox.Show(ex.Message);
240                         }
241                 }
242
243         }
244 }