TransCetakBarcode

Share:
Imports MySql.Data.MySqlClient
Imports System.Data.DataTable
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Interop
Imports System.Drawing.Printing.PrinterSettings.StringCollection

Public Class TransCetakBarcode
    Dim TABLE As New System.Data.DataTable("Table")
    Dim cSQL As String
    Private Sub CTable()

        TABLE.Columns.Add("Kode Barang", Type.GetType("System.String"))
        TABLE.Columns.Add("Nama Barang", Type.GetType("System.String"))
        TABLE.Columns.Add("QTY", Type.GetType("System.String"))
        TABLE.Columns.Add("Harga Jual", Type.GetType("System.String"))

        DGV.DataSource = TABLE
        DGV.Columns(0).Width = 50
        'DGV.Columns(0).Visible = False
        DGV.Columns(1).Width = 200
        DGV.Columns(2).Width = 75
        DGV.Columns(3).Width = 100
        DGV.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft

    End Sub
    Private Sub TransCetakBarcode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim pkInstalledPrinters As String
        CTable()
        ComboBox1.Text = "1"
        For Each pkInstalledPrinters In System.Drawing.Printing.PrinterSettings.InstalledPrinters
            ComboBox2.Items.Add(pkInstalledPrinters)
            ComboBox2.SelectedIndex = 0
        Next
    End Sub

    Private Sub TextBox3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyDown
        Dim Total As Integer
        Dim Ketemu As Boolean
        Dim x As Integer
        If e.KeyCode = Keys.Enter Then
            KONEKSIS()
            cSQL = "select KodeBarang, NamaBarang, QtyToko, HargaEceran from stokbarang where KodeBarang like '" & TextBox3.Text & "' or NamaBarang like '" & TextBox3.Text & "' order by NamaBarang"
            CMDD = New MySqlCommand(cSQL, CONN)
            DR = CMDD.ExecuteReader
            DR.Read()
            Total = 0
            ketemu = False
            If DR.HasRows Then
                For x = 0 To DGV.Rows.Count - 1
                    If DGV.Rows(x).Cells(0).Value = TextBox3.Text Then
                        ketemu = True
                        Exit For
                    End If
                Next x
                If ketemu Then
                    DGV.Rows(x).Cells(2).Value = DGV.Rows(x).Cells(2).Value + 1
                Else
                    TABLE.Rows.Add(DR.Item("KodeBarang"), DR.Item("NamaBarang"), 1, DR.Item("HargaEceran"))
                End If
                For x = 0 To DGV.Rows.Count - 1
                    Total = Total + ((DGV.Rows(x).Cells(2).Value))  ' * DGV.Rows(x).Cells(3).Value)) - ((DGV.Rows(x).Cells(2).Value * DGV.Rows(x).Cells(3).Value) * (DGV.Rows(x).Cells(4).Value / 100))
                Next
                Label7.Text = CStr(Total)
            Else
                MsgBox("Data Barang tidak ada")
            End If
            TextBox3.Text = ""
        End If
    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
     
    End Sub

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

        Dim x As Integer
        Dim Y As Integer, Z As Integer
        Dim nRow As Integer, nCol As Integer
        Dim APPXLS As New Excel.Application
        Dim WBXL As Excel.Workbooks
        Dim SHXLS As Excel.Worksheet
        Dim JML As Integer
        Dim cFileName As String


        Select Case ComboBox1.Text
            Case "1" : cFileName = "D:\Laporan\Barcode.xlsx"
                APPXLS.Workbooks.Open(cFileName)
                WBXL = APPXLS.Workbooks
                SHXLS = APPXLS.ActiveSheet

                Call KONEKSIS()
                nRow = 0
                For x = 0 To DGV.Rows.Count - 1
                    JML = DGV.Rows(x).Cells(2).Value
                    For Y = 0 To JML - 1
                        With SHXLS
                            If Y Mod 2 = 0 Then
                                .Application.Cells(2 + 4 * nRow, 1).Value = DGV.Rows(x).Cells(1).Value
                                .Application.Cells(3 + 4 * nRow, 1).Value = "*" & DGV.Rows(x).Cells(0).Value & "*"
                                .Application.Cells(4 + 4 * nRow, 1).Value = TextBox1.Text & DGV.Rows(x).Cells(3).Value & TextBox2.Text
                            Else
                                .Application.Cells(2 + 4 * nRow, 3).Value = DGV.Rows(x).Cells(1).Value
                                .Application.Cells(3 + 4 * nRow, 3).Value = "*" & DGV.Rows(x).Cells(0).Value & "*"
                                .Application.Cells(4 + 4 * nRow, 3).Value = TextBox1.Text & DGV.Rows(x).Cells(3).Value & TextBox2.Text
                                nRow = nRow + 1
                            End If
                        End With
                    Next Y
                Next x
                APPXLS.Visible = True
                APPXLS.UserControl = True
            Case "2" : cFileName = "D:\Laporan\Barcode2.xlsx"
                APPXLS.Workbooks.Open(cFileName)
                WBXL = APPXLS.Workbooks
                SHXLS = APPXLS.ActiveSheet

                Call KONEKSIS()
                nRow = -1 : nCol = 0 : Z = 1
                For x = 0 To DGV.Rows.Count - 1
                    JML = DGV.Rows(x).Cells(2).Value
                    For Y = 0 To JML - 1
                        With SHXLS
                            If Z Mod 5 = 1 Then
                                nRow = nRow + 1
                                .Application.Cells(2 + 4 * nRow, 1).Value = DGV.Rows(x).Cells(1).Value
                                .Application.Cells(3 + 4 * nRow, 1).Value = "*" & DGV.Rows(x).Cells(0).Value & "*"
                                .Application.Cells(4 + 4 * nRow, 1).Value = TextBox1.Text & DGV.Rows(x).Cells(3).Value & TextBox2.Text
                                nCol = 1
                            Else
                                .Application.Cells(2 + 4 * nRow, 1 + nCol * 2).Value = DGV.Rows(x).Cells(1).Value
                                .Application.Cells(3 + 4 * nRow, 1 + nCol * 2).Value = "*" & DGV.Rows(x).Cells(0).Value & "*"
                                .Application.Cells(4 + 4 * nRow, 1 + nCol * 2).Value = TextBox1.Text & DGV.Rows(x).Cells(3).Value & TextBox2.Text
                                nCol = nCol + 1
                                'nRow = nRow + 1
                            End If
                        End With
                        Z = Z + 1
                    Next Y
                Next x
                APPXLS.Visible = True
                APPXLS.UserControl = True
                APPXLS.Sheets.PrintOutEx(From:=1, [To]:=1, Copies:=1, ActivePrinter:=ComboBox2.Text)
            Case "3" : cFileName = "D:\Laporan\Barcode3.xlsx"
            Case "4" : cFileName = "D:\Laporan\Barcode4.xlsx"
            Case "5" : cFileName = "D:\Laporan\Barcode5.xlsx"
            Case "6" : cFileName = "D:\Laporan\Barcode6.xlsx"
        End Select


     
    End Sub

End Class

No comments