Imports Microsoft.Reporting.WinForms
Imports System.Text

Public Class frmLabel

    Private Sub frmLabel__Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.ReportViewer1.RefreshReport()
    End Sub

    Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click

        Dim report As New LocalReport()
        report.ReportPath = Application.StartupPath & "\Testreport.rdlc"
        ' print_microsoft_report(report, 10, 14, False, "Schaum-Drucker")

        ClassPrintReport.Run(report)
        'Print("Schaum-Drucker")


    End Sub


    Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
        Print_NVEZPL("Digital Data", "Ludwg-Rinn Str 16", "35452", "Heuchelheim", "Marlon Schreiber", "Zum Maiplatz 7", "35398", "Gießen", "426000947600963763")
    End Sub
    Public Shared Function Print_NVEZPL(absName As String, absStrasse As String, absPLZ As String, absOrt As String, empname As String, empStrasse As String, empPLZ As String, empOrt As String, _NVE As String)
        Try
            Dim pText As New StringBuilder
            pText.AppendLine("^XA") 'Every Format must start with this command
            pText.AppendLine("^CI28")
            'Barcode
            pText.AppendLine("^BY4^FO650,50^BCR,160,N,N,N,A^FD00" & _NVE & "^FS")
            pText.AppendLine("^CFA,30^FWr^FO620,60^FDNVE 00" & _NVE & "^FS")

            pText.AppendLine("^AU^FO750,700^FDS.T.a.R.^FS")
            pText.AppendLine("^CF0,22^FWr^FO720,700^FDSYSTEM-TRANSPORT auf RÄDERN^FS")
            pText.AppendLine("^CF0,40^FWr^FO680,700^FD35 - Giessen^FS")
            pText.AppendLine("^FWr^FO650,700^FDHellmold & Plank^FS")
            pText.AppendLine("^CF0,40^FWr^FO560,50^FDS.T.a.R. GmbH, Werner von Siemens-Str. 1, 34576 Homberg-Efze Telefon: 05681/988823^FS")
            pText.AppendLine("^FO480,50^FDHinweise:^FS")
            pText.AppendLine("^FO430,50^FDFixtermin! Nicht früher oder später - ^FS")

            pText.AppendLine("^FO540,50^GB1,1050,3^FS") 'Breite Linie
            pText.AppendLine("^FO50,600^GB490,1,3^FS") 'Senkrechte Linie
            pText.AppendLine("^FO510,610^FDVersender:^FS")
            pText.AppendLine("^FO510,780^FDReinhard Schaum^FS")
            pText.AppendLine("^FO460,780^FDRheinstrasse 8^FS")
            pText.AppendLine("^FO420,780^FDDE - 35625 Hüttenberg^FS")
            pText.AppendLine("^FO405,600^GB1,500,3^FS")
            pText.AppendLine("^AT^^FO360,610^FDAnzahl Packstücke:^FS")
            pText.AppendLine("^AT^^FO360,950^FD99^FS") 'Anzahl Packstücke Linie
            pText.AppendLine("^FO330,600^GB1,500,3^FS")
            pText.AppendLine("^AT^FO290,610^FDEmpfänger:^FS")
            pText.AppendLine("^AU^FO230,610^FD" & empname & "^FS")
            pText.AppendLine("^AU^FO150,610^FD" & empStrasse & "^FS")
            pText.AppendLine("^AU^FO80,610^FDDE-" & empPLZ & " " & empOrt & "^FS")
            pText.AppendLine("^XZ") 'Every Format must end with this command
            RawPrinter.SendToPrinter("NVE-Etikett", pText.ToString, "Schaum-Drucker") 'print the String
            Return True
        Catch ex As Exception
            MsgBox("Fehler in Print_NVE_ZPL: " & ex.Message, MsgBoxStyle.Critical)
            Return False
        End Try
    End Function
    Sub PrintViaIP(IP As String, empname As String, empStrasse As String, empPLZ As String, empOrt As String, _NVE As String)
        Dim ipAddress As String = IP
        Dim port As Integer = 9100

        Dim pText As New StringBuilder
        pText.AppendLine("^XA") 'Every Format must start with this command
        pText.AppendLine("^CI28")
        'Barcode
        pText.AppendLine("^BY4^FO650,50^BCR,160,N,N,N,A^FD00" & _NVE & "^FS")
        pText.AppendLine("^CFA,30^FWr^FO620,60^FDNVE 00" & _NVE & "^FS")

        pText.AppendLine("^AU^FO750,700^FDS.T.a.R.^FS")
        pText.AppendLine("^CF0,22^FWr^FO720,700^FDSYSTEM-TRANSPORT auf RÄDERN^FS")
        pText.AppendLine("^AQ^FO680,700^FD35 - Giessen^FS")
        pText.AppendLine("^AQ^FO650,700^FDHellmold & Plank^FS")
        pText.AppendLine("^AQ^FO560,50^FDS.T.a.R. GmbH, Werner von Siemens-Str. 1, 34576 Homberg-Efze Telefon: 05681/988823^FS")
        pText.AppendLine("^AQ^FO480,50^FDHinweise:^FS")
        pText.AppendLine("^AQ^FO430,50^FDFixtermin! Nicht früher oder später - ^FS")

        pText.AppendLine("^FO540,50^GB1,1050,3^FS") 'Breite Linie
        pText.AppendLine("^FO50,600^GB490,1,3^FS") 'Senkrechte Linie
        pText.AppendLine("^AR^FO510,610^FDVersender:^FS")
        pText.AppendLine("^AR^FO510,780^FDReinhard Schaum^FS")
        pText.AppendLine("^AR^FO460,780^FDRheinstrasse 8^FS")
        pText.AppendLine("^AR^FO420,780^FDDE - 35625 Hüttenberg^FS")

        pText.AppendLine("^FO405,600^GB1,500,3^FS")
        pText.AppendLine("^AT^^FO360,610^FDAnzahl Packstücke:^FS")
        pText.AppendLine("^AT^^FO360,950^FD99^FS") 'Anzahl Packstücke Linie
        pText.AppendLine("^FO330,600^GB1,500,3^FS")
        pText.AppendLine("^AT^FO290,610^FDEmpfänger:^FS")
        pText.AppendLine("^AU^FO230,610^FD" & empname & "^FS")
        pText.AppendLine("^AU^FO150,610^FD" & empStrasse & "^FS")
        pText.AppendLine("^AU^FO80,610^FDDE-" & empPLZ & " " & empOrt & "^FS")
        pText.AppendLine("^XZ") 'Every Format must end with this command

        Try
            'Open Connection
            Dim client As New System.Net.Sockets.TcpClient
            client.Connect(ipAddress, port)

            'Write ZPL String to Connection
            Dim writer As New System.IO.StreamWriter(client.GetStream())
            writer.Write(pText)
            writer.Flush()

            'Close Connection
            writer.Close()
            client.Close()

        Catch ex As Exception

            'Catch Exception Here

        End Try
    End Sub

    Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click
        PrintViaIP("172.24.10.18", "Marlon Schreiber", "Zum Maiplatz 7", "35398", "Gießen", "426000947600963763")
    End Sub
End Class