Option Strict Off
Imports System.Data.Odbc
Public Class FrmLapHasil
    Dim cNama, cNip, cJabatan As String
    Dim Awal As Boolean = False
    Private Sub FrmLapHasil_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call TampilPeriode()
    End Sub
    Sub TampilPeriode()
        cboPeriode.Items.Clear()
        cmd = New OdbcCommand("select distinct Periode from tbnilaialternatif order by periode desc", Conn)
        rd = cmd.ExecuteReader
        While rd.Read
            cboPeriode.Items.Add(rd.Item(0))
        End While
    End Sub
    Sub TampilHasil()
        da = New OdbcDataAdapter("Select A.no_importir,B.nama_importir,B.Asal_Negara,A.Nama_Barang,A.Hasil,A.Ket from tbhasil A, tbimportir B where " & _
                                 " a.periode = '" & cboPeriode.Text & "' and a.no_importir=b.no_importir order by ket,hasil Desc", Conn)
        ds = New DataSet
        ds.Clear()
        da.Fill(ds, "tbimportir")
        DG2.DataSource = (ds.Tables("tbimportir"))
        dg2.ReadOnly = True
        dg2.AllowUserToAddRows = False
        dg2.Columns(0).Width = 90
        dg2.Columns(1).Width = 170
        dg2.Columns(2).Width = 160
        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(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        DG2.Columns(4).DefaultCellStyle.Format = "0.00"
        DG2.Columns(0).HeaderText = "No.Importir"
        DG2.Columns(1).HeaderText = "Nama Importir"
        DG2.Columns(2).HeaderText = "Asala Negara"
        DG2.Columns(4).HeaderText = "Hasil"
    End Sub

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

   
    Sub CekPenilai()
        cmd = New OdbcCommand("select * from tbpejabat where status='Aktif'", Conn)
        rd = cmd.ExecuteReader
        rd.Read()
        If rd.HasRows = True Then
            cNama = rd.Item(1)
            cJabatan = rd.Item(2)
            cNip = "NIP. " & rd.Item(0)
        Else
            cNama = ""
            cNip = ""
        End If
    End Sub
    Sub CekData()

        cmd = New OdbcCommand("select * from tbhasil where  periode = '" & cboPeriode.Text & "' ", Conn)
        rd = cmd.ExecuteReader
        rd.Read()
        If rd.HasRows = True Then
            Call TampilHasil()
            btnCetak.Enabled = True
        Else
            If Awal = True Then
                DG2.Columns.Clear()
                MsgBox("Maaf, Penilaian Importir  pada Periode tsb, belum ada", , "Perhatian...!")
                btnCetak.Enabled = False
                Exit Sub
            End If
        End If
    End Sub
    Private Sub btnCetak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCetak.Click
        Dim cetakdata As CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim frmPenilaian As New FrmLaporan
        cetakdata = New rptHasil
        Call CekPenilai()
        frmPenilaian.CRV.ReportSource = Nothing
        frmPenilaian.CRV.SelectionFormula = "{tbhasil1.periode}='" & cboPeriode.Text & "'"
        cetakdata.DataDefinition.FormulaFields(0).Text = "'" & cNama & "'"
        cetakdata.DataDefinition.FormulaFields(1).Text = "'" & cNip & "'"
        cetakdata.DataDefinition.FormulaFields(2).Text = "'" & cJabatan & "'"
        frmPenilaian.CRV.ReportSource = cetakdata
        frmPenilaian.CRV.Refresh()
        frmPenilaian.CRV.RefreshReport()
        frmPenilaian.Show(Me)
    End Sub

    Private Sub cboPeriode_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPeriode.LostFocus
        Awal = True
    End Sub

    Private Sub cboPeriode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPeriode.SelectedIndexChanged
        Call CekData()
    End Sub
End Class