You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
776 lines
32 KiB
776 lines
32 KiB
Imports System.ServiceProcess
|
|
Imports System.Threading
|
|
Imports System.IO
|
|
Imports System.Reflection
|
|
Imports System.IO.File
|
|
Imports System.Data.SqlClient
|
|
Imports System.Data.SqlTypes
|
|
Imports System.ComponentModel
|
|
Imports System
|
|
Imports System.SystemException
|
|
Imports System.Web.Mail
|
|
|
|
'''<summary></summary>
|
|
Public Class Service1
|
|
Inherits System.ServiceProcess.ServiceBase
|
|
|
|
#Region " Vom Component Designer generierter Code "
|
|
|
|
Public Sub New()
|
|
MyBase.New()
|
|
|
|
' Dieser Aufruf wird vom Komponenten-Designer benötigt.
|
|
InitializeComponent()
|
|
|
|
' Fügen Sie Initialisierungscode hinter dem InitializeComponent()-Aufruf ein
|
|
|
|
End Sub
|
|
|
|
'UserService überschreibt den Löschvorgang zum Bereinigen der Komponentenliste.
|
|
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
|
|
If disposing Then
|
|
If Not (components Is Nothing) Then
|
|
components.Dispose()
|
|
End If
|
|
End If
|
|
MyBase.Dispose(disposing)
|
|
End Sub
|
|
|
|
' Der Haupteinstiegspunkt für den Vorgang
|
|
<MTAThread()> _
|
|
Shared Sub Main()
|
|
|
|
|
|
'#If Debug Then
|
|
' Dim service As New Service1()
|
|
' service.Run(Service1)
|
|
' service.StartService()
|
|
' System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
|
|
'#Else
|
|
' Dim ServicesToRun() As System.ServiceProcess.ServiceBase
|
|
' ServicesToRun = New System.ServiceProcess.ServiceBase() {New service1}
|
|
' System.ServiceProcess.ServiceBase.Run(ServicesToRun)
|
|
'#End If
|
|
|
|
|
|
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
|
|
|
|
ServicesToRun = New System.ServiceProcess.ServiceBase() {New Service1()}
|
|
|
|
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
|
|
End Sub
|
|
|
|
' Für Komponenten-Designer erforderlich
|
|
Private components As System.ComponentModel.IContainer
|
|
|
|
' HINWEIS: Die folgende Prozedur wird vom Komponenten-Designer benötigt.
|
|
' Sie kann mit dem Komponenten-Designer modifiziert werden. Verwenden Sie nicht
|
|
' den Code-Editor zur Bearbeitung.
|
|
'Friend WithEvents ServiceIcon As System.Windows.Forms.NotifyIcon
|
|
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
|
|
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
|
|
Me.components = New System.ComponentModel.Container()
|
|
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Service1))
|
|
'Me.ServiceIcon = New System.Windows.Forms.NotifyIcon(Me.components)
|
|
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
|
|
'
|
|
'ServiceIcon
|
|
'
|
|
'Me.ServiceIcon.Icon = CType(resources.GetObject("ServiceIcon.Icon"), System.Drawing.Icon)
|
|
'Me.ServiceIcon.Text = "EDKB08WS"
|
|
'Me.ServiceIcon.Visible = True
|
|
'
|
|
'ImageList1
|
|
'
|
|
Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
|
|
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
|
|
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
|
|
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
|
|
'
|
|
'Service1
|
|
'
|
|
Me.ServiceName = "Service1"
|
|
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "Deklarationen"
|
|
Private StopThread As Boolean = False
|
|
'''<summary>Variable mit dem Namen des zu überwachenden Verzeichnises</summary>
|
|
Dim Watch_Directory As String
|
|
'''<summary>FileSystemWatcher</summary>
|
|
'''<remarks>Dieser Reagiert auf das Ereignis OnCreate im angegebenen Verzeichnis
|
|
'''(Watch_Directory)</remarks>
|
|
Dim FileWatch As New FileSystemWatcher()
|
|
|
|
'''<summary>Varaible zum Zwischenspeichern der Indexdaten einer
|
|
'''Indexdaten-Datei</summary>
|
|
Dim indexdata As DataTable
|
|
|
|
'''<summary>Timer zur Auslösung der täglichen Journalaufbereitung</summary>
|
|
Dim WithEvents JournalTimer As New Timers.Timer()
|
|
|
|
'Anpassungen GSF
|
|
Dim WithEvents GSF_Timer As New Timers.Timer()
|
|
|
|
#End Region
|
|
|
|
#Region "Hauptverarbeitung"
|
|
|
|
'''<summary>Start des Dienstes EDKB08WS</summary>
|
|
'''<remarks>Beim Start des Dienstes werden neben dem Einlesen der Parameter der
|
|
'''Journaltimer sowie der Systemfilewatcher zur Verzeichnisüberwachung
|
|
'''initialisiert.</remarks>
|
|
'''<param name="args"></param>
|
|
Protected Overrides Sub OnStart(ByVal args() As String)
|
|
Try
|
|
'Dim bmp As New Bitmap(Me.ImageList1.Images(2))
|
|
'ServiceIcon.Icon = Icon.FromHandle(bmp.GetHicon())
|
|
'ServiceIcon.Visible = True
|
|
'ServiceIcon.Text = "Starting ..."
|
|
|
|
PrintOut("Start EDKB08")
|
|
|
|
'Parameter auslesen
|
|
If Params.Loadparameters = False Then
|
|
PrintOut(Params.Meldung)
|
|
PrintOut("Verarbeitung abgebrochen")
|
|
Exit Sub
|
|
Else
|
|
GSF_Timer.Interval = Params.Prop_gsf_TimerInterval
|
|
GSF_Timer.Enabled = True
|
|
|
|
Watch_Directory = Params.Inputverzeichnis
|
|
PrintOut(Params.Meldung)
|
|
PrintOut("Parameter:")
|
|
PrintOut("Überwachtes Verzeichnis: " + Params.Inputverzeichnis)
|
|
PrintOut("E-Mail OK: " + Params.MailAdresseOK)
|
|
PrintOut("E-Mail NOK:" + Params.MailAdresseNOK)
|
|
PrintOut("GSF_Timer:" + Params.Prop_gsf_TimerInterval.ToString)
|
|
PrintOut("GSF_ConfigPath:" + Params.Prop_gsf_ConfigPath)
|
|
End If
|
|
'Datenbank initialisieren
|
|
Dim db_conn As New edokadb.DB_Connection()
|
|
JournalTimer.Interval = Params.JournalTimer_Time
|
|
JournalTimer.Enabled = True
|
|
PrintOut("Journaltimer initialisiert. Eventhalndler alle " + LTrim(Str(JournalTimer.Interval / (1000 * 60))) + " Minuten")
|
|
|
|
'Verzeichnis-Überwachung initialisieren und starten
|
|
If Not Init_Filewatcher() Then
|
|
PrintOut("Verarbeitung gestoppt", EventLogEntryType.Error)
|
|
End If
|
|
If Not Start_Watching() Then
|
|
PrintOut("Verarbeitung gestoppt", EventLogEntryType.Error)
|
|
Exit Sub
|
|
End If
|
|
'Dim bmp1 As New Bitmap(Me.ImageList1.Images(1))
|
|
'ServiceIcon.Icon = Icon.FromHandle(bmp1.GetHicon())
|
|
'ServiceIcon.Text = "Waiting ..."
|
|
Catch ex As Exception
|
|
' Dim bmp1 As New Bitmap(Me.ImageList1.Images(2))
|
|
'ServiceIcon.Icon = Icon.FromHandle(bmp1.GetHicon())
|
|
PrintOut("Fehler beim Start von EDKB08" + ex.Message, EventLogEntryType.Error)
|
|
End Try
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnStop()
|
|
' Dim bmp1 As New Bitmap(Me.ImageList1.Images(2))
|
|
'ServiceIcon.Icon = Icon.FromHandle(bmp1.GetHicon())
|
|
'ServiceIcon.Text = "Stopping..."
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "FileWatcher"
|
|
|
|
'''<summary>Initialisierung des Filewacher-Objektes</summary>
|
|
'''<remarks>Das Filewacher-Objekt wird mit den entpsrechenden Pfad- sowie
|
|
'''Dateifilter-Angaben initialisiert.</remarks>
|
|
Private Function Init_Filewatcher() As Boolean
|
|
Try
|
|
FileWatch.Path = Watch_Directory
|
|
FileWatch.IncludeSubdirectories = False
|
|
FileWatch.Filter = "*.*"
|
|
Return True
|
|
Catch ex As Exception
|
|
PrintOut("Fehler bei der Initialisierung des Filewacherobjekts auf " + Watch_Directory + ex.Message,EventLogEntryType.Error)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
'''<summary>Eventhandler des FileWatching-Objektes aktivieren</summary>
|
|
Private Function Start_Watching() As Boolean
|
|
Try
|
|
AddHandler FileWatch.Created, New FileSystemEventHandler(AddressOf OnFileEvent)
|
|
AddHandler FileWatch.Renamed, AddressOf OnFileEventRename
|
|
FileWatch.EnableRaisingEvents = True
|
|
PrintOut("Filewatch Event-Handler initialisiert: " + Me.Watch_Directory)
|
|
Return True
|
|
Catch ex As Exception
|
|
PrintOut("Fehler bei der Event-Initialisierung " + ex.Message, EventLogEntryType.Error)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Dim EventStopped As Boolean = False
|
|
'''<summary>Aktivitäten im Inputverzeichnis verarbeiten</summary>
|
|
'''<remarks>Wird eine Datei mit der Endung .IND angeliefert, wird der Eventhandler
|
|
'''gestoppt und die anstehenden Dokumente verarbeitet.
|
|
'''
|
|
'''Nach abgeschlossener Verarbeitung wird der Eventhandler wieder
|
|
'''eingeschaltet</remarks>
|
|
'''<param name="source"></param>
|
|
'''<param name="e"></param>
|
|
Private Sub OnFileEvent(ByVal source As Object, ByVal e As FileSystemEventArgs)
|
|
If EventStopped = True Then Exit Sub
|
|
If UCase(Microsoft.VisualBasic.Right(e.FullPath, 4)) = ".IND" Then
|
|
FileWatch.EnableRaisingEvents = False
|
|
EventStopped = True
|
|
PrintOut("Neue Datei " + e.FullPath)
|
|
'ServiceIcon.Text = "Working..."
|
|
Verarbeiten()
|
|
' ServiceThread = New Thread(AddressOf Verarbeiten)
|
|
' ServiceThread.Start()
|
|
FileWatch.EnableRaisingEvents = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub OnFileEventRename(ByVal source As Object, ByVal e As RenamedEventArgs)
|
|
If EventStopped = True Then Exit Sub
|
|
If UCase(Microsoft.VisualBasic.Right(e.FullPath, 4)) = ".IND" Then
|
|
FileWatch.EnableRaisingEvents = False
|
|
EventStopped = True
|
|
PrintOut("Neue Datei " + e.FullPath)
|
|
'20130131 - Sleep von 1000 auf 3000 geändert, damit bei FinFox-Dokumente die Verarbeitung nicht aussteigt, sofern die Datei noch nicht angeliefert wurde
|
|
Threading.Thread.CurrentThread.Sleep(3000)
|
|
Verarbeiten()
|
|
FileWatch.EnableRaisingEvents = True
|
|
End If
|
|
End Sub
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
#Region "Verarbeitung"
|
|
|
|
'''<summary>Verarbeiten von angelieferten Daten</summary>
|
|
'''<remarks>In dieser Methode werden angelieferte Indexdateien verarbeitet.
|
|
'''<para></para>
|
|
'''<para>Bevor die Verarbeitung startet, wird der Systemfilewacher
|
|
'''ausgeschaltet.</para>
|
|
'''<para>Die Verarbeitung wird solange durchgeführt, bis alle anstehenden
|
|
'''Indexdaten und Dokumente abgearbeitet sind.</para>
|
|
'''<para>Am Schluss der Verarbeitung wird der Systemfilewacher wieder
|
|
'''gestartet.</para></remarks>
|
|
Private Sub Verarbeiten()
|
|
Dim gsffilename As String = ""
|
|
Try
|
|
PrintOut("Bei Verarbeiten() zuerst 5000ms warten", EventLogEntryType.Information)
|
|
'Thread.Sleep(5000) 'hallo, wieder aktivieren
|
|
|
|
'Dim bmp As New Bitmap(Me.ImageList1.Images(0))
|
|
'ServiceIcon.Icon = Icon.FromHandle(bmp.GetHicon())
|
|
Dim looper As Boolean = True
|
|
While looper = True
|
|
'Alle .IND-Dateien im Verzeichnis auslesen
|
|
Dim clsindex As New clsIndexData()
|
|
Dim di As New IO.DirectoryInfo(Watch_Directory)
|
|
Dim diar1 As IO.FileInfo() = di.GetFiles("*.ind")
|
|
Dim dra As IO.FileInfo
|
|
If diar1.Length = 0 Then
|
|
looper = False
|
|
clsindex = Nothing
|
|
di = Nothing
|
|
diar1 = Nothing
|
|
'Globals.Journal.Delete_Entry()
|
|
'Dim bmp1 As New Bitmap(Me.ImageList1.Images(1))
|
|
'ServiceIcon.Icon = Icon.FromHandle(bmp1.GetHicon())
|
|
'ServiceIcon.Text = "Waiting..."
|
|
EventStopped = False
|
|
Exit Sub
|
|
End If
|
|
Try
|
|
For Each dra In diar1
|
|
gsffilename = dra.Name.Substring(0, dra.Name.IndexOf("."))
|
|
PrintOut("File: " + dra.FullName)
|
|
Globals.Journal.Open_Journal()
|
|
Globals.Journal.Insert_Journal("", "", "", dra.FullName, "", "Start der Verarbeitung", "", "")
|
|
DivFnkt.Save_Indexdata(Journal.JournalNr, dra.FullName)
|
|
clsindex.IndexFileName = dra.FullName
|
|
If clsindex.getindexdata Then
|
|
indexdata = clsindex.Indexdata
|
|
Dim check_and_import As New clsCheckandImport()
|
|
check_and_import.IndexData = indexdata
|
|
|
|
If check_and_import.Herkunftsapplikationen_auslesen = False And indexdata.Rows(0).Item(17) = "" Then
|
|
Journal.Insert_Journal("", "", "", dra.FullName, "16", "Zuordnung zur Herkunftsapplikation fehlt.", "", "")
|
|
Else
|
|
If check_and_import.Herkunftsapplikationen_auslesen Then
|
|
'Sofern die Herkunftsapplikation erruiert werden konnte, wird die Journaltabelle mit der Applikationsid nachgeführt
|
|
Globals.Journal.Update_Journal()
|
|
'PrintOut("test", EventLogEntryType.Error)
|
|
'Verarbeitung der Daten
|
|
check_and_import.CheckandImport()
|
|
check_and_import = Nothing
|
|
End If
|
|
End If
|
|
End If
|
|
Journal.Insert_Journal("", "", "", dra.FullName, "", "Total Index-Datensätze: " + LTrim(Str(indexdata.Rows.Count)), "", "")
|
|
Journal.Insert_Journal("", "", "", dra.FullName, "", "Verarbeitung abgeschlossen.", "", "")
|
|
Logdatei_Erstellen()
|
|
Globals.Journal.Close_Journal()
|
|
'Anpassungen EBES-LSV
|
|
If GSF = True Then
|
|
If Fehler <> 0 Then
|
|
OBJ_GSF.Set_DokStatus(dra.Name.Substring(0, dra.Name.IndexOf(".")), EDKB08_GSF.Common.Enum_DokStatus.OK)
|
|
Else
|
|
OBJ_GSF.Set_DokStatus(dra.Name.Substring(0, dra.Name.IndexOf(".")), EDKB08_GSF.Common.Enum_DokStatus.OK)
|
|
End If
|
|
End If
|
|
|
|
Next
|
|
Catch ex As Exception
|
|
PrintOut(ex.Message, EventLogEntryType.Error)
|
|
End Try
|
|
clsindex = Nothing
|
|
di = Nothing
|
|
diar1 = Nothing
|
|
End While
|
|
Catch ex As Exception
|
|
Try
|
|
Globals.conn_edoka.CloseConnection(True)
|
|
Catch
|
|
End Try
|
|
Try
|
|
Globals.conn_journale.CloseConnection(True)
|
|
Catch
|
|
End Try
|
|
Fehler = -16
|
|
Try
|
|
Journal.Insert_Journal("", "", "", "", "-16", ex.Message + ex.StackTrace, "", "")
|
|
Catch
|
|
End Try
|
|
Try
|
|
Journal.Insert_Journal("", "", "", "", "", "Verarbeitung abgebrochen", "", "")
|
|
Catch
|
|
End Try
|
|
Try
|
|
Journal.Close_Journal()
|
|
Catch
|
|
|
|
End Try
|
|
|
|
Try
|
|
OBJ_GSF.Set_DokStatus(gsffilename, EDKB08_GSF.Common.Enum_DokStatus.FehlerEDKB08)
|
|
Catch
|
|
End Try
|
|
|
|
PrintOut("Folgender Fehler ist in EDKB08 aufgetreten:" + ex.Message, EventLogEntryType.Error)
|
|
FileWatch.EnableRaisingEvents = True
|
|
'Dim bmp1 As New Bitmap(Me.ImageList1.Images(1))
|
|
'ServiceIcon.Icon = Icon.FromHandle(bmp1.GetHicon())
|
|
'ServiceIcon.Text = "Waiting ..."
|
|
EventStopped = False
|
|
End Try
|
|
End Sub
|
|
|
|
'''<summary>Journaldatei erstellen und je nach Applikationseinstellungen
|
|
'''versenden</summary>
|
|
'''<remarks>Erstellt eine Journaldatei mit den Journaldaten der Verarbeitung und
|
|
'''sendet diese mittels Mail bzw. mittls DTO weiter</remarks>
|
|
Private Sub Logdatei_Erstellen()
|
|
Dim filename As String = ""
|
|
Try
|
|
If Globals.Herkunftsapplikation.Rows(0).Item("log_erstellung") <> 1 And Globals.Herkunftsapplikation.Rows(0).Item("log_erstellung") <> 2 Then Exit Sub
|
|
If Globals.Herkunftsapplikation.Rows(0).Item("log_erstellung") = 1 And Globals.Herkunftsapplikation.Rows(0).Item("Mail_Periodizitaet") = 0 Then
|
|
filename = Journal.Print_Log(Globals.Herkunftsapplikation.Rows(0).Item(0), Globals.Herkunftsapplikation.Rows(0).Item(1), Globals.Herkunftsapplikation.Rows(0).Item("outputformat"))
|
|
PrintOut("Aufruf Sendmail")
|
|
Send_Mail(filename, Globals.Herkunftsapplikation.Rows(0).Item("Mail_Empfaneger"))
|
|
End If
|
|
If Globals.Herkunftsapplikation.Rows(0).Item("log_erstellung") = 2 Then
|
|
filename = Journal.Print_Log(Globals.Herkunftsapplikation.Rows(0).Item(0), Globals.Herkunftsapplikation.Rows(0).Item(1), Globals.Herkunftsapplikation.Rows(0).Item("outputformat"))
|
|
Send_DTO(filename)
|
|
End If
|
|
Catch ex As Exception
|
|
Journal.Insert_Journal("", "", "", filename, "-16", "Das Journal " + filename + " konnte nicht erstellt werden." + ex.Message, "", "")
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
'''<summary>DTO-Versand</summary>
|
|
'''<param name="filename"></param>
|
|
Private Function Send_DTO(ByVal filename As String) As Boolean
|
|
Try
|
|
Dim i As Integer
|
|
Dim tw As TextWriter
|
|
Dim s As String
|
|
s = Herkunftsapplikation.Rows(0).Item(3)
|
|
s = s.Replace("%1", filename)
|
|
s = s.Replace("%2", filename)
|
|
tw = New StreamWriter(New FileStream(Params.TempPfad + "dtotransfer.cmd", FileMode.Create))
|
|
tw.WriteLine(s)
|
|
tw.Flush()
|
|
tw.Close()
|
|
i = Microsoft.VisualBasic.Shell(Params.TempPfad + "dtotransfer.cmd", AppWinStyle.Hide, True)
|
|
If i <> 0 Then
|
|
Journal.Insert_Journal("", "", "", filename, "0", "DTO-Datei konnte nicht übermittelt werden. RC: " + LTrim(Str(i)), "", "")
|
|
Else
|
|
Journal.Insert_Journal("", "", "", filename, "0", "DTO-Datei konnte nicht übermittelt werden. RC: " + LTrim(Str(i)), "", "")
|
|
End If
|
|
Return True
|
|
Catch ex As Exception
|
|
Fehler = 4
|
|
Journal.Insert_Journal("", "", "", filename, "-16", "DTO-Datei konnte nicht übermittelt werden. " + ex.Message, "", "")
|
|
'PrintOut("Der Journalversand mittls DTO ist fehlgeschlagen. " + ex.Message, EventLogEntryType.Warning)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
'''<summary>Versand von Journaldaten mittels Email</summary>
|
|
'''<param name="filename"></param>
|
|
'''<param name="empfaenger"></param>
|
|
Private Function Send_Mail(ByVal filename As String, ByVal empfaenger As String) As Boolean
|
|
'Sofern ein SMTP-Server angegeben wird, wird vie SMTP Versendet
|
|
If Params.Mailserver <> "" Then
|
|
|
|
Dim strArgs() As String = Command.Split(",")
|
|
Dim blnSMTP As Boolean = False
|
|
Dim blnCC As Boolean = False
|
|
Dim blnAttachments As Boolean = False
|
|
Try
|
|
Dim insMail As New System.Net.Mail.MailMessage(Params.Mailabsender, empfaenger)
|
|
With insMail
|
|
.Subject = "EDKB08-Journal"
|
|
'.BodyEndoding = System.Text.Encoding.Unicode
|
|
.Body = "Dieses Email wurde automatisch von EDKB08 erstellt"
|
|
' .Attachments.Add(New MailAttachment(filename))
|
|
End With
|
|
Dim myMail As New System.Net.Mail.SmtpClient
|
|
myMail.Host = Params.Mailserver
|
|
myMail.Send(insMail)
|
|
''PrintOut("Journal erfolgreich versandt.", EventLogEntryType.Information)
|
|
Journal.Insert_Journal("", "", "", filename, "0", "E-Mail mit Journal versandt.", "", "")
|
|
Catch ex As Exception
|
|
Fehler = 4
|
|
Journal.Insert_Journal("", "", "", filename, "-10", "E-Mail konnte nicht versandt werden. " + ex.Message, "", "")
|
|
'PrintOut("Journal konnte nicht versandt werden." + ex.Message, EventLogEntryType.Error)
|
|
Return False
|
|
End Try
|
|
Else
|
|
If Save_Report_To_DB(filename) Then
|
|
If Fehler = 0 Then
|
|
send_db_mail(empfaenger, "EDKB08-Dokumentimport erfolgreich: " + filename.Substring(filename.LastIndexOf("\") + 1), filename)
|
|
Else
|
|
send_db_mail(empfaenger, "EDKB08-Dokumentimport mit Fehlern: " + filename.Substring(filename.LastIndexOf("\") + 1), filename)
|
|
End If
|
|
End If
|
|
End If
|
|
End Function
|
|
|
|
Private Function send_db_mail(ByVal empfaenger As String, ByVal Subject As String, ByVal filename As String) As Boolean
|
|
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
|
|
Dim dtToReturn As DataTable = New DataTable()
|
|
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
|
|
scmCmdToExecute.CommandText = "dbo.sp_edoka_import_send_mail"
|
|
scmCmdToExecute.CommandType = CommandType.StoredProcedure
|
|
scmCmdToExecute.Connection = conn_journale_Mail.scoDBConnection
|
|
scmCmdToExecute.Parameters.Add(New SqlParameter("@empfaenger", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, empfaenger))
|
|
scmCmdToExecute.Parameters.Add(New SqlParameter("@betreff", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, Subject))
|
|
filename = filename.Substring(filename.LastIndexOf("\") + 1)
|
|
|
|
scmCmdToExecute.Parameters.Add(New SqlParameter("@filename", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, filename))
|
|
scmCmdToExecute.Parameters.Add(New SqlParameter("@jobnr", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, Journal.JournalNr))
|
|
scmCmdToExecute.Parameters.Add(New SqlParameter("@errorcode", SqlDbType.Int, 4, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, 9))
|
|
Try
|
|
sdaAdapter.Fill(dtToReturn)
|
|
If scmCmdToExecute.Parameters("@errorcode").Value <> 0 Then
|
|
'Journal.Insert_Journal("", "", "", filename, "20", "Mail konnte nicht versandt werden. " + scmCmdToExecute.Parameters("@errorcode").Value, "", "")
|
|
PrintLog("Mail konnte nicht versandt werden. " + scmCmdToExecute.Parameters("@errorcode").Value, EventLogEntryType.Warning)
|
|
Return False
|
|
End If
|
|
Catch ex As Exception
|
|
'Journal.Insert_Journal("", "", "", filename, "20", "Mail konnte nicht versandt werden." + ex.Message, "", "")
|
|
PrintLog("Mail konnte nicht versandt werden." + ex.Message, EventLogEntryType.Warning)
|
|
Return False
|
|
Finally
|
|
scmCmdToExecute.Dispose()
|
|
sdaAdapter.Dispose()
|
|
dtToReturn.Dispose()
|
|
End Try
|
|
End Function
|
|
|
|
Private Function Save_Report_To_DB(ByVal Filename As String) As Boolean
|
|
Dim connection As New SqlConnection()
|
|
Dim da As New SqlDataAdapter("Select * From import_journaldatei where import_jobnr=" + Journal.JournalNr.ToString, connection)
|
|
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
|
|
Dim ds As New DataSet()
|
|
Try
|
|
'Connectionstring zur Datenbank
|
|
connection.ConnectionString = Globals.sConnectionString_journale
|
|
connection.Open()
|
|
da.Fill(ds, "docs")
|
|
Dim fs As New FileStream(Filename, FileMode.Open, FileAccess.Read)
|
|
Dim mydata(fs.Length) As Byte
|
|
fs.Read(mydata, 0, fs.Length)
|
|
fs.Close()
|
|
Dim myRow As DataRow
|
|
If ds.Tables(0).Rows.Count = 0 Then
|
|
' Neues Dokument speichern
|
|
myRow = ds.Tables(0).NewRow
|
|
myRow.Item(0) = Journal.JournalNr
|
|
myRow.Item(1) = mydata
|
|
ds.Tables(0).Rows.Add(myRow)
|
|
da.Update(ds, "docs")
|
|
Else
|
|
'Bestehendes Dokument sichenr
|
|
myRow = ds.Tables(0).Rows(0)
|
|
myRow.Item(1) = mydata
|
|
da.Update(ds, "docs")
|
|
End If
|
|
fs.Close()
|
|
fs = Nothing
|
|
File.Delete(Filename)
|
|
Return True
|
|
Catch ex As Exception
|
|
Journal.Insert_Journal("", "", "", Filename, "20", "Das Journal konnte nicht auf der Datenbank gespeichert werden." + vbNewLine + ex.Message, "", "")
|
|
Return False
|
|
End Try
|
|
CB = Nothing
|
|
ds = Nothing
|
|
da = Nothing
|
|
connection.Close()
|
|
connection = Nothing
|
|
End Function
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
#Region "Journaltimer Funktionen"
|
|
|
|
Public Sub JournalTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles JournalTimer.Elapsed
|
|
Dim restartdok As New DataTable()
|
|
Dim restartjob As New DataTable()
|
|
restartdok = get_restartdok()
|
|
restartjob = get_restartjob()
|
|
Me.JournalTimer.Enabled = False
|
|
Dim i As Integer
|
|
Me.FileWatch.EnableRaisingEvents = False
|
|
For i = 0 To restartdok.Rows.Count - 1
|
|
Write_Restartfiles(restartdok.Rows(i).Item(0))
|
|
Next
|
|
For i = 0 To restartjob.Rows.Count - 1
|
|
Write_Restartjobfiles(restartjob.Rows(i).Item(0))
|
|
Next
|
|
If restartdok.Rows.Count <> 0 Or restartjob.Rows.Count <> 0 Then
|
|
Verarbeiten()
|
|
End If
|
|
'20120905 - SHU - Wenn IND-Dateien im Input-Verzeichnis vorhanden sind, diese verarbeiten
|
|
Dim di As New IO.DirectoryInfo(Watch_Directory)
|
|
Dim diar1 As IO.FileInfo() = di.GetFiles("*.ind")
|
|
If diar1.Length > 0 Then Verarbeiten()
|
|
restartjob.Dispose()
|
|
restartdok.Dispose()
|
|
|
|
If Now.Hour > 0 And Now.Hour < 1 Then
|
|
Dim filename As String
|
|
Dim dt As DataTable
|
|
PrintOut("Start Tägliche Journalerstellung")
|
|
dt = get_applikationen()
|
|
For i = 0 To dt.Rows.Count - 1
|
|
filename = Journal.Print_Log_Batch(dt.Rows(i).Item(0), dt.Rows(i).Item(1), dt.Rows(i).Item(2))
|
|
Send_Mail(filename, dt.Rows(i).Item(3))
|
|
PrintOut(dt.Rows(i).Item(1) + ": " + "Journal gesendet")
|
|
Next
|
|
End If
|
|
Me.JournalTimer.Enabled = True
|
|
Me.FileWatch.EnableRaisingEvents = True
|
|
End Sub
|
|
|
|
Private Sub Write_Restartfiles(ByVal itemid As Integer)
|
|
Dim connection As New SqlConnection()
|
|
Dim da As New SqlDataAdapter("Select * From import_daten where import_data_nr=" + LTrim(Str(itemid)), connection)
|
|
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
|
|
Dim ds As New DataSet()
|
|
Dim Dokumentfilename As String
|
|
Dim XMLFilename As String
|
|
Dim xmlstring As String
|
|
Dim xmlds As New DataSet()
|
|
|
|
Try
|
|
'Connectionstring zur Datenbank
|
|
connection.ConnectionString = Globals.sConnectionString_journale
|
|
connection.Open()
|
|
da.Fill(ds, "docs")
|
|
Dim myRow As DataRow
|
|
xmlstring = ds.Tables(0).Rows(0).Item(3)
|
|
myRow = ds.Tables(0).Rows(0)
|
|
|
|
'Indexfile schreiben
|
|
XMLFilename = Params.Inputverzeichnis + LTrim(Str(itemid)) + "_" + Format(Now, "yyyyMMddHHmmss") + ".ind"
|
|
FileOpen(11, XMLFilename, OpenMode.Output)
|
|
PrintLine(11, xmlstring)
|
|
FileClose(11)
|
|
xmlds.ReadXml(XMLFilename)
|
|
Dokumentfilename = Params.Inputverzeichnis + xmlds.Tables(0).Rows(0).Item(12)
|
|
xmlds.Dispose()
|
|
'Dokumentdatei schreiben
|
|
Dim MyData() As Byte
|
|
MyData = myRow.Item(4)
|
|
Dim K As Long
|
|
K = UBound(MyData)
|
|
Dim fs As New FileStream(Dokumentfilename, FileMode.OpenOrCreate, FileAccess.Write)
|
|
fs.Write(MyData, 0, K)
|
|
fs.Close()
|
|
fs = Nothing
|
|
Catch ex As Exception
|
|
FileClose(11)
|
|
End Try
|
|
CB = Nothing
|
|
ds = Nothing
|
|
da = Nothing
|
|
connection.Close()
|
|
connection = Nothing
|
|
End Sub
|
|
|
|
Private Sub Write_Restartjobfiles(ByVal itemid As Integer)
|
|
Dim connection As New SqlConnection()
|
|
Dim da As New SqlDataAdapter("Select * From import_job where import_jobnr=" + LTrim(Str(itemid)), connection)
|
|
Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da)
|
|
Dim ds As New DataSet()
|
|
|
|
Try
|
|
'Connectionstring zur Datenbank
|
|
connection.ConnectionString = Globals.sConnectionString_journale
|
|
connection.Open()
|
|
da.Fill(ds, "docs")
|
|
Dim myRow As DataRow
|
|
myRow = ds.Tables(0).Rows(0)
|
|
|
|
Dim MyData() As Byte
|
|
MyData = myRow.Item(7)
|
|
Dim K As Long
|
|
K = UBound(MyData)
|
|
Dim fs As New FileStream(Params.Inputverzeichnis + LTrim(Str(itemid)) + "_" + Format(Now, "yyyyMMddHHmmss") + ".ind", FileMode.OpenOrCreate, FileAccess.Write)
|
|
fs.Write(MyData, 0, K)
|
|
fs.Close()
|
|
fs = Nothing
|
|
Catch ex As Exception
|
|
End Try
|
|
CB = Nothing
|
|
ds = Nothing
|
|
da = Nothing
|
|
connection.Close()
|
|
connection = Nothing
|
|
End Sub
|
|
|
|
'''<summary></summary>
|
|
Private Function get_applikationen() As DataTable
|
|
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
|
|
Dim dtToReturn As DataTable = New DataTable()
|
|
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
|
|
scmCmdToExecute.CommandText = "dbo.sp_edoka_import_get_journalprotag"
|
|
scmCmdToExecute.CommandType = CommandType.StoredProcedure
|
|
scmCmdToExecute.Connection = conn_edoka.scoDBConnection
|
|
Try
|
|
sdaAdapter.Fill(dtToReturn)
|
|
Return dtToReturn
|
|
Catch ex As Exception
|
|
PrintOut("Tägliche Journalerstellung fehlgeschlagen. " + ex.Message, EventLogEntryType.Error)
|
|
Return dtToReturn
|
|
Finally
|
|
scmCmdToExecute.Dispose()
|
|
sdaAdapter.Dispose()
|
|
dtToReturn.Dispose()
|
|
End Try
|
|
End Function
|
|
|
|
Private Function get_restartdok() As DataTable
|
|
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
|
|
Dim dtToReturn As DataTable = New DataTable()
|
|
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
|
|
scmCmdToExecute.CommandText = "dbo.sp_get_restartdok"
|
|
scmCmdToExecute.CommandType = CommandType.StoredProcedure
|
|
scmCmdToExecute.Connection = conn_journale.scoDBConnection
|
|
Try
|
|
sdaAdapter.Fill(dtToReturn)
|
|
Return dtToReturn
|
|
Catch ex As Exception
|
|
PrintOut("Auslesen von erneut zu ladenden Dokumenten ist fehlgeschlagen. " + ex.Message, EventLogEntryType.Error)
|
|
Return dtToReturn
|
|
Finally
|
|
scmCmdToExecute.Dispose()
|
|
sdaAdapter.Dispose()
|
|
dtToReturn.Dispose()
|
|
End Try
|
|
End Function
|
|
|
|
Private Function get_restartjob() As DataTable
|
|
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
|
|
Dim dtToReturn As DataTable = New DataTable()
|
|
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
|
|
scmCmdToExecute.CommandText = "dbo.sp_get_restartjob"
|
|
scmCmdToExecute.CommandType = CommandType.StoredProcedure
|
|
scmCmdToExecute.Connection = conn_journale.scoDBConnection
|
|
Try
|
|
sdaAdapter.Fill(dtToReturn)
|
|
Return dtToReturn
|
|
Catch ex As Exception
|
|
PrintOut("Auslesen von erneut zu ladenden Dokumenten ist fehlgeschlagen. " + ex.Message, EventLogEntryType.Error)
|
|
Return dtToReturn
|
|
Finally
|
|
scmCmdToExecute.Dispose()
|
|
sdaAdapter.Dispose()
|
|
dtToReturn.Dispose()
|
|
End Try
|
|
End Function
|
|
|
|
#End Region
|
|
|
|
|
|
#Region "GSF"
|
|
|
|
Dim WithEvents OBJ_GSF As New EDKB08_GSF.Common()
|
|
|
|
'Anpassungen EBES-LSV'
|
|
Dim GSF As Boolean
|
|
|
|
Public Sub GSF_Verarbeitung(ByVal Startverzeichnis As String) Handles OBJ_GSF.StartVerarbeitung
|
|
Dim savewatch_directory As String
|
|
Dim saveInputVerzeichnis As String
|
|
saveInputVerzeichnis = Params.Inputverzeichnis
|
|
savewatch_directory = Watch_Directory
|
|
Try
|
|
Params.Inputverzeichnis = Startverzeichnis
|
|
Watch_Directory = Startverzeichnis
|
|
GSF = True
|
|
Verarbeiten()
|
|
GSF = False
|
|
Catch
|
|
Finally
|
|
Params.Inputverzeichnis = saveInputVerzeichnis
|
|
Watch_Directory = savewatch_directory
|
|
End Try
|
|
End Sub
|
|
|
|
Public Sub GSF_Timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles GSF_Timer.Elapsed
|
|
|
|
GSF_Timer.Enabled = False
|
|
FileWatch.EnableRaisingEvents = False
|
|
OBJ_GSF.Sub_Init(Params.Prop_gsf_ConfigPath, Params.Prop_gsf_ConfigDateiendung)
|
|
OBJ_GSF.Start_Checking()
|
|
OBJ_GSF.Sub_End()
|
|
FileWatch.EnableRaisingEvents = True
|
|
GSF_Timer.Enabled = True
|
|
End Sub
|
|
|
|
Sub GSF_logging(ByVal logeintrag As String, ByVal itype As Integer) Handles OBJ_GSF.LogToBMS
|
|
PrintOut(logeintrag + " " + itype.ToString)
|
|
End Sub
|
|
#End Region
|
|
|
|
|
|
End Class
|