Imports DAKOSY_Worker
Imports VERAG_PROG_ALLGEMEIN

Public Class frmZollanmeldung
    Dim ART As String = ""
    Dim AVISO As VERAG_PROG_ALLGEMEIN.cAviso
    Dim SENDUNG As VERAG_PROG_ALLGEMEIN.cSendungen
    Dim FilialenNr As Integer
    Dim AbfertigungsNr As Integer
    Dim JAHR As Integer = Now.ToString("yy")

    Public isSTAMMREF As Boolean = False
    Public STAMMREF As String = ""
    Public CopyFromZA_Id As Integer = -1
    '  Dim NCTS As DAKOSY_Worker.cDakosyNCTSOut = Nothing
    '   Dim AES As DAKOSY_Worker.cDakosyAES = Nothing

    Dim FIRMA_DY = ""
    Dim ZOLL_SYSTEM = "DAKOSY"

    Dim DY As DAKOSY_Worker.cDakosy_Zollanmeldungen = Nothing

    Dim GesamtsicherheitREF As cAufschubKonten = Nothing
    Dim Standort As String = ""
    Dim gsnr As Integer = -1
    Dim WarenwertEUR As Double = 0



    Sub New(ART As String, DY As DAKOSY_Worker.cDakosy_Zollanmeldungen, Optional ZOLL_SYSTEM As String = "DAKOSY") ', JAHR As Integer) ', Optional ZA = Nothing)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        ' If DY Is Nothing Then DY = New DAKOSY_Worker.cDakosy_Zollanmeldungen

        Me.DY = DY
        If DY.dy_AvisoId IsNot Nothing AndAlso DY.dy_AvisoId > 0 Then
            Dim AV As New VERAG_PROG_ALLGEMEIN.cAvisoDAL
            Me.AVISO = AV.LesenAviso(DY.dy_AvisoId, "")
        End If
        Me.ART = ART
        If DY.dy_SendungsId IsNot Nothing AndAlso DY.dy_SendungsId > 0 Then
            Me.SENDUNG = New VERAG_PROG_ALLGEMEIN.cSendungen(DY.dy_SendungsId)
            Me.FilialenNr = SENDUNG.FilialenNr
            Me.AbfertigungsNr = SENDUNG.AbfertigungsNr
        End If
        Me.JAHR = JAHR
        Me.ZOLL_SYSTEM = ZOLL_SYSTEM

    End Sub

    Sub New(ART As String, DY As DAKOSY_Worker.cDakosy_Zollanmeldungen, AVISO As VERAG_PROG_ALLGEMEIN.cAviso, SENDUNG As VERAG_PROG_ALLGEMEIN.cSendungen, JAHR As Integer, Optional ZOLL_SYSTEM As String = "DAKOSY") ', Optional ZA = Nothing)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        '  If DY Is Nothing Then DY = New DAKOSY_Worker.cDakosy_Zollanmeldungen

        Me.DY = DY
        Me.AVISO = AVISO
        Me.ART = ART
        Me.SENDUNG = SENDUNG
        Me.JAHR = JAHR
        Me.ZOLL_SYSTEM = ZOLL_SYSTEM

        If SENDUNG IsNot Nothing Then
            Me.FilialenNr = SENDUNG.FilialenNr
            Me.AbfertigungsNr = SENDUNG.AbfertigungsNr
        End If
        ' If ZA IsNot Nothing Then
        'Select Case ZA.GetType.ToString
        '     Case GetType(DAKOSY_Worker.cDakosyNCTSOut).ToString : NCTS = ZA
        '      Case GetType(DAKOSY_Worker.cDakosyAES).ToString : AES = ZA
        '  End Select
        '   End If


        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub


    Sub New(ART As String, DY As DAKOSY_Worker.cDakosy_Zollanmeldungen, AVISO As VERAG_PROG_ALLGEMEIN.cAviso, SENDUNG As VERAG_PROG_ALLGEMEIN.cSendungen, JAHR As Integer, GesamtsicherheitREF As cAufschubKonten, Standort As String, WarenwertEUR As Double, Optional gsnr As Integer = -1, Optional ZOLL_SYSTEM As String = "DAKOSY") ', Optional ZA = Nothing)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        '  If DY Is Nothing Then DY = New DAKOSY_Worker.cDakosy_Zollanmeldungen

        Me.DY = DY
        Me.AVISO = AVISO
        Me.ART = ART
        Me.SENDUNG = SENDUNG
        Me.JAHR = JAHR
        Me.ZOLL_SYSTEM = ZOLL_SYSTEM

        Me.GesamtsicherheitREF = GesamtsicherheitREF
        Me.Standort = Standort
        Me.gsnr = gsnr
        Me.WarenwertEUR = WarenwertEUR

        If SENDUNG IsNot Nothing Then
            Me.FilialenNr = SENDUNG.FilialenNr
            Me.AbfertigungsNr = SENDUNG.AbfertigungsNr
        End If
        ' If ZA IsNot Nothing Then
        'Select Case ZA.GetType.ToString
        '     Case GetType(DAKOSY_Worker.cDakosyNCTSOut).ToString : NCTS = ZA
        '      Case GetType(DAKOSY_Worker.cDakosyAES).ToString : AES = ZA
        '  End Select
        '   End If


        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub



    Private Sub frmZollanmeldung_Load(sender As Object, e As EventArgs) Handles Me.Load

        FIRMA_DY = cDakosyFunftions.getFirma_DY(FilialenNr, Me, ART.Replace("T1", "NCTS").Replace("T2", "NCTS"))

        Select Case ZOLL_SYSTEM
            Case "SGS"
                Select Case ART
                    Case "T1", "T2", "NCTS", "ÜT"

                        If ART = "ÜT" Then
                            ART = "T1"
                            isSTAMMREF = False
                            STAMMREF = "" '??????????????????????????????
                        End If

                        If Me.DY Is Nothing Then
                            Dim usrcntl As New usrCntlSGS_NCTS(ART, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF, FIRMA_DY)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)

                        Else
                            Dim usrcntl As New usrCntlSGS_NCTS(DY, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)
                        End If

                End Select

            Case "MIC"
                Select Case ART
                    Case "T1", "T2", "NCTS", "ÜT"

                        If ART = "ÜT" Then
                            ART = "T1"
                            isSTAMMREF = False
                            STAMMREF = "" '??????????????????????????????
                        End If

                        If Me.DY Is Nothing Then
                            Dim usrcntl As New usrCntlMIC_NCTS(ART, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF, FIRMA_DY)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)

                        Else
                            Dim usrcntl As New usrCntlMIC_NCTS(DY, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)
                        End If

                End Select

            Case "MODALTRANS"
                Select Case ART
                    Case "T1", "T2", "NCTS", "ÜT"

                        If ART = "ÜT" Then
                            ART = "T1"
                            isSTAMMREF = False
                            STAMMREF = "" '??????????????????????????????
                        End If

                        If Me.DY Is Nothing Then
                            Dim usrcntl As New usrCntlModaltrans_NCTS(ART, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF, FIRMA_DY)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)

                        Else
                            MsgBox("Funktíon nicht implementiert")
                            'Dim usrcntl As New usrCntlModaltrans_NCTS(DY, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF)
                            'usrcntl.Dock = DockStyle.Fill
                            'Me.pnl.Controls.Add(usrcntl)
                        End If

                End Select

            Case Else '"DAKOSY'


                Select Case ART
                    Case "T1", "T2", "NCTS", "ÜT"
                        '   DY.dy_ART = ART
                        '  Sub New(DY_ANM As cDakosy_Zollanmeldungen, AVISO As VERAG_PROG_ALLGEMEIN.caviso, SENDUNG As VERAG_PROG_ALLGEMEIN.cSendungen, Jahr2Stellig As Integer, Optional zusatz As String = "")
                        'Dim usrcntl As New usrCntlATLAS_NCTS(DY, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF)

                        If ART = "ÜT" Then
                            ART = "T1"
                            isSTAMMREF = False
                            STAMMREF = "" '??????????????????????????????
                        End If

                        If Me.DY Is Nothing Then
                            Dim usrcntl As New usrCntlATLAS_NCTS004(ART, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF, FIRMA_DY)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)

                        Else
                            If Me.DY.dy_Erstellung >= "24.09.2023" Then
                                Dim usrcntl As New usrCntlATLAS_NCTS004(DY, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF)
                                usrcntl.Dock = DockStyle.Fill
                                Me.pnl.Controls.Add(usrcntl)
                            Else
                                Dim usrcntl As New usrCntlATLAS_NCTS(DY, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF)
                                usrcntl.Dock = DockStyle.Fill
                                Me.pnl.Controls.Add(usrcntl)
                            End If

                        End If

                    Case "AES", "EX", "EU", "CO"

                        If Me.DY Is Nothing Then
                            Dim usrcntl As New usrCntlATLAS_AES(ART, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)

                        Else
                            Dim usrcntl As New usrCntlATLAS_AES(DY, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)

                        End If

                    Case "EZA", "VZA"

                        If Me.DY Is Nothing Then
                            Dim usrcntl As New usrCntlATLAS_EZA(ART, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF, FIRMA_DY)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)

                        Else
                            Dim usrcntl As New usrCntlATLAS_EZA(DY, AVISO, SENDUNG, JAHR, , isSTAMMREF, STAMMREF)
                            usrcntl.Dock = DockStyle.Fill
                            Me.pnl.Controls.Add(usrcntl)

                        End If

                    Case "AA" 'AnkunftsAnzeige
                        Dim usrcntl As New usrCntlATLAS_AnkunftsAnzeige(AVISO, SENDUNG, FIRMA_DY, GesamtsicherheitREF, Standort, gsnr, WarenwertEUR)
                        usrcntl.Dock = DockStyle.Fill
                        Me.pnl.Controls.Add(usrcntl)
                        Me.Text = "AnkunftsAnzeige - Verwahrung"

                    Case "EXG" 'Ausfuhr Gestellung
                        Dim usrcntl As New usrCntlATLAS_EXGestellung(AVISO, SENDUNG, FIRMA_DY)
                        usrcntl.Dock = DockStyle.Fill
                        Me.pnl.Controls.Add(usrcntl)
                        Me.Text = "Ausfuhr - Gestellung"

                End Select
        End Select
    End Sub



    Shared Sub setZollstelle(ByRef zst As String, AVISO As VERAG_PROG_ALLGEMEIN.cAviso)
        Try
            If AVISO Is Nothing Then Exit Sub
            If AVISO.Grenzstelle.Replace("???", "") = "" Then
                zst = AVISO.Zollstelle
            Else

                Dim GRZ As New VERAG_PROG_ALLGEMEIN.cGrenzstelle(AVISO.Grenzstelle)
                If GRZ IsNot Nothing AndAlso GRZ.hasEntry Then
                    If GRZ.grz_ZollamtDST IsNot Nothing Then zst = GRZ.grz_ZollamtDST ' ZollDST setzen, zB "DE007701"'Suben Autobahngrenze
                End If


                'Select Case AVISO.Grenzstelle
                '    Case "SUB" : zst = "DE007701"'Suben Autobahngrenze
                '    Case "SBG", "AMB" : zst = "DE007458" 'Bad Reichenhall-Autobahn
                '    Case "WAI" : zst = "DE008904" 'Weiden-Waidhaus
                '    Case "NEU" : zst = "DE007703" 'Passau
                '    Case "WO_GE" : zst = "DE008752" 'Erlangen 
                '        ' Case "SFD" : zst = Asd ....DAKOS DE -.-
                'End Select
            End If
        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
    End Sub

End Class