当前位置:编程学习 > asp >>

ASP.Net MVC3连接SAP实践

[csharp]
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using SAP.Middleware.Connector; 
using System.Data; 
namespace SAPMVC.Controllers 

    public class HomeController : Controller 
    { 
        string MATNR = string.Empty; 
        public ActionResult Index() 
        { 
            ViewBag.Message = "Welcome to ASP.NET MVC!"; 
            nco(); 
            //nco2();  
 
            return View(); 
        } 
 
        public void nco2() 
        { 
            RfcConfigParameters rfcPar = new RfcConfigParameters(); 
            //rfcPar.Add(RfcConfigParameters.Name, "CON");  
            //rfcPar.Add(RfcConfigParameters.AppServerHost, "192.168.1.3");  
            //rfcPar.Add(RfcConfigParameters.Client, "800");  
            //rfcPar.Add(RfcConfigParameters.User, "UserID");  
            //rfcPar.Add(RfcConfigParameters.Password, "Password");  
            //rfcPar.Add(RfcConfigParameters.SystemNumber, "02");  
            //rfcPar.Add(RfcConfigParameters.Language, "EN");  
 
            rfcPar.Add(RfcConfigParameters.Name, "CON"); 
            rfcPar.Add(RfcConfigParameters.AppServerHost, "192.168.1.3");   //SAP主机IP  
            rfcPar.Add(RfcConfigParameters.SystemNumber, "00");  //SAP实例  
            rfcPar.Add(RfcConfigParameters.User, "MENGXIN");  //用户名  
            rfcPar.Add(RfcConfigParameters.Password, "5239898");  //密码  
            rfcPar.Add(RfcConfigParameters.Client, "888");  // Client  
            //rfcPar.Add(RfcConfigParameters.Language, "ZH");  //登陆语言  
            //rfcPar.Add(RfcConfigParameters.PoolSize, "5");  
            //rfcPar.Add(RfcConfigParameters.MaxPoolSize, "10");  
            //rfcPar.Add(RfcConfigParameters.IdleTimeout, "60");  
 
            RfcDestination dest = RfcDestinationManager.GetDestination(rfcPar); 
            RfcRepository rfcrep = dest.Repository; 
            IRfcFunction myfun = null; 
            myfun = rfcrep.CreateFunction("SAP里面的函数名称"); 
            myfun.SetValue("VTYPE", "0");//SAP里面的传入参数  
            myfun.Invoke(dest); 
            IRfcTable IrfTable = myfun.GetTable("IT_ZMYTB2"); 
            //提前实例化一个空的表结构出来  
            DataTable dt = new DataTable(); 
            dt.Columns.Add("USERID"); 
            dt.Columns.Add("USERPWD"); 
            dt.Columns.Add("USERADDRESS"); 
            //循环把IRfcTable里面的数据放入Table里面,因为类型不同,不可直接使用。  
            for (int i = 0; i < IrfTable.Count; i++) 
            { 
                IrfTable.CurrentIndex = i; 
                DataRow dr = dt.NewRow(); 
                dr["USERID"] = IrfTable.GetString("USERID"); 
                dr["USERPWD"] = IrfTable.GetString("USERPWD"); 
                dr["USERADDRESS"] = IrfTable.GetString("USERADDRESS"); 
                dt.Rows.Add(dr); 
            } 
        } 
 
        public void nco() 
        { 
            IDestinationConfiguration ID = new MyBackendConfig(); 
            RfcDestinationManager.RegisterDestinationConfiguration(ID); 
            RfcDestination prd = RfcDestinationManager.GetDestination("PRD_000"); 
            RfcDestinationManager.UnregisterDestinationConfiguration(ID); 
            nco(prd); 
        } 
        public void nco(RfcDestination prd) 
        { 
            RfcRepository repo = prd.Re
补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,