免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 9192 | 回复: 20
打印 上一主题 下一主题

用ASP.NET调用CL [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-18 16:01 |只看该作者 |倒序浏览
最近公司要逐步把ERP转形,用C#来显示画面,400进行后台数据处理,运算~~

通过ASP.NET调用RPG,已经实现了,但是调用CL一直也没有眉目(ASP.NET是通过调用Program来调用RPG的)

想请教一下各位大侠,看看各位有没有什么好的方法,谢谢大家!

论坛徽章:
0
2 [报告]
发表于 2009-05-19 08:43 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
3 [报告]
发表于 2009-05-19 08:56 |只看该作者
谢谢mario663大侠的指导!
对于在AS400上建立PROCEDURE这个我还没试过,能否指点下.
(通过ASP.NET调用RPG,不用建PROCEDURE也可以调用.为何CL不行呢,想不明白,呵呵)
再次感谢!

论坛徽章:
0
4 [报告]
发表于 2009-05-19 09:25 |只看该作者
楼主,你怎么实现的C#调用RPG哈,
指点一下,谢谢

论坛徽章:
0
5 [报告]
发表于 2009-05-19 09:33 |只看该作者
楼主怎么实现ASP.NET调用RPG?代码可否参考一下,想知道?
还有就是有没有实现VB调用RPG的?请指点一下,非常感谢!

论坛徽章:
0
6 [报告]
发表于 2009-05-19 14:05 |只看该作者
怎么调用RPG, 我不大会说,我把代码贴出来吧~大家一起讨论下~~~
下面这段代码是APP_CODE下面的~
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using cwbx; //引用iseries插件,// cwbx.dll is in the Iseries access folder C:\Program Files\IBM\Client Access\Shared

/// <summary>
/// AS400Program 的摘要描述
/// </summary>
//namespace Interfaces.Source

    public class AS400Program
    {
        private bool as400Configured = false;
        public cwbx.AS400System as400;
        public cwbx.Program program;

        // configuration format:
        // as400;userid;password;library;program
        public AS400Program(string configuration)
        {
            if (!as400Configured)
            {
                string[] settings = configuration.Split(';');
                if (settings.Length == 5)
                {
                    as400 = new cwbx.AS400SystemClass();  // creates an as/400 object
                    program = new cwbx.Program(); // Create a program object
                    as400.Define(settings[0]); // IP of AS/400
                    program.system = as400;
                    program.system.UserID = settings[1]; // Your user name
                    program.system.Password = settings[2]; // Your password
                    program.LibraryName = settings[3]; //Library where your program is located
                    program.ProgramName = settings[4]; // Program that this app will call
                    as400Configured = true;
                }
                else
                {
                    throw (new Exception(
                        string.Format("Invalid AS400Program configuration string : [{0}]", configuration)));
                }
            }
        }

        public bool Invoke(bool throwInsteadOfReturn, ref cwbx.ProgramParameters parameters)
        {
            bool success = false;

            try
            {
                if (as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0)
                {
                    //  Lost connection with the AS400.  Disconnect, then reconnect.
                    as400.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll);
                    as400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd);

                    if (as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0)
                    {
                        //  Log something here.
                    }
                }

                //program.Call(parameters);
                cwbx.ProgramParameters para = new cwbx.ProgramParametersClass();
                program.Call(para);
                success = true;
            }
            catch (Exception e)
            {
                // Capture to log the errors but then re-throw it to let caller know there was trouble.
                if (as400.Errors.Count > 0)
                {
                    foreach (cwbx.Error error in as400.Errors)
                    {
                        //  Log something here.
                    }
                }

                if (program.Errors.Count > 0)
                {
                    foreach (cwbx.Error error in program.Errors)
                    {
                        //  Log something here.
                    }
                }

                if (throwInsteadOfReturn)
                {
                    throw (e);
                }
            }

            return (success);
        }

        public void Close()
        {
            as400.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll);
        }
    }

论坛徽章:
0
7 [报告]
发表于 2009-05-19 14:09 |只看该作者
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Reflection;


    public partial class UsingAS400Program : System.Web.UI.Page
    {
        //protected enum DataLengths : int

        protected enum DataLengths : int
        {
            UserId = 7, //定義UserId長度為7
            UserName = 10,//定義UserName長度為10
        }


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public string CALLAS400()
        {
            //  Assume the RPG program being called takes one input paramater, UserId, and returns the UserName.

            //從web.config中去讀取  partsPricingConfig 的值,並傳遞給 AS400Program.cs 中的 AS400Program();
            AS400Program program = new AS400Program(System.Configuration.ConfigurationManager.AppSettings["partsPricingConfig"]);


            cwbx.StringConverter stringConverter = new cwbx.StringConverterClass();
            cwbx.PackedConverter packedConverter = new cwbx.PackedConverterClass();
            //packedConverter.DecimalPosition = 4;
            //packedConverter.Digits = (int)DataLengths.UserName;

            cwbx.ProgramParameters parameters = new cwbx.ProgramParametersClass();

            //傳遞參數給as400
            parameters.Append("PEMN", cwbx.cwbrcParameterTypeEnum.cwbrcInput, (int)DataLengths.UserId);
            parameters["PEMN"].Value = stringConverter.ToBytes("2060113");

            parameters.Append("NAME", cwbx.cwbrcParameterTypeEnum.cwbrcInput, (int)DataLengths.UserName);
            parameters["NAME"].Value = stringConverter.ToBytes("aaabbbb");

            //調用 AS400Program.cs 中的 傳遞parameters 給 Invoke 調用AS400 中的 Program
            program.Invoke(true, ref parameters);

            //string price = packedConverter.FromBytes(parameters["UserName"].Value);

            //調用完成後關閉連結
            program.Close();

            return "恭喜你,調用成功!!";
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string aa = CALLAS400();

            TextBox1.Text = aa.ToString();
        }
}

论坛徽章:
0
8 [报告]
发表于 2009-05-19 14:12 |只看该作者
<?xml version="1.0"?>
<!--
    注意: 除了手動編輯這個檔案以外,您也可以使用
    Web 管理工具設定您的應用程式設定值。請使用
    Visual Studio 中的 [網站] -> [ASP.NET 組態] 選項。
    如需完整的設定與註解清單,請參考
    machine.config.comments (通常位於
    \Windows\Microsoft.Net\Framework\v2.x\Config)
-->
<configuration>
  <appSettings>
    <!--以下定義連結AS400的參數:value="value="server;userid;password;library;program"-->
    <!--<add key="partsPricingConfig" value="10.81.1.14;pgma04;pgma04;TPCLIBA;NETTEST1"/>-->
    <add key="partsPricingConfig" value="10.81.1.14;pgma04;pgma04;TPCLIBA;SFRE86"/>
  </appSettings>
        <connectionStrings/>
        <system.web>
                <!--
            設定 compilation debug="true" 會將偵錯
            符號插入編譯過的頁面。因為這樣會
            影響效能,所以只有在開發期間才能將
            這個值設定為 true。
        -->
                <compilation debug="true"/>
                <!--
            <authentication> 區段可以用來設定 ASP.NET
            使用的安全性驗證模式,以識別連入的
            使用者。
        -->
                <authentication mode="Windows"/>
                <!--
            <customErrors> 區段可以用來設定
            在執行要求期間發生未處理
            錯誤時所要執行的動作。具體來說,
            它可以讓開發人員設定要顯示的 HTML 錯誤網頁,
            以取代錯誤堆疊追蹤。

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
        </system.web>
</configuration>

论坛徽章:
0
9 [报告]
发表于 2009-05-19 14:14 |只看该作者
所有的连接代码就在上面,不知道能不能看懂,有点乱~~~我也不知道该怎么说

实现的功能就是:通过一个BOTTON执行400里的一个RPG~~~(连接的RPG在最后发的那段代码上)

如果有不明白的,可以留言~~~

论坛徽章:
0
10 [报告]
发表于 2009-05-19 14:15 |只看该作者
VB我没用过,不好意思~~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP