Find all our projects in development below.
All source code is GNU General Public License (GPL)
Browsing frmDBSpy.vb (30.84 KB)
Option Explicit On
Imports System.Data
Imports System.Text.ASCIIEncoding
Imports System.Text.RegularExpressions
Imports System.Threading
Public Class frmDBSpy
Private _dbConn As Object = Nothing
Private _lastErrorException As Exception = Nothing
Private _workerQuery As frmDBSpyQuery = Nothing
Private _workerThread As Thread = Nothing
Private Const lvCol_Name As Integer = 0
Private Const lvCol_Type As Integer = 1
Private Const CONNSTR_ODBC_IFX_MATCH_REGEX As String = ".*DRIVER\=.*INFORMIX.*\;.*"
Private Const CONNSTR_ODBC_IFX_USER_REGEX As String = ".*UID\=([^\;]*)\;.*|.*UID\=([^\;]*)"
Private Const CONNSTR_ODBC_IFX_PASS_REGEX As String = ".*PWD\=([^\;]*)\;.*|.*PWD\=([^\;]*)"
Private Const CONNSTR_ODBC_IFX_DB_REGEX As String = ".*DATABASE\=([^\;]*)\;.*|.*DATABASE\=([^\;]*)"
Private Const CONNSTR_ODBC_IFX_HOST_REGEX As String = ".*HOST\=([^\;]*)\;.*|.*HOST\=([^\;]*)"
Private Const CONNSTR_OLEDB_IFX_MATCH_REGEX As String = ".*Provider\=Ifxoledbc\;.*"
Private Const CONNSTR_OLEDB_IFX_USER_REGEX As String = ".*User ID\=([^\;]*)\;.*|.*User ID\=([^\;]*)"
Private Const CONNSTR_OLEDB_IFX_PASS_REGEX As String = ".*Password\=([^\;]*)\;.*|.*Password\=([^\;]*)"
Private Const CONNSTR_OLEDB_IFX_DB_REGEX As String = ".*Data Source\=([^\@]*)\@.*"
Private Const CONNSTR_OLEDB_IFX_HOST_REGEX As String = ".*Data Source\=.*\@([^\;]*)\;.*|.*Data Source\=.*\@([^\;]*)"
Private Const CONNSTR_MSSQL_MATCH_REGEX As String = ".*Data\sSource\=.*"
Private Const CONNSTR_MSSQL_USER_REGEX As String = ".*User\sId\=([^\;]*)\;.*|.*User\sId\=([^\;]*)"
Private Const CONNSTR_MSSQL_PASS_REGEX As String = ".*Password\=([^\;]*)\;.*|.*Password\=([^\;]*)"
Private Const CONNSTR_MSSQL_DB_REGEX As String = ".*Initial\sCatalog\=([^\;]*)\;.*|.*Initial\sCatalog\=([^\;]*)"
Private Const CONNSTR_MSSQL_HOST_REGEX As String = ".*Data\sSource\=([^\;]*)\;.*|.*Data\sSource\=([^\;]*)"
Private Delegate Function DB_EnumQueryColumns_Func(ByVal inQueryResult As Object) As ArrayList
Private Delegate Sub DB_Query_Result_Sub()
Private Delegate Function DB_Grid_AddRow_Func() As Integer
Private Delegate Sub DB_Update_Grid_Sub(ByVal rowId As Integer, ByVal colName As String, ByVal value As String)
Private Delegate Sub DB_Update_Status_Sub(ByVal statusText As String)
Private Enum ConnStates
ConnInactive
ConnDisconnected
ConnConnected
End Enum
Private Function CleanString(ByVal input As Object) As String
If input Is Nothing Then
Return ""
ElseIf TypeOf input Is DBNull Then
Return ""
Else
Return CType(input, String)
End If
End Function
Private Function DB_Init() As Boolean
_showWaitCursor(True)
txtConnString.SelectionStart = 0
txtConnString.Enabled = False
btnCommand.Enabled = False
If Not (_dbConn Is Nothing) Then
_dbConn.Dispose()
_dbConn = Nothing
End If
_setConnState(ConnStates.ConnInactive)
tvTables.Nodes.Clear()
lvColumns.Items.Clear()
grpTables.Text = "Tables"
grpTables.Enabled = False
grpColumns.Text = "Columns"
grpColumns.Enabled = False
tabMain.SelectedTab.Tag.TabText = "Query #" + CInt(tabMain.SelectedTab.Tag.Tag).ToString("#00")
tabMain.SelectedTab.Tag.txtQuery.Text = ""
tabMain.SelectedTab.Tag.dataQuery.Columns.Clear()
tabMain.SelectedTab.Tag.dataQuery.Rows.Clear()
tabMain.Enabled = False
If radTypeIfx.Checked Then
If radDriverODBC.Checked Then
_dbConn = New clsDbConn_ODBC(txtConnString.Text.Trim)
ElseIf radDriverOleDb.Checked Then
_dbConn = New clsDbConn_OleDb(txtConnString.Text.Trim)
End If
ElseIf radTypeMSSQL.Checked Then
_dbConn = New clsSqlClient(txtConnString.Text.Trim)
Else
_showWaitCursor(False)
txtConnString.Enabled = True
btnCommand.Enabled = True
_lastErrorException = New Exception("Connection string not supported.")
Return False
End If
lblInfo.Text = "Connecting to db server..."
Application.DoEvents()
If Not _dbConn.ConnectDb() Then _
_lastErrorException = _dbConn.LastErrorException
If _dbConn.IsConnected Then
_setConnState(ConnStates.ConnConnected)
lblInfo.Text = "Connected; loading Tables..."
Application.DoEvents()
' enumerate all tables
DB_EnumTables()
tvTables.Sort()
' select default node
If tvTables.Nodes.Count > 0 Then
tvTables.SelectedNode = tvTables.TopNode
lblInfo.Text = "Connected; loading Columns..."
Application.DoEvents()
' enumerate all columns
DB_EnumColumns()
End If
btnCommand.Text = "&Disconnect"
btnCommand.Tag = True
Me.CancelButton = btnCommand
btnCommand.Enabled = True
grpTables.Enabled = True
grpColumns.Enabled = True
tabMain.Enabled = True
_showWaitCursor(False)
frmDBSpy_Resize(Nothing, Nothing)
Dim nodeCount As Integer = tvTables.GetNodeCount(False)
grpTables.Text = "Tables (" + nodeCount.ToString + ")"
grpColumns.Text = "Columns (" + lvColumns.Items.Count.ToString + ")"
lblInfo.Text = "Ready; " + nodeCount.ToString("###,##0") + " Tables(s) found"
tvTables.Focus()
Return True
Else
_setConnState(ConnStates.ConnDisconnected)
txtConnString.Enabled = True
btnCommand.Enabled = True
_showWaitCursor(False)
lblInfo.Text = "Ready"
Return False
End If
End Function
Private Sub DB_EnumTables()
If radTypeIfx.Checked Then
Dim dataTables As DataTable = _dbConn.Conn.GetSchema("Tables")
Dim filteredRows() As DataRow = dataTables.Select("TABLE_TYPE='TABLE'")
For Each thisRow As DataRow In filteredRows
tvTables.Nodes.Add(thisRow("TABLE_NAME"))
Next
ElseIf radTypeMSSQL.Checked Then
Using newQuery As Object = _dbConn.RunQuery("select * from sysobjects where type = 'U'")
If Not (newQuery Is Nothing) Then
Do While newQuery.Read()
tvTables.Nodes.Add(newQuery.GetValue(0))
Loop
End If
End Using
End If
End Sub
Private Sub DB_EnumColumns()
Dim strTable As String = tvTables.SelectedNode.Text
Try
Dim dataColumns As DataTable = _dbConn.Conn.GetSchema("Columns")
Dim filteredRows() As DataRow = dataColumns.Select("TABLE_NAME='" + strTable + "'", "ORDINAL_POSITION")
For Each thisRow As DataRow In filteredRows
With lvColumns.Items.Add(thisRow("COLUMN_NAME"))
Try
If radTypeIfx.Checked Then
.SubItems.Add(thisRow("TYPE_NAME") + IIf(thisRow("COLUMN_SIZE").ToString <> "", "(" + thisRow("COLUMN_SIZE").ToString + ")", ""))
ElseIf radTypeMSSQL.Checked Then
.SubItems.Add(thisRow("DATA_TYPE") + IIf(thisRow("CHARACTER_MAXIMUM_LENGTH").ToString <> "", "(" + thisRow("CHARACTER_MAXIMUM_LENGTH").ToString + ")", ""))
End If
Catch
.SubItems.Add("")
End Try
End With
Next
Catch
End Try
End Sub
Private Function DB_EnumQueryColumns(ByVal inQueryResult As Object) As ArrayList
If Me.InvokeRequired Then
Return Me.Invoke(New DB_EnumQueryColumns_Func(AddressOf DB_EnumQueryColumns), inQueryResult)
Else
Dim ret As New ArrayList
Try
For i As Integer = 0 To inQueryResult.FieldCount - 1
Dim thisCol As String = inQueryResult.GetName(i)
Dim rowId As Integer = _workerQuery.dataQuery.Columns.Add(thisCol.ToLower, thisCol)
If rowId >= 0 Then _
_workerQuery.dataQuery.Columns(rowId).ToolTipText = thisCol
ret.Add(thisCol)
Next
Catch
End Try
Return ret
End If
End Function
Friend Sub DB_Query(ByVal inQuery As String)
_dbConn.LastErrorException = Nothing
_workerQuery = tabMain.SelectedTab.Tag
_workerThread = New Thread(AddressOf DB_Query_Threaded)
_workerThread.IsBackground = True
_workerThread.Start(inQuery)
End Sub
Private Sub DB_Query_Threaded(ByVal inQuery As Object)
Const updateCount As Integer = 100
Dim rowCount As Integer = 0
Dim updateCounter As Integer = updateCount
Try
Dim thisQuery As String = CType(inQuery, String)
If thisQuery.ToLower.Trim.StartsWith("select ") Then
Using newQuery As Object = _dbConn.RunQuery(thisQuery)
If Not (newQuery Is Nothing) Then
Dim colList As ArrayList = Nothing
With New DB_EnumQueryColumns_Func(AddressOf DB_EnumQueryColumns)
colList = .Invoke(newQuery.thisResult)
End With
Do While newQuery.Read()
Dim rowId As Integer = -1
With New DB_Grid_AddRow_Func(AddressOf DB_Grid_AddRow)
rowId = .Invoke()
End With
If rowId >= 0 Then
For Each thisCol As String In colList
Dim value As Object = newQuery.GetValue(thisCol)
If Not (value Is Nothing) Then
If TypeOf value Is Byte() Then
value = ASCII.GetString(value)
Else
value = CleanString(value)
End If
With New DB_Update_Grid_Sub(AddressOf DB_Update_Grid)
.Invoke(rowId, thisCol.ToLower, value.ToString)
End With
End If
Next
End If
rowCount += 1
updateCounter -= 1
If updateCounter = 0 Then
With New DB_Update_Status_Sub(AddressOf DB_Update_Status)
.Invoke("Executing query (" + rowCount.ToString("###,##0") + ")...")
End With
updateCounter = updateCount
End If
Loop
End If
End Using
If Not (_dbConn.LastErrorException Is Nothing) Then _
Throw CType(_dbConn.LastErrorException, Exception)
Else
Dim res As Integer = _dbConn.ExecNonQuery(thisQuery)
If _dbConn.LastErrorException Is Nothing Then
MessageBox.Show(IIf(res > 0, res.ToString + " row(s)", "No rows") + _
" affected by the last query.", Application.ProductName, _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Throw CType(_dbConn.LastErrorException, Exception)
End If
End If
Catch ex As Exception
If Not (TypeOf ex Is ThreadAbortException) Then _
_lastErrorException = ex
End Try
With New DB_Query_Result_Sub(AddressOf DB_Query_Result)
.Invoke()
End With
End Sub
Private Sub DB_Query_Result()
If Me.InvokeRequired Then
Me.Invoke(New DB_Query_Result_Sub(AddressOf DB_Query_Result))
Else
_workerThread = Nothing
btnCommand.Enabled = True
tvTables.Enabled = True
lvColumns.Enabled = True
_showWaitCursor(False)
lblInfo.Spring = True
lblCancel.Visible = False
If Not (_lastErrorException Is Nothing) Then
lblInfo.Text = "Ready"
_workerQuery.TabText = "Query #" + CInt(_workerQuery.Tag).ToString("#00")
MessageBox.Show("Error: " + _lastErrorException.Message, _
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
_lastErrorException = Nothing
Else
If Not _workerQuery.txtQuery.Text.ToLower.Trim.StartsWith("select ") Then
lblInfo.Text = "Ready"
_workerQuery.TabText = "Query #" + CInt(_workerQuery.Tag).ToString("#00")
Else
Dim rowCount As Integer = _workerQuery.dataQuery.RowCount
_workerQuery.TabText = "Query #" + CInt(_workerQuery.Tag).ToString("#00") + " (" + rowCount.ToString("###,##0") + ")"
lblInfo.Text = "Ready; " + rowCount.ToString("###,##0") + " record(s) retrieved"
End If
End If
_workerQuery = Nothing
End If
End Sub
Private Function DB_Grid_AddRow() As Integer
If Me.InvokeRequired Then
Return Me.Invoke(New DB_Grid_AddRow_Func(AddressOf DB_Grid_AddRow))
Else
Return _workerQuery.dataQuery.Rows.Add()
End If
End Function
Private Sub DB_Update_Grid(ByVal rowId As Integer, ByVal propName As String, ByVal value As String)
If Me.InvokeRequired Then
Me.Invoke(New DB_Update_Grid_Sub(AddressOf DB_Update_Grid), rowId, propName, value)
Else
_workerQuery.dataQuery.Rows(rowId).Cells(propName).Value = value
End If
End Sub
Private Sub DB_Update_Status(ByVal statusText As String)
If Me.InvokeRequired Then
Me.Invoke(New DB_Update_Status_Sub(AddressOf DB_Update_Status), statusText)
Else
lblInfo.Text = statusText
End If
End Sub
Friend Function _isConnected() As Boolean
Return Not (_dbConn Is Nothing) AndAlso _
_dbConn.IsConnected
End Function
Friend Function _isBusy() As Boolean
Return Not (_workerThread Is Nothing)
End Function
Friend Sub _showWaitCursor(ByVal bShow As Boolean)
' show/hide the hourglass
If bShow Then
Me.Cursor = Cursors.WaitCursor
Me.UseWaitCursor = True
Else
Try
tabMain.SelectedTab.Tag.dataQuery.Cursor = Cursors.Default
Catch
End Try
Me.UseWaitCursor = False
Me.Cursor = Cursors.Arrow
End If
End Sub
Private Sub _setConnState(ByVal connState As ConnStates)
If connState = ConnStates.ConnInactive Then
lblConn.Image = GetResourceImage("ico_silver")
lblConn.ToolTipText = "No connection"
ElseIf connState = ConnStates.ConnDisconnected Then
lblConn.Image = GetResourceImage("ico_red")
lblConn.ToolTipText = "Disconnected"
ElseIf connState = ConnStates.ConnConnected Then
lblConn.Image = GetResourceImage("ico_green")
lblConn.ToolTipText = "Connected"
End If
End Sub
Private Sub frmDBSpy_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
splitMain.BackColor = Color.FromKnownColor(KnownColor.ControlDark)
splitHorz.BackColor = Color.FromKnownColor(KnownColor.ControlDark)
splitVert.BackColor = Color.FromKnownColor(KnownColor.ControlDark)
End Sub
Private Sub frmDBSpy_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
splitMain.BackColor = Color.FromKnownColor(KnownColor.InactiveBorder)
splitHorz.BackColor = Color.FromKnownColor(KnownColor.InactiveBorder)
splitVert.BackColor = Color.FromKnownColor(KnownColor.InactiveBorder)
End Sub
Private Sub frmDBSpy_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If Not btnCommand.Enabled Then
e.Cancel = True
Exit Sub
End If
If Not (_workerThread Is Nothing) Then
_workerThread.Abort()
_workerThread = Nothing
End If
If Not (_dbConn Is Nothing) Then
_dbConn.Dispose()
_dbConn = Nothing
End If
End Sub
Private Sub frmDBSpy_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
btnCommand.Tag = False
Dim newQuery As New frmDBSpyQuery(Me)
With newQuery
.Location = New Point(0, 0)
.Size = tabQuery.Size
.TopLevel = False
.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or _
AnchorStyles.Left Or AnchorStyles.Right
' add the object to the container
tabQuery.Controls.Add(newQuery)
' set the parent of the object as the container
With New clsWindowObject(newQuery.Handle)
.Parent = New clsWindowObject(tabQuery.Handle)
End With
.Show()
End With
newQuery.Tag = 0
tabQuery.Tag = newQuery
End Sub
Private Sub frmDBSpy_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
lvColumns.Columns(lvCol_Name).Width = Math.Round(Math.Abs(lvColumns.Width - _
lvColumns.Columns(lvCol_Type).Width - SystemInformation.VerticalScrollBarWidth - 6) / 2) * 2
End Sub
Private Sub splitMain_SplitterMoved(ByVal sender As Object, ByVal e As System.Windows.Forms.SplitterEventArgs) Handles splitMain.SplitterMoved
Me.Refresh()
End Sub
Private Sub splitHorz_SplitterMoved(ByVal sender As Object, ByVal e As System.Windows.Forms.SplitterEventArgs) Handles splitHorz.SplitterMoved
Me.Refresh()
End Sub
Private Sub splitVert_SplitterMoved(ByVal sender As System.Object, ByVal e As System.Windows.Forms.SplitterEventArgs) Handles splitVert.SplitterMoved
Me.Refresh()
If Not (btnCommand.Tag Is Nothing) Then _
frmDBSpy_Resize(Nothing, Nothing)
End Sub
Private Sub btnCommand_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommand.Click
If Not btnCommand.Tag Then
If txtConnString.Text.Trim = "" Then
MessageBox.Show("Enter the connection string.", _
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtConnString.SelectAll()
txtConnString.Focus()
ElseIf Not DB_Init() Then
Dim errMsg As String = "Error connecting to DB server."
If Not (_lastErrorException) Is Nothing Then
errMsg += vbCrLf + vbCrLf + "Error: " + _lastErrorException.Message
_lastErrorException = Nothing
End If
If Not errMsg.Contains("not supported.") Then
MessageBox.Show(errMsg, Application.ProductName, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show(errMsg.Substring(errMsg.IndexOf("Error:") + 6), _
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
txtConnString.Focus()
txtConnString.SelectAll()
End If
Else
If lblCancel.Visible Then lblCancel.PerformClick()
If Not (_dbConn Is Nothing) Then
_dbConn.Dispose()
_dbConn = Nothing
End If
_setConnState(ConnStates.ConnInactive)
tvTables.Nodes.Clear()
lvColumns.Items.Clear()
txtConnString.Enabled = True
grpTables.Enabled = False
grpColumns.Enabled = False
tabMain.Enabled = False
btnCommand.Text = "&Connect"
btnCommand.Tag = False
lblInfo.Text = "Ready"
txtConnString.Focus()
txtConnString.SelectAll()
Me.CancelButton = Nothing
End If
End Sub
Private Sub lblCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblCancel.Click
If Not (_workerThread Is Nothing) Then _
_workerThread.Abort()
DB_Query_Result()
End Sub
Private Sub tabMain_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tabMain.MouseUp
If e.Button = Windows.Forms.MouseButtons.Middle AndAlso _
tabMain.TabPages.Count > 1 Then
For tabIndex As Integer = 0 To tabMain.TabPages.Count - 2
If tabMain.GetTabRect(tabIndex).Contains(tabMain.PointToClient(Control.MousePosition)) Then
If _workerQuery Is Nothing Or _
(Not (_workerQuery Is Nothing) AndAlso _
Not _workerQuery.Equals(tabMain.TabPages(tabIndex).Tag)) Then
Dim thisIndex As Integer = tabMain.SelectedIndex
tabMain.TabPages(tabIndex).Tag.Close()
tabMain.TabPages.RemoveAt(tabIndex)
If thisIndex > 0 Then tabMain.SelectedIndex = thisIndex - 1
Else
MessageBox.Show("Unable to close query window. Please cancel your previous query.", _
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Exit For
End If
Next
End If
End Sub
Private Sub tabMain_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabMain.SelectedIndexChanged
If tabMain.SelectedIndex = tabMain.TabPages.Count - 1 Then
Static tabCount As Integer = 0
tabCount += 1
Dim newTab As New TabPage("Query #" + tabCount.ToString("#00"))
Dim newQuery As New frmDBSpyQuery(Me)
With newQuery
.Location = New Point(0, 0)
.Size = newTab.Size
.TopLevel = False
.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or _
AnchorStyles.Left Or AnchorStyles.Right
' add the object to the container
newTab.Controls.Add(newQuery)
' set the parent of the object as the container
With New clsWindowObject(newQuery.Handle)
.Parent = New clsWindowObject(newTab.Handle)
End With
.Show()
End With
newTab.Tag = newQuery
tabMain.TabPages.Insert(tabMain.TabPages.Count - 1, newTab)
tabMain.SelectedTab = newTab
newQuery.Tag = tabCount
newQuery.txtQuery.Focus()
End If
End Sub
Private Sub txtConnString_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtConnString.GotFocus
Me.AcceptButton = btnCommand
End Sub
Private Sub txtConnString_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtConnString.LostFocus
Me.AcceptButton = Nothing
grpConnection.Text = "DB Connection"
txtServer.Text = ""
txtDBName.Text = ""
txtUsername.Text = ""
txtPassword.Text = ""
radTypeIfx.Checked = False
radTypeMSSQL.Checked = False
radDriverODBC.Checked = False
radDriverOleDb.Checked = False
If Regex.IsMatch(txtConnString.Text.Trim, CONNSTR_ODBC_IFX_MATCH_REGEX, RegexOptions.IgnoreCase) Then
Dim thisMatch As Match = Regex.Match(txtConnString.Text.Trim, CONNSTR_ODBC_IFX_USER_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtUsername.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
thisMatch = Regex.Match(txtConnString.Text.Trim, CONNSTR_ODBC_IFX_PASS_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtPassword.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
thisMatch = Regex.Match(txtConnString.Text.Trim, CONNSTR_ODBC_IFX_DB_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtDBName.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
thisMatch = Regex.Match(txtConnString.Text.Trim, CONNSTR_ODBC_IFX_HOST_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtServer.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
radTypeIfx.Checked = True
radDriverODBC.Checked = True
grpConnection.Text += " (Informix ODBC)"
ElseIf Regex.IsMatch(txtConnString.Text.Trim, CONNSTR_OLEDB_IFX_MATCH_REGEX, RegexOptions.IgnoreCase) Then
Dim thisMatch As Match = Regex.Match(txtConnString.Text.Trim, CONNSTR_OLEDB_IFX_USER_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtUsername.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
thisMatch = Regex.Match(txtConnString.Text.Trim, CONNSTR_OLEDB_IFX_PASS_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtPassword.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
thisMatch = Regex.Match(txtConnString.Text.Trim, CONNSTR_OLEDB_IFX_DB_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtDBName.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
thisMatch = Regex.Match(txtConnString.Text.Trim, CONNSTR_OLEDB_IFX_HOST_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtServer.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
radTypeIfx.Checked = True
radDriverOleDb.Checked = True
grpConnection.Text += " (Informix OleDb)"
ElseIf Regex.IsMatch(txtConnString.Text.Trim, CONNSTR_MSSQL_MATCH_REGEX, RegexOptions.IgnoreCase) Then
Dim thisMatch As Match = Regex.Match(txtConnString.Text.Trim, CONNSTR_MSSQL_USER_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtUsername.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
thisMatch = Regex.Match(txtConnString.Text.Trim, CONNSTR_MSSQL_PASS_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtPassword.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
thisMatch = Regex.Match(txtConnString.Text.Trim, CONNSTR_MSSQL_DB_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtDBName.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
thisMatch = Regex.Match(txtConnString.Text.Trim, CONNSTR_MSSQL_HOST_REGEX, RegexOptions.IgnoreCase)
If thisMatch.Groups.Count > 0 Then _
txtServer.Text = thisMatch.Groups(1).Value + thisMatch.Groups(2).Value
radTypeMSSQL.Checked = True
radDriverODBC.Checked = False
radDriverOleDb.Checked = False
grpConnection.Text += " (MS SQL)"
End If
End Sub
Private Sub tvTables_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvTables.AfterSelect
If btnCommand.Enabled Then
_showWaitCursor(True)
grpColumns.Text = "Columns"
Application.DoEvents()
lvColumns.Items.Clear()
DB_EnumColumns()
grpColumns.Text = "Columns (" + lvColumns.Items.Count.ToString + ")"
_showWaitCursor(False)
End If
End Sub
Private Sub tvTables_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvTables.DoubleClick
If Not (tvTables.SelectedNode Is Nothing) Then
tabMain.SelectedTab.Tag.txtQuery.Text = "select * from " + tvTables.SelectedNode.Text
tabMain.SelectedTab.Tag.btnQuery.PerformClick()
End If
End Sub
Private Sub tvTables_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tvTables.KeyDown
If e.KeyCode = Keys.Enter Then _
tvTables_DoubleClick(sender, Nothing)
End Sub
Private Sub tvTables_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvTables.NodeMouseClick
If (e.Button = Windows.Forms.MouseButtons.Left And _
SystemInformation.MouseButtonsSwapped) Or _
(e.Button = Windows.Forms.MouseButtons.Right And _
Not SystemInformation.MouseButtonsSwapped) Then
tvTables.SelectedNode = e.Node
End If
End Sub
Private Sub lvColumns_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvColumns.DoubleClick
If lvColumns.SelectedItems.Count > 0 Then _
tabMain.SelectedTab.Tag.txtQuery.Text += " " + lvColumns.SelectedItems(0).Text
End Sub
Private Sub lvColumns_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lvColumns.KeyDown
If e.KeyCode = Keys.Enter Then _
lvColumns_DoubleClick(sender, Nothing)
End Sub
End Class