需要将Visual Basic SAP登录应用程序转换为C#应用程序

2020-08-21 18:16发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)这是我的Visual Basic...

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


这是我的Visual Basic代码,可以正常工作!〜

================================================ ======================

公共子Logon_Click(作为对象发送,作为EventArgs发送)处理登录。单击

'===激活SAP登录板引擎

应用程序= CreateObject(" Sapgui.ScriptingCtrl.1")

'===启动预定义的SAPlogon pad连接之一

Sapgui = GetObject(" SAPGUI")

应用程序= Sapgui.GetScriptingEngine

connection = Application.OpenConnection(" SP1- ECC 6.0 Production [WM_MM_GRP]",真)

会话= connection.children(0)

'===填写登录屏幕字段

session.findById(" wnd [0]/usr/txtRSYST-BNAME")。text =" tuser_id_here"

session.findById(" wnd [0]/usr/pwdRSYST-BCODE")。text =" passwd_here"

'===发送回车

session.findById(" wnd [0]")。sendVKey(0)

结束子

================================================ =======================

任何人在c#中都有一个示例

我在WPF中使用框架4.72,但如果需要,Windows窗体也可以。

该应用程序的其余部分位于.NET CORE C#WPF中。 就示例而言,那里没有多少东西!

我开始怀疑我是否可以在C#中使用SAP GUI。

谢谢

Pete

6条回答
我是小鹏鹏啊
2020-08-21 18:38

你好 PETER GROVES

我们两年前在这里讨论了这段代码,但观点有所不同。

FindById有效,但是您的ID错误。

 GuiButton btn =(GuiButton)SAPActive.SapSession.FindById("/img/app/con [0]/ses [0]/wnd [0]/tbar [0]/btn [0]"  ); 

this

 GuiButton btn =(GuiButton)SAPActive.SapSession.FindById(" wnd [0]/tbar [0]/btn [0]"); 
>

您处于会话级别,因此无法使用整个ID来标识对象。 仅从会话级别开始,没有/app/con [0]/ses [0]。

这里是我的测试代码:

//-开始------  --------------------------------------------------  -------

//css_host/platform:x86
//css_ref" C:\ Program Files(x86)\ SAP \ NWBC70 \ Interop.SAPFEWSELib.dll"

 使用Interop.SAPFEWSELib;
 使用System.Runtime.InteropServices;

 班级考试{

   静态void Main(string [] args){

     GuiApplication Appl =新的GuiApplicationClass();
     Appl.OpenConnection(" NSP",true);

     var COMConn = Appl.Children.ElementAt(0);
     GuiConnection Conn =(GuiConnection)Marshal.CreateWrapperOfType(COMConn,typeof(GuiConnectionClass));
    
     var COMSess = Conn.Children.ElementAt(0);
     GuiSession Sess =(GuiSession)Marshal.CreateWrapperOfType(COMSess,typeof(GuiSessionClass));

     var COMtxtMandt = Sess.FindById(" wnd [0]/usr/txtRSYST-MANDT");
     GuiTextField txtMandt =(GuiTextField)Marshal.CreateWrapperOfType(COMtxtMandt,typeof(GuiTextFieldClass));
     txtMandt.Text =" 500";

     var COMbtnEnter = Sess.FindById(" wnd [0]/tbar [0]/btn [0]");
     GuiButton btnEnter =(GuiButton)Marshal.CreateWrapperOfType(COMbtnEnter,typeof(GuiButtonClass));
     btnEnter.Press();

     Sess.ActiveWindow.Close();

   }

 }

//-结束 -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  --------------------
 

最诚挚的问候
Stefan

一周热门 更多>