ITPub博客

首页 > 数据库 > 数据库开发技术 > DBReader/Classes/Proxy

DBReader/Classes/Proxy

原创 数据库开发技术 作者:njms 时间:2007-09-11 23:07:55 0 删除 编辑

/**
*
* DBReader 1.0, Access to SAP tables using SAP's .Net Connector.
*
* Author: hardteck
* Email: hardteck@web.de
*
* Last modified: Fr, 17. Okt 2003, 11:31:20
*/
namespace SAPReader {
using System;
///


/// A proxy encapsulates the a SAPProxy to accessing SAP.
/// The class is responsible for a connection to SAP through
/// a Destination object ().
///
///

public class Proxy {
///
/// The proxy to accessing SAP as generated by
/// C#.Net Connector Wizard. This proxy provides only
/// the RFC_READ_TABLE function to read anly table from
/// SAP's database.
///

private SAPReader.SAPKernel.SAPProxy proxy = null;
///
/// The destination object.
///

private SAP.Connector.Destination dest = null;
///
/// Indicates whether the proxy is connected to SAP.
///

private bool isConnected = false;

///


/// The constructor.
/// Destination information.
///

public Proxy(SAP.Connector.Destination dest){
this.dest = dest;
}
///
/// The constructor.
/// Destination information provided
/// by a ConnectionInfo object.
///
///

public Proxy(SAPReader.ConnectionInfo conInfo) {
this.dest = new SAP.Connector.Destination();
this.updateDestination(conInfo);
}
///
/// The proxy to accessing SAP as generated by
/// C#.Net Connector Wizard. This proxy provides only
/// the RFC_READ_TABLE function to read anly table from
/// SAP's database.
///

public SAPReader.SAPKernel.SAPProxy SAPProxy {
set{this.proxy = value;}
get{return this.proxy;}
}
///
/// Updates the destination information.
///
///

public void updateDestination(SAPReader.ConnectionInfo conInfo){
this.dest.AppServerHost = conInfo.SAPServer;
this.dest.Client = conInfo.Client;
this.dest.Language = conInfo.Language;
this.dest.Password = conInfo.Password;
this.dest.SystemNumber = conInfo.SystemNumber;
this.dest.Username = conInfo.Username;
}
///
/// Indicates whether the proxy is connected to SAP.
///

public bool connected(){
return this.isConnected;
}
///
/// Connects the proxy to the SAP system.
/// Thrown when the
/// connection fails.

///

public void connectSAP(){
if (this.proxy == null) {
this.proxy = new SAPReader.SAPKernel.SAPProxy();
}
if (this.isConnected == false) {
proxy.Connection = new SAP.Connector.SAPConnection(dest);
try {
proxy.Connection.Open();
this.isConnected = true;
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
Environment.Exit(0);
}
}
}
///
/// Disconnects the proxy from the SAP system.
/// Thrown when the
/// disconnection fails.

///

public void disConnectSAP(){
if(this.isConnected == true){
try{
proxy.Connection.Close();
this.isConnected = false;;
}
catch(Exception e){
Console.WriteLine(e.ToString());
Environment.Exit(0);
}
}
}
///
/// Toggles the connection.
///

public void toggleConnection(){
if(this.isConnected)
this.disConnectSAP();
else
this.connectSAP();
}
}
}

[@more@]DBReaderClasses

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/232040/viewspace-968999/,如需转载,请注明出处,否则将追究法律责任。

上一篇: DBReader/Classes/Logon
请登录后发表评论 登录
全部评论
  • 博文量
    15
  • 访问量
    53960