Chinaunix首页 | 论坛 | 博客
  • 博客访问: 393648
  • 博文数量: 66
  • 博客积分: 1235
  • 博客等级: 少尉
  • 技术积分: 694
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-05 12:24
文章分类

全部博文(66)

文章存档

2010年(66)

分类:

2010-08-30 14:21:05

1.创建SAP 函数组和 RFC函数(事物代码SE37)
 

2.创建RFC需要用到的结构(事物代码SE11)

3.ASP.NET项目中添加相关组件:Interop.SAPFunctionsOCX.dll,Interop.SAPLogonCtrl.dll,Interop.SAPTableFactoryCtrl.dll

4.以下为ASP.NET中代码

***Default.aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>



    Default


   


   

  
  
  
              GridLines="None">
           
           
           
           
           
           
           
  

   

   



***Default.aspx.cs:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SAPFunctionsOCX;
using SAPLogonCtrl;
using SAPTableFactoryCtrl;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        public DataTable dt = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            System.Threading.Thread s = new System.Threading.Thread(new System.Threading.ThreadStart(test)); //Create a new thread and set the method test() run in this thread
            s.SetApartmentState(System.Threading.ApartmentState.STA);                                        //Set the run mode 'STA'
            s.Start();                                                                                       //Start the thread
            s.Join();                                                                                        //Wait until thread run OK.
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        private void test()
        {
            SAPLogonCtrl.SAPLogonControlClass login = new SAPLogonCtrl.SAPLogonControlClass();
            login.ApplicationServer = "192.168.18.7";
            login.Client = "200";
            login.Language = "ZH";
            login.User = "RFC01";
            login.Password = "123456789";
            login.SystemNumber = 00;
            SAPLogonCtrl.Connection conn = (SAPLogonCtrl.Connection)login.NewConnection();

            if (conn.Logon(0, true))
            {
                SAPFunctionsOCX.SAPFunctionsClass func = new SAPFunctionsOCX.SAPFunctionsClass();
                func.Connection = conn;
                SAPFunctionsOCX.IFunction ifunc = (SAPFunctionsOCX.IFunction)func.Add("Z_TEST");
                SAPFunctionsOCX.IParameter matnr = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("S_MATNR");
                string str_matnr = this.TextBox1.Text.ToString();
                str_matnr = str_matnr.PadLeft(18, '0');//补0
                matnr.Value = str_matnr;
                ifunc.Call();
                SAPTableFactoryCtrl.Tables tables = (SAPTableFactoryCtrl.Tables)ifunc.Tables;
                SAPTableFactoryCtrl.Table ENQ = (SAPTableFactoryCtrl.Table)tables.get_Item("P_MARA");
                int n = ENQ.RowCount;
                for (int i = 1; i <= ENQ.RowCount; i++)
                {
                    DataRow dr = dt.NewRow();
                    if (i == 1)
                    {
                        dt.Columns.Add("MATNR");
                        dt.Columns.Add("MEINS");
                        dt.Columns.Add("BRGEW");
                        dt.Columns.Add("NTGEW");
                        dt.Columns.Add("VOLUM");
                        dt.Columns.Add("体积单位");
                    }

                    dr["MATNR"] = (String)ENQ.get_Value(i, "MATNR");
                    dr["MEINS"] = (String)ENQ.get_Value(i, "MEINS");
                    dr["BRGEW"] = (String)ENQ.get_Value(i, "BRGEW");
                    dr["NTGEW"] = (String)ENQ.get_Value(i, "NTGEW");
                    dr["VOLUM"] = (String)ENQ.get_Value(i, "VOLUM");
                    dr["体积单位"] = (String)ENQ.get_Value(i, "VOLEH");
                    dt.Rows.Add(dr);
                }

            }
        }
    }
}

阅读(4795) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~