Find all our projects in development below.
All source code is GNU General Public License (GPL)
Browsing frmDBSpyQuery.vb (6.63 KB)
Option Explicit On
Imports System.IO
Public Class frmDBSpyQuery
Private _host As frmDBSpy = Nothing
Public Sub New(ByVal thisHost As frmDBSpy)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
_host = thisHost
End Sub
Public Property TabText() As String
Get
Dim parentTab As TabPage = CType(Me.Parent, TabPage)
Return parentTab.Text
End Get
Set(ByVal value As String)
Dim parentTab As TabPage = CType(Me.Parent, TabPage)
parentTab.Text = value
End Set
End Property
Private Sub btnQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuery.Click
If _host._isConnected() Then
If txtQuery.Text.Trim <> "" Then
If Not _host._isBusy() Then
_host._showWaitCursor(True)
_host.tvTables.Enabled = False
_host.lvColumns.Enabled = False
dataQuery.Columns.Clear()
dataQuery.Rows.Clear()
_host.lblInfo.Text = "Executing query..."
_host.lblCancel.Visible = True
_host.lblInfo.Spring = False
_host.DB_Query(txtQuery.Text)
Else
MessageBox.Show("Only one query allowed at a time. Please cancel your previous query.", _
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Else
MessageBox.Show("Enter the query.", _
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtQuery.SelectAll()
txtQuery.Focus()
End If
Else
_host.lblInfo.Text = "Not connected"
End If
End Sub
Private Sub mnuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCopy.Click
If Not (dataQuery.CurrentRow Is Nothing) AndAlso _
dataQuery.RowCount > 0 Then
Try
Dim copyData As String = ""
For i As Integer = 0 To dataQuery.CurrentRow.Cells.Count - 1
If Not (dataQuery.CurrentRow.Cells(i).Value Is Nothing) Then _
copyData += dataQuery.CurrentRow.Cells(i).Value.ToString
If i < dataQuery.CurrentRow.Cells.Count - 1 Then _
copyData += vbTab
Next
Clipboard.SetText(copyData, TextDataFormat.Text)
Catch
End Try
End If
End Sub
Private Sub mnuExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExport.Click
Try
exportFile.ShowDialog()
If exportFile.FileName <> "" Then
_host._showWaitCursor(True)
Try
Dim fs As New StreamWriter(exportFile.FileName)
Dim headerData As String = ""
For i As Integer = 0 To dataQuery.ColumnCount - 1
headerData += dataQuery.Columns(i).HeaderText + _
IIf(i < dataQuery.ColumnCount - 1, ",", "")
Next
fs.WriteLine(headerData)
For x As Integer = 0 To dataQuery.RowCount - 1
Dim rowData As String = ""
For i As Integer = 0 To dataQuery.Rows(x).Cells.Count - 1
If Not (dataQuery.Rows(x).Cells(i).Value Is Nothing) Then _
rowData += """" + dataQuery.Rows(x).Cells(i).Value.ToString.Replace("""", """""""") + """"
If i < dataQuery.Rows(x).Cells.Count - 1 Then _
rowData += ","
Next
fs.WriteLine(rowData)
Next
fs.Close()
Catch ex As Exception
MessageBox.Show("Error: " + ex.Message, _
Application.ProductName, MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
_host._showWaitCursor(False)
End If
Catch
End Try
End Sub
Private Sub txtQuery_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQuery.KeyPress
If e.KeyChar = vbCr Or e.KeyChar = vbLf Then
e.Handled = True
btnQuery.PerformClick()
End If
End Sub
Private Sub txtQuery_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtQuery.MouseEnter
pnlCmd.Visible = True
End Sub
Private Sub txtQuery_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtQuery.MouseLeave
Dim pnlRect As Rectangle = Me.RectangleToScreen( _
New Rectangle(pnlCmd.Left, pnlCmd.Top, _
pnlCmd.Width, pnlCmd.Height))
If Not pnlRect.Contains(Control.MousePosition) Then _
pnlCmd.Visible = False
End Sub
Private Sub dataQuery_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dataQuery.CellDoubleClick
If e.RowIndex >= 0 And e.ColumnIndex >= 0 Then
Dim cellValue As Object = dataQuery.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
If Not (cellValue Is Nothing) Then
With New clsEditDialog(Me)
.ReadOnly = True
.InputText = cellValue.ToString
.Show("Edit Cell [read-only]")
End With
Else
Beep()
End If
End If
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
With New clsEditDialog(Me)
.CustomButtonImage = btnQuery.Image
.CustomButtonToolTip = "Update and Run Query"
.InputText = txtQuery.Text
.Show("Edit Query")
If Not .Aborted Then txtQuery.Text = .OutputText
If .CustomButtonClicked Then btnQuery.PerformClick()
End With
txtQuery.Focus()
txtQuery.SelectAll()
End Sub
End Class