Imports System.Data.SqlClient
Imports System.Reflection

Public Class cVERAG_in_shippmentWHST '????????

    Property in_sh_id As Object = Nothing '                       INT             Not NULL,
    Property in_sh_AvisoId As Object = Nothing '                  INT             NULL,
    Property in_sh_SendungsId As Object = Nothing '               INT             NULL,
    Property in_sh_Erstellung As Object = Nothing '               DATETIME        Default (getdate()) Not NULL,
    Property in_sh_firma As Object = Nothing '                    VARCHAR(10)    NULL,
    Property in_sh_niederlassung As Object = Nothing '            VARCHAR(10)    NULL,

    'Property MsgType As Object = Nothing '                         VARCHAR(10)    NULL,
    'Property dec_ProzessArt As Object = Nothing '                  VARCHAR(4)     Not NULL,
    'Property dec_Anmelde_ID As Object = Nothing '                  INT             NULL,
    'Property dec_Template_ID As Object = Nothing '                 INT             NULL,
    'Property dec_Lager_ID As Object = Nothing '                    VARCHAR(6)     NULL,
    'Property dec_Lag_IND As Object = Nothing '                     BIT             NULL,
    'Property dec_CreateDate As Object = Nothing '                  DATETIME        Not NULL,
    'Property dec_CreatePersonalID As Object = Nothing '            VARCHAR(12)    NULL,
    'Property dec_PreDec_IND As Object = Nothing '                  BIT             NULL,
    'Property dec_TotNet As Object = Nothing '                      Decimal (14, 3) NULL,
    'Property dec_TotNetSplit_IND As Object = Nothing '             BIT             NULL,
    'Property dec_FillPackList_IND As Object = Nothing '            BIT             NULL,
    'Property dec_Memo As Object = Nothing '                        VARCHAR(1000)  NULL,
    'Property Refs_LRN As Object = Nothing '                        VARCHAR(22)    Not NULL,
    'Property Refs_CRN As Object = Nothing '                        VARCHAR(21)    NULL,
    'Property Refs_CSRN As Object = Nothing '                       VARCHAR(21)    NULL,
    'Property Refs_ERN As Object = Nothing '                        VARCHAR(21)    NULL,
    'Property Refs_FRN As Object = Nothing '                        VARCHAR(21)    NULL,
    'Property Refs_Stat As Object = Nothing '                       VARCHAR(2)     NULL,
    Property Hea_DecTy As Object = Nothing '                      Type --> T1, T2, EZA
    Property Hea_TotItem As Object = Nothing '                     Pos gesamt
    Property Hea_TotPack As Object = Nothing '                     Packstücke gesamt
    Property Hea_TotGross As Object = Nothing '                    GesRohmasse
    'Property Hea_DepLNG As Object = Nothing '                      VARCHAR(2)     NULL,
    'Property Hea_DestLNG As Object = Nothing '                     VARCHAR(2)     NULL,
    'Property Hea_PayTy As Object = Nothing '                       VARCHAR(1)     NULL,
    'Property Hea_DefPayRef As Object = Nothing '                   INT             NULL,
    'Property Hea_PerPayRef As Object = Nothing '                   INT             NULL,
    'Property Hea_PayMet As Object = Nothing '                      INT             NULL,
    'Property Hea_AExpRef As Object = Nothing '                     BIT             NULL,
    'Property Hea_Fin As Object = Nothing '                         VARCHAR(2)     NULL,
    'Property Hea_Simp As Object = Nothing '                        BIT             Not NULL,
    'Property Hea_IssD As Object = Nothing '                        Date            NULL,
    Property Hea_AuthID As Object = Nothing '                  ? ATA
    Property Hea_Incoterm As Object = Nothing '                  ? Lieferkondition
    'Property Hea_TransDat As Object = Nothing '                    BIT             NULL,
    'Property Hea_WoffD As Object = Nothing '                       Date            NULL,
    'Property Hea_DecDT As Object = Nothing '                       Date            Not NULL,
    'Property Hea_DecPlc As Object = Nothing '                      VARCHAR(35)    Not NULL,
    'Property Hea_AccDT As Object = Nothing '                       DATETIME        NULL,
    'Property Hea_SecInd As Object = Nothing '                      BIT             NULL,
    'Property Hea_ComRef As Object = Nothing '                      VARCHAR(70)    NULL,
    'Property Hea_ProArrDT As Object = Nothing '                    DATETIME        NULL,
    'Property Hea_PlaDepDT As Object = Nothing '                    DATETIME        NULL,
    'Property Locs_TradCtry As Object = Nothing '                   VARCHAR(2)     NULL,
    Property Locs_Disp As Object = Nothing '                       VARCHAR(2)     NULL,
    Property Locs_Dest As Object = Nothing '                       VARCHAR(2)     NULL,
    'Property Locs_GdsLocCd As Object = Nothing '                   VARCHAR(17)    NULL,
    'Property Locs_GdsLoc As Object = Nothing '                     VARCHAR(35)    NULL,
    'Property Locs_GdsLocAuth As Object = Nothing '                 VARCHAR(17)    NULL,
    'Property Locs_LoadPlcCd As Object = Nothing '                  VARCHAR(17)    NULL,
    'Property Locs_LoadPlc As Object = Nothing '                    VARCHAR(35)    NULL,
    'Property Locs_CustPlc As Object = Nothing '                    VARCHAR(17)    NULL,
    'Property Locs_ArrLocCd As Object = Nothing '                   VARCHAR(17)    NULL,
    'Property Locs_ArrLoc As Object = Nothing '                     VARCHAR(35)    NULL,
    'Property Locs_ArrLocAuth As Object = Nothing '                 VARCHAR(17)    NULL,
    'Property Locs_WarTy As Object = Nothing '                      VARCHAR(1)     NULL,
    'Property Locs_WarCtry As Object = Nothing '                    VARCHAR(2)     NULL,
    'Property Locs_War As Object = Nothing '                        VARCHAR(17)    NULL,
    Property Transp_InMo As Object = Nothing '                 Transportmittel INland
    Property Transp_BordMo As Object = Nothing '                   Transportmittel Grenze
    Property Transp_DepTy As Object = Nothing '                   Transportmittel TypAbfahrt
    Property Transp_DepIdnt As Object = Nothing '                  Transportmittel Kennezeichen Abfahrt
    Property Transp_DepNat As Object = Nothing '                   Transportmittel Nationalität Abfahrt
    Property Transp_CrossTy As Object = Nothing '                   Transportmittel Typ Grenze
    Property Transp_CrossIdnt As Object = Nothing '                Transportmittel Kennezeichen Grenze
    Property Transp_CrossIdntNat As Object = Nothing '             Transportmittel Nationalität Grenze
    Property Transp_ContInd As Object = Nothing '                  BIT             NULL,
    'Property ValData_TermDelCd As Object = Nothing '               VARCHAR(3)     NULL,
    'Property ValData_TermDelPlc As Object = Nothing '              VARCHAR(35)    NULL,
    'Property ValData_TermDelSit As Object = Nothing '              VARCHAR(1)     NULL,
    'Property ValData_InvCurr As Object = Nothing '                 VARCHAR(3)     NULL,
    'Property ValData_ExRa As Object = Nothing '                    Decimal (20, 7) NULL,
    'Property ValData_InvVal As Object = Nothing '                  Decimal (18, 2) NULL,
    'Property ValData_TransacCd As Object = Nothing '               INT             NULL,
    Property ConorTra_Na As Object = Nothing '                    ABSENDER
    Property ConorTra_Strt As Object = Nothing '                   
    Property ConorTra_Pst As Object = Nothing '                     
    Property ConorTra_Cty As Object = Nothing '                  
    Property ConorTra_Ctry As Object = Nothing '                    
    Property ConorTra_EORI As Object = Nothing '                    
    Property ConorTra_UIDCtry As Object = Nothing '               
    Property ConorTra_UID As Object = Nothing '                    
    Property ConeeTra_Na As Object = Nothing '                  EMPFÄNGER
    Property ConeeTra_Strt As Object = Nothing '               
    Property ConeeTra_Pst As Object = Nothing '                    
    Property ConeeTra_Cty As Object = Nothing '                    
    Property ConeeTra_Ctry As Object = Nothing '                   
    Property ConeeTra_EORI As Object = Nothing '                   
    Property ConeeTra_UIDCtry As Object = Nothing '               
    Property ConeeTra_UID As Object = Nothing '                  
    Property ExpTra_Na As Object = Nothing '                    EXPORTEUR
    Property ExpTra_Strt As Object = Nothing '                      
    Property ExpTra_Pst As Object = Nothing '                      
    Property ExpTra_Cty As Object = Nothing '                      
    Property ExpTra_Ctry As Object = Nothing '                   
    Property ExpTra_EORI As Object = Nothing '                      
    Property ExpTra_UIDCtry As Object = Nothing '                  
    Property ExpTra_UID As Object = Nothing '                     
    Property Declarant_Na As Object = Nothing '                 ZOLLAGENT    
    Property Declarant_Strt As Object = Nothing '                
    Property Declarant_Pst As Object = Nothing '                   
    Property Declarant_Cty As Object = Nothing '              
    Property Declarant_Ctry As Object = Nothing '                
    Property Declarant_EORI As Object = Nothing '                   
    Property Declarant_UIDCtry As Object = Nothing '               
    Property Declarant_UID As Object = Nothing '                
    Property Declarant_DecRep As Object = Nothing '             
    Property DestCO_Ref As Object = Nothing '                      Zielzollstelle 
    Property DepCO_Ref As Object = Nothing '                       Abgangszollstelle
    Property CtrlRslt_DLimit As Object = Nothing '                NCTS_GEstellung 


    Property DOCUMENTS As New List(Of cVERAG_in_shipment_Document)
    Property POSITIONSDATEN As New List(Of cVERAG_in_shippment_Position)
    'Property SICHERHEIT As New List(Of cVERAG_in_shippment_Sicherheit)
    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL



    Sub New()
    End Sub


    Sub New(in_sh_id)
        Me.in_sh_id = in_sh_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("in_sh_id", in_sh_id, , True, True))

        'list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("telanm_ART", telanm_ART)) '                      VARCHAR(50)    Not NULL, 

        Return list
    End Function



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

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

        in_sh_id = SQL.doSQLVarListID(in_sh_id, sqlstr, "FMZOLL", , list)
        If in_sh_id > 0 And saveAll Then
            SAVE_Positionsdaten()
            SAVE_Documents()
            ' SAVE_Sicherheit()
        End If
        Return in_sh_id > 0
    End Function





    Public Sub LOAD(Optional loadALL = True)
        Try
            If loadALL Then
                POSITIONSDATEN.Clear()
                DOCUMENTS.Clear()
                '  SICHERHEIT.Clear()
            End If
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblTR_Shipment WHERE in_sh_id=@in_sh_id  ", conn)
                    cmd.Parameters.AddWithValue("@in_sh_id", in_sh_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_Positionsdaten()
                            LOAD_Documents()
                            '  LOAD_Sicherheit()
                        End If
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
    End Sub

    'Public Function UPDATE_Status(status As Integer) As String
    '    If in_sh_id > 0 Then
    '        Try
    '            Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
    '            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("in_sh_id", in_sh_id, , True))
    '            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("telanm_Status_KEWILL_Equivalent", status, , True))
    '            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("telanm_Status", status, , True))
    '            'telanm_Status_KEWILL_Equivalent = status
    '            'telanm_Status = status

    '            Return SQL.doSQLVarList(" UPDATE [tblTR_Shipment] SET telanm_Status_KEWILL_Equivalent=@telanm_Status_KEWILL_Equivalent,telanm_Status=@telanm_Status WHERE in_sh_id=@in_sh_id ", "FMZOLL", , list)

    '        Catch ex As Exception
    '            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
    '        End Try
    '    End If
    '    Return ""
    'End Function


    'Shared Function UPDATE_StatusById(in_sh_id As Integer, status As Integer) As String
    '    If in_sh_id > 0 Then
    '        Try
    '            Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
    '            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("in_sh_id", in_sh_id, , True))
    '            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("telanm_Status_KEWILL_Equivalent", status, , True))
    '            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("telanm_Status", status, , True))
    '            'telanm_Status_KEWILL_Equivalent = status
    '            'telanm_Status = status
    '            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    '            Return SQL.doSQLVarList(" UPDATE [tblTR_Shipment] SET telanm_Status_KEWILL_Equivalent=@telanm_Status_KEWILL_Equivalent,telanm_Status=@telanm_Status WHERE in_sh_id=@in_sh_id ", "FMZOLL", , list)

    '        Catch ex As Exception
    '            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
    '        End Try
    '    End If
    '    Return ""
    'End Function



    'Public Sub UPDATE_DATA()
    '    Try
    '        Select Case telanm_ART
    '            Case "T1", "T2"
    '                'SQL, die daten aus den jeweiligen tabellen ausliest und hier aktualisiert
    '                Dim Dakosy_NCTSOut As New DAKOSY_Worker.cDakosyNCTSOut
    '                Dakosy_NCTSOut.LOADByAnmID(in_sh_id, False)
    '                If Dakosy_NCTSOut IsNot Nothing Then
    '                    Me.telanm_BezugsNr = Dakosy_NCTSOut.ncts_ObjectName
    '                    Me.telanm_Status = Dakosy_NCTSOut.ncts_Status
    '                    Me.telanm_Status_KEWILL_Equivalent = Dakosy_NCTSOut.ncts_Status_KEWILL_Equivalent
    '                    Me.telanm_Erstellung = Dakosy_NCTSOut.ncts_Erstellung
    '                    Me.telanm_Erstellung_SB = Dakosy_NCTSOut.ncts_Erstellung_SB
    '                    Me.telanm_LetzteBearbeitung = Dakosy_NCTSOut.ncts_LetzteBearbeitung
    '                    Me.telanm_LetzteBearbeitung_SB = Dakosy_NCTSOut.ncts_LetzteBearbeitung_SB
    '                End If

    '        End Select

    '    Catch ex As Exception
    '        VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
    '    End Try
    'End Sub



    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 [tblTR_Shipment] SET " & str & " WHERE in_sh_id=@in_sh_id ")

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        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 tblTR_Shipment  (" & 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








    Shared Function getWaehr(s As String, SQL As VERAG_PROG_ALLGEMEIN.SQL) As String
        'Return KDSQL.getValueTxtBySql("SELECT TOP 1 isnull([LandNr],-1) FROM [Länderverzeichnis für die Außenhandelsstatistik] WHERE [Währungscode]='" & s & "'", "FMZOLL")
        s = s.Replace("TRY", "TRL") ' Türkische Lira
        Return SQL.getValueTxtBySql("SELECT TOP 1 isnull([Währungsschlüssel],-1) FROM [Währungstabelle] WHERE [Währungscode]='" & s & "'", "FMZOLL")

    End Function



    Public Sub LOAD_Positionsdaten()
        Try
            POSITIONSDATEN.Clear()
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblVERAG_in_shippment_Positionsdaten WHERE in_pos_inShId=@in_sh_id  ", conn)
                    cmd.Parameters.AddWithValue("@in_sh_id", Me.in_sh_id)
                    Dim dr = cmd.ExecuteReader()
                    While dr.Read
                        Dim l As New cVERAG_in_shippment_Position
                        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_Packstücke()
                        POSITIONSDATEN.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_Documents()
        'Try
        '    DOCUMENTS.Clear()
        '    Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
        '        Using cmd As New SqlCommand("SELECT * FROM tblTR_Shipment_Document WHERE shTrDoc_ShTrId=@in_sh_id  ", conn)
        '            cmd.Parameters.AddWithValue("@in_sh_id", Me.in_sh_id)
        '            Dim dr = cmd.ExecuteReader()
        '            While dr.Read
        '                Dim l As New cVERAG_in_shipment_Document
        '                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
        '                DOCUMENTS.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



    Function DELETE_Packstücke() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
        Dim sqlstr = " DELETE FROM [tblVERAG_in_shippment_Packstuecke] WHERE in_posPk_inShId =" & Me.in_sh_id & " "
        Return SQL.doSQL(sqlstr, "FMZOLL")
    End Function

    Function DELETE_Positionsdaten() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
        Dim sqlstr = " DELETE FROM [tblVERAG_in_shippment_Positionsdaten] WHERE in_pos_inShId =" & Me.in_sh_id & " "
        Return SQL.doSQL(sqlstr, "FMZOLL")
    End Function

    Function DELETE_Documents() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
        Dim sqlstr = " DELETE FROM [tblTR_Shipment_Document] WHERE shTrDoc_ShTrId =" & Me.in_sh_id & " "
        Return SQL.doSQL(sqlstr, "FMZOLL")
    End Function


    Public Function SAVE_Positionsdaten() As Boolean
        'Zuserst alle OffertenPos von dem Offert löschen
        If DELETE_Positionsdaten() And DELETE_Packstücke() Then 'And DELETE_PositionsdatenUnterlagen() And DELETE_PositionsdatenVerbrauchssteuer() Then
            'jetzt die Standartofferten  einfügen
            For Each p In POSITIONSDATEN
                p.in_pos_inShId = in_sh_id
                If p.INSERT() Then
                    p.INSERT_Packstücke(p.in_pos_id, Me.in_sh_id)
                    'p.INSERT_PositionsdatenUnterlagen(p.ezaWP_Id, Me.eza_Id)
                    'p.INSERT_PositionsdatenVerbrauchssteuer(p.ezaWP_Id, Me.eza_Id)
                Else
                    Return False
                End If
            Next
        Else
            Return False
        End If

        Return True
    End Function

    Public Function SAVE_Documents() As Boolean
        '    'Zuserst alle OffertenPos von dem Offert löschen
        '    If DELETE_Documents() Then 'And DELETE_PositionsdatenUnterlagen() And DELETE_PositionsdatenVerbrauchssteuer() Then
        '        'jetzt die Standartofferten  einfügen
        '        For Each p In DOCUMENTS
        '            p.shTrDoc_ShTrId = in_sh_id
        '            If p.INSERT() Then

        '            Else
        '                Return False
        '            End If
        '        Next
        '    Else
        '        Return False
        '    End If

        '    Return True
    End Function

End Class


Public Class cVERAG_in_shippment_Position

    Property in_pos_id As Integer
    Property in_pos_inShId As Integer
    'Property Mandant_ID As Object = Nothing
    'Property Bereich_ID As Object = Nothing
    'Property Referenz_ID As Object = Nothing
    'Property ComIndicator As Object = Nothing
    Property Pos_Nr As Integer
    Property Item_GdsDes As Object = Nothing
    'Property Item_Status As Object = Nothing
    'Property Item_ComCd As Object = Nothing
    Property Item_TarNr As Object = Nothing
    Property Item_Gross As Object = Nothing
    Property Item_Net As Object = Nothing
    Property Item_Orig As Object = Nothing
    'Property Item_ProcCd As Object = Nothing
    'Property Item_ProcAddCd As Object = Nothing
    Property Item_ItVal As Object = Nothing
    'Property Item_Pref As Object = Nothing
    'Property Item_Quota As Object = Nothing
    'Property Item_ValMet As Object = Nothing
    'Property Item_VATInd As Object = Nothing
    'Property Item_StatVal As Object = Nothing
    'Property SurvCO_Ref As Object = Nothing
    'Property Telo_Artikel_ID As Object = Nothing
    Property Telo_Artikelmenge As Object = Nothing
    Property Telo_ArtikelMEH As Object = Nothing

    Property PACKSTUECKE As New List(Of cVERAG_in_shippment_Packing)

    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    Sub New()
    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("in_pos_id", in_pos_id, , True, True))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("in_pos_inShId", in_pos_inShId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Pos_Nr", Pos_Nr))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Item_GdsDes", Item_GdsDes))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Item_TarNr", Item_TarNr))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Item_Gross", Item_Gross))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Item_Net", Item_Net))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Item_Orig", Item_Orig))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Item_ItVal", Item_ItVal))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Telo_Artikelmenge", Telo_Artikelmenge))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Telo_ArtikelMEH", Telo_ArtikelMEH))

        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)
        in_pos_id = SQL.doSQLVarListID(in_pos_id, getInsertCmd, "FMZOLL", , list)
        Return in_pos_id > 0
    End Function

    Public Function INSERT_Packstücke(in_pos_id, in_sh_id) As Boolean
        For Each p In PACKSTUECKE
            p.in_posPk_inShId = in_sh_id
            p.in_posPk_inPosId = in_pos_id
            If Not p.INSERT() Then Return False
        Next
        Return True
    End Function

    Public Sub LOAD_Packstücke()
        Try
            PACKSTUECKE.Clear()
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblVERAG_in_shippment_Packstuecke WHERE in_posPk_inPosId=@in_pos_id  ", conn)
                    cmd.Parameters.AddWithValue("@in_pos_id", Me.in_pos_id)
                    Dim dr = cmd.ExecuteReader()
                    While dr.Read
                        Dim l As New cVERAG_in_shippment_Packing
                        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
                        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 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 tblVERAG_in_shippment_Positionsdaten  (" & 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





Public Class cVERAG_in_shippment_Packing

    Property in_posPk_id As Integer
    Property in_posPk_inShId As Integer
    Property in_posPk_inPosId As Integer
    Property Pack_Mark As Object = Nothing
    Property Pack_Kind As Object = Nothing
    Property Pack_Nr As Object = Nothing
    Property Pack_Piec As Object = Nothing
    Property Telo_Gross As Object = Nothing


    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    Sub New()
    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("in_posPk_id", in_posPk_id, , True, True))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("in_posPk_inShId", in_posPk_inShId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("in_posPk_inPosId", in_posPk_inPosId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Pack_Mark", Pack_Mark))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Pack_Kind", Pack_Kind))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Pack_Nr", Pack_Nr))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Pack_Piec", Pack_Piec))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Telo_Gross", Telo_Gross))

        Return list
    End Function

    Public Function INSERT() As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
        in_posPk_id = SQL.doSQLVarListID(in_posPk_id, getInsertCmd, "FMZOLL", , list)
        Return in_posPk_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 tblVERAG_in_shippment_Packstuecke  (" & 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




