Click here to Skip to main content
15,887,946 members
Articles / Programming Languages / Visual Basic

Open Door - Reporting, Charts, Enquiry Drill-Downs

Rate me:
Please Sign up or sign in to vote.
4.37/5 (11 votes)
2 Feb 2009CPOL6 min read 39.3K   2K   59  
A utility for generating user editable reports, charts, documents, enquiries
Imports System.Reflection
Imports System.Runtime.Serialization.Formatters.soap
Public Class OpendoorMenu
    Private repCaller As odReportCaller.modHost
    Private cSettings As ConnectionSettings
    Private hdb As nbfDB.HDBC
    Private Sub FileNewMenuItem(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not chkConnect() Then Exit Sub
        repCaller.EditReport()
    End Sub
    Private Sub FileOpenMenuItem(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not chkConnect() Then Exit Sub
        repCaller.OpenReport()
    End Sub
    Private Sub FileRunMenuItem(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not chkConnect() Then Exit Sub
        repCaller.RunReport()
    End Sub
    Private Sub FilePrintMenuItem(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not chkConnect() Then Exit Sub
        repCaller.PrintReport()
    End Sub
    Private Sub FileDeleteMenuItem(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not chkConnect() Then Exit Sub
        repCaller.DeleteReport()
    End Sub
    Private Sub FileSetConnect(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not setConnect() Then Exit Sub
    End Sub
    Sub ExitApp(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub
    Private Function chkConnect() As Boolean
        Try
            If repCaller Is Nothing Then
                If cSettings Is Nothing Then
                    Dim sFile As String = System.Windows.Forms.Application.StartupPath & "\ConnectionSettings.cfg"
                    If Not System.IO.File.Exists(sFile) Then
                        Dim cs As New ConnectSettings
                        cs.ShowDialog()
                        If cs.Abandoned Then
                            MsgBox("Operation cancelled")
                            Return False
                        End If
                        cSettings = New ConnectionSettings
                        cSettings.ODBCSource = cs.txtODBC.Text
                        cSettings.UserName = cs.txtUserName.Text
                        cSettings.Password = cs.txtPassword.Text
                        cSettings.Database = cs.txtDatabase.Text
                        If System.IO.File.Exists(sFile) Then
                            System.IO.File.Delete(sFile)
                        End If
                        Dim fs As System.IO.Stream = System.IO.File.Create(sFile)
                        Dim serializer As New SoapFormatter
                        serializer.Serialize(fs, cSettings)
                        fs.Close()
                    Else
                        Dim fs As System.IO.Stream = System.IO.File.OpenRead(sFile)
                        Try
                            Dim deserializer As New SoapFormatter
                            cSettings = CType(deserializer.Deserialize(fs), ConnectionSettings)
                        Catch ex2 As Exception
                            MsgBox(ex2.Message)
                            Return False
                        Finally
                            fs.Close()
                        End Try
                    End If
                End If
                If Not hdb Is Nothing Then
                    hdb.Dispose()
                    hdb = Nothing
                End If
                hdb = New nbfDB.HDBC
                hdb.logon(cSettings.ODBCSource, cSettings.UserName, cSettings.Password)
                If hdb.handle <= 0 Then
                    hdb.Dispose()
                    hdb = Nothing
                    MsgBox("Database Logon Failed")
                    Return False
                End If
                If Not String.IsNullOrEmpty(cSettings.Database) Then
                    hdb.execute("use " & cSettings.Database)
                End If
                repCaller = New odReportCaller.modHost(hdb, Me)
            End If
            Return True
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
    End Function
    Private Function setConnect() As Boolean
        Try
            Dim sFile As String = System.Windows.Forms.Application.StartupPath & "\ConnectionSettings.cfg"
            Dim cs As New ConnectSettings
            If Not cSettings Is Nothing Then
                cs.txtODBC.Text = cSettings.ODBCSource
                cs.txtUserName.Text = cSettings.UserName
                cs.txtPassword.Text = cSettings.Password
                cs.txtDatabase.Text = cSettings.Database
            End If
            cs.ShowDialog()
            If cs.Abandoned Then
                MsgBox("Operation cancelled")
                Return False
            End If
            cSettings = Nothing
            cSettings = New ConnectionSettings
            cSettings.ODBCSource = cs.txtODBC.Text
            cSettings.UserName = cs.txtUserName.Text
            cSettings.Password = cs.txtPassword.Text
            cSettings.Database = cs.txtDatabase.Text
            If System.IO.File.Exists(sFile) Then
                System.IO.File.Delete(sFile)
            End If
            Dim fs As System.IO.Stream = System.IO.File.Create(sFile)
            Dim serializer As New SoapFormatter
            serializer.Serialize(fs, cSettings)
            fs.Close()
            If Not hdb Is Nothing Then
                hdb.Dispose()
                hdb = Nothing
            End If
            hdb = New nbfDB.HDBC
            hdb.logon(cSettings.ODBCSource, cSettings.UserName, cSettings.Password)
            If hdb.handle <= 0 Then
                hdb.Dispose()
                hdb = Nothing
                MsgBox("Database Logon Failed")
                Return False
            End If
            If Not String.IsNullOrEmpty(cSettings.Database) Then
                hdb.execute("use " & cSettings.Database)
            End If
            repCaller = Nothing
            repCaller = New odReportCaller.modHost(hdb, Me)
            Return True
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
    End Function
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not chkConnect() Then Exit Sub
        repCaller.EditReport()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Not chkConnect() Then Exit Sub
        repCaller.OpenReport()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Not chkConnect() Then Exit Sub
        repCaller.RunReport()
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Not chkConnect() Then Exit Sub
        repCaller.DeleteReport()
    End Sub
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Not setConnect() Then Exit Sub
    End Sub
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.Close()
    End Sub
    Private Sub OpendoorMenu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.HelpProvider1.HelpNamespace = "OpenDoor.chm"
        Me.HelpProvider1.SetShowHelp(Me, True)
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions