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 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 _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 edkDokBezeichnung As String Get Return _edkDokBezeichnung End Get End Property Private Sub InitItem() _hasErrors = False _dlvEDK = True _dlvAVQ = True _bpnr = Nothing _edkDokNr = Nothing _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) InitItem() _qrcode = Instructions 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 If Len(_edkDokNr) = 0 Then _edkDokNr = XmlDokTypNr 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 End Sub Private Sub GetAvqData(ByVal BPNr As String, ByVal Instructions As String) 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 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.VarChar, 20)).Direction = ParameterDirection.Output command.Parameters.Add(New OracleParameter("o_edk_dok_nr", OracleType.VarChar, 25)).Direction = ParameterDirection.Output command.Parameters.Add(New OracleParameter("o_edk_dok_bez", OracleType.VarChar, 50)).Direction = ParameterDirection.Output 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 rbpnr As String = command.Parameters.Item(2).Value Dim rdoktypnr As String = command.Parameters.Item(3).Value Dim rdokbez As String = command.Parameters.Item(4).Value Dim ret As String = command.Parameters.Item(5).Value If ret = "OK" Then _hasErrors = False Else _hasErrors = True End If _bpnr = rbpnr _edkDokNr = rdoktypnr _edkDokBezeichnung = rdokbez dataReader.Close() dataReader.Dispose() connectionSession.Close() connectionSession.Dispose() 'ACHTUNG connectionSession = Nothing dataReader = Nothing command = Nothing 'ACHTUNG Catch ex As Exception 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 End Sub Public Sub SendData() 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 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 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 End Sub End Class End Namespace