Files
SDL/VERAG_PROG_ALLGEMEIN/Classes/cAvisoStatusMails.vb
2024-02-26 12:42:52 +01:00

129 lines
5.1 KiB
VB.net

Imports System.Data.SqlClient
Imports System.Reflection
Public Class cAvisoStatusMails
Property asm_AvisoId As Integer
Property asm_KdNr As Integer
Property asm_StatuscodeSent As Integer
Property asm_datetime As Date = Now
Public hasEntry = False
Dim SQL As New SQL
Sub New(asm_AvisoId, asm_KdNr, asm_StatuscodeSent)
Me.asm_AvisoId = asm_AvisoId
Me.asm_KdNr = asm_KdNr
Me.asm_StatuscodeSent = asm_StatuscodeSent
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("asm_AvisoId", asm_AvisoId))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("asm_KdNr", asm_KdNr))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("asm_StatuscodeSent", asm_StatuscodeSent))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("asm_datetime", asm_datetime))
Return list
End Function
Public Shared Function INSERT_INTO(asm_AvisoId, asm_KdNr, asm_StatuscodeSent) As Boolean
Dim AST As New cAvisoStatusMails(asm_AvisoId, asm_KdNr, asm_StatuscodeSent)
AST.asm_AvisoId = asm_AvisoId
AST.asm_KdNr = asm_KdNr
AST.asm_StatuscodeSent = asm_StatuscodeSent
Return AST.SAVE()
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 tblAvisoStatusMails WHERE asm_AvisoId=@asm_AvisoId and asm_KdNr=@asm_KdNr and asm_StatuscodeSent=@asm_StatuscodeSent) " &
" BEGIN " & getUpdateCmd() & " END " &
" Else " &
" BEGIN " & getInsertCmd() & " END " &
" commit tran "
Return SQL.doSQLVarList(sqlstr, "AVISO", , list)
End Function
Public Sub LOAD()
Try
hasEntry = False
Using conn As SqlConnection = SQL.GetNewOpenConnectionAVISO()
Using cmd As New SqlCommand("SELECT * FROM tblAvisoStatusMails WHERE asm_AvisoId=@asm_AvisoId and asm_KdNr=@asm_KdNr and asm_StatuscodeSent=@asm_StatuscodeSent ", conn)
cmd.Parameters.AddWithValue("@asm_AvisoId", asm_AvisoId)
cmd.Parameters.AddWithValue("@asm_KdNr", asm_KdNr)
cmd.Parameters.AddWithValue("@asm_StatuscodeSent", asm_StatuscodeSent)
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 [tblAvisoStatusMails] SET " & str & " WHERE asm_AvisoId=@asm_AvisoId and asm_KdNr=@asm_KdNr and asm_StatuscodeSent=@asm_StatuscodeSent ")
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 tblAvisoStatusMails (" & 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