Imports System.Globalization
Imports GrapeCity.ActiveReports
Imports GrapeCity.ActiveReports.Document

Public Class subRptLaufzettelZollDE_ATA

    Dim ATA As New List(Of VERAG_PROG_ALLGEMEIN.cSendHandling)
    Dim Fremdspedition As Boolean
    Dim Vorpapier As String
    Dim Rechnungspreis As Object = Nothing
    Dim Handelsrechnung As Object = Nothing
    Dim Rechnungswaehrung As Object = Nothing

    Sub New(ATA As List(Of VERAG_PROG_ALLGEMEIN.cSendHandling), Fremdspedition As Boolean, Vorpapier As String, Rechnungspreis As Object, Rechnungswaehrung As Object, Handelsrechnung As Object)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.ATA = ATA
        Me.Fremdspedition = Fremdspedition
        Me.Vorpapier = Vorpapier
        Me.Rechnungspreis = Rechnungspreis
        Me.Handelsrechnung = Handelsrechnung
        Me.Rechnungswaehrung = Rechnungswaehrung
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
    End Sub

    Private Sub Detail_Format(sender As Object, e As EventArgs) Handles Detail.Format
        picBarcodeATAMRN.Image = Nothing
        picBarcodeATAMRN.Visible = False
        txtATAMRN.Text = ""
        txtVorpapier.Text = ""

        If Fremdspedition Then
            lblSieheFremdspedition.Visible = True
            TextBox3.Visible = False
            TextBox1.Visible = False
            txtColli.Visible = False
            txtGewicht.Visible = False
        Else
            'txtVorpapier.Text = Vorpapier
            'txtVorpapier.Visible = True

            If Rechnungspreis IsNot Nothing AndAlso IsNumeric(Rechnungspreis) Then
                txtRechnungspreisHeader.Visible = True
                txtRechnungspreis.Visible = True
                ' txtRechnungspreis.Text = CDbl(Rechnungspreis).ToString(".00") & " " & If(Rechnungswaehrung, "")
                txtRechnungspreis.Text = CDbl(Rechnungspreis).ToString("N2", CultureInfo.CurrentCulture) & " " & If(Rechnungswaehrung, "")
            End If
        End If


        If Me.DataSource IsNot Nothing AndAlso Me.Fields IsNot Nothing AndAlso Me.Fields.Item("ATA").Value IsNot Nothing Then
            Dim ATAMRN As String = Me.Fields.Item("ATA").Value

            txtATAMRN.Text = ATAMRN
            If ATAMRN <> "" Then
                Dim barcodeString = ATAMRN
                barcodeString = barcodeString.Replace(" ", "")
                barcodeString = barcodeString.Replace("/", "")
                barcodeString = barcodeString.Replace("-", "")
                Dim ACD = ""
                Dim monat = ""
                If barcodeString.Length > 13 Then monat = barcodeString.Substring(11, 2)

                If barcodeString.StartsWith("ATA") And barcodeString.Length > 11 Then barcodeString = barcodeString.Substring(4, 7) : ACD = "A"
                If barcodeString.StartsWith("ATC") And barcodeString.Length > 11 Then barcodeString = barcodeString.Substring(5, 6) : ACD = "C"
                If barcodeString.StartsWith("ATD") And barcodeString.Length > 11 Then barcodeString = barcodeString.Substring(5, 6) : ACD = "D"


                If ACD <> "" Then 'ATA/C/D
                    txtATNr.Visible = True
                    If IsNumeric(barcodeString) Then barcodeString = CInt(barcodeString).ToString()
                    txtATNr.Value = ACD & " " & barcodeString & " / " & monat
                    picBarcodeATAMRN.Visible = False
                ElseIf ATAMRN.Length > 10 Then 'grobe Prüfung der Länge, ob es eine gültige ATA Nr sein kann..
                    txtATNr.Visible = False

                    Dim barcodeATA As Image = Code128Rendering.MakeBarcodeImage(ATAMRN, 1, True, 20)
                    'barcodeATA.RotateFlip(RotateFlipType.Rotate270FlipNone)
                    picBarcodeATAMRN.Image = barcodeATA
                    picBarcodeATAMRN.Visible = True

                End If

            End If

            txtColli.Text = ""
            txtGewicht.Text = ""
            If Me.Fields.Item("Colli").Value IsNot Nothing Then txtColli.Text = CDbl(Me.Fields.Item("Colli").Value).ToString("N0") & " Pk"
            If Me.Fields.Item("Gewicht").Value IsNot Nothing Then txtGewicht.Text = CDbl(Me.Fields.Item("Gewicht").Value).ToString("N1") & " kg"

            If If(Handelsrechnung, "") <> "" Then
                TextBox2.Text = "Handelsrg.: " & Handelsrechnung
                TextBox2.Visible = True
            End If

        End If

    End Sub
    Private Sub rptAuswertung_ReportStart(sender As System.Object, e As System.EventArgs) Handles MyBase.ReportStart
        Dim dt As New DataTable
        dt.Columns.Add("ATA", System.Type.GetType("System.String"))
        dt.Columns.Add("Colli", System.Type.GetType("System.String"))
        dt.Columns.Add("Gewicht", System.Type.GetType("System.String"))
        For Each s In ATA
            dt.Rows.Add({s.sndhdg_nr, s.sndhdg_colli, s.sndhdg_gewicht})
        Next
        Me.DataSource = dt
    End Sub

End Class
