Practice (101) - Create Simple Connection to SGC Server

<< Click to Display Table of Contents >>

Navigation:  All About SAP Interface > SAP r/3 and VB.Net > Create Desktop Application using SGC Server > Basic Knowledge >

Practice (101) - Create Simple Connection to SGC Server

Objective

Creating Program

Result

SGC Server

v1.0, v1.1

Support

Source Code is available (Download)

 

No

Description

 

1

Difficulty Level

Easy

2

.Net Library

System

System.Data

System.Deployment

System.Drawing

System.Windows.Forms

System.XML

 

Creating Program

1.Create Folder \Desktop-Application\

2.Run Microsoft Visual Studio

3.Create New Project

4.Enter Project name as "Practice101" Save into  \Desktop-Application\Practice101\

VB.Net_da0001

5.Rename File name and Form name from "Form1" to "Main1"

VB.Net_da0002

6.Add and design a components according to component list bellow

No

Component

Properties

Value

Design

1

Forms.Button

Name

bConnect

VB.Net_da0003

 

 

Text

&Connect

2

Forms.TextBox

Name

eIPAddress

 

 

Text

127.0.0.1

3

Forms.NumericUpDown

Name

sePort1

 

 

Value

10001

5

Forms.Button

Name

bLogin

 

 

Text

&Login

 

 

Enabled

False

5

Forms.TextBox

Name

Memo1

 

 

ScrollBars

Both

 

 

Multiline

True

 

 

WordWarp

False

6

Forms.TextBox

Name

Memo2

 

 

ScrollBars

Both

 

 

Multiline

True

 

 

WordWarp

False

7

Forms.TextBox

Name

mSLog

 

 

ScrollBars

Vertical

 

 

Multiline

True

 

7.Create New Module "mdlGlobalVariabel.vb"

VB.Net_da0004

8.Create New Class "clsClientSocket.vb"

VB.Net_da0005

 

9.Create Global Variable at module "mdlGlobalVariabel.vb"

Module mdlGlobalVariabel

  'SGC Info

  Public isConnected, isLogin As Boolean

 

  'SGC Login Variable

  Public cEncryptionType As String

  Public cUserID, cPassword, cCompanyCode, cProgramType, cProgramCode As String

  Public TCPClient As New clsClientSocket

 

  'SGC Command

  Public ClientString, LoginString As String

 

End Module

 

10.Copy this Source Code bellow to "clsClientSocket.vb"

View Source Code

11.Open Desain of Main1.vb

12.Double click the Form to add new Event Procedure "Main_Load"

13.Write this code bellow

  Private Sub Main1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim NumDate, NumTime As Double

 

    mSLog.Text = "Run Application"

 

    NumDate = Date.Today.ToOADate

    NumTime = DateAndTime.TimeOfDay.ToOADate

 

    ClientString = "<?xml version=""1.0"" encoding=""utf-8""?>"

    ClientString = ClientString & Environment.NewLine & "<SGC_CLIENT DATE=""" & NumDate & """ TIME=""" & NumTime & """>"

    ClientString = ClientString & Environment.NewLine & "  <CLIENT_STRING COMMAND=""Get Server String"" USERNAME="""" PASSWORD="""" COMPANY_CODE="""" PROGRAM_TYPE="""" PROGRAM_CODE="""" PARAMETER1="""" PARAMETER2="""" PARAMETER3=""""/>"

    ClientString = ClientString & Environment.NewLine & "</SGC_CLIENT>"

    ClientString = ClientString & Environment.NewLine & " " 'Add empty line after "</SGC_CLIENT>"

 

    'SGC Server has an authorization system. The authorization system will be blocked and limited the connection from any SGC Client connection.

    'There are a several required field to Login and go through the authorization, such as :

    '=> USERNAME=""

    '=> PASSWORD=""

    '=> COMPANY_CODE=""

    '=> PROGRAM_TYPE=""

    '=> PROGRAM_CODE=""

    'If the required fields value doesn't match with authorization configuration at SGC Server then the connection will be refuse (Login Failed).

 

    'Assume that you are not login to SGC Server, then Login String always automaticaly filled with this value bellow :

    '=> USERNAME="DEMO"

    '=> PASSWORD="123456"

    '=> COMPANY_CODE="1000"

    '=> PROGRAM_TYPE="Examples"

    '=> PROGRAM_CODE="Client_Example_01"

 

    'Set Default SGC Client Login for Demo Only

    cUserID = "DEMO"

    cPassword = "123456"

    cCompanyCode = "1000"

    cProgramType = "Examples"

    cProgramCode = "Client_Example_01"

 

    LoginString = "<?xml version=""1.0"" encoding=""utf-8""?>"

    LoginString = LoginString & Environment.NewLine & "<SGC_CLIENT DATE=""" & NumDate & """ TIME=""" & NumTime & """>"

    LoginString = LoginString & Environment.NewLine & "  <CLIENT_STRING COMMAND=""Login"" " & _

      "USERNAME=""" & cUserID & """ " & _

      "PASSWORD=""" & cPassword & """ " & _

      "COMPANY_CODE=""" & cCompanyCode & """ " & _

      "PROGRAM_TYPE=""" & cProgramType & """ " & _

      "PROGRAM_CODE=""" & cProgramCode & """ " & _

      "PARAMETER1="""" PARAMETER2="""" PARAMETER3=""""/>"

    LoginString = LoginString & Environment.NewLine & "</SGC_CLIENT>"

    LoginString = LoginString & Environment.NewLine & " " 'Add empty line after "</SGC_CLIENT>"

 

  End Sub

 

14.Add Event Click at bConnect button and then write code to connect and disconnect to SGC Server

  Private Sub bConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bConnect.Click

    Dim tmpReceive As String

 

    If bConnect.Text = "&Connect" Then

      mSLog.Text = mSLog.Text & Environment.NewLine & "Try connect to SGC Server"

 

      'Connect to SGC Server

      If TCPClient.Connect(eIPAddress.Text, sePort1.Value, 30000) Then '30000 > Time out 30 Second

 

        'Sending command to SGC Server

        TCPClient.SendText(mSLog, ClientString, tmpReceive)

 

        'Display XML Data

        Memo1.Text = ClientString

        Memo2.Text = tmpReceive

 

        'Free temporary data

        tmpReceive = ""

 

      End If

 

    Else

      TCPClient.Disconnect()

    End If

 

    'Set Component Atribute

    If TCPClient.isConnected Then

      bConnect.Text = "&Disconnect"

      mSLog.Text = mSLog.Text & Environment.NewLine & "Connections is succeed"

    Else

      bConnect.Text = "&Connect"

      mSLog.Text = mSLog.Text & Environment.NewLine & "Disconnected form server"

      Memo1.Text = ""

      Memo2.Text = ""

    End If

 

    eIPAddress.Enabled = Not TCPClient.isConnected

    sePort1.Enabled = Not TCPClient.isConnected

    bLogin.Enabled = TCPClient.isConnected

    isConnected = TCPClient.isConnected

    bLogin.Enabled = TCPClient.isConnected

 

  End Sub

 

15.Add Event Click at bLogin button and then write code to send "Login String"

  Private Sub bLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bLogin.Click

    Dim tmpReceive As String

 

    'Sending command to SGC Server

    TCPClient.SendText(mSLog, LoginString, tmpReceive)

 

    'Display XML Data

    Memo1.Text = ClientString

    Memo2.Text = tmpReceive

 

    'Free temporary data

    tmpReceive = ""

  End Sub

16.Save and Run the application

 

Result

Screen 1. Connected to SGC Server

VB.Net_da0006

 

Screen 2. Login to SGC Server

VB.Net_da0007