Imports System.Data.SqlClient
Imports System.Reflection

Public Class cNCTS_TR

    Property ncts_Id As Integer
    Property ncts_Partnersystem As Object = Nothing 'DAKOSY_Worker.cDY_Statusliste.S_00
    Property ncts_Status As Object = 0
    Property ncts_Status_KEWILL_Equivalent As Object = 0 'DAKOSY_Worker.cDY_Statusliste.S_00
    Property ncts_dyaArt As String = ""
    Property ncts_dyaAnmID As Integer

    Property ncts_ANR As Object = Nothing
    Property ncts_MRN As Object = Nothing

    Property ncts_Erstellung As DateTime = Now
    Property ncts_Erstellung_SB As Object = Nothing
    Property ncts_LetzteBearbeitung As DateTime = Now
    Property ncts_LetzteBearbeitung_SB As Object = Nothing
    Property ncts_firma As Object = Nothing
    Property ncts_niederlassung As Object = Nothing


    Property ncts_Gestellt As Boolean = False
    Property ncts_GestelltAm As Object = Nothing
    Property ncts_Trans_Partner As Object = Nothing
    Property ncts_Trans_Div1 As Object = Nothing
    Property ncts_Trans_Div2 As Object = Nothing
    Property ncts_Trans_Div3 As Object = Nothing
    Property ncts_Trans_Referenz As Object = Nothing
    Property ncts_Trans_DatumZeit As DateTime = Now
    Property ncts_Trans_Version As Object = Nothing
    Property ncts_NachrichtenSenderTIN As Object = Nothing
    Property ncts_NachrichtenSenderNLNR As Object = Nothing
    Property ncts_NachrichtenempfaengerDST As Object = Nothing

    Property ncts_ObjectName As Object = Nothing
    Property ncts_ObjectAlias As Object = Nothing
    Property ncts_BezugsnummerVorblendung As Object = Nothing
    Property ncts_Bearbeiter As Object = Nothing
    Property ncts_VersendungsLandCode As Object = Nothing
    Property ncts_BestimmungslandCode As Object = Nothing
    Property ncts_ArtAnmeldung As Object = Nothing
    Property ncts_BeladungsOrt As Object = Nothing

    Property ncts_DurchgangszollstelleDienststellnummer1 As Object = Nothing
    Property ncts_DurchgangszollstelleDienststellnummer2 As Object = Nothing
    Property ncts_DurchgangszollstelleDienststellnummer3 As Object = Nothing
    Property ncts_DurchgangszollstelleDienststellnummer4 As Object = Nothing
    Property ncts_DurchgangszollstelleDienststellnummer5 As Object = Nothing
    Property ncts_DurchgangszollstelleDienststellnummer6 As Object = Nothing
    Property ncts_DurchgangszollstelleDienststellnummer7 As Object = Nothing
    Property ncts_DurchgangszollstelleDienststellnummer8 As Object = Nothing
    Property ncts_DurchgangszollstelleDienststellnummer9 As Object = Nothing

    Property ncts_BestimmungsstelleDienststellennummer As Object = Nothing
    Property ncts_AbgangsDienststellennummer As Object = Nothing
    Property ncts_Wiedergestellungsdatum As Object = Nothing
    Property ncts_KzVereinfachtesVerfahren As Object = Nothing
    Property ncts_GesamtRohmasse As Object = Nothing
    Property ncts_GesamtAnzahlPackstuecke As Object = Nothing
    Property ncts_Verschluss_ArtCode As Object = Nothing
    Property ncts_Verschluss_Anzahl As Object = Nothing
    Property ncts_Verschluss_Zeichen1 As Object = Nothing
    Property ncts_Verschluss_Zeichen2 As Object = Nothing
    Property ncts_Verschluss_Zeichen3 As Object = Nothing
    Property ncts_Verschluss_Zeichen4 As Object = Nothing
    Property ncts_Verschluss_Zeichen5 As Object = Nothing
    Property ncts_Verschluss_Zeichen6 As Object = Nothing
    Property ncts_Verschluss_Zeichen7 As Object = Nothing
    Property ncts_Verschluss_Zeichen8 As Object = Nothing
    Property ncts_Verschluss_Zeichen9 As Object = Nothing
    Property ncts_Verschluss_Zeichen10 As Object = Nothing
    Property ncts_Verschluss_Zeichen11 As Object = Nothing
    Property ncts_Verschluss_Zeichen12 As Object = Nothing
    Property ncts_Verschluss_Zeichen13 As Object = Nothing
    Property ncts_Verschluss_Zeichen14 As Object = Nothing
    Property ncts_Verschluss_Zeichen15 As Object = Nothing
    Property ncts_Verschluss_Zeichen16 As Object = Nothing
    Property ncts_Befoerderungsmittel_KennzeichenAbgang As Object = Nothing
    Property ncts_Befoerderungsmittel_SttaszugehoerigkeitAbgangCode As Object = Nothing
    Property ncts_Befoerderungsmittel_VerkehrszweigGrenzueberschreitent As Object = Nothing
    Property ncts_Befoerderungsmittel_ArtGrenzueberschreitung As Object = Nothing
    Property ncts_Befoerderungsmittel_KennzeichenGrenzueberschreitend As Object = Nothing
    Property ncts_Befoerderungsmittel_StaatszugehoerigkeitGrenzueberschreitendCode As Object = Nothing
    Property ncts_Versender_EORI As Object = Nothing
    Property ncts_Versender_NLNR As Object = Nothing
    Property ncts_Versender_TIN As Object = Nothing
    Property ncts_Versender_Name As Object = Nothing
    Property ncts_Versender_StrasseHausnummer As Object = Nothing
    Property ncts_Versender_Ort As Object = Nothing
    Property ncts_Versender_PLZ As Object = Nothing
    Property ncts_Versender_Land As Object = Nothing
    Property ncts_Empfaenger_EORI As Object = Nothing
    Property ncts_Empfaenger_NLNR As Object = Nothing
    Property ncts_Empfaenger_TIN As Object = Nothing
    Property ncts_Empfaenger_Name As Object = Nothing
    Property ncts_Empfaenger_StrasseHausnummer As Object = Nothing
    Property ncts_Empfaenger_Ort As Object = Nothing
    Property ncts_Empfaenger_PLZ As Object = Nothing
    Property ncts_Empfaenger_Land As Object = Nothing
    Property ncts_Hauptverpflichteter_EORI As Object = Nothing
    Property ncts_Hauptverpflichteter_NLNR As Object = Nothing
    Property ncts_Hauptverpflichteter_TIN As Object = Nothing
    Property ncts_Hauptverpflichteter_Name As Object = Nothing
    Property ncts_Hauptverpflichteter_StrasseHausnummer As Object = Nothing
    Property ncts_Hauptverpflichteter_Ort As Object = Nothing
    Property ncts_Hauptverpflichteter_PLZ As Object = Nothing
    Property ncts_Hauptverpflichteter_Land As Object = Nothing
    Property ncts_ZugelassenerEmpfaenger_IDCarnet As Object = Nothing
    Property ncts_ZugelassenerEmpfaenger_BewilligungsnummerVersender As Object = Nothing
    Property ncts_ZugelassenerEmpfaenger_EORI As Object = Nothing
    Property ncts_ZugelassenerEmpfaenger_TIN As Object = Nothing

    Property ncts_SumA_KzSumASicherheit As Object = Nothing
    Property ncts_SumA_KennnummerSendung As Object = Nothing
    Property ncts_SumA_BesondereUmstaende As Object = Nothing
    Property ncts_SumA_NummerBefoerderung As Object = Nothing
    Property ncts_SumA_Ladeort As Object = Nothing
    Property ncts_SumA_Entladeort As Object = Nothing
    Property ncts_SumA_BefoerderungskostenZahlungsweise As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand1 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand2 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand3 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand4 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand5 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand6 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand7 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand8 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand9 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand10 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand11 As Object = Nothing
    Property ncts_SumA_BefoerderungsrouteLand12 As Object = Nothing
    Property ncts_SumA_Versender_EORI As Object = Nothing
    Property ncts_SumA_Versender_NLNR As Object = Nothing
    Property ncts_SumA_Versender_TIN As Object = Nothing
    Property ncts_SumA_Versender_Name As Object = Nothing
    Property ncts_SumA_Versender_StrasseHausnummer As Object = Nothing
    Property ncts_SumA_Versender_Land As Object = Nothing
    Property ncts_SumA_Versender_PLZ As Object = Nothing
    Property ncts_SumA_Versender_Ort As Object = Nothing

    Property ncts_SumA_Empfaenger_EORI As Object = Nothing
    Property ncts_SumA_Empfaenger_NLNR As Object = Nothing
    Property ncts_SumA_Empfaenger_TIN As Object = Nothing
    Property ncts_SumA_Empfaenger_Name As Object = Nothing
    Property ncts_SumA_Empfaenger_StrasseHausnummer As Object = Nothing
    Property ncts_SumA_Empfaenger_Land As Object = Nothing
    Property ncts_SumA_Empfaenger_PLZ As Object = Nothing
    Property ncts_SumA_Empfaenger_Ort As Object = Nothing

    Property ncts_SumA_Befoerderer_EORI As Object = Nothing
    Property ncts_SumA_Befoerderer_NLNR As Object = Nothing
    Property ncts_SumA_Befoerderer_TIN As Object = Nothing
    Property ncts_SumA_Befoerderer_Name As Object = Nothing
    Property ncts_SumA_Befoerderer_StrasseHausnummer As Object = Nothing
    Property ncts_SumA_Befoerderer_Land As Object = Nothing
    Property ncts_SumA_Befoerderer_PLZ As Object = Nothing
    Property ncts_SumA_Befoerderer_Ort As Object = Nothing
    Property ncts_Stammreferenz As Object = Nothing

    Property ncts_GUID As Object = Nothing
    Property ncts_Eroeffnung As Object = Nothing
    Property ncts_Ankunft As Object = Nothing
    Property ncts_Erledigung As Object = Nothing
    Property ncts_AVISO_einarbeitet As Boolean = False

    Property ncts_SICHERHEITSANGABEN As New List(Of cNCTS_TR_Sicherheitsangaben)
    Property ncts_WARENPOS As New List(Of cNCTS_TR_Warenposition)


    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL


    Function GET_SHIPMENTS(Partnersystem, VorpapierArt, VorpapierNr) As List(Of VERAG_PROG_ALLGEMEIN.cVERAG_in_eza_FULL)
        GET_SHIPMENTS = New List(Of VERAG_PROG_ALLGEMEIN.cVERAG_in_eza_FULL)
        Dim dt = SQL.loadDgvBySql("Select [shTr_id] FROM [tblTR_Shipment] where shTr_Partnersystem='" & Partnersystem & "' AND [PrePaperCode]='" & VorpapierArt & "' and  [PrePaperNr]='" & VorpapierNr & "'", "FMZOLL")
        '   MsgBox("Select [shTr_id] FROM [tblTR_Shipment] where shTr_Partnersystem='" & Partnersystem & "' AND [PrePaperCode]='" & VorpapierArt & "' and  [PrePaperNr]='" & VorpapierNr & "'")
        If dt IsNot Nothing Then
            For Each r In dt.Rows
                Dim SH As New VERAG_PROG_ALLGEMEIN.cVERAG_in_eza_FULL(CInt(r("shTr_id")))
                If SH IsNot Nothing Then
                    GET_SHIPMENTS.Add(SH)
                End If
            Next
        End If

    End Function

    Sub New()

    End Sub

    Sub New(ncts_dyaAnmID As Integer, ncts_Erstellung_SB As Integer)
        Me.ncts_dyaAnmID = ncts_dyaAnmID
        Me.ncts_Erstellung_SB = ncts_Erstellung_SB
        Me.ncts_LetzteBearbeitung_SB = ncts_Erstellung_SB
    End Sub

    Sub New(ncts_Id)
        Me.ncts_Id = ncts_Id
        LOAD()
    End Sub

    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Id", ncts_Id, , True, True))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Partnersystem", ncts_Partnersystem))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Status", ncts_Status))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Status_KEWILL_Equivalent", ncts_Status_KEWILL_Equivalent))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_dyaArt", ncts_dyaArt))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_dyaAnmID", ncts_dyaAnmID))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_ANR", ncts_ANR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_MRN", ncts_MRN))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Erstellung", ncts_Erstellung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Erstellung_SB", ncts_Erstellung_SB))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_LetzteBearbeitung", ncts_LetzteBearbeitung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_LetzteBearbeitung_SB", ncts_LetzteBearbeitung_SB))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_firma", ncts_firma))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_niederlassung", ncts_niederlassung))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Gestellt", ncts_Gestellt))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_GestelltAm", ncts_GestelltAm))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Trans_Partner", ncts_Trans_Partner))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Trans_Div1", ncts_Trans_Div1))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Trans_Div2", ncts_Trans_Div2))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Trans_Div3", ncts_Trans_Div3))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Trans_Referenz", ncts_Trans_Referenz))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Trans_DatumZeit", ncts_Trans_DatumZeit))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Trans_Version", ncts_Trans_Version))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_NachrichtenSenderTIN", ncts_NachrichtenSenderTIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_NachrichtenSenderNLNR", ncts_NachrichtenSenderNLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_NachrichtenempfaengerDST", ncts_NachrichtenempfaengerDST))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_ObjectName", ncts_ObjectName))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_ObjectAlias", ncts_ObjectAlias))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_BezugsnummerVorblendung", ncts_BezugsnummerVorblendung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Bearbeiter", ncts_Bearbeiter))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_VersendungsLandCode", ncts_VersendungsLandCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_BestimmungslandCode", ncts_BestimmungslandCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_ArtAnmeldung", ncts_ArtAnmeldung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_BeladungsOrt", ncts_BeladungsOrt))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_DurchgangszollstelleDienststellnummer1", ncts_DurchgangszollstelleDienststellnummer1))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_DurchgangszollstelleDienststellnummer2", ncts_DurchgangszollstelleDienststellnummer2))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_DurchgangszollstelleDienststellnummer3", ncts_DurchgangszollstelleDienststellnummer3))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_DurchgangszollstelleDienststellnummer4", ncts_DurchgangszollstelleDienststellnummer4))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_DurchgangszollstelleDienststellnummer5", ncts_DurchgangszollstelleDienststellnummer5))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_DurchgangszollstelleDienststellnummer6", ncts_DurchgangszollstelleDienststellnummer6))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_DurchgangszollstelleDienststellnummer7", ncts_DurchgangszollstelleDienststellnummer7))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_DurchgangszollstelleDienststellnummer8", ncts_DurchgangszollstelleDienststellnummer8))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_DurchgangszollstelleDienststellnummer9", ncts_DurchgangszollstelleDienststellnummer9))


        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_BestimmungsstelleDienststellennummer", ncts_BestimmungsstelleDienststellennummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_AbgangsDienststellennummer", ncts_AbgangsDienststellennummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Wiedergestellungsdatum", ncts_Wiedergestellungsdatum))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_KzVereinfachtesVerfahren", ncts_KzVereinfachtesVerfahren))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_GesamtRohmasse", ncts_GesamtRohmasse))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_GesamtAnzahlPackstuecke", ncts_GesamtAnzahlPackstuecke))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_ArtCode", ncts_Verschluss_ArtCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Anzahl", ncts_Verschluss_Anzahl))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen1", ncts_Verschluss_Zeichen1))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen2", ncts_Verschluss_Zeichen2))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen3", ncts_Verschluss_Zeichen3))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen4", ncts_Verschluss_Zeichen4))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen5", ncts_Verschluss_Zeichen5))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen6", ncts_Verschluss_Zeichen6))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen7", ncts_Verschluss_Zeichen7))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen8", ncts_Verschluss_Zeichen8))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen9", ncts_Verschluss_Zeichen9))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen10", ncts_Verschluss_Zeichen10))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen11", ncts_Verschluss_Zeichen11))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen12", ncts_Verschluss_Zeichen12))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen13", ncts_Verschluss_Zeichen13))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen14", ncts_Verschluss_Zeichen14))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen15", ncts_Verschluss_Zeichen15))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Verschluss_Zeichen16", ncts_Verschluss_Zeichen16))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Befoerderungsmittel_KennzeichenAbgang", ncts_Befoerderungsmittel_KennzeichenAbgang))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Befoerderungsmittel_SttaszugehoerigkeitAbgangCode", ncts_Befoerderungsmittel_SttaszugehoerigkeitAbgangCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Befoerderungsmittel_VerkehrszweigGrenzueberschreitent", ncts_Befoerderungsmittel_VerkehrszweigGrenzueberschreitent))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Befoerderungsmittel_ArtGrenzueberschreitung", ncts_Befoerderungsmittel_ArtGrenzueberschreitung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Befoerderungsmittel_KennzeichenGrenzueberschreitend", ncts_Befoerderungsmittel_KennzeichenGrenzueberschreitend))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Befoerderungsmittel_StaatszugehoerigkeitGrenzueberschreitendCode", ncts_Befoerderungsmittel_StaatszugehoerigkeitGrenzueberschreitendCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Versender_EORI", ncts_Versender_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Versender_NLNR", ncts_Versender_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Versender_TIN", ncts_Versender_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Versender_Name", ncts_Versender_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Versender_StrasseHausnummer", ncts_Versender_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Versender_Ort", ncts_Versender_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Versender_PLZ", ncts_Versender_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Versender_Land", ncts_Versender_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Empfaenger_EORI", ncts_Empfaenger_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Empfaenger_NLNR", ncts_Empfaenger_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Empfaenger_TIN", ncts_Empfaenger_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Empfaenger_Name", ncts_Empfaenger_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Empfaenger_StrasseHausnummer", ncts_Empfaenger_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Empfaenger_Ort", ncts_Empfaenger_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Empfaenger_PLZ", ncts_Empfaenger_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Empfaenger_Land", ncts_Empfaenger_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Hauptverpflichteter_EORI", ncts_Hauptverpflichteter_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Hauptverpflichteter_NLNR", ncts_Hauptverpflichteter_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Hauptverpflichteter_TIN", ncts_Hauptverpflichteter_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Hauptverpflichteter_Name", ncts_Hauptverpflichteter_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Hauptverpflichteter_StrasseHausnummer", ncts_Hauptverpflichteter_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Hauptverpflichteter_Ort", ncts_Hauptverpflichteter_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Hauptverpflichteter_PLZ", ncts_Hauptverpflichteter_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Hauptverpflichteter_Land", ncts_Hauptverpflichteter_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_ZugelassenerEmpfaenger_IDCarnet", ncts_ZugelassenerEmpfaenger_IDCarnet))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_ZugelassenerEmpfaenger_BewilligungsnummerVersender", ncts_ZugelassenerEmpfaenger_BewilligungsnummerVersender))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_ZugelassenerEmpfaenger_EORI", ncts_ZugelassenerEmpfaenger_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_ZugelassenerEmpfaenger_TIN", ncts_ZugelassenerEmpfaenger_TIN))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_KzSumASicherheit", ncts_SumA_KzSumASicherheit))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_KennnummerSendung", ncts_SumA_KennnummerSendung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_NummerBefoerderung", ncts_SumA_NummerBefoerderung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BesondereUmstaende", ncts_SumA_BesondereUmstaende))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Ladeort", ncts_SumA_Ladeort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Entladeort", ncts_SumA_Entladeort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungskostenZahlungsweise", ncts_SumA_BefoerderungskostenZahlungsweise))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand1", ncts_SumA_BefoerderungsrouteLand1))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand2", ncts_SumA_BefoerderungsrouteLand2))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand3", ncts_SumA_BefoerderungsrouteLand3))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand4", ncts_SumA_BefoerderungsrouteLand4))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand5", ncts_SumA_BefoerderungsrouteLand5))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand6", ncts_SumA_BefoerderungsrouteLand6))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand7", ncts_SumA_BefoerderungsrouteLand7))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand8", ncts_SumA_BefoerderungsrouteLand8))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand9", ncts_SumA_BefoerderungsrouteLand9))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand10", ncts_SumA_BefoerderungsrouteLand10))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand11", ncts_SumA_BefoerderungsrouteLand11))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_BefoerderungsrouteLand12", ncts_SumA_BefoerderungsrouteLand12))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Versender_EORI", ncts_SumA_Versender_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Versender_NLNR", ncts_SumA_Versender_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Versender_TIN", ncts_SumA_Versender_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Versender_Name", ncts_SumA_Versender_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Versender_StrasseHausnummer", ncts_SumA_Versender_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Versender_Land", ncts_SumA_Versender_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Versender_PLZ", ncts_SumA_Versender_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Versender_Ort", ncts_SumA_Versender_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Empfaenger_EORI", ncts_SumA_Empfaenger_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Empfaenger_NLNR", ncts_SumA_Empfaenger_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Empfaenger_TIN", ncts_SumA_Empfaenger_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Empfaenger_Name", ncts_SumA_Empfaenger_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Empfaenger_StrasseHausnummer", ncts_SumA_Empfaenger_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Empfaenger_Land", ncts_SumA_Empfaenger_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Empfaenger_PLZ", ncts_SumA_Empfaenger_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Empfaenger_Ort", ncts_SumA_Empfaenger_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Befoerderer_EORI", ncts_SumA_Befoerderer_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Befoerderer_NLNR", ncts_SumA_Befoerderer_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Befoerderer_TIN", ncts_SumA_Befoerderer_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Befoerderer_Name", ncts_SumA_Befoerderer_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Befoerderer_StrasseHausnummer", ncts_SumA_Befoerderer_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Befoerderer_Land", ncts_SumA_Befoerderer_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Befoerderer_PLZ", ncts_SumA_Befoerderer_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_SumA_Befoerderer_Ort", ncts_SumA_Befoerderer_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Stammreferenz", ncts_Stammreferenz))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_GUID", ncts_GUID))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Eroeffnung", ncts_Eroeffnung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Ankunft", ncts_Ankunft))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Erledigung", ncts_Erledigung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_AVISO_einarbeitet", ncts_AVISO_einarbeitet))

        Return list
    End Function

    Public Function UPDATE_STATUS(status) As Boolean
        Me.ncts_Status = status
        Return Me.SAVE
    End Function

    Public Function SAVE(Optional errHinweis = "") As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

        Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblNCTS_TR WITH(updlock,serializable) WHERE ncts_Id=@ncts_Id) " &
                       " BEGIN " & getUpdateCmd() & " END " &
                       " Else " &
                       " BEGIN " & getInsertCmd() & " END " &
                       " commit tran "

        Dim ncts_IdTMP = ncts_Id
        ncts_IdTMP = SQL.doSQLVarListID(ncts_IdTMP, sqlstr, "FMZOLL", , list, , errHinweis)
        If ncts_Id <= 0 Then ncts_Id = ncts_IdTMP
        Return ncts_Id > 0
    End Function

    Public Function SAVE_ALL(Optional errHinweis = "") As Boolean
        If Not SAVE(errHinweis) Then Return False
        If Not SAVE_Warenposition() Or Not SAVE_Sicherheitsangaben() Then Return False

        Return True
    End Function

    Public Function LOAD(Optional loadALL As Boolean = True) As Boolean
        Try
            LOAD = False
            If loadALL Then
                ncts_SICHERHEITSANGABEN.Clear()
                ncts_WARENPOS.Clear()
            End If
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblNCTS_TR WHERE ncts_Id=@ncts_Id  ", conn)
                    cmd.Parameters.AddWithValue("@ncts_Id", ncts_Id)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In getParameterList()
                            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(Me, Nothing)
                            Else
                                propInfo.SetValue(Me, dr.Item(li.Text))
                            End If

                        Next
                        If loadALL Then
                            LOAD_Sicherheitsangaben()
                            LOAD_Warenposition()
                        End If
                        LOAD = True
                    End If
                    dr.Close()

                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return LOAD
    End Function




    Shared Function LOADByAnmIDFull(ncts_dyaAnmID As String, loadALL As Boolean) As cNCTS_TR
        Try
            Dim NCTS As New cNCTS_TR
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_dyaAnmID=@ncts_dyaAnmID  ", conn)
                    cmd.Parameters.AddWithValue("@ncts_dyaAnmID", ncts_dyaAnmID)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In NCTS.getParameterList()
                            Dim propInfo As PropertyInfo = NCTS.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(NCTS, Nothing)
                            Else
                                propInfo.SetValue(NCTS, dr.Item(li.Text))
                            End If

                        Next
                        If loadALL Then
                            NCTS.LOAD_Sicherheitsangaben()
                            NCTS.LOAD_Warenposition()
                        End If

                        dr.Close()
                        Return NCTS
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return Nothing
    End Function

    Shared Function UPDATE_StatusById(ncts_Id As Integer, status As Integer) As String
        If ncts_Id > 0 Then
            Try
                Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
                list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Id", ncts_Id, , True))
                list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Status_KEWILL_Equivalent", status, , True))
                list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Status", status, , True))
                'dy_Status_KEWILL_Equivalent = status
                'dy_Status = status
                Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

                Return SQL.doSQLVarList(" UPDATE [tblNCTS_TR] SET ncts_Status_KEWILL_Equivalent=@ncts_Status_KEWILL_Equivalent,ncts_Status=@ncts_Status WHERE ncts_Id=@ncts_Id ", "FMZOLL", , list)

            Catch ex As Exception
                MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
            End Try
        End If
        Return ""
    End Function


    Public Function LOADByAnmID(ncts_dyaAnmID As String, loadALL As Boolean) As Boolean
        Try
            LOADByAnmID = False
            If loadALL Then
                ncts_SICHERHEITSANGABEN.Clear()
                ncts_WARENPOS.Clear()
            End If
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_dyaAnmID=@ncts_dyaAnmID  ", conn)
                    cmd.Parameters.AddWithValue("@ncts_dyaAnmID", ncts_dyaAnmID)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In getParameterList()
                            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(Me, Nothing)
                            Else
                                propInfo.SetValue(Me, dr.Item(li.Text))
                            End If

                        Next
                        If loadALL Then
                            LOAD_Sicherheitsangaben()
                            LOAD_Warenposition()
                        End If
                        LOADByAnmID = True
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return LOADByAnmID
    End Function

    Shared Function LOADByBezugsNr_or_GUID_or_MRN(bezugsNr As String, GUID As String, MRN As String, loadALL As Boolean, Optional checkValidStatus As Boolean = False, Optional Partnersystem As String = "") As cNCTS_TR
        LOADByBezugsNr_or_GUID_or_MRN = Nothing

        If bezugsNr <> "" Then LOADByBezugsNr_or_GUID_or_MRN = LOADByBezugsNr(bezugsNr, loadALL, checkValidStatus, Partnersystem)

        If LOADByBezugsNr_or_GUID_or_MRN Is Nothing Then
            If GUID <> "" Then LOADByBezugsNr_or_GUID_or_MRN = LOADByGUID(GUID, loadALL, checkValidStatus, Partnersystem)
        End If
        If LOADByBezugsNr_or_GUID_or_MRN Is Nothing Then
            If MRN <> "" Then LOADByBezugsNr_or_GUID_or_MRN = LOADByMRN(MRN, loadALL, checkValidStatus, Partnersystem)
        End If
    End Function


    Shared Function LOADByMRN(MRN As String, loadALL As Boolean, Optional checkValidStatus As Boolean = False, Optional Partnersystem As String = "") As cNCTS_TR
        Try
            Dim NCTS As New cNCTS_TR
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                '    Using cmd As New SqlCommand("SELECT TOP 1 * FROM (SELECT * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE @bezugsNr " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & " ) AS T order by ncts_status desc, (SELECT top 1 dySt_ts  FROM [tblDakosy_Statusmeldungen] WHERE ncts_dyaAnmID=ncts_dyaAnmID order by dySt_ts desc)  desc,ncts_LetzteBearbeitung desc ", conn)
                'Using cmd As New SqlCommand("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE @bezugsNr " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & " order by ncts_status desc, (SELECT top 1 dySt_ts  FROM [tblDakosy_Statusmeldungen] WHERE ncts_dyaAnmID=ncts_dyaAnmID order by dySt_ts desc)  desc,ncts_LetzteBearbeitung desc ", conn)
                Using cmd As New SqlCommand("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_MRN LIKE @MRN " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & If(Partnersystem <> "", " AND ncts_Partnersystem ='" & Partnersystem & "' ", "") & " order by ncts_LetzteBearbeitung desc", conn)
                    'MsgBox("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE " & bezugsNr & " " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & " order by ncts_status desc, (SELECT top 1 dySt_ts  FROM [tblDakosy_Statusmeldungen] inner join tblDakosy_Zollanmeldungen on dy_id = dySt_dyId WHERE ncts_dyaAnmID=dy_id order by dySt_ts desc)  desc,ncts_LetzteBearbeitung desc ")
                    cmd.Parameters.AddWithValue("@MRN", MRN)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In NCTS.getParameterList()
                            Dim propInfo As PropertyInfo = NCTS.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(NCTS, Nothing)
                            Else
                                propInfo.SetValue(NCTS, dr.Item(li.Text))
                            End If

                        Next
                        If loadALL Then
                            NCTS.LOAD_Sicherheitsangaben()
                            NCTS.LOAD_Warenposition()
                        End If

                        dr.Close()
                        Return NCTS
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return Nothing

    End Function
    Shared Function LOADByBezugsNr(bezugsNr As String, loadALL As Boolean, Optional checkValidStatus As Boolean = False, Optional Partnersystem As String = "") As cNCTS_TR
        Try
            Dim NCTS As New cNCTS_TR
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                '    Using cmd As New SqlCommand("SELECT TOP 1 * FROM (SELECT * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE @bezugsNr " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & " ) AS T order by ncts_status desc, (SELECT top 1 dySt_ts  FROM [tblDakosy_Statusmeldungen] WHERE ncts_dyaAnmID=ncts_dyaAnmID order by dySt_ts desc)  desc,ncts_LetzteBearbeitung desc ", conn)
                'Using cmd As New SqlCommand("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE @bezugsNr " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & " order by ncts_status desc, (SELECT top 1 dySt_ts  FROM [tblDakosy_Statusmeldungen] WHERE ncts_dyaAnmID=ncts_dyaAnmID order by dySt_ts desc)  desc,ncts_LetzteBearbeitung desc ", conn)
                Using cmd As New SqlCommand("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE @bezugsNr " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & If(Partnersystem <> "", " AND ncts_Partnersystem ='" & Partnersystem & "' ", "") & " order by ncts_LetzteBearbeitung desc", conn)
                    '    MsgBox("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE '" & bezugsNr & "' " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & If(Partnersystem <> "", " AND ncts_Partnersystem ='" & Partnersystem & "' ", "") & " order by ncts_LetzteBearbeitung desc")
                    cmd.Parameters.AddWithValue("@bezugsNr", bezugsNr)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In NCTS.getParameterList()
                            Dim propInfo As PropertyInfo = NCTS.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(NCTS, Nothing)
                            Else
                                propInfo.SetValue(NCTS, dr.Item(li.Text))
                            End If

                        Next
                        If loadALL Then
                            NCTS.LOAD_Sicherheitsangaben()
                            NCTS.LOAD_Warenposition()
                        End If

                        dr.Close()
                        Return NCTS
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return Nothing
    End Function

    Shared Function LOADByGUID(GUID As String, loadALL As Boolean, Optional checkValidStatus As Boolean = False, Optional Partnersystem As String = "") As cNCTS_TR
        Try
            Dim NCTS As New cNCTS_TR
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                '    Using cmd As New SqlCommand("SELECT TOP 1 * FROM (SELECT * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE @bezugsNr " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & " ) AS T order by ncts_status desc, (SELECT top 1 dySt_ts  FROM [tblDakosy_Statusmeldungen] WHERE ncts_dyaAnmID=ncts_dyaAnmID order by dySt_ts desc)  desc,ncts_LetzteBearbeitung desc ", conn)
                'Using cmd As New SqlCommand("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE @bezugsNr " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & " order by ncts_status desc, (SELECT top 1 dySt_ts  FROM [tblDakosy_Statusmeldungen] WHERE ncts_dyaAnmID=ncts_dyaAnmID order by dySt_ts desc)  desc,ncts_LetzteBearbeitung desc ", conn)
                Using cmd As New SqlCommand("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_GUID LIKE @GUID " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & If(Partnersystem <> "", " AND ncts_Partnersystem ='" & Partnersystem & "' ", "") & " order by ncts_LetzteBearbeitung desc", conn)
                    'MsgBox("SELECT TOP 1 * FROM tblNCTS_TR WHERE ncts_ObjectName LIKE " & bezugsNr & " " & If(checkValidStatus, " AND ncts_status BETWEEN 40 and 90 ", "") & " order by ncts_status desc, (SELECT top 1 dySt_ts  FROM [tblDakosy_Statusmeldungen] inner join tblDakosy_Zollanmeldungen on dy_id = dySt_dyId WHERE ncts_dyaAnmID=dy_id order by dySt_ts desc)  desc,ncts_LetzteBearbeitung desc ")
                    cmd.Parameters.AddWithValue("@GUID", GUID)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In NCTS.getParameterList()
                            Dim propInfo As PropertyInfo = NCTS.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(NCTS, Nothing)
                            Else
                                propInfo.SetValue(NCTS, dr.Item(li.Text))
                            End If

                        Next
                        If loadALL Then
                            NCTS.LOAD_Sicherheitsangaben()
                            NCTS.LOAD_Warenposition()
                        End If

                        dr.Close()
                        Return NCTS
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return Nothing
    End Function


    Public Function UPDATE_Status(status As Integer) As String
        If ncts_Id > 0 Then
            Try
                Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
                list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Id", ncts_Id, , True))
                list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Status", status, , True))
                list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Status_KEWILL_Equivalent", status, , True))
                ncts_Status = status
                ncts_Status_KEWILL_Equivalent = status
                Return SQL.doSQLVarList(" UPDATE [tblNCTS_TR] SET ncts_Status=@ncts_Status WHERE ncts_Id=@ncts_Id ", "FMZOLL", , list)

            Catch ex As Exception
                MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
            End Try
        End If
        Return ""
    End Function


    Public Function UPDATE_AVISO_Einarbeitet(ncts_AVISO_einarbeitet As Boolean) As String
        If ncts_Id > 0 Then
            Try

                Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
                list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_Id", ncts_Id, , True))
                list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ncts_AVISO_einarbeitet", ncts_AVISO_einarbeitet))
                ncts_AVISO_einarbeitet = ncts_AVISO_einarbeitet
                Return SQL.doSQLVarList(" UPDATE [tblNCTS_TR] SET ncts_AVISO_einarbeitet=@ncts_AVISO_einarbeitet WHERE ncts_Id=@ncts_Id ", "FMZOLL", , list)

            Catch ex As Exception
                MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
            End Try
        End If
        Return ""
    End Function

    Public Function getUpdateCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

            Dim str As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            Return (" UPDATE [tblNCTS_TR] SET " & str & " WHERE ncts_Id=@ncts_Id ")

        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function


    Public Function getInsertCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblNCTS_TR  (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function

    Public Sub LOAD_Sicherheitsangaben()
        Try
            ncts_SICHERHEITSANGABEN.Clear()
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblNCTS_TR_Sicherheitsangaben WHERE nctsSA_NctsId=@ncts_Id  ", conn)
                    cmd.Parameters.AddWithValue("@ncts_Id", Me.ncts_Id)
                    Dim dr = cmd.ExecuteReader()
                    While dr.Read
                        Dim l As New cNCTS_TR_Sicherheitsangaben
                        For Each i In l.getParameterList()
                            Dim propInfo As PropertyInfo = l.GetType.GetProperty(i.Scalarvariable)
                            If dr.Item(i.Text) Is DBNull.Value Then
                                propInfo.SetValue(l, Nothing)
                            Else
                                propInfo.SetValue(l, dr.Item(i.Text))
                            End If
                        Next
                        ncts_SICHERHEITSANGABEN.Add(l)
                    End While
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
    End Sub

    Public Sub LOAD_Warenposition()
        Try
            ncts_WARENPOS.Clear()
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblNCTS_TR_Warenposition WHERE nctsWP_NctsId=@ncts_Id  ", conn)
                    cmd.Parameters.AddWithValue("@ncts_Id", Me.ncts_Id)
                    Dim dr = cmd.ExecuteReader()
                    While dr.Read
                        Dim l As New cNCTS_TR_Warenposition()
                        For Each i In l.getParameterList()
                            Dim propInfo As PropertyInfo = l.GetType.GetProperty(i.Scalarvariable)
                            If dr.Item(i.Text) Is DBNull.Value Then
                                propInfo.SetValue(l, Nothing)
                            Else
                                propInfo.SetValue(l, dr.Item(i.Text))
                            End If
                        Next
                        l.LOAD_WarenpositionPackstuecke()
                        'l.LOAD_WarenpositionUnterlagen()
                        ncts_WARENPOS.Add(l)
                    End While
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
    End Sub


    Public Shared Function get_Warenposition(ncts_Id As Integer, Optional loadAll As Boolean = False) As List(Of cNCTS_TR_Warenposition)
        Try
            Dim ncts_WARENPOS As New List(Of cNCTS_TR_Warenposition)
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblNCTS_TR_Warenposition WHERE nctsWP_NctsId=@ncts_Id  ", conn)
                    cmd.Parameters.AddWithValue("@ncts_Id", ncts_Id)
                    Dim dr = cmd.ExecuteReader()
                    While dr.Read
                        Dim l As New cNCTS_TR_Warenposition()
                        For Each i In l.getParameterList()
                            Dim propInfo As PropertyInfo = l.GetType.GetProperty(i.Scalarvariable)
                            If dr.Item(i.Text) Is DBNull.Value Then
                                propInfo.SetValue(l, Nothing)
                            Else
                                propInfo.SetValue(l, dr.Item(i.Text))
                            End If
                        Next
                        l.LOAD_WarenpositionPackstuecke()
                        ' l.LOAD_WarenpositionUnterlagen()
                        ncts_WARENPOS.Add(l)
                    End While
                    dr.Close()
                End Using
            End Using
            Return ncts_WARENPOS
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return Nothing
    End Function

    Function DELETE_Warenpositionen() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
        Dim sqlstr = " DELETE FROM [tblNCTS_TR_Warenposition] WHERE nctsWP_NctsId=" & Me.ncts_Id & " "
        '  MsgBox(sqlstr)
        Return SQL.doSQL(sqlstr, "FMZOLL")
    End Function

    Function DELETE_WarenpositionPackstuecke() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
        Dim sqlstr = " DELETE FROM [tblNCTS_TR_WarenpositionPackstuecke] WHERE nctsWpPk_NctsId=" & Me.ncts_Id & " "
        Return SQL.doSQL(sqlstr, "FMZOLL")
    End Function

    'Function DELETE_WarenpositionUnterlagen() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
    '    Dim sqlstr = " DELETE FROM [tblNCTS_TR_WarenpositionVorgelegteUnterlagen] WHERE nctsWpUl_NctsId =" & Me.ncts_Id & " "
    '    Return SQL.doSQL(sqlstr, "FMZOLL")
    'End Function

    Public Function SAVE_Warenposition() As Boolean
        'Zuserst alle OffertenPos von dem Offert löschen
        If DELETE_Warenpositionen() And DELETE_WarenpositionPackstuecke() Then 'And DELETE_WarenpositionUnterlagen() Then
            'jetzt die Standartofferten  einfügen
            For Each p In ncts_WARENPOS
                p.nctsWP_NctsId = ncts_Id
                If p.INSERT() Then
                    p.INSERT_WarenpositionPackstuecke(p.nctsWP_Id, Me.ncts_Id)
                    'p.INSERT_WarenpositionUnterlagen(p.nctsWP_Id, Me.ncts_Id)
                Else
                    Return False
                End If
            Next
        Else
            Return False
        End If

        Return True
    End Function

    Function DELETE_Sicherheitsangaben() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
        Dim sqlstr = " DELETE FROM [tblNCTS_TR_Sicherheitsangaben] WHERE nctsSA_NctsId=" & Me.ncts_Id & " "
        Return SQL.doSQL(sqlstr, "FMZOLL")
    End Function

    Public Function SAVE_Sicherheitsangaben() As Boolean
        'Zuserst alle OffertenPos von dem Offert löschen
        If DELETE_Sicherheitsangaben() Then
            'jetzt die Standartofferten  einfügen
            For Each p In ncts_SICHERHEITSANGABEN
                p.nctsSA_NctsId = ncts_Id
                If Not p.INSERT() Then
                    Return False
                End If
            Next
        Else
            Return False
        End If
        Return True
    End Function

    Function countSpedbuchEntrys(filiale, ncts) As Integer
        If If(ncts, "") = "" Then Return 0
        Return SQL.getValueTxtBySqlVarList("SELECT isnull(count(*),0) FROM Speditionsbuch WHERE [FilialenNr]='" & filiale & "' AND AtlasBezNrNCTS='" & ncts & "'", "FMZOLL")
    End Function



    Function countSpedbuchEntrysFilialeAbf(filiale, abfertigungsnummer) As Integer
        If If(abfertigungsnummer, "") = "" Then Return 0
        Return SQL.getValueTxtBySqlVarList("SELECT isnull(count(*),0) FROM Speditionsbuch WHERE [FilialenNr]='" & filiale & "' AND AbfertigungsNr='" & abfertigungsnummer & "'", "FMZOLL")
    End Function





    Shared Function getFiliale(ByVal bezugsNr, ByRef filialeBez) As String
        getFiliale = ""
        If If(bezugsNr, "").ToString.Length > 4 Then
            Select Case bezugsNr.ToString.Substring(0, 4)
                Case "4803" : Return bezugsNr.ToString.Substring(0, 4) '...... derzeit nur 4803
                Case "4811" : Return bezugsNr.ToString.Substring(0, 4) '...... derzeit nur 4803
                Case "5003" : Return bezugsNr.ToString.Substring(0, 4) '...... derzeit nur 4803
                Case "5103" : Return bezugsNr.ToString.Substring(0, 4) '...... derzeit nur 4803
                Case "5303" : Return bezugsNr.ToString.Substring(0, 4) '...... derzeit nur 4803
                Case "5501", "5601", "5701", "5801" : Return bezugsNr.ToString.Substring(0, 4) '...... derzeit nur 4803
                Case Else
                    If IsNumeric(bezugsNr.ToString.Substring(0, 4)) Then Return bezugsNr.ToString.Substring(0, 4)    'Case Else : Return bezugsNr.ToString.Substring(0, 4) '...... derzeit nur 4803
                    'Case "4801", "4803", "4805", "4807", "4811", "5003", "5103", "5303" : Return bezugsNr.ToString.Substring(0, 4) ...... derzeit nur 4803
                    'filialeBez SUB, NKD, WAI,.-..
            End Select
        End If
    End Function


    Shared Function getAbfertigungsnummer(ByVal bezugsNr) As String
        getAbfertigungsnummer = ""
        If If(bezugsNr, "").ToString.Length > 5 Then

            Dim abf = ""
            For Each s In bezugsNr.ToString.Substring(5)
                If Not IsNumeric(s) Then Exit For
                abf &= s
            Next


            If IsNumeric(abf) Then
                If CLng(abf) < 99000000 Then ' wenn zu groß, fehlerhaft
                    If CLng(abf) > 18000000 And CLng(abf) < 99000000 Then
                        Return abf
                    Else
                        Return "18" & CInt(abf).ToString("000000")
                    End If
                End If
            End If
        End If
        Return ""
    End Function
    Sub getFilialeAbfertigungsnummerFromSendung(ByRef filiale, ByRef abfertigungsnummer, dy_SendungsId)
        If dy_SendungsId IsNot Nothing AndAlso IsNumeric(dy_SendungsId) Then
            Dim SND As New VERAG_PROG_ALLGEMEIN.cSendungen(dy_SendungsId)
            If SND IsNot Nothing Then
                If SND.FilialenNr > 0 Then filiale = SND.FilialenNr
                If SND.AbfertigungsNr > 0 Then abfertigungsnummer = SND.AbfertigungsNr
            End If
        End If
    End Sub




    Shared Function getAdresseFromEORI(EORI As String, EORI_NL As String, SQL As VERAG_PROG_ALLGEMEIN.SQL, Firma As String)
        If EORI Is Nothing Then Return Nothing
        If If(EORI, "") <> "" Then
            Dim kdNrTmp = SQL.getFMZOLLKdNrFromEORI(EORI, EORI_NL, Firma)
            If IsNumeric(kdNrTmp) Then
                Dim ADRESSE As New VERAG_PROG_ALLGEMEIN.cAdressen(kdNrTmp)
                Return ADRESSE
            End If
        End If
        Return Nothing
    End Function

End Class



Public Class cNCTS_TR_Sicherheitsangaben

    Property nctsSA_Id As Integer
    Property nctsSA_NctsId As Object = Nothing
    Property nctsSA_ArtCode As Object = Nothing
    Property nctsSA_BezeichnungBescheinigun As Object = Nothing
    Property nctsSA_AbgabenBetrag As Object = Nothing
    Property nctsSA_AbgabenBetragFremdWaehrung As Object = Nothing
    Property nctsSA_GRN As Object = Nothing
    Property nctsSA_Waerung As Object = Nothing
    Property nctsSA_Zugriffcode As Object = Nothing
    Property nctsSA_TIN As Object = Nothing


    'Public selButton As Object = Nothing ' Für die GUI
    'Public SA_OBJECT As Object = Nothing ' Für die GUI

    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    Sub New()
    End Sub

    'Sub New(nctsSA_Id)
    '    Me.nctsSA_Id = nctsSA_Id
    ' LOAD()
    ' End Sub


    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_Id", nctsSA_Id, , True, True))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_NctsId", nctsSA_NctsId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_ArtCode", nctsSA_ArtCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_BezeichnungBescheinigun", nctsSA_BezeichnungBescheinigun))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_AbgabenBetrag", nctsSA_AbgabenBetrag))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_GRN", nctsSA_GRN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_AbgabenBetragFremdWaehrung", nctsSA_AbgabenBetragFremdWaehrung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_Waerung", nctsSA_Waerung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_Zugriffcode", nctsSA_Zugriffcode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsSA_TIN", nctsSA_TIN))

        Return list
    End Function


    Public Function INSERT() As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
        'Return SQL.doSQLVarList(getInsertCmd, "FMZOLL", , list)
        nctsSA_Id = SQL.doSQLVarListID(nctsSA_Id, getInsertCmd, "FMZOLL", , list)
        Return nctsSA_Id > 0
    End Function

    Public Function getInsertCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblNCTS_TR_Sicherheitsangaben  (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return ""
    End Function

End Class


Public Class cNCTS_TR_Warenposition
    Property nctsWP_Id As Integer
    Property nctsWP_NctsId As Integer
    Property nctsWP_PositionsNummer As Object = Nothing
    Property nctsWP_Warennummer As Object = Nothing
    Property nctsWP_ArtAnmeldungPositionCode As Object = Nothing
    Property nctsWP_Warenbezeichnung As Object = Nothing
    Property nctsWP_Warenwert As Object = Nothing
    Property nctsWP_WarenwertWaehrung As Object = Nothing
    Property nctsWP_SchaetzKz As Object = Nothing
    Property nctsWP_WarenwertProzent As Object = Nothing
    Property nctsWP_VersendungslandPositionCode As Object = Nothing
    Property nctsWP_BestimmungslandPositionCode As Object = Nothing
    Property nctsWP_Rohmasse As Object = Nothing
    Property nctsWP_Eigenmasse As Object = Nothing


    Property nctsWP_VorpapierTyp As Object = Nothing
    Property nctsWP_VorpapierReferenz1 As Object = Nothing
    Property nctsWP_VorpapierZusatz1 As Object = Nothing
    Property nctsWP_VorpapierReferenz2 As Object = Nothing
    Property nctsWP_VorpapierZusatz2 As Object = Nothing
    Property nctsWP_VorpapierReferenz3 As Object = Nothing
    Property nctsWP_VorpapierZusatz3 As Object = Nothing
    Property nctsWP_VorpapierReferenz4 As Object = Nothing
    Property nctsWP_VorpapierZusatz4 As Object = Nothing
    Property nctsWP_VorpapierReferenz5 As Object = Nothing
    Property nctsWP_VorpapierZusatz5 As Object = Nothing
    Property nctsWP_VorpapierReferenz6 As Object = Nothing
    Property nctsWP_VorpapierZusatz6 As Object = Nothing
    Property nctsWP_VorpapierReferenz7 As Object = Nothing
    Property nctsWP_VorpapierZusatz7 As Object = Nothing
    Property nctsWP_VorpapierReferenz8 As Object = Nothing
    Property nctsWP_VorpapierZusatz8 As Object = Nothing
    Property nctsWP_VorpapierReferenz9 As Object = Nothing
    Property nctsWP_VorpapierZusatz9 As Object = Nothing



    Property nctsWP_BesondereVermeke_ExportAusEU As Object = Nothing
    Property nctsWP_BesondereVermeke_ExportAusLand As Object = Nothing
    Property nctsWP_BesondereVermeke_Export As Object = Nothing

    Property nctsWP_BesondereVermeke_ExportBeschraenkung As Object = Nothing
    Property nctsWP_BesondereVermeke_ExportAbgaben As Object = Nothing
    Property nctsWP_BesondereVermeke_Vermerk As Object = Nothing
    Property nctsWP_BesondereVermeke_Kz10600 As Object = Nothing


    Property nctsWP_Versender_EORI As Object = Nothing
    Property nctsWP_Versender_NLNR As Object = Nothing
    Property nctsWP_Versender_TIN As Object = Nothing
    Property nctsWP_Versender_Name As Object = Nothing
    Property nctsWP_Versender_StrasseHausnummer As Object = Nothing
    Property nctsWP_Versender_Ort As Object = Nothing
    Property nctsWP_Versender_PLZ As Object = Nothing
    Property nctsWP_Versender_Land As Object = Nothing
    Property nctsWP_Empfaenger_EORI As Object = Nothing
    Property nctsWP_Empfaenger_NLNR As Object = Nothing
    Property nctsWP_Empfaenger_TIN As Object = Nothing
    Property nctsWP_Empfaenger_Name As Object = Nothing
    Property nctsWP_Empfaenger_StrasseHausnummer As Object = Nothing
    Property nctsWP_Empfaenger_Ort As Object = Nothing
    Property nctsWP_Empfaenger_PLZ As Object = Nothing
    Property nctsWP_Empfaenger_Land As Object = Nothing
    Property nctsWP_SumAKennnummerSendung As Object = Nothing
    Property nctsWP_SumABefoerderungskostenZahlungsweise As Object = Nothing
    Property nctsWP_SumAUNGefahrgutnummer As Object = Nothing
    Property nctsWP_SumAVersender_EORI As Object = Nothing
    Property nctsWP_SumAVersender_NLNR As Object = Nothing
    Property nctsWP_SumAVersender_TIN As Object = Nothing
    Property nctsWP_SumAVersender_Name As Object = Nothing
    Property nctsWP_SumAVersender_StrasseHausnummer As Object = Nothing
    Property nctsWP_SumAVersender_Ort As Object = Nothing
    Property nctsWP_SumAVersender_PLZ As Object = Nothing
    Property nctsWP_SumAVersender_Land As Object = Nothing
    Property nctsWP_SumAEmpfaenger_EORI As Object = Nothing
    Property nctsWP_SumAEmpfaenger_NLNR As Object = Nothing
    Property nctsWP_SumAEmpfaenger_TIN As Object = Nothing
    Property nctsWP_SumAEmpfaenger_Name As Object = Nothing
    Property nctsWP_SumAEmpfaenger_StrasseHausnummer As Object = Nothing
    Property nctsWP_SumAEmpfaenger_Ort As Object = Nothing
    Property nctsWP_SumAEmpfaenger_PLZ As Object = Nothing
    Property nctsWP_SumAEmpfaenger_Land As Object = Nothing


    Property nctsWP_KdRefNr As Object = Nothing


    Property nctsWP_PACKSTUECKE As New List(Of cNCTS_TR_WarenpositionPackstuecke)
    Property nctsWP_UNTERLAGEN As New List(Of cNCTS_TR_WarenpositionVorgelegteUnterlagen) 'NOCH NCIHT SQL!!

    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    Sub New()
        '  Me.nctsWP_NctsId = nctsWP_NctsId
    End Sub

    'Sub New(nctsSA_Id)
    '    Me.nctsSA_Id = nctsSA_Id
    ' LOAD()
    ' End Sub


    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Id", nctsWP_Id, , True, True))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_NctsId", nctsWP_NctsId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_PositionsNummer", nctsWP_PositionsNummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Warennummer", nctsWP_Warennummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_ArtAnmeldungPositionCode", nctsWP_ArtAnmeldungPositionCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Warenbezeichnung", nctsWP_Warenbezeichnung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Warenwert", nctsWP_Warenwert))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_WarenwertWaehrung", nctsWP_WarenwertWaehrung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SchaetzKz", nctsWP_SchaetzKz))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_WarenwertProzent", nctsWP_WarenwertProzent))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VersendungslandPositionCode", nctsWP_VersendungslandPositionCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_BestimmungslandPositionCode", nctsWP_BestimmungslandPositionCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Rohmasse", nctsWP_Rohmasse))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Eigenmasse", nctsWP_Eigenmasse))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierTyp", nctsWP_VorpapierTyp))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierReferenz1", nctsWP_VorpapierReferenz1))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierZusatz1", nctsWP_VorpapierZusatz1))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierReferenz2", nctsWP_VorpapierReferenz2))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierZusatz2", nctsWP_VorpapierZusatz2))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierReferenz3", nctsWP_VorpapierReferenz3))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierZusatz3", nctsWP_VorpapierZusatz3))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierReferenz4", nctsWP_VorpapierReferenz4))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierZusatz4", nctsWP_VorpapierZusatz4))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierReferenz5", nctsWP_VorpapierReferenz5))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierZusatz5", nctsWP_VorpapierZusatz5))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierReferenz6", nctsWP_VorpapierReferenz6))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierZusatz6", nctsWP_VorpapierZusatz6))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierReferenz7", nctsWP_VorpapierReferenz7))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierZusatz7", nctsWP_VorpapierZusatz7))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierReferenz8", nctsWP_VorpapierReferenz8))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierZusatz8", nctsWP_VorpapierZusatz8))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierReferenz9", nctsWP_VorpapierReferenz9))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_VorpapierZusatz9", nctsWP_VorpapierZusatz9))


        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_BesondereVermeke_ExportAusEU", nctsWP_BesondereVermeke_ExportAusEU))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_BesondereVermeke_ExportAusLand", nctsWP_BesondereVermeke_ExportAusLand))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_BesondereVermeke_Export", nctsWP_BesondereVermeke_Export))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_BesondereVermeke_ExportBeschraenkung", nctsWP_BesondereVermeke_ExportBeschraenkung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_BesondereVermeke_ExportAbgaben", nctsWP_BesondereVermeke_ExportAbgaben))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_BesondereVermeke_Vermerk", nctsWP_BesondereVermeke_Vermerk))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_BesondereVermeke_Kz10600", nctsWP_BesondereVermeke_Kz10600))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Versender_EORI", nctsWP_Versender_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Versender_NLNR", nctsWP_Versender_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Versender_TIN", nctsWP_Versender_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Versender_Name", nctsWP_Versender_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Versender_StrasseHausnummer", nctsWP_Versender_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Versender_Ort", nctsWP_Versender_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Versender_PLZ", nctsWP_Versender_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Versender_Land", nctsWP_Versender_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Empfaenger_EORI", nctsWP_Empfaenger_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Empfaenger_NLNR", nctsWP_Empfaenger_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Empfaenger_TIN", nctsWP_Empfaenger_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Empfaenger_Name", nctsWP_Empfaenger_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Empfaenger_StrasseHausnummer", nctsWP_Empfaenger_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Empfaenger_Ort", nctsWP_Empfaenger_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Empfaenger_PLZ", nctsWP_Empfaenger_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_Empfaenger_Land", nctsWP_Empfaenger_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAKennnummerSendung", nctsWP_SumAKennnummerSendung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumABefoerderungskostenZahlungsweise", nctsWP_SumABefoerderungskostenZahlungsweise))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAUNGefahrgutnummer", nctsWP_SumAUNGefahrgutnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAVersender_EORI", nctsWP_SumAVersender_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAVersender_NLNR", nctsWP_SumAVersender_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAVersender_TIN", nctsWP_SumAVersender_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAVersender_Name", nctsWP_SumAVersender_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAVersender_StrasseHausnummer", nctsWP_SumAVersender_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAVersender_Ort", nctsWP_SumAVersender_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAVersender_PLZ", nctsWP_SumAVersender_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAVersender_Land", nctsWP_SumAVersender_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAEmpfaenger_EORI", nctsWP_SumAEmpfaenger_EORI))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAEmpfaenger_NLNR", nctsWP_SumAEmpfaenger_NLNR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAEmpfaenger_TIN", nctsWP_SumAEmpfaenger_TIN))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAEmpfaenger_Name", nctsWP_SumAEmpfaenger_Name))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAEmpfaenger_StrasseHausnummer", nctsWP_SumAEmpfaenger_StrasseHausnummer))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAEmpfaenger_Ort", nctsWP_SumAEmpfaenger_Ort))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAEmpfaenger_PLZ", nctsWP_SumAEmpfaenger_PLZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_SumAEmpfaenger_Land", nctsWP_SumAEmpfaenger_Land))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWP_KdRefNr", nctsWP_KdRefNr))


        Return list
    End Function


    Public Function INSERT() As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
        'Return SQL.doSQLVarList(getInsertCmd, "FMZOLL", , list)
        nctsWP_Id = SQL.doSQLVarListID(nctsWP_Id, getInsertCmd, "FMZOLL", , list)
        Return nctsWP_Id > 0
    End Function

    Public Function getInsertCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblNCTS_TR_Warenposition (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function




    Public Sub LOAD_WarenpositionPackstuecke()
        Try
            nctsWP_PACKSTUECKE.Clear()
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblNCTS_TR_WarenpositionPackstuecke WHERE nctsWpPk_nctsWPId=@nctsWP_Id  ", conn)
                    cmd.Parameters.AddWithValue("@nctsWP_Id", Me.nctsWP_Id)
                    Dim dr = cmd.ExecuteReader()
                    While dr.Read
                        Dim l As New cNCTS_TR_WarenpositionPackstuecke()
                        For Each i In l.getParameterList()
                            Dim propInfo As PropertyInfo = l.GetType.GetProperty(i.Scalarvariable)
                            If dr.Item(i.Text) Is DBNull.Value Then
                                propInfo.SetValue(l, Nothing)
                            Else
                                propInfo.SetValue(l, dr.Item(i.Text))
                            End If
                        Next
                        nctsWP_PACKSTUECKE.Add(l)
                    End While
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
    End Sub

    Public Function DELETE_WarenpositionPackstuecke() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
        Dim sqlstr = " DELETE FROM [tblNCTS_TR_WarenpositionPackstuecke] WHERE nctsWpPk_nctsWPId=" & Me.nctsWP_Id & " "
        Return SQL.doSQL(sqlstr, "FMZOLL")
    End Function

    Public Function INSERT_WarenpositionPackstuecke(wp_id, ncts_id) As Boolean
        'Zuserst alle OffertenPos von dem Offert löschen

        'jetzt die Standartofferten  einfügen
        For Each p In nctsWP_PACKSTUECKE
            p.nctsWpPk_nctsWPId = wp_id
            p.nctsWpPk_NctsId = ncts_id
            If Not p.INSERT() Then
                Return False
            End If
        Next

        Return True
    End Function



    'Public Sub LOAD_WarenpositionUnterlagen()
    '    Try
    '        nctsWP_UNTERLAGEN.Clear()
    '        Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
    '            Using cmd As New SqlCommand("SELECT * FROM tblNCTS_TR_WarenpositionVorgelegteUnterlagen WHERE nctsWpUl_nctsWPId=@nctsWP_Id  ", conn)
    '                cmd.Parameters.AddWithValue("@nctsWP_Id", Me.nctsWP_Id)
    '                Dim dr = cmd.ExecuteReader()
    '                While dr.Read
    '                    Dim l As New cNCTS_TR_WarenpositionVorgelegteUnterlagen
    '                    For Each i In l.getParameterList()
    '                        Dim propInfo As PropertyInfo = l.GetType.GetProperty(i.Scalarvariable)
    '                        If dr.Item(i.Text) Is DBNull.Value Then
    '                            propInfo.SetValue(l, Nothing)
    '                        Else
    '                            propInfo.SetValue(l, dr.Item(i.Text))
    '                        End If
    '                    Next
    '                    nctsWP_UNTERLAGEN.Add(l)
    '                End While
    '                dr.Close()
    '            End Using
    '        End Using
    '    Catch ex As Exception
    '        MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
    '    End Try
    'End Sub

    'Public Function DELETE_WarenpositionUnterlagen() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
    '    Dim sqlstr = " DELETE FROM [tblNCTS_TR_WarenpositionVorgelegteUnterlagen] WHERE nctsWpUl_nctsWPId=" & Me.nctsWP_Id & " "
    '    Return SQL.doSQL(sqlstr, "FMZOLL")
    'End Function

    'Public Function INSERT_WarenpositionUnterlagen(wp_id, ncts_id) As Boolean
    '    'Zuserst alle OffertenPos von dem Offert löschen

    '    'jetzt die Standartofferten  einfügen
    '    For Each p In nctsWP_UNTERLAGEN
    '        p.nctsWpUl_nctsWPId = wp_id
    '        p.nctsWpUl_NctsId = ncts_id
    '        If Not p.INSERT() Then
    '            Return False
    '        End If
    '    Next

    '    Return True
    'End Function




End Class



Public Class cNCTS_TR_WarenpositionPackstuecke

    Property nctsWpPk_Id As Integer
    Property nctsWpPk_nctsWPId As Integer
    Property nctsWpPk_NctsId As Integer

    Property nctsWpPk_PackstueckeAnzahl As Object = Nothing
    Property nctsWpPk_Verpackungsart As Object = Nothing
    Property nctsWpPk_ZeichenNummern As Object = Nothing


    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    Sub New()
        '   Me.nctsWpPk_nctsWPId = nctsWpPk_nctsWPId
    End Sub


    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpPk_Id", nctsWpPk_Id, , True, True))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpPk_nctsWPId", nctsWpPk_nctsWPId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpPk_NctsId", nctsWpPk_NctsId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpPk_PackstueckeAnzahl", nctsWpPk_PackstueckeAnzahl))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpPk_Verpackungsart", nctsWpPk_Verpackungsart))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpPk_ZeichenNummern", nctsWpPk_ZeichenNummern))
        Return list
    End Function


    Public Function INSERT() As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
        nctsWpPk_Id = SQL.doSQLVarListID(nctsWpPk_Id, getInsertCmd(), "FMZOLL", , list)
        Return nctsWpPk_Id > 0
    End Function

    Public Function getInsertCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblNCTS_TR_WarenpositionPackstuecke (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function

End Class



'NOCH NCIHT IM SQL!!!!!!!!!!!!!!!
Public Class cNCTS_TR_WarenpositionVorgelegteUnterlagen

    Property nctsWpUl_Id As Integer
    Property nctsWpUl_nctsWPId As Integer
    Property nctsWpUl_NctsId As Integer
    Property nctsWpUl_Typ As Object = Nothing
    Property nctsWpUl_Referenz As Object = Nothing
    Property nctsWpUl_Zusatz As Object = Nothing



    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    Sub New()
        '  Me.nctsWpUl_nctsWPId = nctsWpUl_nctsWPId
    End Sub


    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpUl_Id", nctsWpUl_Id, , True, True))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpUl_nctsWPId", nctsWpUl_nctsWPId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpUl_NctsId", nctsWpUl_NctsId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpUl_Typ", nctsWpUl_Typ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpUl_Referenz", nctsWpUl_Referenz))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("nctsWpUl_Zusatz", nctsWpUl_Zusatz))
        Return list
    End Function


    Public Function INSERT() As Boolean
        Return True 'NOCH NCIHT!!!!!
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
        nctsWpUl_Id = SQL.doSQLVarListID(nctsWpUl_Id, getInsertCmd(), "FMZOLL", , list)
        Return nctsWpUl_Id > 0
    End Function

    Public Function getInsertCmd() As String

        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblNCTS_TR_WarenpositionVorgelegteUnterlagen (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function



End Class
