Imports System.Data.Odbc
Imports System.Data.OleDb
Public Class frmLapHasilPrediksi
  
    Sub Tampilkandata()
        dg2.Columns.Clear()
        dg2.Columns.Add("kode", "Tahun")
        dg2.Columns.Add("kode", "Bulan")
        dg2.Columns.Add("kode", "Pendapatan Bulan-1 (X) ")
        dg2.Columns.Add("kode", "Prediksi Bulan Ini (Y) ")

        Dim sql As String = "Select tahun,id_bulan,nilai_X,prediksi_y " & _
                                 " from tbprediksi  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)
            dg2.Item(3, i).Value = rd(3)
            i += 1
        End While

        rd.Close()
        dg2.ReadOnly = True
        dg2.AllowUserToAddRows = False
        dg2.Columns(0).Width = 80
        dg2.Columns(1).Width = 100
        dg2.Columns(2).Width = 110
        dg2.Columns(3).Width = 110
        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(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dg2.Columns(2).DefaultCellStyle.Format = "#,##0"
        dg2.Columns(3).DefaultCellStyle.Format = "#,##0"

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


    Private Sub frmLapHasilPrediksi_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 frmLapHasilPrediksi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        btnCetak.Enabled = False
        Call Tampilkandata()

    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 frmCetakHasil As New frmLaporan
        Dim Cetakdata As CrystalDecisions.CrystalReports.Engine.ReportDocument
        Cetakdata = New rptHasilPrediksi
        frmCetakHasil.CRV.ReportSource = Nothing
        frmCetakHasil.CRV.ReportSource = Cetakdata
        frmCetakHasil.CRV.Refresh()
        frmCetakHasil.CRV.RefreshReport()
        frmCetakHasil.Show(Me)
    End Sub

End Class