Imports System.Data.OleDb
Imports System.IO

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class MainFrm
    Dim cmd As System.Data.SqlClient.SqlCommand
    Dim Dst = New DataSet
    Dim con As New OleDbConnection

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try

            OleCn.Close()
            Me.Dispose()

        Catch ex As Exception
        End Try
    End Sub

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        e.SuppressKeyPress = e.Control
        If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{tab}")
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        If (PrintmakerGridView.Rows.Count > 0) Then
            PrintmakerGridView.Rows(0).Selected = True
        End If


        Try
            With OleCn
                If .State <> ConnectionState.Open Then
                    .ConnectionString = StrConnection()
                    .Open()
                    With OleDa

                        .SelectCommand = New OleDbCommand()
                        .SelectCommand.CommandText = "SELECT * FROM Table1 order by SerialNo"
                        .SelectCommand.Connection = OleCn

                        Dim Ole As New OleDbCommandBuilder(OleDa) 'For Delete... 

                        DtaSet.Clear()
                        .Fill(DtaSet, "Table1")
                        Call GridView(Me.PrintmakerGridView)
                        Call Navigation()
                    End With
                End If
            End With
            ' cmdRefresh_Click(sender, e)
        Catch ex As Exception
            MsgBox(ex.Message(), MsgBoxStyle.Critical, "Error...")
        Finally
            OleCn.Close()
        End Try

    End Sub
    Private Sub Navigation()

        Try
            'if navigated to first record....
            If Me.BindingContext(DtaSet, "Table1").Position = 0 Then
                Me.cmdFirst.Enabled = False
                Me.cmdPrevious.Enabled = False
            Else
                Me.cmdFirst.Enabled = True
                Me.cmdPrevious.Enabled = True
            End If

            'if navigated to last record....
            If Me.BindingContext(DtaSet, "Table1").Position = Me.BindingContext(DtaSet, "Table1").Count - 1 Then
                Me.cmdLast.Enabled = False
                Me.cmdNext.Enabled = False
            Else
                Me.cmdLast.Enabled = True
                Me.cmdNext.Enabled = True
            End If
            Me.LblRecord.Text = Me.BindingContext(DtaSet, "Table1").Position + 1 & " of " & Me.BindingContext(DtaSet, "Table1").Count

            Me.PrintmakerGridView.Focus()

        Catch ex As Exception
        End Try

    End Sub
    Private Sub cmdFind_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Click
        Try
            Dim obj As New FrmFilter
            obj.ShowDialog()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub PrintmakerGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles PrintmakerGridView.CellClick
        If PrintmakerGridView.Columns(0).HeaderText = "" Then
            If e.ColumnIndex = 0 Then

                If PrintmakerGridView.SelectedCells(0).Value = False Then
                    PrintmakerGridView.SelectedCells(0).Value = True
                Else
                    PrintmakerGridView.SelectedCells(0).Value = False
                End If

                Try
                    With OleCn
                        If .State <> ConnectionState.Open Then
                            .ConnectionString = StrConnection()
                            .Open()
                        End If
                    End With
                Catch ex As Exception
                    MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try

                If PrintmakerGridView.SelectedCells(0).Value = True Then

                    Dim a As Integer = PrintmakerGridView(1, e.RowIndex).Value.ToString()
                    Dim sqlQRY As String = "Update Table1 set RecSelection = Yes where SerialNo = " & a & " "
                    Dim cmd As New OleDbCommand(sqlQRY)
                    cmd.Connection = OleCn
                    cmd.ExecuteNonQuery()
                    OleCn.Close()
                    Exit Sub

                Else
                    If PrintmakerGridView.SelectedCells(0).Value = False Then
                        Dim a As Integer = PrintmakerGridView(1, e.RowIndex).Value.ToString()
                        Dim sqlQRY2 As String = "Update Table1 set RecSelection = No where SerialNo = " & a & " "
                        Dim cmd2 As New OleDbCommand(sqlQRY2)
                        cmd2.Connection = OleCn
                        cmd2.ExecuteNonQuery()
                        OleCn.Close()
                        Exit Sub
                    End If

                End If
            End If
        End If
    End Sub

    Private Sub PrintmakerGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PrintmakerGridView.SelectionChanged
        Call Navigation()
    End Sub

    Private Sub cmdRefresh_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
        Try

            Me.PrintmakerGridView.DataSource = Nothing
            Me.PrintmakerGridView.Columns.Clear()

            With OleCn
                If .State <> ConnectionState.Open Then
                    .ConnectionString = StrConnection()
                    .Open()
                    With OleDa

                        .SelectCommand = New OleDbCommand()
                        .SelectCommand.CommandText = "SELECT * FROM table1 order by SerialNo"
                        .SelectCommand.Connection = OleCn

                        Dim Ole As New OleDbCommandBuilder(OleDa) 'For Delete... 

                        DtaSet.Clear()
                        .Fill(DtaSet, "Table1")
                        Call GridView(Me.PrintmakerGridView)
                        Call Navigation()
                        Me.PrintmakerGridView.Focus()
                        Me.BindingContext.Item(DtaSet, "Table1").Position = 0
                        MultipleToolStripMenuItemDelete.Text = "Multiple"
                        MultipleToolStripMenuItemPrint.Text = "Multiple"
                        MultipleToolStripMenuItemPrint.Enabled = True
                        MultipleToolStripMenuItemDelete.Enabled = True
                        EditToolStripMenuItem.Enabled = True
                        SelectedToolStripMenuItemDelete.Enabled = True
                        SelectedToolStripMenuItemPrint.Enabled = True
                    End With
                End If
            End With

        Catch ex As Exception
            MsgBox(ex.Message(), MsgBoxStyle.Critical, "Error...")
        Finally
            OleCn.Close()
        End Try
    End Sub

    Private Sub cmdLast_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLast.Click
        Try
            Me.BindingContext(DtaSet, "Table1").Position = Me.BindingContext(DtaSet, "Table1").Count - 1
            Call Navigation()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
        Try
            If Not Me.BindingContext(DtaSet, "Table1").Position = Me.BindingContext(DtaSet, "Table1").Count - 1 Then
                Me.BindingContext.Item(DtaSet, "Table1").Position += 1
                Call Navigation()
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub cmdPrevious_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrevious.Click
        Try
            If Not Me.BindingContext(DtaSet, "Table1").Position = 0 Then
                Me.BindingContext.Item(DtaSet, "Table1").Position -= 1
                Call Navigation()
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub cmdFirst_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFirst.Click
        Try
            Me.BindingContext.Item(DtaSet, "Table1").Position = 0
            Call Navigation()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        Try

            OleCn.Close()
            Me.Close()

        Catch ex As Exception
        End Try
    End Sub
    Private Sub CloseToolStripMenuItem_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        cmdClose.PerformClick()
    End Sub
    Private Sub FindToolStripMenuItem_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindToolStripMenuItem.Click
        cmdFind.PerformClick()
    End Sub
    Private Sub RefreshToolStripMenuItem_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles RefreshToolStripMenuItem.Click
        cmdRefresh.PerformClick()
    End Sub

    Private Sub EditToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.Click
        Dim dr1 As OleDbDataReader
        Dim com1 As New OleDbCommand

        Try
            With OleCn
                If .State <> ConnectionState.Open Then
                    .ConnectionString = StrConnection()
                    .Open()
                End If
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

        Try
            com1.CommandText = "select [SerialNo],[CabinNo],[Dat],[CustomerName],[ID_Proof],[LoginTime],[LogoutTime],[Duration],[Amount],[Particular] from Table1 where SerialNo = " & Me.PrintmakerGridView.SelectedCells(0).Value.ToString() & ""
            com1.Connection = OleCn

            dr1 = com1.ExecuteReader
            If dr1.Read Then
                ' EntryFrm.Show()
                Dim obj As New EditFrm
                obj.WindowState = FormWindowState.Normal
                'obj.CBFormState.Text = "16"
                obj.txtSerialNo.Text = UCase(dr1(0)).ToString()
                obj.CBFormState.SelectedItem = dr1(1).ToString()
                obj.txtDate.Value = UCase(dr1(2)).ToString()
                obj.txtName.Text = UCase(dr1(3)).ToString()
                obj.txtIDProof.Text = UCase(dr1(4)).ToString()
                obj.txtLogin.Text = (dr1(5)).ToString()
                obj.TxtLogout.Text = (dr1(6)).ToString()
                obj.TxtDuration.Text = (dr1(7)).ToString()
                obj.TxtAmount.Text = (dr1(8)).ToString()
                obj.TxtParticular.Text = UCase(dr1(9)).ToString()
                obj.ShowDialog()
            End If
            OleCn.Close()
            dr1.Close()

        Catch ex As Exception
        End Try

    End Sub

    Private Sub SelectedToolStripMenuItemDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SelectedToolStripMenuItemDelete.Click

        Try

            Dim msg As DialogResult = MessageBox.Show("Do you want to delete Record(s)? ", "Response", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            If (msg = vbYes) Then

                Try
                    With OleCn
                        If .State <> ConnectionState.Open Then
                            .ConnectionString = StrConnection()
                            .Open()
                        End If
                    End With
                Catch ex As Exception
                    MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try

                Try
                    Dim sSQL As String = "Delete From Table1 where [SerialNo]=@SerialNo"
                    Dim cmd As OleDbCommand = New OleDbCommand(sSQL, OleCn)


                    'Serial No
                    Dim SerialNo As OleDbParameter = New OleDbParameter("@SerialNo", SqlDbType.Int)
                    SerialNo.Value = PrintmakerGridView.SelectedCells(0).Value.ToString()
                    cmd.Parameters.Add(SerialNo)


                    If cmd.ExecuteNonQuery() Then
                        OleCn.Close()
                        MsgBox("Record Deleted Successfully", MsgBoxStyle.Information, "Record Deleted")
                        Me.cmdRefresh.PerformClick()
                    Else
                        MsgBox("Record Deletion Failed ", MsgBoxStyle.Critical, "Deletion Failed")
                        Return
                    End If

                Catch ex As Exception
                    MessageBox.Show(ex.Message.ToString(), "Deletion Error")
                    Exit Sub
                End Try
            End If

        Catch ex As Exception
        End Try
    End Sub

    Private Sub DeleteOneSNoToAnotherSNoToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DeleteOneSNoToAnotherSNoToolStripMenuItem.Click
        Try
            RecordsSelection1.CBFormState.SelectedItem = "Delete"
            RecordsSelection1.cmdDelete.Visible = True
            RecordsSelection1.cmdPrint.Visible = False
            RecordsSelection1.ShowDialog()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub DeleteOneDateToAnotherDateToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DeleteOneDateToAnotherDateToolStripMenuItem.Click
        Try
            RecordsSelection2.CBFormState.SelectedItem = "Delete"
            RecordsSelection2.cmdDelete.Visible = True
            RecordsSelection2.cmdPrint.Visible = False
            RecordsSelection2.txtFirstDate.Value = Today
            RecordsSelection2.TxtLastDate.Value = Today
            RecordsSelection2.ShowDialog()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub SelectedToolStripMenuItemPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SelectedToolStripMenuItemPrint.Click


        Me.Cursor = Cursors.WaitCursor
        Dim cryRpt As New ReportDocument
        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Dim CrTables As Tables
        Dim CrTable As Table

        Try
            With OleCn
                If .State <> ConnectionState.Open Then
                    .ConnectionString = StrConnection()
                    .Open()
                End If
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try


        Try
            cryRpt.Load(My.Application.Info.DirectoryPath & "\Reports\Report1.rpt")

            With crConnectionInfo
                .ServerName = Application.StartupPath & "\BackUp\Printmaker11.Accdb"
                .DatabaseName = Application.StartupPath & "\BackUp\Printmaker11.Accdb"
                .UserID = ""
                .Password = ""
            End With

            CrTables = cryRpt.Database.Tables
            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next


            Dim QueryString As String
            QueryString = "Select SerialNo,CabinNo,Dat,CustomerName,ID_Proof,LoginTime,LogoutTime,Duration,Amount,Particular from Table1 where SerialNo like @SerialNo "

            Dim Cmd As New OleDbCommand(QueryString, OleCn)
            Cmd.Parameters.Add("@SerialNo", OleDbType.VarChar).Value = PrintmakerGridView.SelectedCells(0).Value.ToString()

            Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter(Cmd)
            Dim ds As DataSet = New DataSet()
            Adapter.Fill(ds, "Table1")

            cryRpt.SetDataSource(ds)
            Reports.CrystalReportViewer1.ReportSource = cryRpt
            Reports.GroupBox1.Visible = False
            Reports.cmdPrint.Visible = False
            Reports.cmdRefresh.Visible = False
            Reports.cmdExit.Visible = False
            Reports.Show()
            OleCn.Close()
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            MsgBox(ex.Message(), MsgBoxStyle.Critical, "Print Report Error...")
        End Try
    End Sub

    Private Sub OneSNoToAnotherSNoToolStripMenuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OneSNoToAnotherSNoToolStripMenuItem1.Click
        Try
            RecordsSelection1.CBFormState.SelectedItem = "Print"
            RecordsSelection1.cmdDelete.Visible = False
            RecordsSelection1.cmdPrint.Visible = True
            RecordsSelection1.ShowDialog()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub OneDateToAnotherDateToolStripMenuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OneDateToAnotherDateToolStripMenuItem1.Click
        Try
            RecordsSelection2.CBFormState.SelectedItem = "Print"
            RecordsSelection2.cmdDelete.Visible = False
            RecordsSelection2.cmdPrint.Visible = True
            RecordsSelection2.txtFirstDate.Value = Today
            RecordsSelection2.TxtLastDate.Value = Today
            RecordsSelection2.ShowDialog()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub MultipleToolStripMenuItemDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MultipleToolStripMenuItemDelete.Click


        If MultipleToolStripMenuItemDelete.Text = "Multiple" Then
            Call RecordSelection()
            Me.PrintmakerGridView.DataSource = Nothing
            Me.PrintmakerGridView.Columns.Clear()

            Try
                With OleCn
                    If .State <> ConnectionState.Open Then
                        .ConnectionString = StrConnection()
                        .Open()
                        With OleDa

                            .SelectCommand = New OleDbCommand()
                            .SelectCommand.CommandText = "SELECT * FROM Table1 order by SerialNo"
                            .SelectCommand.Connection = OleCn

                            Dim Ole As New OleDbCommandBuilder(OleDa) 'For Delete... 

                            DtaSet.Clear()
                            .Fill(DtaSet, "Table1")
                            Call GridView2(Me.PrintmakerGridView)
                            Call Navigation()
                            MultipleToolStripMenuItemDelete.Text = "Delete Selected Records"
                            MultipleToolStripMenuItemPrint.Enabled = False
                            EditToolStripMenuItem.Enabled = False
                            SelectedToolStripMenuItemDelete.Enabled = False
                            SelectedToolStripMenuItemPrint.Enabled = False
                        End With
                    End If
                End With

            Catch ex As Exception
                MsgBox(ex.Message(), MsgBoxStyle.Critical, "Error...")
            Finally
                OleCn.Close()
            End Try
            Exit Sub
        End If

        If MultipleToolStripMenuItemDelete.Text = "Delete Selected Records" Then

            Dim msg As DialogResult = MessageBox.Show("Do you want to delete Record(s)? ", "Response", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            If (msg = vbYes) Then

                Try
                    With OleCn
                        If .State <> ConnectionState.Open Then
                            .ConnectionString = StrConnection()
                            .Open()
                        End If
                    End With
                Catch ex As Exception
                    MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End Try

                Dim dap As OleDbDataAdapter = New OleDbDataAdapter("select * from Table1 where RecSelection = Yes", OleCn)
                Dim ds As DataSet = New DataSet
                dap.Fill(ds, "table1")

                Dim sqlQRY As String
                sqlQRY = "Delete FROM Table1 where RecSelection = Yes"
                Dim cmd As New OleDbCommand(sqlQRY)
                cmd.Connection = OleCn

                Dim temp As Integer = 0
                temp = cmd.ExecuteNonQuery()
                If temp > 0 Then
                    MsgBox("( " & Me.BindingContext(ds, "Table1").Count & " ) Records Deleted Successfully", MsgBoxStyle.Information, "Records Deleted")
                    OleCn.Close()
                    cmdRefresh.PerformClick()

                Else
                    MessageBox.Show("Deletion Faild")
                    OleCn.Close()
                End If

            End If
            Exit Sub
        End If
    End Sub

    Sub RecordSelection()
        Try
            With OleCn
                If .State <> ConnectionState.Open Then
                    .ConnectionString = StrConnection()
                    .Open()
                End If
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try

        Dim sqlQRY2 As String = "Update Table1 set RecSelection = No"
        Dim cmd2 As New OleDbCommand(sqlQRY2)
        cmd2.Connection = OleCn
        cmd2.ExecuteNonQuery()
        OleCn.Close()
    End Sub

    Private Sub AllToolStripMenuItem_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles AllToolStripMenuItem.Click
        Me.Cursor = Cursors.WaitCursor
        Dim cryRpt As New ReportDocument
        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Dim CrTables As Tables
        Dim CrTable As Table

        Try
            With OleCn
                If .State <> ConnectionState.Open Then
                    .ConnectionString = StrConnection()
                    .Open()
                End If
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try


        Try
            cryRpt.Load(My.Application.Info.DirectoryPath & "\Reports\Report1.rpt")

            With crConnectionInfo
                .ServerName = Application.StartupPath & "\BackUp\Printmaker11.Accdb"
                .DatabaseName = Application.StartupPath & "\BackUp\Printmaker11.Accdb"
                .UserID = ""
                .Password = ""
            End With

            CrTables = cryRpt.Database.Tables
            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next


            Dim QueryString As String
            QueryString = "Select SerialNo,CabinNo,Dat,CustomerName,ID_Proof,LoginTime,LogoutTime,Duration,Amount,Particular from Table1 order by SerialNo"

            Dim Cmd As New OleDbCommand(QueryString, OleCn)
            Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter(Cmd)
            Dim ds As DataSet = New DataSet()
            Adapter.Fill(ds, "Table1")

            cryRpt.SetDataSource(ds)
            Reports.CrystalReportViewer1.ReportSource = cryRpt
            Reports.Show()
            OleCn.Close()
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            MsgBox(ex.Message(), MsgBoxStyle.Critical, "Print Report Error...")
        End Try
    End Sub

    Private Sub MultipleToolStripMenuItemPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MultipleToolStripMenuItemPrint.Click

        If MultipleToolStripMenuItemPrint.Text = "Multiple" Then
            Call RecordSelection()
            Me.PrintmakerGridView.DataSource = Nothing
            Me.PrintmakerGridView.Columns.Clear()

            Try
                With OleCn
                    If .State <> ConnectionState.Open Then
                        .ConnectionString = StrConnection()
                        .Open()
                        With OleDa

                            .SelectCommand = New OleDbCommand()
                            .SelectCommand.CommandText = "SELECT * FROM Table1 order by SerialNo"
                            .SelectCommand.Connection = OleCn

                            Dim Ole As New OleDbCommandBuilder(OleDa) 'For Delete... 
                            DtaSet.Clear()
                            .Fill(DtaSet, "Table1")
                            Call GridView2(Me.PrintmakerGridView)
                            Call Navigation()
                            MultipleToolStripMenuItemPrint.Text = "Print Selected Records"
                            MultipleToolStripMenuItemDelete.Enabled = False
                            EditToolStripMenuItem.Enabled = False
                            SelectedToolStripMenuItemDelete.Enabled = False
                            SelectedToolStripMenuItemPrint.Enabled = False
                        End With
                    End If
                End With

            Catch ex As Exception
                MsgBox(ex.Message(), MsgBoxStyle.Critical, "Error...")
            Finally
                OleCn.Close()
            End Try
            Exit Sub
        End If

        If MultipleToolStripMenuItemPrint.Text = "Print Selected Records" Then

            Me.Cursor = Cursors.WaitCursor
            Dim cryRpt As New ReportDocument
            Dim crtableLogoninfos As New TableLogOnInfos
            Dim crtableLogoninfo As New TableLogOnInfo
            Dim crConnectionInfo As New ConnectionInfo
            Dim CrTables As Tables
            Dim CrTable As Table

            Try
                With OleCn
                    If .State <> ConnectionState.Open Then
                        .ConnectionString = StrConnection()
                        .Open()
                    End If
                End With
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End Try


            Try
                cryRpt.Load(My.Application.Info.DirectoryPath & "\Reports\Report1.rpt")

                With crConnectionInfo
                    .ServerName = Application.StartupPath & "\BackUp\Printmaker11.Accdb"
                    .DatabaseName = Application.StartupPath & "\BackUp\Printmaker11.Accdb"
                    .UserID = ""
                    .Password = ""
                End With

                CrTables = cryRpt.Database.Tables
                For Each CrTable In CrTables
                    crtableLogoninfo = CrTable.LogOnInfo
                    crtableLogoninfo.ConnectionInfo = crConnectionInfo
                    CrTable.ApplyLogOnInfo(crtableLogoninfo)
                Next


                Dim QueryString As String
                QueryString = "Select SerialNo,CabinNo,Dat,CustomerName,ID_Proof,LoginTime,LogoutTime,Duration,Amount,Particular from Table1 where RecSelection = Yes order by SerialNo"

                Dim Cmd As New OleDbCommand(QueryString, OleCn)
                Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter(Cmd)
                Dim ds As DataSet = New DataSet()
                Adapter.Fill(ds, "Table1")
                cryRpt.SetDataSource(ds)

                Reports.CrystalReportViewer1.ReportSource = cryRpt
                Reports.GroupBox1.Visible = False
                Reports.cmdPrint.Visible = False
                Reports.cmdRefresh.Visible = False
                Reports.cmdExit.Visible = False
                Reports.Show()
                OleCn.Close()
                Me.Cursor = Cursors.Default
            Catch ex As Exception
                Me.Cursor = Cursors.Default
                MsgBox(ex.Message(), MsgBoxStyle.Critical, "Print Report Error...")
            End Try
            Exit Sub
        End If

    End Sub
End Class
