.net 连接 SAP for NCO3.0(三)
来源:互联网 发布:开盘数据恢复成功率 编辑:程序博客网 时间:2024/05/29 18:05
Imports Microsoft.VisualBasic
Imports SAP.Middleware.Connector
Imports System.Data
Imports System.IO
Imports LogInfo
Imports System.Diagnostics
Imports System.Collections
Imports System.Collections.Generic
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 ID As IDestinationConfiguration '继承
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, "") '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.PeakConnectionsLimit, "10")
parms.Add(RfcConfigParameters.IdleTimeout, "600")
Return parms
ElseIf ("prd_000".Equals(destinationName)) Then
'parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.SystemNumber, "") 'SAP实例
parms.Add(RfcConfigParameters.User, "") ' 用户名
parms.Add(RfcConfigParameters.Password, "") '密码
parms.Add(RfcConfigParameters.Client, "777") ' Client
parms.Add(RfcConfigParameters.Language, "ZH") '登陆语言
parms.Add(RfcConfigParameters.PoolSize, "5")
'parms.Add(RfcConfigParameters.MaxPoolSize, "10")
parms.Add(RfcConfigParameters.PeakConnectionsLimit, "10")
parms.Add(RfcConfigParameters.IdleTimeout, "600")
Return parms
ElseIf ("qa1_000".Equals(destinationName)) Then
parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.SystemNumber, "") '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.PeakConnectionsLimit, "10")
parms.Add(RfcConfigParameters.IdleTimeout, "600")
Return parms
Else
Return Nothing
End If
End Function
'SAP3.0 连接SAP
Function ConnectSAP() As Boolean
Dim GetSapValue = System.Configuration.ConfigurationManager.AppSettings("Description")
'Dim ID As IDestinationConfiguration = New SAPRFC() '继承
ID = New SAPRFC()
Try
If Destination Is Nothing Then
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
ElseIf GetSapValue = "QA1" Then
Destination = RfcDestinationManager.GetDestination("qa1_000") '连接SAP, SAPConnector 3.0方式 PRD SYSTEM
End If
'RfcDestinationManager.UnregisterDestinationConfiguration(ID)
End If
Return True
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Return False
End Try
End Function
Public Function GetMaterial(ByVal material As String) As DataTable
Try
Destination = Nothing
SapFunction = Nothing
mystruct = Nothing
If ConnectSAP() = True Then
SapFunction = Destination.Repository.CreateFunction("BAPI_MATERIAL_GET_DETAIL") '建立一个函数对象
SapFunction.SetValue("MATERIAL", material) '传递参数
SapFunction.Invoke(Destination) '激活提交
mystruct = SapFunction.GetStructure("MATERIAL_GENERAL_DATA") '返回表
End If
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Finally
RfcDestinationManager.UnregisterDestinationConfiguration(ID)
ID = Nothing
SapFunction = Nothing
Destination = Nothing
End Try
Return GetDataTableFromRfcStruct(mystruct)
End Function
Public Function GetPO(ByVal PO As String) As DataTable
Try
Destination = Nothing
SapFunction = Nothing
mystruct = Nothing
If ConnectSAP() = True Then
SapFunction = Destination.Repository.CreateFunction("BAPI_PO_GETDETAIL") '建立一个函数对象
SapFunction.SetValue("PURCHASEORDER", PO) '传递参数
SapFunction.Invoke(Destination) '激活提交
mystruct = SapFunction.GetStructure("PO_HEADER") '返回表
End If
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Finally
RfcDestinationManager.UnregisterDestinationConfiguration(ID)
ID = Nothing
SapFunction = Nothing
Destination = Nothing
End Try
Return GetDataTableFromRfcStruct(mystruct)
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 Function GetDataTableFromRfcStruct(ByVal rfcStruct As IRfcStructure) As DataTable
Dim rowTable As New DataTable
For i As Integer = 0 To rfcStruct.ElementCount - 1
rowTable.Columns.Add(rfcStruct.GetElementMetadata(i).Name)
Next
Dim dr As DataRow = rowTable.NewRow()
For j As Integer = 0 To rfcStruct.ElementCount - 1
dr(j) = rfcStruct.GetValue(j)
Next
rowTable.Rows.Add(dr)
Return rowTable
End Function
End Class
Imports SAP.Middleware.Connector
Imports System.Data
Imports System.IO
Imports LogInfo
Imports System.Diagnostics
Imports System.Collections
Imports System.Collections.Generic
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 ID As IDestinationConfiguration '继承
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, "") '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.PeakConnectionsLimit, "10")
parms.Add(RfcConfigParameters.IdleTimeout, "600")
Return parms
ElseIf ("prd_000".Equals(destinationName)) Then
'parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.SystemNumber, "") 'SAP实例
parms.Add(RfcConfigParameters.User, "") ' 用户名
parms.Add(RfcConfigParameters.Password, "") '密码
parms.Add(RfcConfigParameters.Client, "777") ' Client
parms.Add(RfcConfigParameters.Language, "ZH") '登陆语言
parms.Add(RfcConfigParameters.PoolSize, "5")
'parms.Add(RfcConfigParameters.MaxPoolSize, "10")
parms.Add(RfcConfigParameters.PeakConnectionsLimit, "10")
parms.Add(RfcConfigParameters.IdleTimeout, "600")
Return parms
ElseIf ("qa1_000".Equals(destinationName)) Then
parms.Add(RfcConfigParameters.AppServerHost, "") 'SAP主机IP
parms.Add(RfcConfigParameters.SystemNumber, "") '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.PeakConnectionsLimit, "10")
parms.Add(RfcConfigParameters.IdleTimeout, "600")
Return parms
Else
Return Nothing
End If
End Function
'SAP3.0 连接SAP
Function ConnectSAP() As Boolean
Dim GetSapValue = System.Configuration.ConfigurationManager.AppSettings("Description")
'Dim ID As IDestinationConfiguration = New SAPRFC() '继承
ID = New SAPRFC()
Try
If Destination Is Nothing Then
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
ElseIf GetSapValue = "QA1" Then
Destination = RfcDestinationManager.GetDestination("qa1_000") '连接SAP, SAPConnector 3.0方式 PRD SYSTEM
End If
'RfcDestinationManager.UnregisterDestinationConfiguration(ID)
End If
Return True
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Return False
End Try
End Function
Public Function GetMaterial(ByVal material As String) As DataTable
Try
Destination = Nothing
SapFunction = Nothing
mystruct = Nothing
If ConnectSAP() = True Then
SapFunction = Destination.Repository.CreateFunction("BAPI_MATERIAL_GET_DETAIL") '建立一个函数对象
SapFunction.SetValue("MATERIAL", material) '传递参数
SapFunction.Invoke(Destination) '激活提交
mystruct = SapFunction.GetStructure("MATERIAL_GENERAL_DATA") '返回表
End If
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Finally
RfcDestinationManager.UnregisterDestinationConfiguration(ID)
ID = Nothing
SapFunction = Nothing
Destination = Nothing
End Try
Return GetDataTableFromRfcStruct(mystruct)
End Function
Public Function GetPO(ByVal PO As String) As DataTable
Try
Destination = Nothing
SapFunction = Nothing
mystruct = Nothing
If ConnectSAP() = True Then
SapFunction = Destination.Repository.CreateFunction("BAPI_PO_GETDETAIL") '建立一个函数对象
SapFunction.SetValue("PURCHASEORDER", PO) '传递参数
SapFunction.Invoke(Destination) '激活提交
mystruct = SapFunction.GetStructure("PO_HEADER") '返回表
End If
Catch ex As Exception
Loger.Error(ex.Message.ToString)
Finally
RfcDestinationManager.UnregisterDestinationConfiguration(ID)
ID = Nothing
SapFunction = Nothing
Destination = Nothing
End Try
Return GetDataTableFromRfcStruct(mystruct)
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 Function GetDataTableFromRfcStruct(ByVal rfcStruct As IRfcStructure) As DataTable
Dim rowTable As New DataTable
For i As Integer = 0 To rfcStruct.ElementCount - 1
rowTable.Columns.Add(rfcStruct.GetElementMetadata(i).Name)
Next
Dim dr As DataRow = rowTable.NewRow()
For j As Integer = 0 To rfcStruct.ElementCount - 1
dr(j) = rfcStruct.GetValue(j)
Next
rowTable.Rows.Add(dr)
Return rowTable
End Function
End Class
- .net 连接 SAP for NCO3.0(三)
- .NET连接SAP系统专题:C#(NCO3)调用BAPI(五)
- .NET连接SAP系统专题:NCO3调用BAPI的一些说明(六)
- .NET连接SAP系统专题:NCO3调用BAPI的代码(七)
- NCO3.0连接SAP报错处理Could not load file or assembly 'sapnco' or one of its dependencies
- .net 连接SAP for NCO 3.0
- .NET 连接 SAP for NCO 3.0 (二)
- SAP接口编程-Nco3.0系列01 : RfcDestination
- SAP接口编程之 NCo3.0系列(06) : 会话管理
- SAP接口编程之 NCo3.0系列(07) : 异常处理
- 一步一步教你用SAP NCO3.0调用RFC(菜鸟必看)
- VS2010+NCO3.0调用SAP BAPI获得定义的公司名单(源代码)
- 一步一步教你用SAP NCO3.0调用RFC(菜鸟必看)
- 一步一步教你用SAP NCO3.0调用RFC(菜鸟必看)
- step by step 教你用SAP NCO3.0调用RFC
- SAP接口编程之 NCo3.0系列(02) : RFC Client Programs
- SAP接口编程之 NCo3.0系列(03) : Meta-data和Container
- SAP接口编程之 NCo3.0系列(04) : Table作为输出参数
- Windows 下搭建Objective-C 开发环境
- 回首过去的那些事儿(3)
- c#基础---数据类型
- ubuntu终端命令
- ARM Linux Boot Sequence
- .net 连接 SAP for NCO3.0(三)
- Ubuntu中网页各种插件安装命令
- Ubuntu下的实用命令
- 获取设备当前连接的WIFI信息(No Private API)
- PHP中GD库的使用
- 使用tar命令备份Ubuntu系统
- 编译---没有引用头文件却能使用头文件的内容
- ubuntu 常用软件
- 如何实现手势缩放图片