Imports System.Data.Odbc
Public Class FrmLapDataset
    Sub Tampilkandata()
        DG2.Columns.Clear()
        DG2.Columns.Add("kode", "Tahun")
        DG2.Columns.Add("kode", "Bulan")
        DG2.Columns.Add("kode", "Jml Pendapatan")
        Dim sql As String = "Select tahun,id_bulan,jml_pendapatan " & _
                                 " from tbdataset  order by tahun,id_bulan"

        cmd = New OdbcCommand(sql, Conn)
        rd = cmd.ExecuteReader
        Dim i As Integer = 0
        While rd.Read
            DG2.Rows.Add()
            DG2.Item(0, i).Value = rd(0)
            DG2.Item(1, i).Value = NamaBulan(rd(1) - 1)
            DG2.Item(2, i).Value = rd(2)

            i += 1
        End While

        rd.Close()
        DG2.ReadOnly = True
        DG2.AllowUserToAddRows = False
        DG2.Columns(0).Width = 90
        DG2.Columns(1).Width = 100
        DG2.Columns(2).Width = 120

        DG2.GridColor = Color.Blue
        DG2.DefaultCellStyle.ForeColor = Color.Blue
        DG2.RowHeadersDefaultCellStyle.BackColor = Color.DeepPink
        DG2.AlternatingRowsDefaultCellStyle.BackColor = Color.Yellow
        DG2.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        DG2.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        DG2.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        DG2.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        DG2.Columns(2).DefaultCellStyle.Format = "#,##0"

        If DG2.RowCount > 0 Then
            btnCetak.Enabled = True
        Else
            btnCetak.Enabled = False
        End If
    End Sub



    Private Sub btnTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTutup.Click
        Me.Dispose()
    End Sub

    Private Sub btnCetak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCetak.Click
        Dim frmCetak As New frmLaporan
        Dim Cetakdata As CrystalDecisions.CrystalReports.Engine.ReportDocument
        Cetakdata = New rptDataSet
        frmCetak.CRV.ReportSource = Nothing
        frmCetak.CRV.ReportSource = Cetakdata
        frmCetak.CRV.Refresh()
        frmCetak.CRV.RefreshReport()
        frmCetak.Show(Me)
    End Sub



    Private Sub FrmLapDataset_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If Asc(e.KeyChar) = Keys.Enter Then
            SendKeys.Send("{tab}")
        End If
    End Sub

    Private Sub FrmLapDataset_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call Koneksi()
        Call Tampilkandata()

    End Sub
End Class