Imports System.Data
Imports System.IO
Imports System.Data.OracleClient
Imports System.Diagnostics
Imports System.Collections
Imports System.Collections.Generic
Imports OracleHelper
Imports ADOR
Public Class SAPRFC
Implements IDestinationConfiguration '继承接口
Public Destination As RfcDestination 'SAP Connector3.0 的RFC源
Public SapFunction As IRfcFunction 'SAP RFC函数调用
Public mystruct As IRfcStructure
Public datatbl As IRfcTable '调用到的RFC SAP table
Public optionstbl As IRfcTable '调用到的OPTIONS table
Public fieldtbl As IRfcTable '调用到的FIELD table
Public Function ChangeEventsSupported() As Boolean Implements IDestinationConfiguration.ChangeEventsSupported
Return False
End Function
Public Event ConfigurationChanged(ByVal destinationName As String, ByVal args As RfcConfigurationEventArgs) Implements IDestinationConfiguration.ConfigurationChanged '事件
Public Function GetParameters(ByVal destinationName As String) As RfcConfigParameters Implements IDestinationConfiguration.GetParameters
Dim parms As RfcConfigParameters = New RfcConfigParameters()
If ("qas_000".Equals(destinationName)) Then
parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.SystemNumber, "70") 'SAP实例
parms.Add(RfcConfigParameters.User, "") ' 用户名
parms.Add(RfcConfigParameters.Password, "") '密码
parms.Add(RfcConfigParameters.Client, "777") ' Client
parms.Add(RfcConfigParameters.Language, "EN") '登陆语言
parms.Add(RfcConfigParameters.PoolSize, "5")
parms.Add(RfcConfigParameters.MaxPoolSize, "10")
' parms.Add(RfcConfigParameters.IdleTimeout, "60")
Return parms
ElseIf ("prd_000".Equals(destinationName)) Then
parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.SystemNumber, "02") 'SAP实例
parms.Add(RfcConfigParameters.User, "") ' 用户名
parms.Add(RfcConfigParameters.Password, "") '密码
parms.Add(RfcConfigParameters.Client, "777") ' Client
parms.Add(RfcConfigParameters.Language, "EN") '登陆语言
parms.Add(RfcConfigParameters.PoolSize, "5")
parms.Add(RfcConfigParameters.MaxPoolSize, "10")
' parms.Add(RfcConfigParameters.IdleTimeout, "60")
Return parms
Else
Return Nothing
End If
End Function
'SAP3.0 连接SAP
Function ConnectSAP() As Boolean
Dim GetSapValue = System.Configuration.ConfigurationManager.AppSettings("SAP_Destination")
Dim ID As IDestinationConfiguration = New SAPRFC() '继承
Try
RfcDestinationManager.RegisterDestinationConfiguration(ID)
If GetSapValue = "QAS" Then
Destination = RfcDestinationManager.GetDestination("qas_000") '连接SAP, SAPConnector 3.0方式 QAS SYSTEM
ElseIf GetSapValue = "PRDALL" Then
Destination = RfcDestinationManager.GetDestination("prd_000") '连接SAP, SAPConnector 3.0方式 PRD SYSTEM
End If
RfcDestinationManager.UnregisterDestinationConfiguration(ID)
Return True
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Return False
End Try
End Function
Public Function GetDataTableFromRfcTable(ByVal rfcTable As IRfcTable) As DataTable
Dim dt As New DataTable()
If rfcTable Is Nothing Then
dt = Nothing
Else
Dim liElement As Integer = 0
Dim rfcEMD As RfcElementMetadata
Dim dr As DataRow
Dim row As IRfcStructure
For liElement = 0 To rfcTable.ElementCount - 1
rfcEMD = rfcTable.GetElementMetadata(liElement)
dt.Columns.Add(rfcEMD.Name)
Next
For Each row In rfcTable
dr = dt.NewRow()
For liElement = 0 To rfcTable.ElementCount - 1
rfcEMD = rfcTable.GetElementMetadata(liElement)
dr(rfcEMD.Name) = row.GetString(rfcEMD.Name)
Next
dt.Rows.Add(dr)
Next
End If
Return dt
End Function
Public Sub TEST()
Try
Destination = Nothing
If ConnectSAP() = True Then
SapFunction = Destination.Repository.CreateFunction("BAPI_EXCHANGERATE_GETDETAIL") '建立一个函数对象
SapFunction.SetValue("RATE_TYPE", "M") '传递参数
SapFunction.SetValue("FROM_CURR", "RMB")
SapFunction.SetValue("TO_CURRNCY", "USD")
SapFunction.SetValue("DATE", "2012-05-03")
SapFunction.Invoke(Destination) '激活提交
mystruct = SapFunction.GetStructure("EXCH_RATE")
Dim Exch_Rate As String = mystruct.GetValue("EXCH_RATE").ToString()
' GetTable = SapFunction.GetTable("YTABLE") '返回表 The backend has added one more line to it.
End If
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Finally
Destination = Nothing
End Try
End Sub
Public Function ReadPlantLocationFromSap() As DataTable
Try
datatbl = Nothing
Destination = Nothing
SapFunction = Nothing
If ConnectSAP() = True Then
SapFunction = Destination.Repository.CreateFunction("RFC_READ_TABLE") '建立一个函数对象
'If SapFunction Is Nothing Then
' Exit Function
'End If
SapFunction.SetValue("QUERY_TABLE", "T001L")
SapFunction.SetValue("DELIMITER", ";")
'SapFunction.SetValue("NO_DATA", "X")
fieldtbl = SapFunction.GetTable("FIELDS")
If fieldtbl.ElementCount = 0 Then
fieldtbl.Append()
fieldtbl.SetValue(0, "WERKS")
fieldtbl.Append()
fieldtbl.SetValue(0, "LGORT")
End If
optionstbl = SapFunction.GetTable("OPTIONS")
Imports System.IO
Imports System.Data.OracleClient
Imports System.Diagnostics
Imports System.Collections
Imports System.Collections.Generic
Imports OracleHelper
Imports ADOR
Public Class SAPRFC
Implements IDestinationConfiguration '继承接口
Public Destination As RfcDestination 'SAP Connector3.0 的RFC源
Public SapFunction As IRfcFunction 'SAP RFC函数调用
Public mystruct As IRfcStructure
Public datatbl As IRfcTable '调用到的RFC SAP table
Public optionstbl As IRfcTable '调用到的OPTIONS table
Public fieldtbl As IRfcTable '调用到的FIELD table
Public Function ChangeEventsSupported() As Boolean Implements IDestinationConfiguration.ChangeEventsSupported
Return False
End Function
Public Event ConfigurationChanged(ByVal destinationName As String, ByVal args As RfcConfigurationEventArgs) Implements IDestinationConfiguration.ConfigurationChanged '事件
Public Function GetParameters(ByVal destinationName As String) As RfcConfigParameters Implements IDestinationConfiguration.GetParameters
Dim parms As RfcConfigParameters = New RfcConfigParameters()
If ("qas_000".Equals(destinationName)) Then
parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.SystemNumber, "70") 'SAP实例
parms.Add(RfcConfigParameters.User, "") ' 用户名
parms.Add(RfcConfigParameters.Password, "") '密码
parms.Add(RfcConfigParameters.Client, "777") ' Client
parms.Add(RfcConfigParameters.Language, "EN") '登陆语言
parms.Add(RfcConfigParameters.PoolSize, "5")
parms.Add(RfcConfigParameters.MaxPoolSize, "10")
' parms.Add(RfcConfigParameters.IdleTimeout, "60")
Return parms
ElseIf ("prd_000".Equals(destinationName)) Then
parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.SystemNumber, "02") 'SAP实例
parms.Add(RfcConfigParameters.User, "") ' 用户名
parms.Add(RfcConfigParameters.Password, "") '密码
parms.Add(RfcConfigParameters.Client, "777") ' Client
parms.Add(RfcConfigParameters.Language, "EN") '登陆语言
parms.Add(RfcConfigParameters.PoolSize, "5")
parms.Add(RfcConfigParameters.MaxPoolSize, "10")
' parms.Add(RfcConfigParameters.IdleTimeout, "60")
Return parms
Else
Return Nothing
End If
End Function
'SAP3.0 连接SAP
Function ConnectSAP() As Boolean
Dim GetSapValue = System.Configuration.ConfigurationManager.AppSettings("SAP_Destination")
Dim ID As IDestinationConfiguration = New SAPRFC() '继承
Try
RfcDestinationManager.RegisterDestinationConfiguration(ID)
If GetSapValue = "QAS" Then
Destination = RfcDestinationManager.GetDestination("qas_000") '连接SAP, SAPConnector 3.0方式 QAS SYSTEM
ElseIf GetSapValue = "PRDALL" Then
Destination = RfcDestinationManager.GetDestination("prd_000") '连接SAP, SAPConnector 3.0方式 PRD SYSTEM
End If
RfcDestinationManager.UnregisterDestinationConfiguration(ID)
Return True
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Return False
End Try
End Function
Public Function GetDataTableFromRfcTable(ByVal rfcTable As IRfcTable) As DataTable
Dim dt As New DataTable()
If rfcTable Is Nothing Then
dt = Nothing
Else
Dim liElement As Integer = 0
Dim rfcEMD As RfcElementMetadata
Dim dr As DataRow
Dim row As IRfcStructure
For liElement = 0 To rfcTable.ElementCount - 1
rfcEMD = rfcTable.GetElementMetadata(liElement)
dt.Columns.Add(rfcEMD.Name)
Next
For Each row In rfcTable
dr = dt.NewRow()
For liElement = 0 To rfcTable.ElementCount - 1
rfcEMD = rfcTable.GetElementMetadata(liElement)
dr(rfcEMD.Name) = row.GetString(rfcEMD.Name)
Next
dt.Rows.Add(dr)
Next
End If
Return dt
End Function
Public Sub TEST()
Try
Destination = Nothing
If ConnectSAP() = True Then
SapFunction = Destination.Repository.CreateFunction("BAPI_EXCHANGERATE_GETDETAIL") '建立一个函数对象
SapFunction.SetValue("RATE_TYPE", "M") '传递参数
SapFunction.SetValue("FROM_CURR", "RMB")
SapFunction.SetValue("TO_CURRNCY", "USD")
SapFunction.SetValue("DATE", "2012-05-03")
SapFunction.Invoke(Destination) '激活提交
mystruct = SapFunction.GetStructure("EXCH_RATE")
Dim Exch_Rate As String = mystruct.GetValue("EXCH_RATE").ToString()
' GetTable = SapFunction.GetTable("YTABLE") '返回表 The backend has added one more line to it.
End If
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Finally
Destination = Nothing
End Try
End Sub
Public Function ReadPlantLocationFromSap() As DataTable
Try
datatbl = Nothing
Destination = Nothing
SapFunction = Nothing
If ConnectSAP() = True Then
SapFunction = Destination.Repository.CreateFunction("RFC_READ_TABLE") '建立一个函数对象
'If SapFunction Is Nothing Then
' Exit Function
'End If
SapFunction.SetValue("QUERY_TABLE", "T001L")
SapFunction.SetValue("DELIMITER", ";")
'SapFunction.SetValue("NO_DATA", "X")
fieldtbl = SapFunction.GetTable("FIELDS")
If fieldtbl.ElementCount = 0 Then
fieldtbl.Append()
fieldtbl.SetValue(0, "WERKS")
fieldtbl.Append()
fieldtbl.SetValue(0, "LGORT")
End If
optionstbl = SapFunction.GetTable("OPTIONS")