Public Class frmVotingDetails


    Dim acscmd As New OleDb.OleDbCommand
    Dim acsda As New OleDb.OleDbDataAdapter
    Dim acscon As OleDb.OleDbConnection = myconn()
    Dim acsds As New DataSet
    Dim strsql As String
    Dim strreportname As String

    Public Sub report(ByVal sql As String, ByVal rptname As String)
        acsds = New DataSet
        strsql = sql
        acscmd.CommandText = strsql
        acscmd.Connection = acscon
        acsda.SelectCommand = acscmd
        acsda.Fill(acsds)

        strreportname = rptname
        Dim strreportpath As String = Application.StartupPath & "\reports\" & strreportname & ".rpt"
        '  Dim strreportpath As String = "C:\Users\DELL\Documents\Visual Studio 2008\Projects\mytest\mytest\bin\reports\" & strreportname & ".rpt"
        If Not IO.File.Exists(strreportpath) Then
            MsgBox("Unable to locate file:" & vbCrLf & strreportpath)

        End If

        Dim reportdoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument

        reportdoc.Load(strreportpath)
        reportdoc.SetDataSource(acsds.Tables(0))

        CrystalReportViewer1.ShowRefreshButton = False
        CrystalReportViewer1.ShowCloseButton = False
        CrystalReportViewer1.ShowGroupTreeButton = False
        CrystalReportViewer1.ReportSource = reportdoc
    End Sub


    
    'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '    report("select * from tblCandidate", "CrystalReport1")
    '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 Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If ComboBox2.Text = Nothing Then

            MsgBox("Please select year level")
        Else

            report("select * from tblCandidate where candidacy ='Governor' and gov_id =" & ComboBox2.Text & "", "CrystalReport1")

        End If

        'report("select * from tblcandidate where cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Governor' and gov_id =" & ComboBox2.Text & "))", "CrystalReport1")
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        report("select * from tblCandidate where candidacy = 'Vice-Governor' and gov_id =" & ComboBox2.Text & "", "CrystalReport1")
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        report("select * from tblCandidate where candidacy ='" & ComboBox1.Text & "'", "CrystalReport1")
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        report("select * from tblcandidate where cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='" & ComboBox1.Text & "'))", "CrystalReport1")
        'report("select * from tblCandidate where candidacy ='" & ComboBox1.Text & "'", "CrystalReport1")
    End Sub

   
    

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        report("select * from tblcandidate where cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='President'))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Vice-President'))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Secretary'))" & _
        "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Treasurer'))" & _
         "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Auditor'))" & _
        "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='PIO'))" & _
        "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Senator'))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Governor' and gov_id =1))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Governor' and gov_id =2))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Governor' and gov_id =3))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Governor' and gov_id =4))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Vice-Governor' and gov_id =1))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Vice-Governor' and gov_id =2))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Vice-Governor' and gov_id =3))" & _
               "or cand_score = (select max(cand_score) from (select * from tblcandidate where candidacy ='Vice-Governor' and gov_id =4))order by priority, gov_id", "CrystalReport1")

      
    End Sub

    Private Sub frmVotingDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class