Imports MicroFour.StrataFrame.Data

Public Class OurMain

#Region " Declare Privates "

    Private WithEvents _MDIClient As New System.Windows.Forms.MdiClient()

#End Region

#Region " Database Connection Event "

    ''' <summary>
    ''' Show the connection string information
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ToolStripMenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem8.Click
        
		'-- Show the available connection strings
        If ConnectionManager.ShowAvailableConnectionStrings() Then

            '-- Set the connections
            ConnectionManager.SetConnections()

            '-- TODO: close all child forms to force them to use the new connection string


        End If
        
    End Sub

#End Region

#Region " Handled Events "

    Private Sub tsi_Customers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsi_Customers.Click
        ShowForm(GetType(BrowseSample))
    End Sub

    Private Sub tsiCustomControls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsiCustomControls.Click
        ShowForm(GetType(Form2), False)
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        ShowForm(GetType(ExplorerForm1))
    End Sub

#End Region

#Region " Common Methods "

    ''' <summary>
    ''' Show a form of the passed type
    ''' </summary>
    ''' <param name="ItemType"></param>
    ''' <remarks></remarks>
    Private Sub ShowForm(ByVal ItemType As System.Type)
        ShowForm(ItemType, True)
    End Sub

    ''' <summary>
    ''' Show a form of the passed type
    ''' </summary>
    ''' <param name="ItemType"></param>
    ''' <remarks></remarks>
    Private Sub ShowForm(ByVal ItemType As System.Type, ByVal AllowDuplicate As Boolean)
        '-- Establish Locals
        Dim loForm As System.Windows.Forms.Form
        Dim llAllow As Boolean = True

        '-- Determine if a form check is required
        If Not AllowDuplicate Then
            For Each loForm In Me.MdiChildren
                If loForm.GetType() Is ItemType Then
                    '-- Show the form
                    loForm.Focus()

                    '-- Prevent creation and exit
                    llAllow = False
                    Exit For
                End If
            Next
        End If

        If llAllow Then
            '-- Creates the form instance
            loForm = CType(Activator.CreateInstance(ItemType), System.Windows.Forms.Form)

            '-- Associate the form with the MDI
            loForm.MdiParent = Me

            '-- Show the form
            loForm.Show()
        End If
    End Sub

#End Region

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        '-- Create a more customizable MDI client
        _MDIClient.BackColor = Drawing.Color.White
        Me.Controls.Add(_MDIClient)
    End Sub

    Private Sub _MDIClient_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles _MDIClient.Paint
        e.Graphics.DrawString("StrataFrame", Me.Font, Drawing.Brushes.Red, 100, 100)
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        Me.ShowForm(GetType(WizardForm1))
    End Sub
End Class