Imports System.Data.SqlClient Imports System.Reflection Public Class cTextkonserve_LIST Public LIST As New List(Of cTextkonserve) Public SPRACHENLIST As New List(Of String) Dim SQL As New SQL Sub New(txt_kategorie As String, txt_sprache As String, txt_FIRMA As String) LOAD_LIST(txt_kategorie, txt_sprache, txt_FIRMA) End Sub Sub New(txt_Type As Integer, txt_sprache As String, txt_FIRMA As String) LOAD_LIST_TYPE(txt_Type, txt_sprache, txt_FIRMA) End Sub Sub New(txt_Type As Integer, txt_sprache As String, FIRMAID As Integer) Dim FIRMA As New VERAG_PROG_ALLGEMEIN.cFirmen(FIRMAID) LOAD_LIST_TYPE(txt_Type, txt_sprache, FIRMA.Firmengruppe) End Sub Sub New(txt_FIRMA As String) LOAD_SPRACHENLIST(txt_FIRMA) End Sub Public Sub LOAD_LIST(txt_kategorie As String, txt_sprache As String, txt_FIRMA As String) Try LIST.Clear() Dim sqlSprache As String = "" If txt_sprache <> "" Then sqlSprache = " And txt_sprache = '" & txt_sprache & "'" For Each r In SQL.loadDgvBySql("Select txt_Id FROM [tblTextkonserve] WHERE txt_kategorie='" & txt_kategorie & "' AND txt_FIRMA = '" & txt_FIRMA & "' and txt_dynMailvorlage = 1" & sqlSprache & " ORDER BY txt_kategorie asc", "FMZOLL").Rows LIST.Add(New VERAG_PROG_ALLGEMEIN.cTextkonserve(r("txt_Id"))) Next 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_LIST_TYPE(txt_type As Integer, txt_sprache As String, txt_FIRMA As String) Try LIST.Clear() Dim sqlSprache As String = "" If txt_sprache <> "" Then sqlSprache = " And txt_sprache = '" & txt_sprache & "'" For Each r In SQL.loadDgvBySql("Select txt_Id FROM [tblTextkonserve] WHERE txt_typ='" & txt_type & "' AND txt_FIRMA = '" & txt_FIRMA & "' and txt_dynMailvorlage = 1" & sqlSprache & " ORDER BY txt_kategorie asc", "FMZOLL").Rows LIST.Add(New VERAG_PROG_ALLGEMEIN.cTextkonserve(r("txt_Id"))) Next 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_SPRACHENLIST(txt_FIRMA As String) Try SPRACHENLIST.Clear() For Each r In SQL.loadDgvBySql("Select distinct(txt_sprache) FROM [tblTextkonserve] WHERE txt_FIRMA = '" & txt_FIRMA & "' and txt_dynMailvorlage = 1 order by txt_sprache", "FMZOLL").Rows SPRACHENLIST.Add(r("txt_sprache")) Next 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 End Class Public Class cTextkonserve Property txt_Id As Integer Property txt_kategorie As String Property txt_bezeichnung As String Property txt_sprache As String Property txt_text As String Property txt_betreff As String Property txt_FIRMA As String Property txt_firmaSig As Integer Property txt_dynMailvorlage As Boolean Property txt_letzteAenderungUser As String Property txt_letzteAenderung As DateTime Property txt_sendungsvermerk As Boolean Property txt_sendungsvermerkId As Integer Property txt_sendungsvermerkText As String Property txt_fixerEmpfaengerEmail As String Property txt_typ As Object Public hasEntry As Boolean = False Dim SQL As New SQL Sub New() End Sub Sub New(txt_Id) ' If txt_Id IsNot Nothing Then Me.txt_Id = txt_Id LOAD() ' End If End Sub Sub New(txt_kategorie, txt_bezeichnung, txt_sprache, txt_FIRMA) ' If txt_Id IsNot Nothing Then Me.txt_kategorie = txt_kategorie Me.txt_bezeichnung = txt_bezeichnung Me.txt_sprache = txt_sprache Me.txt_FIRMA = txt_FIRMA LOAD(txt_kategorie, txt_bezeichnung, txt_sprache, txt_FIRMA) ' End If End Sub Public 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("txt_Id", txt_Id, , True, True)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_kategorie", txt_kategorie)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_bezeichnung", txt_bezeichnung)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_sprache", txt_sprache)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_text", txt_text)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_betreff", txt_betreff)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_FIRMA", txt_FIRMA)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_firmaSig", txt_firmaSig)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_dynMailvorlage", txt_dynMailvorlage)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_letzteAenderungUser", txt_letzteAenderungUser)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_letzteAenderung", txt_letzteAenderung)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_sendungsvermerk", txt_sendungsvermerk)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_sendungsvermerkId", txt_sendungsvermerkId)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_sendungsvermerkText", txt_sendungsvermerkText)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_fixerEmpfaengerEmail", txt_fixerEmpfaengerEmail)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("txt_typ", txt_typ)) Return list End Function Public Function SAVE(Optional errHinweis = "") As Boolean Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList() Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblTextkonserve WITH(updlock,serializable) WHERE txt_Id=@txt_Id) " & " BEGIN " & getUpdateCmd() & " END " & " Else " & " BEGIN " & getInsertCmd() & " END " & " commit tran " txt_Id = SQL.doSQLVarListID(txt_Id, sqlstr, "FMZOLL", , list,, errHinweis) Return txt_Id > 0 End Function Public Sub LOAD() Try Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL Using cmd As New SqlCommand("SELECT * FROM tblTextkonserve WHERE txt_Id=@txt_Id ", conn) cmd.Parameters.AddWithValue("@txt_Id", txt_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 hasEntry = True Next 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 Sub LOAD(txt_kategorie, txt_bezeichnung, txt_sprache, txt_FIRMA) Try Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL Using cmd As New SqlCommand("SELECT TOP 1 * FROM tblTextkonserve WHERE txt_kategorie=@txt_kategorie AND txt_bezeichnung=@txt_bezeichnung AND txt_sprache=@txt_sprache AND txt_FIRMA=@txt_FIRMA ", conn) cmd.Parameters.AddWithValue("@txt_kategorie", txt_kategorie) cmd.Parameters.AddWithValue("@txt_bezeichnung", txt_bezeichnung) cmd.Parameters.AddWithValue("@txt_sprache", txt_sprache) cmd.Parameters.AddWithValue("@txt_FIRMA", txt_FIRMA) 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 hasEntry = True Next 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 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 [tblTextkonserve] SET " & str & " WHERE txt_Id=@txt_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 tblTextkonserve (" & 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 Public Function DELETE() As Boolean 'obj As Object, tablename As String, where As String) As Boolean Dim sqlstr = " DELETE FROM [tblTextkonserve] WITH(updlock,serializable) WHERE txt_Id=" & Me.txt_Id Return SQL.doSQL(sqlstr, "FMZOLL") End Function Public Shared Function DELETE(id As Integer) As Boolean 'obj As Object, tablename As String, where As String) As Boolean Dim sqlstr = " DELETE FROM [tblTextkonserve] WITH(updlock,serializable) WHERE txt_Id=" & id Return (New VERAG_PROG_ALLGEMEIN.SQL).doSQL(sqlstr, "FMZOLL") End Function End Class