Imports com.esendex.sdk.messaging Imports com.esendex.sdk.sent Imports System.Data.SqlClient Imports System.Reflection Public Class cSMS Property sms_id As Integer Property sms_Datum As Date = Now Property sms_Firma As Object = Nothing Property sms_Account As Object = Nothing Property sms_Fahrername As Object = Nothing Property sms_KundenNr As Object = Nothing Property sms_Kunde As Object = Nothing Property sms_Vorwahl As Object = Nothing Property sms_Handynummer As Object = Nothing Property sms_Nachricht As Object = Nothing Property sms_BatchId As Object = Nothing Property sms_MessageIds As Object = Nothing Property sms_Uris As Object = Nothing Property sms_Sachbearbeiter As String = Nothing Property sms_SachbearbeiterId As Integer Property sms_AvisoId As Object = Nothing Property sms_Status As Integer = -1 Property sms_Queued As Object = Nothing Property sms_Sent As Object = Nothing Property sms_Delivered As Object = Nothing Property sms_Failure As Object = Nothing Dim ESENDEX_USER As String = "al@verag.ag" Dim ESENDEX_PWD As String = "Developer#2" Dim SQL As New SQL Sub New() sms_Sachbearbeiter = If(sms_Sachbearbeiter, VERAG_PROG_ALLGEMEIN.cAllgemein.USRKURZNAME) If sms_SachbearbeiterId <= 0 Then sms_SachbearbeiterId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID End Sub Sub New(sms_id) Me.sms_id = sms_id LOAD() 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("sms_id", sms_id, , True, True)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Datum", sms_Datum)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Firma", sms_Firma)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Account", sms_Account)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Fahrername", sms_Fahrername)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_KundenNr", sms_KundenNr)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Kunde", sms_Kunde)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Vorwahl", sms_Vorwahl)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Handynummer", sms_Handynummer)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Nachricht", sms_Nachricht)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_BatchId", sms_BatchId)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_MessageIds", sms_MessageIds)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Uris", sms_Uris)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Sachbearbeiter", sms_Sachbearbeiter)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_SachbearbeiterId", sms_SachbearbeiterId)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_AvisoId", sms_AvisoId)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Status", sms_Status)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Queued", sms_Queued)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Sent", sms_Sent)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Delivered", sms_Delivered)) list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Failure", sms_Failure)) 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 tblSMS WITH(updlock,serializable) WHERE sms_id=@sms_id) " & " BEGIN " & getUpdateCmd() & " END " & " Else " & " BEGIN " & getInsertCmd() & " END " & " commit tran " sms_id = SQL.doSQLVarListID(sms_id, sqlstr, "FMZOLL", , list) Return sms_id > 0 End Function Public Sub LOAD() Try Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL() Using cmd As New SqlCommand("SELECT * FROM tblSMS WHERE sms_id=@sms_id ", conn) cmd.Parameters.AddWithValue("@sms_id", sms_id) Dim dr = cmd.ExecuteReader() If dr.Read Then For Each l In getParameterList() Dim propInfo As PropertyInfo = Me.GetType.GetProperty(l.Scalarvariable) If dr.Item(l.Text) Is DBNull.Value Then propInfo.SetValue(Me, Nothing) Else propInfo.SetValue(Me, dr.Item(l.Text)) End If 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 [tblSMS] SET " & str & " WHERE sms_id=@sms_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 tblSMS (" & 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 [tblSMS] WITH(updlock,serializable) WHERE sms_id=" & Me.sms_id Return SQL.doSQL(sqlstr, "FMZOLL") End Function Function sendSMS() As Boolean Try Dim messagingService As New MessagingService(ESENDEX_USER, ESENDEX_PWD) 'SENDEN DER SMS Dim result = messagingService.SendMessage(New SmsMessage(Me.sms_Handynummer, Me.sms_Nachricht, Me.sms_Account)) Dim Uris As String = "" Dim msgIDs As String = "" Try Me.sms_BatchId = result.BatchId If result.MessageIds IsNot Nothing Then For Each m In result.MessageIds Uris &= m.Uri & ";;" msgIDs &= m.Id.ToString & ";;" Next End If Catch ex As Exception End Try While Uris.EndsWith(";;") Uris = Uris.Substring(0, Uris.Length - 2) End While While msgIDs.EndsWith(";;") msgIDs = msgIDs.Substring(0, msgIDs.Length - 2) End While Me.sms_MessageIds = msgIDs Me.sms_Uris = Uris If Not Me.SAVE() Then MsgBox("Fehler: SMS Daten wurden nicht gespeichert!") End If Return True Catch ex As Exception MsgBox("Fehler beim Senden der SMS!" & vbNewLine & ex.Message & ex.StackTrace) Return False End Try End Function Function checkSMSStatus() As String Try If Me.sms_Status >= 3 Then Return Me.sms_Status ' Bereits finaler Status, keine Abfrage nötig If If(Me.sms_MessageIds, "") = "" Then MsgBox("Keine MessageId gefunden!") : Return False ' Keine MsgId Dim sendService As New SentService(ESENDEX_USER, ESENDEX_PWD) 'Send a message and retrieve the message ID Dim MSG = sendService.GetMessage(New Guid(Me.sms_MessageIds.ToString)) Dim messageStatus = MSG.Status MsgBox(MSG.Status) 'Status in DB Ubdaten Me.sms_Status = messageStatus Me.sms_Sent = MSG.SentAt Me.sms_Delivered = MSG.DeliveredAt If MSG.FailureReason IsNot Nothing Then Me.sms_Failure = MSG.FailureReason.Description Me.SAVE() Return messageStatus Catch ex As Exception MsgBox("Fehler beim Prüfen des SMS Status!" & vbNewLine & ex.Message & ex.StackTrace) End Try Return "" End Function End Class