Imports System.Data
Imports System.Data.OleDb
Public Class ShowOrder
    Dim dr As OleDbDataReader
    Dim cmd As New OleDbCommand
    Dim gsql As String
    Private Sub ShowOrder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ConnectDatabase()
        showlist()
        SetGrid()
        SetHeaderGrid()
    End Sub
    Private Sub showlist() 'dataGridView
        Dim dt As New DataTable
        gsql = "select * from Order_H"
        With cmd
            .CommandType = CommandType.Text
            .CommandText = gsql
            .Connection = cnn
            dr = .ExecuteReader
        End With
        If dr.HasRows Then
            dt.Load(dr)
            dgvOrder.DataSource = dt 'dtโหลด dr ให้ dgv=dt
        End If
        dr.Close()
    End Sub
    Private Sub SetHeaderGrid()
        'datagrid
        If dgvOrder.RowCount > 0 Then
            dgvOrder.Columns(0).HeaderText = "รหัสการสั่งซื้อสินค้า"
            dgvOrder.Columns(0).Width = 100
            dgvOrder.Columns(1).HeaderText = "รหัสบริษัท"
            dgvOrder.Columns(1).Width = 100
            dgvOrder.Columns(2).HeaderText = "ราคารวม"
            dgvOrder.Columns(2).Width = 100
            dgvOrder.Columns(3).HeaderText = "วันที่สั่งซื้อสินค้า"
            dgvOrder.Columns(3).Width = 150
            dgvOrder.Columns(3).HeaderText = "สถานะ"
            dgvOrder.Columns(3).Width = 100
        End If

    End Sub
    Private Sub SetGrid() 'สร้างข้อความหัวคอลัมน์ แก้ไขหัวคอลัมน์ตามต้องการ
        'If dgvOrder.Columns(0).HeaderText = "รหัสการสั่งซื้อสินค้า" Then
        '    dgvOrder.Columns(0).Width = 100
        '    dgvOrder.Columns(1).HeaderText = "รหัสบริษัท"
        '    dgvOrder.Columns(1).Width = 100
        '    dgvOrder.Columns(2).HeaderText = "ราคารวม"
        '    dgvOrder.Columns(2).Width = 100
        '    dgvOrder.Columns(3).HeaderText = "วันที่สั่งซื้อสินค้า"
        '    dgvOrder.Columns(3).Width = 150
        '    dgvOrder.Columns(3).HeaderText = "สถานะ"
        '    dgvOrder.Columns(3).Width = 100
        'End If
    End Sub

    Private Sub dgvOrder_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvOrder.CellContentClick
        Dim i As Integer 'ดับเบิ้ลคลิก
        'With dgvOrder
        '    If e.RowIndex >= 0 Then
        '        i = .CurrentRow.Index
        '        FmReceire.txtOderID.Text = .Rows(i).Cells(0).Value.ToString
        '        FmReceire.txtcomID.Text = .Rows(i).Cells(1).Value.ToString
        '        FmReceire.txtcomID.Text = .Rows(i).Cells(2).Value.ToString
        '        FmReceire.txtcomName.Text = .Rows(i).Cells(3).Value.ToString
        '        FmReceire.txtstatus.Text = .Rows(i).Cells(4).Value.ToString
        '    End If
        'End With
        'Me.Close()

    End Sub
End Class