Files
SDL/SDL/Classes/cEORIPruefung.vb

165 lines
6.7 KiB
VB.net

Imports System.Data.SqlClient
Imports System.Reflection
Imports VERAG_PROG_ALLGEMEIN
Public Class cEORIPruefung
Property eori_id As Integer
Property eori_KdNr As Object = Nothing
Property eori_valid As Object = Nothing
Property eori_datum As Object = Nothing
Property eori_maid As Object = Nothing
Property eori_sendungsid As Object = Nothing
Property eori_firma As Object = Nothing
Property eori_sachbearbeiter As Object = Nothing
Property eori_sessionID As Object = Nothing
Property eori_AvisoID As Object = Nothing
Property eori_Nr As Object = Nothing
Public hasEntry = False
Shared SQL As New VERAG_PROG_ALLGEMEIN.SQL
Sub New(eori_id)
Me.eori_id = eori_id
LOAD()
End Sub
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("eori_id", eori_id,, True))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_KdNr", eori_KdNr))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_valid", eori_valid))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_datum", eori_datum))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_maid", eori_maid))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_sendungsid", eori_sendungsid))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_firma", eori_firma))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_sachbearbeiter", eori_sachbearbeiter))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_sessionID", eori_sessionID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_AvisoID", eori_AvisoID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("eori_Nr", eori_Nr))
Return list
End Function
Public Function SAVE() As Boolean
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblEORIPruefung WHERE eori_id=@eori_id) " &
" BEGIN " & getUpdateCmd() & " END " &
" Else " &
" BEGIN " & getInsertCmd() & " END " &
" commit tran "
Return SQL.doSQLVarList(sqlstr, "FMZOLL", , list)
End Function
Public Sub LOAD()
Try
hasEntry = False
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
Using cmd As New SqlCommand("SELECT * FROM tblEORIPruefung WHERE eori_id=@eori_id ", conn)
cmd.Parameters.AddWithValue("@eori_id", eori_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
hasEntry = 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
End Sub
Public Shared Function LOADByKdNrDate(eori_KdNr As Integer) As cEORIPruefung
Try
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
Dim EORI As New cEORIPruefung
Using cmd As New SqlCommand("SELECT Top 1 * FROM tblEORIPruefung WHERE [eori_KdNr]=@eori_KdNr AND eori_valid = 1 ORDER BY [eori_datum] DESC", conn)
cmd.Parameters.AddWithValue("@eori_KdNr", eori_KdNr)
Dim dr = cmd.ExecuteReader()
If dr.Read Then
For Each li In EORI.getParameterList()
Dim propInfo As PropertyInfo = EORI.GetType.GetProperty(li.Scalarvariable)
If dr.Item(li.Text) Is DBNull.Value Then
propInfo.SetValue(EORI, Nothing)
Else
propInfo.SetValue(EORI, dr.Item(li.Text))
End If
Next
dr.Close()
Return EORI
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 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 [tblEORIPruefung] SET " & str & " WHERE eori_id=@eori_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 tblEORIPruefung (" & 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