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.

286 lines
12 KiB

Imports System.Data
Imports System.IO
Imports System.Data.SqlTypes
Imports System.Data.SqlClient
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Color
Imports EDOKALib.Common
Public Class frmAvaloqSpooler
Inherits System.Windows.Forms.Form
Dim boolActionisRunning As Boolean
Dim boolFilesInSpooler As Boolean
Dim boolStartManuell As Boolean
Dim strFileWatchDir As String
Dim boolFileCorrupted As Boolean
Public NoEdit As Integer
#Region "Load"
Public Sub New()
MyBase.New()
' Dieser Aufruf ist für den Windows Form-Designer erforderlich.
InitializeComponent()
End Sub
Public Sub init()
End Sub
#End Region
Private Sub Spooler_Close(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
objSpooler.Visible = False
EDOKAMain.menuSpooler.Enabled = True
e.Cancel = True
End Sub
Public Sub addItem(ByVal action As String, ByVal parnr As String, ByVal ordernr As String, ByVal doctype As String, ByRef obj As DataGridView, ByVal xmlFile As String, ByVal intSort As Integer, ByVal dokPaket As String)
Dim i As Integer
Dim row0 As String()
Dim strDocType As String = ""
Dim strPartner As String = ""
Dim arrActions(0 To 5) As String
'20090927 - Ergänung uvm und ZV
arrActions = New String() {"Anzeige Partnerdossier", "Dokument anzeige", "Dokument Erstellung", "Dokument Bearbeitung", "Statusmutation", "Host Dokument Anzeige", "UVM-Dokumentanzeige", "ZV-Dokumentanzeige"}
If dokPaket = "" Then
dokPaket = 0
End If
Try
' Get Dokumenttyp kurzbeschreibung
If doctype <> "" Then
Try
doctype = doctype - 900000000
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
Dim s As String
Dim dtToReturn As DataTable = New DataTable()
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
scmCmdToExecute.CommandText = "dbo.sp_GetDokumenttyp"
scmCmdToExecute.CommandType = CommandType.StoredProcedure
scmCmdToExecute.Connection = conn.scoDBConnection
scmCmdToExecute.Parameters.Add(New SqlParameter("@DokumenttypNr", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, CInt(doctype)))
scmCmdToExecute.Parameters.Add(New SqlParameter("@DP", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, dokPaket))
sdaAdapter.Fill(dtToReturn)
strDocType = dtToReturn.Rows(0).Item("bezeichnung")
Catch ex As Exception
'20090729 - shu uvm und zv-dokumentanzeige
If action = 7 Then strDocType = doctype
If action = 8 Then strDocType = doctype
If action < 7 Then
TKBLib.Errorhandling.TraceHelper.Msg("Edoka.Spooler Add Item Error DocType", ex.Message & ex.StackTrace, TraceLevel.Error)
End If
End Try
End If
If dokPaket = "1" Then
strDocType = "Dokumentpaket"
End If
' Get Partner kurzbeschreibung
If parnr <> "" Then
Try
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
Dim s As String
Dim dtToReturn As DataTable = New DataTable()
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
scmCmdToExecute.CommandText = "dbo.sp_getPartnerInformation"
scmCmdToExecute.CommandType = CommandType.StoredProcedure
scmCmdToExecute.Connection = conn.scoDBConnection
scmCmdToExecute.Parameters.Add(New SqlParameter("@parnr", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, parnr))
sdaAdapter.Fill(dtToReturn)
strPartner = dtToReturn.Rows(0).Item("BKPAR00")
Catch ex As Exception
TKBLib.Errorhandling.TraceHelper.Msg("Edoka.Spooler Add Item Error parnr", ex.Message & ex.StackTrace, TraceLevel.Error)
End Try
End If
row0 = New String() {arrActions(CInt(action) - 1), strDocType, parnr, strPartner, ordernr, xmlFile, intSort}
obj.Rows.Insert(intSort, row0)
If DokList.Rows.Count > 2 Then
btnNextAction.Enabled = True
End If
Catch ex As Exception
TKBLib.Errorhandling.TraceHelper.Msg("Edoka.Spooler Add Item Error", ex.Message & ex.StackTrace, TraceLevel.Error)
End Try
End Sub
Public Sub startNextAction()
Try
Dim xmlFile As String
xmlFile = DokList.Rows(0).Cells("xml").Value
If actionIsRunning = False Then
Me.StartManuell = True
actionIsRunning = True
EDOKAMain.HandleCommand(New String() {xmlFile})
End If
Catch ex As Exception
TKBLib.Errorhandling.TraceHelper.Msg("Edoka.Spooler Start Next Action", ex.Message & ex.StackTrace, TraceLevel.Error)
End Try
End Sub
Public Property actionIsRunning() As Boolean
Get
Return boolActionisRunning
End Get
Set(ByVal value As Boolean)
boolActionisRunning = value
End Set
End Property
Public Property FilesInSpooler() As Boolean
Get
Return boolFilesInSpooler
End Get
Set(ByVal value As Boolean)
boolFilesInSpooler = value
End Set
End Property
Public Property StartManuell() As Boolean
Get
Return boolStartManuell
End Get
Set(ByVal value As Boolean)
boolStartManuell = value
End Set
End Property
Public Property FileWatchDir() As String
Get
Return strFileWatchDir
End Get
Set(ByVal value As String)
strFileWatchDir = value
End Set
End Property
Public Property fileCorrupted() As Boolean
Get
Return boolFileCorrupted
End Get
Set(ByVal value As Boolean)
boolFileCorrupted = value
End Set
End Property
Private Sub btnNextAction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextAction.Click
startNextAction()
End Sub
Public Sub refreshList()
'Rel 4.03 Deklaration aus dem Try entfernt, damit diese im Catch wieder verwendet werden kann
Dim file As IO.FileInfo
Try
Dim arr_Folders As String()
Dim i As Integer
DokList.Rows.Clear()
Dim dir As New IO.DirectoryInfo(Globals.SpoolerDir)
If dir.Exists Then
Dim iCounter As Integer
iCounter = 0
Dim files As IO.FileInfo() = dir.GetFiles("*.*", SearchOption.AllDirectories)
' Dim file As IO.FileInfo
Dim tmpAction As Action
tmpAction = New Action
For Each file In files
If UCase(file.Extension) = "." & UCase(Consts.ACTION_FILE_EXTENSION) Then
Try
tmpAction.Load(file)
Me.btnNextAction.Enabled = True
addItem(tmpAction.ActionType, tmpAction.GetParameterByName("PartnerNr").Value, tmpAction.GetParameterByName("fanummer3").Value, tmpAction.GetParameterByName("DokumentTypNr").Value, DokList, file.DirectoryName & "\" & file.Name, iCounter, tmpAction.GetParameterByName("Dokumentpaket").Value)
iCounter = iCounter + 1
Catch
Dim fi As New FileInfo(file.FullName)
Dim f As New frmErrorAVQ_File(file.FullName)
f.ShowDialog()
If fi.Length > 0 Then
save_edkfile(-1, fi)
fi.Delete()
End If
End Try
End If
Next
If iCounter = 0 Then
Me.FilesInSpooler = False
Me.btnNextAction.Enabled = False
Else
Me.FilesInSpooler = True
End If
Else
dir.Create()
refreshList()
End If
Catch ex As Exception
Dim intStart As Integer = InStr(ex.ToString, Globals.SpoolerDir) + Len(Globals.SpoolerDir)
Dim intEnd As Integer = InStr(ex.ToString, "edk") + 3
Dim intLength As Integer = intEnd - intStart
'Rel 4.03 Anpassung Deklaration Filename
Dim filename As String = file.FullName
'Dim fileName As String = Mid(ex.ToString, intStart + 1, intLength)
Dim fiAction As New FileInfo(Globals.SpoolerDir & "\" & fileName)
fiAction.MoveTo(Globals.SpoolerTempDir & "\" & Replace(DateTime.Now.ToShortDateString, ".", "") & Now.TimeOfDay.Hours & Now.TimeOfDay.Minutes & Now.TimeOfDay.Seconds & fileName)
'Throw New ActionException(1, "Datei " & Globals.SpoolerDir & "\" & fileName & " weist keine gültige Struktur auf.")
MsgBox("Datei " & Globals.SpoolerDir & "\" & fileName & " weist keine gültige Struktur auf." & vbNewLine & "Datei wird nach:""" & Globals.SpoolerTempDir & """ kopiert.", MsgBoxStyle.Critical)
refreshList()
TKBLib.Errorhandling.TraceHelper.Msg("Edoka.Spooler Refresh Lsit", ex.Message & ex.StackTrace, TraceLevel.Error)
'Throw ex
End Try
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
refreshList()
End Sub
'Rel 4.03 - neu für die Verarbeitung Hinzugefügt
'Rel 4.02 20080820 - Save EDK-File
Public Sub save_edkfile(ByVal status As Integer, ByVal datei As FileInfo)
Dim Connection As New SqlConnection()
Dim DA As New SqlDataAdapter("select * from edk_log where rowid=-1 ", Connection)
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(DA)
Dim ds As New DataSet()
Dim fs As New FileStream(datei.FullName, FileMode.OpenOrCreate, FileAccess.Read)
Dim mydata(fs.Length) As Byte
fs.Read(mydata, 0, fs.Length)
fs.Close()
Try
Connection.ConnectionString = Globals.sConnectionString
Connection.Open()
DA.Fill(ds, "edk_log")
Dim myRow As DataRow
If ds.Tables(0).Rows.Count = 0 Then
' Neues Dokument speichern
myRow = ds.Tables(0).NewRow
myRow.Item(1) = status
myRow.Item(2) = MitarbeiterNr
myRow.Item(5) = Now
myRow.Item(6) = mydata
myRow.Item(7) = datei.FullName
ds.Tables(0).Rows.Add(myRow)
DA.Update(ds, "edk_log")
End If
Catch ex As Exception
End Try
fs = Nothing
cb = Nothing
ds = Nothing
DA = Nothing
Connection.Close()
Connection = Nothing
End Sub
' Ende Rel. 4.02
End Class