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.

391 lines
14 KiB

Imports System
Imports System.Data
Imports System.Data.OracleClient
Namespace Avaloq
Public Class SST
Const queryString As String = "k.tkb$out_dsp_in#.edoka_in"
Const queryStringGetValues As String = "k.tkb$out_dsp_in#.edoka_get_values"
Const queryStringOpenSession As String = "k.session#.open_session"
Const queryStringCloseSession As String = "k.session#.close_session"
Const avqOracleUser As String = "TKB$I_EDOKA"
Const avqSecUserId As Integer = 34
Const avqBuId As Integer = 1
Const edkFaDokTyp As String = "1688"
'Const edkDokBezeichnungKey As String = "edk_bez"
'Const edkDokBezeichnungDflt As String = "Antworttalon"
Dim connStrg As String
Private _hasErrors As Boolean
Private _dlvEDK As Boolean
Private _dlvAVQ As Boolean
Private _edkDokNr As String
Private _edkDokTypOvr As Boolean
Private _edkDokBezeichnung As String
Private _qrcode As String
Private _bpnr As String
Public Sub New()
oread = System.IO.File.OpenText(DivFnkt.ApplicationPath + "avaloqconn.cfg")
connStrg = oread.ReadLine
oread.Close()
End Sub
Public ReadOnly Property hasErrors() As Boolean
Get
Return _hasErrors
End Get
End Property
Public ReadOnly Property DeliverToEDK As Boolean
Get
Return _dlvEDK
End Get
End Property
Public ReadOnly Property DeliverToAVQ As Boolean
Get
Return _dlvAVQ
End Get
End Property
Public ReadOnly Property BPNr As String
Get
Return _bpnr
End Get
End Property
Public ReadOnly Property edkDokNr As String
Get
Return _edkDokNr
End Get
End Property
Public ReadOnly Property edkDokTypOvr As Boolean
Get
Return _edkDokTypOvr
End Get
End Property
Public ReadOnly Property edkDokBezeichnung As String
Get
Return _edkDokBezeichnung
End Get
End Property
Private Sub InitItem()
_hasErrors = False
_dlvEDK = True
_dlvAVQ = True
_bpnr = Nothing
_edkDokNr = Nothing
_edkDokTypOvr = False
_edkDokBezeichnung = Nothing
_qrcode = Nothing
End Sub
Public Sub Prepare(ByVal BPNr As String, ByVal XmlDokTypNr As String, ByVal Instructions As String, ByVal dlvEDK As String, ByVal dlvAVQ As String)
PrintOut("AVQ Prepare Start")
InitItem()
If Instructions.IndexOf("dms_id:;bp_nr:;attr1:") > -1 Then
Instructions = Instructions.Replace("dms_id:;bp_nr:;attr1:", "")
End If
_qrcode = Instructions
If Len(XmlDokTypNr) > 0 Then
If XmlDokTypNr <> edkFaDokTyp Then
'DokTyp ist ein Edoka-Doktyp
_edkDokNr = XmlDokTypNr
_edkDokTypOvr = True
End If
End If
If dlvEDK = "0" Then
_dlvEDK = False
End If
If dlvAVQ = "0" Then
_dlvAVQ = False
End If
If Len(_qrcode) > 0 Then
End If
If _dlvAVQ = True Or _dlvEDK = True Then
GetAvqData(BPNr, Instructions)
If Len(BPNr) > 0 And BPNr <> _bpnr Then
'Wahrscheinlich falsch manuell indexiert
End If
End If
'If Len(_qrcode) > 0 Then
' _hasQrCode = True
'
''EDOKA-Dokument-Bezeichnung auslesen
'Try
'For Each pairs As String In _qrcode.Split(";"c)
'Dim values As String() = pairs.Split(":"c)
'If values(0) = edkDokBezeichnungKey Then
' _edkDokBezeichnung = values(1)
' End If
' Next
' Catch ex As Exception
' _hasErrors = True
' _edkDokBezeichnung = edkDokBezeichnungDflt
' End Try
' Else
' _hasErrors = True
' _edkDokBezeichnung = edkDokBezeichnungDflt
' End If
PrintOut("AVQ Prepare Ende")
End Sub
Private Sub GetAvqData(ByVal BPNr As String, ByVal Instructions As String)
PrintOut("GetAVQData Start")
Dim dataReader As OracleDataReader
Dim connectionSession As New OracleConnection
connectionSession.ConnectionString = connStrg
'OracleConnection.ClearAllPools()
Dim command As OracleCommand = connectionSession.CreateCommand()
command.Parameters.Clear()
command.CommandText = queryStringOpenSession
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New OracleParameter("i_sec_user_id", OracleType.Int32)).Value = avqSecUserId
command.Parameters.Add(New OracleParameter("i_oracle_user", OracleType.VarChar)).Value = avqOracleUser
command.Parameters.Add(New OracleParameter("i_bu_id", OracleType.Int32)).Value = avqBuId
Try
connectionSession.Open()
command.ExecuteReader()
'dataReader.Read()
'dataReader.Close()
'dataReader.Dispose()
Catch ex As Exception
PrintOut("Get_AVQ_Data (1):" + ex.Message)
If connectionSession.State = ConnectionState.Closed Then
connectionSession.Open()
command.ExecuteReader()
End If
End Try
command.Parameters.Clear()
command.CommandText = queryStringGetValues
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New OracleParameter("i_bp_nr", OracleType.VarChar)).Value = BPNr
command.Parameters.Add(New OracleParameter("i_instructions", OracleType.VarChar)).Value = Instructions
command.Parameters.Add(New OracleParameter("o_bp_nr", OracleType.Char, 4000)).Direction = ParameterDirection.Output
command.Parameters.Add(New OracleParameter("o_edk_dok_nr", OracleType.Char, 4000)).Direction = ParameterDirection.Output
command.Parameters.Add(New OracleParameter("o_edk_dok_bez", OracleType.Char, 4000)).Direction = ParameterDirection.Output
command.Parameters.Add(New OracleParameter("o_ret_val", OracleType.Char, 4000)).Direction = ParameterDirection.Output
Try
If connectionSession.State = ConnectionState.Open Then
'nothing
Else
connectionSession.Open()
End If
dataReader = command.ExecuteReader()
dataReader.Read()
Dim rbpnr As String = Trim(command.Parameters.Item(2).Value)
Dim rdoktypnr As String = Trim(command.Parameters.Item(3).Value)
Dim rdokbez As String = Trim(command.Parameters.Item(4).Value)
Dim ret As String = Trim(command.Parameters.Item(5).Value)
If ret = "OK" Then
_hasErrors = False
Else
_hasErrors = True
End If
_bpnr = rbpnr
_edkDokBezeichnung = rdokbez 'Edoka-Dokumentbezeichnung für allfälligen Override UND für den Standard-Fall
If _edkDokTypOvr = False Then
'Falls Doktyp-Override aus Scanning kommt, ist Definition in Avaloq-Table-Editor irrelevant
If Len(rdoktypnr) > 0 And rdoktypnr <> edkFaDokTyp Then
_edkDokNr = rdoktypnr
_edkDokTypOvr = True
End If
End If
dataReader.Close()
dataReader.Dispose()
connectionSession.Close()
connectionSession.Dispose()
'ACHTUNG
connectionSession = Nothing
dataReader = Nothing
command = Nothing
'ACHTUNG
Catch ex As Exception
PrintOut("Get_AVQ_Data (2):" + ex.Message)
Console.WriteLine(ex.Message)
If connectionSession.State = ConnectionState.Open Then
command.Parameters.Clear()
command.CommandText = "k.session#.close_session"
command.CommandType = CommandType.StoredProcedure
Try
dataReader = command.ExecuteReader()
dataReader.Read()
dataReader.Close()
dataReader.Dispose()
Catch ex1 As Exception
End Try
command.Dispose()
connectionSession.Close()
connectionSession.Dispose()
Console.WriteLine(connectionSession.State)
End If
End Try
PrintOut("GetAVQData Ende")
End Sub
Public Sub SendData()
PrintOut("AVQ Sendata Start")
If Len(_bpnr) = 0 Or Len(_qrcode) = 0 Then
_hasErrors = True
Return
End If
_hasErrors = True 'wird bei erfolgreicher Übermittlung auf false gesetellt
Dim dataReader As OracleDataReader
Dim connectionSession As New OracleConnection
connectionSession.ConnectionString = connStrg
'OracleConnection.ClearAllPools()
Dim command As OracleCommand = connectionSession.CreateCommand()
command.Parameters.Clear()
command.CommandText = queryStringOpenSession
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New OracleParameter("i_sec_user_id", OracleType.Int32)).Value = avqSecUserId
command.Parameters.Add(New OracleParameter("i_oracle_user", OracleType.VarChar)).Value = avqOracleUser
command.Parameters.Add(New OracleParameter("i_bu_id", OracleType.Int32)).Value = avqBuId
Try
connectionSession.Open()
'connectionSession.Open()
'connectionSession.open
'dataReader =
command.ExecuteReader()
'dataReader.Read()
'dataReader.Close()
'dataReader.Dispose()
Catch ex As Exception
PrintOut("AVQ Send_Data (1):" + ex.Message)
If connectionSession.State = ConnectionState.Closed Then
connectionSession.Open()
command.ExecuteReader()
End If
End Try
command.Parameters.Clear()
command.CommandText = queryString
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New OracleParameter("i_bp_nr", OracleType.VarChar)).Value = _bpnr
command.Parameters.Add(New OracleParameter("i_instructions", OracleType.VarChar)).Value = _qrcode
command.Parameters.Add(New OracleParameter("o_ret_val", OracleType.VarChar, 20)).Direction = ParameterDirection.Output
Try
If connectionSession.State = ConnectionState.Open Then
'nothing
Else
connectionSession.Open()
End If
dataReader = command.ExecuteReader()
dataReader.Read()
Dim result As String = command.Parameters.Item(2).Value
If result = "OK" Then
_hasErrors = False
Else
_hasErrors = True
End If
dataReader.Close()
dataReader.Dispose()
connectionSession.Close()
connectionSession.Dispose()
'ACHTUNG
connectionSession = Nothing
dataReader = Nothing
command = Nothing
'ACHTUNG
Catch ex As Exception
PrintOut("AVQ Send_Data (2):" + ex.Message)
Console.WriteLine(ex.Message)
If connectionSession.State = ConnectionState.Open Then
command.Parameters.Clear()
command.CommandText = "k.session#.close_session"
command.CommandType = CommandType.StoredProcedure
Try
dataReader = command.ExecuteReader()
dataReader.Read()
dataReader.Close()
dataReader.Dispose()
Catch ex1 As Exception
End Try
command.Dispose()
connectionSession.Close()
connectionSession.Dispose()
Console.WriteLine(connectionSession.State)
End If
End Try
PrintOut("AVQ Sendata Ende")
End Sub
End Class
End Namespace