Files
SDL/SDL/Classes/cFiskaltrustClient.vb

936 lines
30 KiB
VB.net

Imports System.Data.SqlClient
Imports System.Net
Imports System.Net.Http
Imports System.Reflection
Imports System.Text
Imports System.Threading
Imports Newtonsoft.Json
Public Class cFiskaltrustClient
Private ReadOnly _baseUrl As String
Private ReadOnly _cashboxId As String
Private ReadOnly _accessToken As String
Private ReadOnly _country As String
Private Shared ReadOnly _httpClient As New HttpClient()
Public Sub New(baseUrl As String, cashboxId As String, accessToken As String, country As String)
_baseUrl = baseUrl.TrimEnd("/"c)
_cashboxId = cashboxId
_accessToken = accessToken
_country = country
End Sub
' ================================
' PUBLIC API
' ================================
Public Async Function SignReceiptAsync(amount As Decimal, vat As Decimal, POS As List(Of EABelegPositionen), KindOfPayment As String, posSystemId As String) As Task(Of String)
Dim payload = BuildPayloadReceipt(amount, vat, POS, KindOfPayment, posSystemId)
Dim endpoint = GetEndpoint("payment")
Dim requestContent As StringContent
If _country = "AT" Then
' Plaintext
Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(text)
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
Else
' JSON Objekt
Dim json As String = JsonConvert.SerializeObject(payload)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(endpoint, payload, requestContent)
End Function
'----- TEST
Public Async Function SignReceiptAsync_test(posSystemId As String) As Task(Of String)
Dim LIST = New List(Of EABelegPositionen)
Dim p = New EABelegPositionen
p.Mandant = "VERA"
p.Niederlassung = "SUB"
p.Benutzer = 74
p.BelegDat = Now
p.BelegNr = 1
p.PreislistenNr = 1
p.PreislistenPos = 1
p.LeistungsNr = 300
p.LeistungsBez = "TEST"
p.Preis = 10
p.Anzahl = 1
LIST.Add(p)
Dim payload = BuildPayloadReceipt(100, CDec(0.0), LIST, "Cash", posSystemId)
Dim endpoint = GetEndpoint("payment")
Dim requestContent As StringContent
If _country = "AT" Then
' Plaintext
'Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(payload)
'requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
Else
' JSON Objekt
Dim json As String = JsonConvert.SerializeObject(payload)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(endpoint, payload, requestContent)
End Function
Public Async Function Echo(KassenName As String) As Task(Of String)
Dim payload = KassenName & " - VERBINDUNG OK"
Dim endpoint = GetEndpoint("test")
Dim requestContent As StringContent
If _country = "AT" Then
' Plaintext
Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(text)
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
Else
' JSON Objekt
Dim obj = New With {
.Message = payload
}
Dim json As String = JsonConvert.SerializeObject(obj)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(endpoint, payload, requestContent)
End Function
' Optional: Storno Beispiel
'reference unique id!
Public Async Function CancelReceiptAsync(reference As String, POS As List(Of EABelegPositionen), amount As Decimal, kindOfPayment As String) As Task(Of String)
' ChargeItems Liste vorbereiten
Dim chargeItems = New List(Of Object)
For Each p In POS
chargeItems.Add(New With {
.Quantity = p.Anzahl,
.Amount = p.Preis,
.VATRate = 0,
.Description = p.LeistungsBez,
.ftChargeItemCase = 4919338167972134929
})
Next
Dim payload = New With {
.ftCashBoxID = _cashboxId,
.ftPosSystemId = "POS-1",
.cbTerminalID = "T1",
.cbReceiptReference = reference,
.cbReceiptMoment = DateTime.UtcNow.ToString("o"),
.ftReceiptCase = 4919338172267102210,
.cbChargeItems = chargeItems,
.cbPayItems = New Object() {
New With {
.Quantity = 1.0,
.Amount = amount,
.Description = kindOfPayment,
.ftPayItemCase = 4919338167972134913
}
}
}
Dim requestContent As StringContent
If _country = "AT" Then
' Plaintext
Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(text)
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
Else
' JSON Objekt
Dim json As String = JsonConvert.SerializeObject(payload)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(GetEndpoint("payment"), payload, requestContent)
End Function
Public Async Function SignNullReceiptAsync(posSystemId As String) As Task(Of String)
Dim payload = BuildPayloadNullReceipt(posSystemId, _country)
Dim endpoint = GetEndpoint("payment")
Dim requestContent As StringContent
If _country = "AT" Then
' Plaintext
Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(text)
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
Else
' JSON Objekt
Dim json As String = JsonConvert.SerializeObject(payload)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(endpoint, payload, requestContent)
End Function
Public Async Function SignClosinglReceiptAsync(type As String, posSystemId As String) As Task(Of String)
Dim payload = BuildPayloadCosinglReceipt(type, posSystemId)
Dim endpoint = GetEndpoint("payment")
Dim requestContent As StringContent
If _country = "AT" Then
' Plaintext
Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(text)
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
Else
' JSON Objekt
Dim json As String = JsonConvert.SerializeObject(payload)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(endpoint, payload, requestContent)
End Function
Public Async Function Journal(type As String) As Task(Of String)
Dim payload = ""
Dim endpoint = GetEndpoint("journal")
If type > 0 Then
endpoint &= "?type=" & type
End If
Dim requestContent As StringContent = Nothing
If _country = "AT" Then
' Plaintext
Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(text)
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
Else
' JSON Objekt
Dim json As String = JsonConvert.SerializeObject(payload)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(endpoint, payload, requestContent, True)
End Function
Public Async Function CancelReceiptAsync_test(reference As String, amount As Decimal, kindOfPayment As String, posSystemId As String) As Task(Of String)
Dim LIST = New List(Of EABelegPositionen)
Dim p = New EABelegPositionen
p.Mandant = "VERA"
p.Niederlassung = "SUB"
p.Benutzer = 74
p.BelegDat = Now
p.BelegNr = 1
p.PreislistenNr = 1
p.PreislistenPos = 1
p.LeistungsNr = 300
p.LeistungsBez = "TEST"
p.Preis = 10
p.Anzahl = 1
LIST.Add(p)
Dim chargeItems = New List(Of Object)
Dim payload = New With {
.ftCashBoxID = _cashboxId,
.ftPosSystemId = getVersion(posSystemId),
.cbTerminalID = posSystemId,
.cbReceiptReference = reference,
.cbReceiptMoment = DateTime.UtcNow.ToString("o"),
.ftReceiptCase = 4919338172267102210,
.cbChargeItems = chargeItems,
.cbPayItems = New Object() {
New With {
.Quantity = 1.0,
.Amount = amount,
.Description = kindOfPayment,
.ftPayItemCase = 4919338167972134913
}
}
}
Dim requestContent As StringContent
If _country = "AT" Then
' Plaintext
Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(text)
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
Else
' JSON Objekt
Dim json As String = JsonConvert.SerializeObject(payload)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(GetEndpoint("payment"), payload, requestContent)
End Function
Private Async Function SendAsync(endpoint As String, payload As Object, requestContent As StringContent, Optional ignorerequestContent As Boolean = False) As Task(Of String)
Dim url = _baseUrl & endpoint
Dim retries As Integer = 3
Dim delayMs As Integer = 500
Dim lastException As Exception = Nothing
Dim shouldRetry As Boolean = False
ServicePointManager.Expect100Continue = False
For attempt As Integer = 1 To retries
shouldRetry = False
Try
Using request As New HttpRequestMessage(HttpMethod.Post, url)
request.Headers.Add("cashboxid", _cashboxId)
request.Headers.Add("accesstoken", _accessToken)
If Not ignorerequestContent AndAlso requestContent IsNot Nothing Then
request.Content = requestContent
End If
Dim cts As New CancellationTokenSource(TimeSpan.FromSeconds(30))
Debug.WriteLine("Before SendAsync")
Dim response = Await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cts.Token)
Debug.WriteLine("Headers received")
Debug.WriteLine("After SendAsync")
Dim result = Await response.Content.ReadAsStringAsync()
Log($"[{DateTime.Now}] Response ({CInt(response.StatusCode)}): {result}")
If response.IsSuccessStatusCode Then
Return result
End If
Dim statusCode As Integer = CInt(response.StatusCode)
If statusCode >= 500 Then
shouldRetry = True
Throw New Exception($"Server error ({statusCode}): {result}")
Else
Throw New Exception($"Client error ({statusCode}): {result}")
End If
End Using
Catch ex As Exception
lastException = ex
Debug.WriteLine(ex.GetType().FullName)
Debug.WriteLine(ex.ToString())
Throw
End Try
' Await außerhalb von Catch
If shouldRetry AndAlso attempt < retries Then
Await Task.Delay(delayMs)
End If
Next
If lastException IsNot Nothing Then
Throw lastException
MsgBox(lastException)
End If
Throw New Exception("Unexpected error")
End Function
Private Function BuildPayloadReceipt(amount As Decimal, vat As Decimal, POS As List(Of EABelegPositionen), KindOfPayment As String, posSystemId As String) As Object
' ChargeItems Liste vorbereiten
Dim chargeItems = New List(Of Object)
Dim PayItemCase As Long
Select Case KindOfPayment
Case "Cash" : PayItemCase = 4919338167972134913
Case "Card" : PayItemCase = 4919338167972134913 '-> richtigen Type finden
End Select
For Each p In POS
chargeItems.Add(New With {
.Quantity = p.Anzahl,
.Amount = p.Preis,
.VATRate = vat,
.Description = p.LeistungsBez,
.ftChargeItemCase = 4919338167972134929
})
Next
' Payload Objekt erstellen
Dim payload = New With {
.ftCashBoxID = _cashboxId,
.ftPosSystemId = getVersion(posSystemId),
.cbTerminalID = posSystemId,
.cbReceiptReference = Guid.NewGuid().ToString(),
.cbReceiptMoment = DateTime.UtcNow.ToString("o"),
.cbChargeItems = chargeItems,
.cbPayItems = New Object() {
New With {
.Quantity = 1.0,
.Amount = amount,
.Description = KindOfPayment,
.ftPayItemCase = PayItemCase
}
},
.ftReceiptCase = 4919338172267102209 'IMPLICIT-FLOW -> STANDARD-BARVERKAUF
}
Return payload
End Function
Private Function BuildPayloadNullReceipt(posSystemId As String, country As String) As Object
Dim ftReceiptCase_ As Long
Dim cbReceiptReference_ As String
Select Case country
Case "DE"
ftReceiptCase_ = 4919338172267102210 'NULL-BELEG DE
cbReceiptReference_ = "ZeroReceiptAfterFailure"
Case Else
ftReceiptCase_ = 4707387510509010946 'NULL-BELEG AT
cbReceiptReference_ = "2"
End Select
Dim payload = New With {
.ftCashBoxID = _cashboxId,
.ftPosSystemId = getVersion(posSystemId),
.cbTerminalID = posSystemId,
.cbReceiptReference = cbReceiptReference_,
.cbReceiptMoment = DateTime.UtcNow.ToString("o"),
.cbChargeItems = New Object() {},
.cbPayItems = New Object() {},
.ftReceiptCase = ftReceiptCase_
}
Return payload
End Function
Private Function BuildPayloadCosinglReceipt(type As String, posSystemId As String)
'Kassenabschlussbelege
Dim caseID As Long
Select Case type
Case "daily" : caseID = 4919338172267102210
Case "monthly" : caseID = 4919338172267102213
Case "yearly" : caseID = 4919338172267102214
End Select
Dim payload = New With {
.ftCashBoxID = _cashboxId,
.ftPosSystemId = getVersion(posSystemId),
.cbTerminalID = posSystemId,
.cbReceiptReference = type & "-closing-" & DateTime.UtcNow.ToString("o"),
.cbReceiptMoment = DateTime.UtcNow.ToString("o"),
.cbChargeItems = New Object() {},
.cbPayItems = New Object() {},
.ftReceiptCase = caseID
}
Return payload
End Function
Private Function GetEndpoint(type As String) As String
If type = "payment" Then
Select Case _country
Case "DE"
Return "/json/v1/Sign"
Case "AT"
Return "/json/Sign"
Case Else
Throw New Exception("Unsupported country")
End Select
ElseIf type = "test" Then
Select Case _country
Case "DE"
Return "/json/v1/Echo"
Case "AT"
Return "/json/Echo"
Case Else
Throw New Exception("Unsupported country")
End Select
ElseIf type = "journal" Then
Select Case _country
Case "DE"
Return "/json/v0/Journal"
Case "AT"
Return "/json/Journal"
Case Else
Throw New Exception("Unsupported country")
End Select
ElseIf type = "storno" Then
Select Case _country
Case "DE"
Return "/json/v1/Sign"
Case "AT"
Return "/json/Sign"
Case Else
Throw New Exception("Unsupported country")
End Select
End If
End Function
Public Function saveRKSV_FT(ByRef result_zahlung As String, ByRef QR_CodeString As String) As Boolean
If result_zahlung <> "" Then
Dim json As New Chilkat.JsonObject
Dim success As Boolean = json.Load(result_zahlung)
If (success <> True) Then
Debug.WriteLine(json.LastErrorText)
Return False
End If
Dim saved As Boolean = False
Dim ftSig As New cFiskaltrustSignatures()
Dim ftReceiptMoment As New Chilkat.CkDateTime
Dim dt As New Chilkat.DtObj
Dim getAsLocal As Boolean = False
Dim ftID As Integer = -1
success = json.DateOf("ftReceiptMoment", ftReceiptMoment)
Debug.WriteLine(ftReceiptMoment.GetAsTimestamp(getAsLocal))
With ftSig
.ftCashBoxID = json.StringOf("ftCashBoxID")
.ftQueueID = json.StringOf("ftQueueID")
.ftQueueItemID = json.StringOf("ftQueueItemID")
.ftQueueRow = json.IntOf("ftQueueRow")
.cbTerminalID = json.StringOf("cbTerminalID")
.cbReceiptReference = json.StringOf("cbReceiptReference")
.ftCashBoxIdentification = json.StringOf("ftCashBoxIdentification")
.ftReceiptIdentification = json.StringOf("ftReceiptIdentification")
.ftReceiptMoment = ftReceiptMoment.GetAsTimestamp(getAsLocal)
.ftState = json.StringOf("ftState")
saved = .SAVE()
End With
Dim num As Integer = json.SizeOfArray("ftSignatures")
If num = 0 Then
Return False
End If
Dim Signatures As Chilkat.JsonArray = json.ArrayOf("ftSignatures")
If (json.LastMethodSuccess = False) Then
Return False
End If
Dim numSignatures As Integer = Signatures.Size
For i = 0 To numSignatures - 1
Dim SignObj As Chilkat.JsonObject = Signatures.ObjectAt(i)
Dim ftSigPos As New cFiskaltrustSignaturPositions()
With ftSigPos
.ftSignatures = ftSig.ft_id
.ftData = SignObj.StringOf("Data")
.ftSignatureFormat = SignObj.StringOf("ftSignatureFormat")
.ftSignatureType = SignObj.StringOf("ftSignatureType")
saved = .SAVE()
If IsNumeric(.ftSignatureType) AndAlso CInt(.ftSignatureType) = IIf(VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM = True, 0, 3) Then
QR_CodeString = .ftData
End If
End With
Next
Return saved
End If
End Function
Public Function exportJournal(ByRef result_Journal As String) As Boolean
If result_Journal <> "" Then
Dim jsonArr As New Chilkat.JsonArray
Dim success As Boolean = jsonArr.Load(result_Journal)
If (success <> True) Then
Debug.WriteLine(jsonArr.LastErrorText)
Return False
End If
Dim dt As New DataTable
dt.Columns.Add("ftReceiptJournalId", GetType(String))
dt.Columns.Add("ftReceiptMoment", GetType(String))
dt.Columns.Add("ftReceiptNumber", GetType(String))
dt.Columns.Add("ftReceiptTotal", GetType(String))
dt.Columns.Add("ftQueueId", GetType(String))
dt.Columns.Add("ftReceiptHash", GetType(String))
dt.Columns.Add("ftQueueItemId", GetType(String))
dt.Columns.Add("TimeStamp", GetType(String))
Dim i = 0
Dim num As Integer = jsonArr.Size
If num = 0 Then
Return False
End If
Dim tmstmp As New Chilkat.CkDateTime
Dim getAsLocal As Boolean = False
While i < num
Dim SignObj As Chilkat.JsonObject = jsonArr.ObjectAt(i)
Dim R As DataRow = dt.NewRow
With SignObj
R("ftReceiptJournalId") = .StringOf("ftReceiptJournalId")
R("ftReceiptMoment") = .StringOf("ftReceiptMoment")
R("ftReceiptNumber") = .IntOf("ftReceiptNumber")
R("ftReceiptTotal") = .StringOf("ftReceiptTotal")
R("ftQueueId") = .StringOf("ftQueueId")
R("ftQueueItemId") = .StringOf("ftQueueItemId")
R("ftReceiptHash") = .StringOf("ftReceiptHash")
R("TimeStamp") = tmstmp.GetAsTimestamp(getAsLocal)
End With
dt.Rows.Add(R)
i = i + 1
End While
If dt.Rows.Count > 0 Then
Dim Path = VERAG_PROG_ALLGEMEIN.cProgramFunctions.genExcelFromDT_NEW(dt)
End If
End If
End Function
Private Function getVersion(Terminal_ID) As String
Return Terminal_ID & "_" & Application.ProductVersion
End Function
Private Sub Log(message As String)
Console.WriteLine(message)
End Sub
End Class
Public Class cFiskaltrustSignatures
Property ft_id As Integer
Property ftQueueID As Object = Nothing
Property ftQueueItemID As Object = Nothing
Property ftQueueRow As Object = Nothing
Property ftCashBoxIdentification As Object = Nothing
Property ftReceiptIdentification As Object = Nothing
Property ftReceiptMoment As Object = Nothing
Property ftState As Object = Nothing
Property ftCashBoxID As Object = Nothing
Property cbTerminalID As Object = Nothing
Property cbReceiptReference As Object = Nothing
Public hasEntry = False
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
Sub New()
End Sub
Sub New(ft_id)
Me.ft_id = ft_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("ft_id", ft_id,, True))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftQueueID", ftQueueID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftQueueItemID", ftQueueItemID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftQueueRow", ftQueueRow))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftCashBoxIdentification", ftCashBoxIdentification))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftReceiptIdentification", ftReceiptIdentification))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftReceiptMoment", ftReceiptMoment))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftState", ftState))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftCashBoxID", ftCashBoxID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("cbTerminalID", cbTerminalID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("cbReceiptReference", cbReceiptReference))
Return list
End Function
Public Function SAVE() As Boolean
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
Dim sqlstr = " BEGIN " & getInsertCmd() & " END " '&
'" commit tran "
Dim id = SQL.doSQLVarListID(ft_id, sqlstr, "FMZOLL", , list)
Me.ft_id = id
Return id > 0
End Function
Public Sub LOAD()
Try
hasEntry = False
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
Using cmd As New SqlCommand("SELECT * FROM tblRKSV_FT WHERE ft_id=@ft_id ", conn)
cmd.Parameters.AddWithValue("@ft_id", ft_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 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 tblRKSV_FT (" & 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 cFiskaltrustSignaturPositions
Property ftSignatures As Integer
Property ftSignatureFormat As Object = Nothing
Property ftSignatureType As Object = Nothing
Property ftData As Object = Nothing
Public hasEntry = False
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
Sub New()
End Sub
Sub New(ftSignatures, ftSignatureType)
Me.ftSignatures = ftSignatures
Me.ftSignatureType = ftSignatureType
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("ftSignatures", ftSignatures))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftSignatureFormat", ftSignatureFormat))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftSignatureType", ftSignatureType))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftData", ftData))
Return list
End Function
Public Function SAVE() As Boolean
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
Dim sqlstr = " 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 tblRKSV_FTSignatures WHERE ftSignatures=@ftSignatures AND ftSignatureType = @ftSignatureType ", conn)
cmd.Parameters.AddWithValue("@ftSignatures", ftSignatures)
cmd.Parameters.AddWithValue("@ftSignatureType", ftSignatureType)
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 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 tblRKSV_FTSignatures (" & 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