Imports System.Globalization

Public Class cTR_NCTS

    Public Shared Function GET_FROM_NCTSTR_CC015B(filePath As String, ByRef NCTS As VERAG_PROG_ALLGEMEIN.cNCTS_TR) As String
        Dim CC015B As cNCTSPartnerWorker.CC015B.CC015BType = cNCTSPartnerWorker.CC015B.CC015BType.LoadFromFile(filePath)
        'NCTS
        If CC015B.HEAHEA IsNot Nothing Then
            If CC015B.HEAHEA.RefNumHEA4 IsNot Nothing Then NCTS.ncts_ObjectName = CC015B.HEAHEA.RefNumHEA4

            If CC015B.HEAHEA.TypOfDecHEA24 IsNot Nothing Then NCTS.ncts_ArtAnmeldung = CC015B.HEAHEA.TypOfDecHEA24
            If CC015B.HEAHEA.CouOfDesCodHEA30 IsNot Nothing Then NCTS.ncts_BestimmungslandCode = CC015B.HEAHEA.CouOfDesCodHEA30
            If CC015B.HEAHEA.PlaOfLoaCodHEA46 IsNot Nothing Then NCTS.ncts_SumA_Ladeort = CC015B.HEAHEA.PlaOfLoaCodHEA46
            If CC015B.HEAHEA.CouOfDisCodHEA55 IsNot Nothing Then NCTS.ncts_VersendungsLandCode = CC015B.HEAHEA.CouOfDisCodHEA55
            If CC015B.HEAHEA.InlTraModHEA75 IsNot Nothing Then NCTS.ncts_Befoerderungsmittel_VerkehrszweigGrenzueberschreitent = CC015B.HEAHEA.InlTraModHEA75
            If CC015B.HEAHEA.TraModAtBorHEA76 IsNot Nothing Then NCTS.ncts_Befoerderungsmittel_ArtGrenzueberschreitung = CC015B.HEAHEA.TraModAtBorHEA76
            If CC015B.HEAHEA.IdeOfMeaOfTraAtDHEA78 IsNot Nothing Then NCTS.ncts_Befoerderungsmittel_KennzeichenAbgang = CC015B.HEAHEA.IdeOfMeaOfTraAtDHEA78
            If CC015B.HEAHEA.NatOfMeaOfTraAtDHEA80 IsNot Nothing Then NCTS.ncts_Befoerderungsmittel_SttaszugehoerigkeitAbgangCode = CC015B.HEAHEA.NatOfMeaOfTraAtDHEA80
            If CC015B.HEAHEA.IdeOfMeaOfTraCroHEA85 IsNot Nothing Then NCTS.ncts_Befoerderungsmittel_KennzeichenGrenzueberschreitend = CC015B.HEAHEA.IdeOfMeaOfTraCroHEA85
            If CC015B.HEAHEA.NatOfMeaOfTraCroHEA87 IsNot Nothing Then NCTS.ncts_Befoerderungsmittel_StaatszugehoerigkeitGrenzueberschreitendCode = CC015B.HEAHEA.NatOfMeaOfTraCroHEA87
            'If CC015B.HEAHEA.ConIndHEA96 IsNot Nothing Then NCTS. = CC015B.HEAHEA.ConIndHEA96 CONTAINER
            If CC015B.HEAHEA.TotNumOfPacHEA306 IsNot Nothing Then NCTS.ncts_GesamtAnzahlPackstuecke = CC015B.HEAHEA.TotNumOfPacHEA306
            'If CC015B.HEAHEA.TotNumOfIteHEA305 IsNot Nothing Then NCTS.itemsGEsamt = CC015B.HEAHEA.TotNumOfIteHEA305

            If CC015B.HEAHEA.TotGroMasHEA307 IsNot Nothing Then NCTS.ncts_GesamtRohmasse = CDbl(CC015B.HEAHEA.TotGroMasHEA307)

            If CC015B.HEAHEA.DecDatHEA383 IsNot Nothing Then NCTS.ncts_Trans_DatumZeit = DateTime.ParseExact(CC015B.HEAHEA.DecDatHEA383, "yyyyMMdd", CultureInfo.CurrentCulture)
            If CC015B.HEAHEA.DecPlaHEA394 IsNot Nothing Then NCTS.ncts_Empfaenger_Ort = CC015B.HEAHEA.DecPlaHEA394 '?
            'If CC015B.HEAHEA.DecPlaHEA394LNG IsNot Nothing Then NCTS.ncts_Empfaenger_Ort = CC015B.HEAHEA.DecPlaHEA394LNG
            If CC015B.HEAHEA.CodPlUnHEA357 IsNot Nothing Then NCTS.ncts_SumA_Entladeort = CC015B.HEAHEA.CodPlUnHEA357

            If CC015B.TRAPRIPC1 IsNot Nothing Then
                If CC015B.TRAPRIPC1.NamPC17 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_Name = CC015B.TRAPRIPC1.NamPC17
                If CC015B.TRAPRIPC1.StrAndNumPC122 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_StrasseHausnummer = CC015B.TRAPRIPC1.StrAndNumPC122
                If CC015B.TRAPRIPC1.PosCodPC123 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_PLZ = CC015B.TRAPRIPC1.PosCodPC123
                If CC015B.TRAPRIPC1.CitPC124 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_Ort = CC015B.TRAPRIPC1.CitPC124
                If CC015B.TRAPRIPC1.CouPC125 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_Land = CC015B.TRAPRIPC1.CouPC125
                If CC015B.TRAPRIPC1.TINPC159 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_EORI = CC015B.TRAPRIPC1.TINPC159
            End If

            'AbgangsZollstelle
            If CC015B.CUSOFFDEPEPT IsNot Nothing Then
                If CC015B.CUSOFFDEPEPT.RefNumEPT1 IsNot Nothing Then NCTS.ncts_AbgangsDienststellennummer = CC015B.CUSOFFDEPEPT.RefNumEPT1
            End If

            'BestimmungsZollstelle
            If CC015B.CUSOFFDESEST IsNot Nothing Then
                If CC015B.CUSOFFDESEST.RefNumEST1 IsNot Nothing Then NCTS.ncts_BestimmungsstelleDienststellennummer = CC015B.CUSOFFDESEST.RefNumEST1
            End If

            'Bearbeiter
            If CC015B.REPREP IsNot Nothing Then
                If CC015B.REPREP.NamREP5 IsNot Nothing Then NCTS.ncts_Bearbeiter = CC015B.REPREP.NamREP5
                'If CC015B.REPREP.RefNumEST1 IsNot Nothing Then NCTS.= CC015B.REPREP.RefNumEST1
            End If

            'Frist
            If CC015B.CONRESERS IsNot Nothing Then
                If CC015B.CONRESERS.DatLimERS69 IsNot Nothing Then NCTS.ncts_Wiedergestellungsdatum = CC015B.CONRESERS.DatLimERS69
            End If

            ''Verschluss
            If CC015B.SEAINFSLI IsNot Nothing Then
                If CC015B.SEAINFSLI.SeaNumSLI2 IsNot Nothing Then NCTS.ncts_Verschluss_Anzahl = CC015B.SEAINFSLI.SeaNumSLI2
                If CC015B.SEAINFSLI.SEAIDSID IsNot Nothing AndAlso CC015B.SEAINFSLI.SEAIDSID.Count > 0 Then
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 0 Then NCTS.ncts_Verschluss_Zeichen1 = CC015B.SEAINFSLI.SEAIDSID(0).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 1 Then NCTS.ncts_Verschluss_Zeichen2 = CC015B.SEAINFSLI.SEAIDSID(1).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 2 Then NCTS.ncts_Verschluss_Zeichen3 = CC015B.SEAINFSLI.SEAIDSID(2).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 3 Then NCTS.ncts_Verschluss_Zeichen4 = CC015B.SEAINFSLI.SEAIDSID(3).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 4 Then NCTS.ncts_Verschluss_Zeichen5 = CC015B.SEAINFSLI.SEAIDSID(4).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 5 Then NCTS.ncts_Verschluss_Zeichen6 = CC015B.SEAINFSLI.SEAIDSID(5).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 6 Then NCTS.ncts_Verschluss_Zeichen7 = CC015B.SEAINFSLI.SEAIDSID(6).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 7 Then NCTS.ncts_Verschluss_Zeichen8 = CC015B.SEAINFSLI.SEAIDSID(7).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 8 Then NCTS.ncts_Verschluss_Zeichen9 = CC015B.SEAINFSLI.SEAIDSID(8).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 9 Then NCTS.ncts_Verschluss_Zeichen10 = CC015B.SEAINFSLI.SEAIDSID(9).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 10 Then NCTS.ncts_Verschluss_Zeichen11 = CC015B.SEAINFSLI.SEAIDSID(10).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 11 Then NCTS.ncts_Verschluss_Zeichen12 = CC015B.SEAINFSLI.SEAIDSID(11).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 12 Then NCTS.ncts_Verschluss_Zeichen13 = CC015B.SEAINFSLI.SEAIDSID(12).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 13 Then NCTS.ncts_Verschluss_Zeichen14 = CC015B.SEAINFSLI.SEAIDSID(13).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 14 Then NCTS.ncts_Verschluss_Zeichen15 = CC015B.SEAINFSLI.SEAIDSID(14).SeaIdeSID1
                    If CC015B.SEAINFSLI.SEAIDSID.Count > 15 Then NCTS.ncts_Verschluss_Zeichen16 = CC015B.SEAINFSLI.SEAIDSID(15).SeaIdeSID1
                End If
                'If CC015B.REPREP.RefNumEST1 IsNot Nothing Then NCTS.= CC015B.REPREP.RefNumEST1
            End If

            'Bürgschaft
            If CC015B.GUAGUA IsNot Nothing AndAlso CC015B.GUAGUA.Count > 0 Then
                For Each GUAGUA In CC015B.GUAGUA
                    If GUAGUA.GUAREFREF IsNot Nothing Then
                        For Each REF In GUAGUA.GUAREFREF
                            Dim BRG As New VERAG_PROG_ALLGEMEIN.cNCTS_TR_Sicherheitsangaben
                            If GUAGUA.GuaTypGUA1 IsNot Nothing Then BRG.nctsSA_ArtCode = GUAGUA.GuaTypGUA1
                            If REF.GuaRefNumGRNREF1 IsNot Nothing Then BRG.nctsSA_GRN = REF.GuaRefNumGRNREF1
                            'If REF.CurREF8 IsNot Nothing Then BRG.nctsSA_Waerung = REF.CurREF8
                            If REF.AccCodREF6 IsNot Nothing Then BRG.nctsSA_Zugriffcode = REF.AccCodREF6
                            If REF.AmoConREF7 IsNot Nothing Then BRG.nctsSA_AbgabenBetragFremdWaehrung = REF.AmoConREF7

                            Try
                                'KEINE AHNUNG...
                                If REF.CurREF8 IsNot Nothing Then
                                    Dim node As System.Xml.XmlNode = REF.CurREF8(0)
                                    BRG.nctsSA_Waerung = node.InnerText
                                End If
                            Catch ex As Exception

                            End Try

                            Try
                                'KEINE AHNUNG...
                                If REF.AmoConREF7 IsNot Nothing Then
                                    Dim node As System.Xml.XmlNode = REF.AmoConREF7(0)
                                    BRG.nctsSA_AbgabenBetragFremdWaehrung = node.InnerText
                                End If
                            Catch ex As Exception

                            End Try

                            '--> EUR
                            If BRG.nctsSA_AbgabenBetragFremdWaehrung IsNot Nothing Then
                                If If(BRG.nctsSA_Waerung, "") <> "EUR" Then
                                    Dim betragEUR = VERAG_PROG_ALLGEMEIN.cEZB_Waehrungskurse.EXCHANGE_CURTOEUR(BRG.nctsSA_AbgabenBetragFremdWaehrung, BRG.nctsSA_Waerung, NCTS.ncts_Trans_DatumZeit)
                                    BRG.nctsSA_AbgabenBetrag = If(betragEUR > 0, betragEUR, BRG.nctsSA_AbgabenBetragFremdWaehrung)
                                Else
                                    BRG.nctsSA_AbgabenBetrag = BRG.nctsSA_AbgabenBetragFremdWaehrung
                                End If
                            End If
                            NCTS.ncts_SICHERHEITSANGABEN.Add(BRG)
                        Next
                    End If
                Next
            End If
        End If
        If CC015B.ITI IsNot Nothing AndAlso CC015B.ITI.Count > 0 Then
            If CC015B.ITI.Count > 0 Then NCTS.ncts_SumA_BefoerderungsrouteLand1 = CC015B.ITI(0).CouOfRouCodITI1
            If CC015B.ITI.Count > 1 Then NCTS.ncts_SumA_BefoerderungsrouteLand2 = CC015B.ITI(1).CouOfRouCodITI1
            If CC015B.ITI.Count > 2 Then NCTS.ncts_SumA_BefoerderungsrouteLand3 = CC015B.ITI(2).CouOfRouCodITI1
            If CC015B.ITI.Count > 3 Then NCTS.ncts_SumA_BefoerderungsrouteLand4 = CC015B.ITI(3).CouOfRouCodITI1
            If CC015B.ITI.Count > 4 Then NCTS.ncts_SumA_BefoerderungsrouteLand5 = CC015B.ITI(4).CouOfRouCodITI1
            If CC015B.ITI.Count > 5 Then NCTS.ncts_SumA_BefoerderungsrouteLand6 = CC015B.ITI(5).CouOfRouCodITI1
            If CC015B.ITI.Count > 6 Then NCTS.ncts_SumA_BefoerderungsrouteLand7 = CC015B.ITI(6).CouOfRouCodITI1
            If CC015B.ITI.Count > 7 Then NCTS.ncts_SumA_BefoerderungsrouteLand8 = CC015B.ITI(7).CouOfRouCodITI1
            If CC015B.ITI.Count > 8 Then NCTS.ncts_SumA_BefoerderungsrouteLand9 = CC015B.ITI(8).CouOfRouCodITI1
            If CC015B.ITI.Count > 9 Then NCTS.ncts_SumA_BefoerderungsrouteLand10 = CC015B.ITI(9).CouOfRouCodITI1
        End If


        'Frächter
        If CC015B.CARTRA100 IsNot Nothing Then
            If CC015B.CARTRA100.NamCARTRA121 IsNot Nothing Then NCTS.ncts_SumA_Befoerderer_Name = CC015B.CARTRA100.NamCARTRA121
            If CC015B.CARTRA100.StrAndNumCARTRA254 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_StrasseHausnummer = CC015B.CARTRA100.StrAndNumCARTRA254
            If CC015B.CARTRA100.PosCodCARTRA121 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_PLZ = CC015B.CARTRA100.PosCodCARTRA121
            If CC015B.CARTRA100.CitCARTRA789 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_Ort = CC015B.CARTRA100.CitCARTRA789
            If CC015B.CARTRA100.CouCodCARTRA587 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_Land = CC015B.CARTRA100.CouCodCARTRA587
            If CC015B.CARTRA100.TINCARTRA254 IsNot Nothing Then NCTS.ncts_Hauptverpflichteter_EORI = CC015B.CARTRA100.TINCARTRA254
        End If

        'WARENPOSITIONEN
        If CC015B.GOOITEGDS IsNot Nothing AndAlso CC015B.GOOITEGDS.Count > 0 Then
            For Each GOOITEGDS In CC015B.GOOITEGDS
                Dim POS As New VERAG_PROG_ALLGEMEIN.cNCTS_TR_Warenposition

                If GOOITEGDS.IteNumGDS7 IsNot Nothing Then POS.nctsWP_PositionsNummer = GOOITEGDS.IteNumGDS7
                If GOOITEGDS.ComCodTarCodGDS10 IsNot Nothing Then POS.nctsWP_Warennummer = GOOITEGDS.ComCodTarCodGDS10
                If GOOITEGDS.GooDesGDS23 IsNot Nothing Then POS.nctsWP_Warenbezeichnung = GOOITEGDS.GooDesGDS23
                If GOOITEGDS.GroMasGDS46 IsNot Nothing Then POS.nctsWP_Rohmasse = CDbl(GOOITEGDS.GroMasGDS46)
                If GOOITEGDS.NetMasGDS48 IsNot Nothing Then POS.nctsWP_Eigenmasse = CDbl(GOOITEGDS.NetMasGDS48)

                'Versender
                If GOOITEGDS.TRACONCO2 IsNot Nothing Then
                    If GOOITEGDS.TRACONCO2.NamCO27 IsNot Nothing Then POS.nctsWP_Versender_Name = GOOITEGDS.TRACONCO2.NamCO27
                    If GOOITEGDS.TRACONCO2.StrAndNumCO222 IsNot Nothing Then POS.nctsWP_Versender_StrasseHausnummer = GOOITEGDS.TRACONCO2.StrAndNumCO222
                    If GOOITEGDS.TRACONCO2.PosCodCO223 IsNot Nothing Then POS.nctsWP_Versender_PLZ = GOOITEGDS.TRACONCO2.PosCodCO223
                    If GOOITEGDS.TRACONCO2.CitCO224 IsNot Nothing Then POS.nctsWP_Versender_Ort = GOOITEGDS.TRACONCO2.CitCO224
                    If GOOITEGDS.TRACONCO2.CouCO225 IsNot Nothing Then POS.nctsWP_Versender_Land = GOOITEGDS.TRACONCO2.CouCO225
                    If GOOITEGDS.TRACONCO2.TINCO259 IsNot Nothing Then POS.nctsWP_Versender_EORI = GOOITEGDS.TRACONCO2.TINCO259
                End If

                'Empfänger
                If GOOITEGDS.TRACONCE2 IsNot Nothing Then
                    If GOOITEGDS.TRACONCE2.NamCE27 IsNot Nothing Then POS.nctsWP_Empfaenger_Name = GOOITEGDS.TRACONCE2.NamCE27
                    If GOOITEGDS.TRACONCE2.StrAndNumCE222 IsNot Nothing Then POS.nctsWP_Empfaenger_StrasseHausnummer = GOOITEGDS.TRACONCE2.StrAndNumCE222
                    If GOOITEGDS.TRACONCE2.PosCodCE223 IsNot Nothing Then POS.nctsWP_Empfaenger_PLZ = GOOITEGDS.TRACONCE2.PosCodCE223
                    If GOOITEGDS.TRACONCE2.CitCE224 IsNot Nothing Then POS.nctsWP_Empfaenger_Ort = GOOITEGDS.TRACONCE2.CitCE224
                    If GOOITEGDS.TRACONCE2.CouCE225 IsNot Nothing Then POS.nctsWP_Empfaenger_Land = GOOITEGDS.TRACONCE2.CouCE225
                    If GOOITEGDS.TRACONCE2.TINCE259 IsNot Nothing Then POS.nctsWP_Empfaenger_EORI = GOOITEGDS.TRACONCE2.TINCE259
                End If


                If GOOITEGDS.PACGS2 IsNot Nothing Then
                    For Each PACGS2 In GOOITEGDS.PACGS2
                        Dim PK As New VERAG_PROG_ALLGEMEIN.cNCTS_TR_WarenpositionPackstuecke
                        If PACGS2.NumOfPacGS24 IsNot Nothing Then PK.nctsWpPk_PackstueckeAnzahl = PACGS2.NumOfPacGS24
                        If PACGS2.KinOfPacGS23 IsNot Nothing Then PK.nctsWpPk_Verpackungsart = PACGS2.KinOfPacGS23
                        If PACGS2.MarNumOfPacGS21 IsNot Nothing Then PK.nctsWpPk_ZeichenNummern = PACGS2.MarNumOfPacGS21
                        POS.nctsWP_PACKSTUECKE.Add(PK)
                    Next
                End If
                NCTS.ncts_WARENPOS.Add(POS)
            Next
        End If

    End Function

End Class
