Imports System.Data.OleDb
Imports System.Object
Public Class frmAELreciept

    Private Sub frmAELreciept_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'add.tblAddOrder_Query' table. You can move, or remove it, as needed.
        Me.tblAddOrder_QueryTableAdapter.Fill(Me.add.tblAddOrder_Query)
        Call connectDatabase()
        Label2.Text = invoices.OrNo1.Text
        Label4.Text = invoices.DateAddedLabel1.Text
        Call loadOrder()

        'Me.ReportViewer1.RefreshReport()
    End Sub
    Private Sub loadsearchresult()
        Dim OleDBC As New OleDbCommand
        Dim OleDBDR As OleDbDataReader
        Dim c As Integer
        c = 0
        With OleDBC
            .Connection = conn
            .CommandText = "SELECT * FROM tblAddOrder"

        End With
        OleDBDR = OleDBC.ExecuteReader
        DataGridView1.Rows.Clear()
        If OleDBDR.HasRows Then
            While OleDBDR.Read
                DataGridView1.Rows.Add()
                DataGridView1.Item(0, c).Value = OleDBDR.Item(2)
                DataGridView1.Item(1, c).Value = OleDBDR.Item(5)
                DataGridView1.Item(2, c).Value = OleDBDR.Item(6)
                DataGridView1.Item(3, c).Value = OleDBDR.Item(7)
                'DataGridView1.Item(4, c).Value = OleDBDR.Item(6)

            End While
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call DisconnectDatabase()
        Me.Close()
        invoices.Show()
    End Sub

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

        Me.Close()

    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim OleDBC As New OleDbCommand
        With OleDBC

            .Connection = conn
            .CommandText = "Insert Into tblInvoicess (InvoiceNo, Encoder, OrNo, OrDate, Total, Cash, Change) VALUES ('" & Label13.Text & _
            "','" & Label12.Text & _
              "','" & Label2.Text & _
            "','" & Label4.Text & _
            "','" & Label6.Text & _
            "','" & Label8.Text & _
            "','" & Label10.Text & "')"
            .ExecuteNonQuery()
        End With
        
        PrintDocument1.Print()


    End Sub
    Private Sub loadOrder()
        Dim oleDBC As New OleDbCommand
        Dim oleDBDR As OleDbDataReader
        Dim c As Integer
        c = 0
        With oleDBC
            .Connection = conn
            .CommandText = "SELECT * FROM tblAddOrder Where OrNo='" & Label2.Text & "'"
        End With
        oleDBDR = oleDBC.ExecuteReader
        DataGridView1.Rows.Clear()
        If oleDBDR.HasRows Then
            While oleDBDR.Read
                DataGridView1.Rows.Add()
                DataGridView1.Item(0, c).Value = oleDBDR.Item(2)
                DataGridView1.Item(1, c).Value = oleDBDR.Item(5)
                DataGridView1.Item(2, c).Value = oleDBDR.Item(6)
                DataGridView1.Item(3, c).Value = oleDBDR.Item(7)
                'DataGridView1.Item(4, c).Value = oleDBDR.Item(6)
                c = c + 1
            End While
        Else
        End If
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim bm As New Bitmap(Me.Panel1.Width, Me.Panel1.Height)

        Panel1.DrawToBitmap(bm, New Rectangle(0, 0, Me.Panel1.Width, Me.Panel1.Height))

        e.Graphics.DrawImage(bm, 0, 0)
        Dim aPS As New PageSetupDialog
        aPS.Document = PrintDocument1
        '
        ' On the 1-rst call to the print dialog initialize the document's 
        ' properties. On subsequent calls use what was previously set.
        '
   
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub

    Private Sub Panel3_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel3.Paint

    End Sub
End Class