Merge branch 'newMaster2024' of https://dev.azure.com/VeragAG/_git/SDL into newMaster2024

This commit is contained in:
2025-02-12 10:56:27 +01:00
5 changed files with 672 additions and 0 deletions

View File

@@ -0,0 +1,158 @@
Imports System.Data.SqlClient
Imports System.Reflection
Public Class cHMRCToken
Property token_id As Integer
Property token_BEARER_TOKEN As String = ""
Property token_datetime As Date = Now
Property token_Firma As String = VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
Property token_Application As String = ""
Property token_refresh_datetime As Object = Nothing
Public hasEntry = False
Dim SQL As New SQL
Sub New(token_id)
Me.token_id = token_id
LOAD()
End Sub
Sub New(token_Firma, token_Application)
Me.token_Firma = token_Firma
Me.token_Application = token_Application
LOAD_ByFirmaAppl()
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("token_id", token_id,, True))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_BEARER_TOKEN", token_BEARER_TOKEN))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_datetime", token_datetime))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_Firma", token_Firma))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_Application", token_Application))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_refresh_datetime", token_refresh_datetime))
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 tblHMRCToken WHERE token_id=@token_id) " &
" BEGIN " & getUpdateCmd() & " END " &
" Else " &
" BEGIN " & getInsertCmd() & " END " &
" commit tran "
If SQL.doSQLVarList(sqlstr, "FMZOLL", , list) Then
hasEntry = True
Return True
Else
Return False
End If
End Function
Public Sub LOAD()
Try
hasEntry = False
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
Using cmd As New SqlCommand("SELECT * FROM tblHMRCToken WHERE token_id=@token_id ", conn)
cmd.Parameters.AddWithValue("@token_id", token_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
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
Public Sub LOAD_ByFirmaAppl()
Try
hasEntry = False
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
Using cmd As New SqlCommand("SELECT * FROM tblHMRCToken WHERE token_Firma=@token_Firma and token_Application=@token_Application ", conn)
cmd.Parameters.AddWithValue("@token_Firma", token_Firma)
cmd.Parameters.AddWithValue("@token_Application", token_Application)
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
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 [tblHMRCToken] SET " & str & " WHERE token_id=@token_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 tblHMRCToken (" & 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