📄 complexform.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "ComplexForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'// SAP MANAGE UI API 2005 SDK Sample
'//****************************************************************************
'//
'// File: ComplexForm.cls
'//
'// Copyright (c) SAP MANAGE
'//
'// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'// PARTICULAR PURPOSE.
'//
'//****************************************************************************
'//**************************************************************************************************
'// BEFORE STARTING:
'// 1. Add reference to the "SAP Business One UI API"
'// 2. Insert the development connection string to the "Command Line Argument"
'//-----------------------------------------------------------------
'// 1.
'// a. Project->References
'// b. check the "SAP Business One UI API" check box
'//
'// 2.
'// a. Project->Properties
'// b. choose 'Make' tab folder
'// c. place the following connection string in the 'Command Line Arguments' field
'// 0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056
'//
'//**************************************************************************************************
Option Explicit
'//*****************************************************************
'// At the begining of every UI API project we should first
'// establish connection with a running SBO application.
'*******************************************************************
Private WithEvents SBO_Application As SAPbouiCOM.Application
Attribute SBO_Application.VB_VarHelpID = -1
Private oForm As SAPbouiCOM.Form
Private Sub SetApplication()
'*******************************************************************
'// Use an SboGuiApi object to establish the connection
'// with the application and return an initialized appliction object
'*******************************************************************
Dim SboGuiApi As SAPbouiCOM.SboGuiApi
Dim sConnectionString As String
Set SboGuiApi = New SAPbouiCOM.SboGuiApi
'// by following the steps specified above, the following
'// statment should be suficient for either development or run mode
sConnectionString = Command
'// connect to a running SBO Application
SboGuiApi.Connect sConnectionString
'// get an initialized application object
Set SBO_Application = SboGuiApi.GetApplication()
End Sub
Private Function CreateMyComplexForm()
Dim oItem As SAPbouiCOM.Item
'// *******************************************
'// we will use the following objects to set
'// the specific values of every item
'// we add.
'// this is the best way to do so
'//*********************************************
Dim oButton As SAPbouiCOM.Button
Dim oFolder As SAPbouiCOM.Folder
Dim oOptionBtn As SAPbouiCOM.OptionBtn
Dim oCheckBox As SAPbouiCOM.CheckBox
Dim i As Integer '// to be used as a counter
'// add a new form
Set oForm = SBO_Application.Forms.Add("MyComplexForm", ft_Sizable)
'// add a user data source
'// bare in mind that every item must be connected to a data source
oForm.DataSources.UserDataSources.Add "FolderDS", dt_SHORT_TEXT, 1
oForm.DataSources.UserDataSources.Add "OpBtnDS", dt_SHORT_TEXT, 1
oForm.DataSources.UserDataSources.Add "CheckDS1", dt_SHORT_TEXT, 1
oForm.DataSources.UserDataSources.Add "CheckDS2", dt_SHORT_TEXT, 1
oForm.DataSources.UserDataSources.Add "CheckDS3", dt_SHORT_TEXT, 1
'// set the form properties
oForm.Title = "Complex Form"
oForm.Left = 300
oForm.Width = 200
oForm.Top = 100
oForm.Height = 160
'//*****************************************
'// Adding Items to the form
'// and setting their properties
'//*****************************************
'/**********************
'// Adding an Ok button
'//*********************
'// We get automatic event handling for
'// the Ok and Cancel Buttons by setting
'// their UIDs to 1 and 2 respectively
Set oItem = oForm.Items.Add("1", it_BUTTON)
oItem.Left = 5
oItem.Width = 65
oItem.Top = oForm.Height - 50
oItem.Height = 19
Set oButton = oItem.Specific
oButton.Caption = "Ok"
'//************************
'// Adding a Cancel button
'//***********************
Set oItem = oForm.Items.Add("2", it_BUTTON)
oItem.Left = 75
oItem.Width = 65
oItem.Top = oForm.Height - 50
oItem.Height = 19
Set oButton = oItem.Specific
oButton.Caption = "Cancel"
'//****************************
'// Adding a Rectangle Item
'// for cosmetic purposes only
'//****************************
Set oItem = oForm.Items.Add("Rect1", it_RECTANGLE)
oItem.Left = 0
oItem.Width = oForm.Width - 8
oItem.Top = 22
oItem.Height = oForm.Height - 80
'//***************************
'// Adding Folder items
'//***************************
For i = 1 To 2
Set oItem = oForm.Items.Add("Folder" & i, it_FOLDER)
oItem.Left = (i - 1) * 100
oItem.Width = 100
oItem.Top = 6
oItem.Height = 19
Set oFolder = oItem.Specific
'// set the caption
oFolder.Caption = "Folder" & i
oFolder.DataBind.SetBound True, "", "FolderDS"
If i = 1 Then
oFolder.Select
Else
oFolder.GroupWith ("Folder" & i - 1)
End If
Next i
'//****************************
'// Adding Option button items
'//****************************
For i = 1 To 3
Set oItem = oForm.Items.Add("OpBtn" & i, it_OPTION_BUTTON)
oItem.Left = 20
oItem.Width = 100
oItem.Top = 30 + (i - 1) * 19
oItem.Height = 19
'// set the Item's Pane Level.
'// by setting the Form's pane level
'// this value will determine the Items visibility
oItem.FromPane = 1
oItem.ToPane = 1
Set oOptionBtn = oItem.Specific
'// set the caption
oOptionBtn.Caption = "Option Button" & i
If i > 1 Then
oOptionBtn.GroupWith ("OpBtn" & i - 1)
End If
oOptionBtn.DataBind.SetBound True, "", "OpBtnDS"
Next i
'//***************************
'// Adding Check Box items
'//***************************
For i = 1 To 3
Set oItem = oForm.Items.Add("CheckBox" & i, it_CHECK_BOX)
oItem.Left = 20
oItem.Width = 100
oItem.Top = 30 + (i - 1) * 19
oItem.Height = 19
'// set the Item's Pane Level.
'// by setting the Form's pane level
'// this value will determine the Items visibility
oItem.FromPane = 2
oItem.ToPane = 2
Set oCheckBox = oItem.Specific
'// set the caption
oCheckBox.Caption = "Check Box" & i
'// binding the Check box with a data source
oCheckBox.DataBind.SetBound True, "", "CheckDS" & i
Next i
'//****************************************
'// Show the Form:
'// we will use the Item Event to Control
'// the behavior of this form
'//****************************************
oForm.PaneLevel = 1
End Function
Public Sub RearrangeItems()
'// this method will update the items on the form
'// after a resize event
Dim oButton As SAPbouiCOM.Button
Dim oFolder As SAPbouiCOM.Folder
Dim oOptionBtn As SAPbouiCOM.OptionBtn
Dim oCheckBox As SAPbouiCOM.CheckBox
Dim oItem As SAPbouiCOM.Item
Dim i As Integer
'// get the required item from the form
'// and change his attributes according to the
'// new form size
'//************************
'// Changing the OK button
'//***********************
Set oItem = oForm.Items.Item("1")
'oItem.Left = 5
'oItem.Width = 65
oItem.Top = oForm.Height - 50
'oItem.Height = 19
'//************************
'// Changing the Cancel button
'//***********************
Set oItem = oForm.Items.Item("2")
'oItem.Left = 75
'oItem.Width = 65
oItem.Top = oForm.Height - 50
'oItem.Height = 19
'//****************************
'// Changing the Rectangle Item
'//****************************
Set oItem = oForm.Items.Item("Rect1")
'oItem.Left = 0
oItem.Width = oForm.Width - 8
'oItem.Top = 22
oItem.Height = oForm.Height - 80
'//**************************************
'// Changing the Option button items
'//**************************************
For i = 1 To 3
Set oItem = oForm.Items.Item("OpBtn" & i)
oItem.Left = 20
oItem.Width = 100
oItem.Top = 30 + (i - 1) * 19
oItem.Height = 19
Next i
'//******************************
'// Changing the Check Box items
'//******************************
For i = 1 To 3
Set oItem = oForm.Items.Item("CheckBox" & i)
oItem.Left = 20
oItem.Width = 100
oItem.Top = 30 + (i - 1) * 19
oItem.Height = 19
Next i
End Sub
Private Sub Class_Initialize()
'//*************************************************************
'// set SBO_Application with an initialized application object
'//*************************************************************
SetApplication
'//*************************************************************
'// Create the Form
'//*************************************************************
CreateMyComplexForm
oForm.Visible = True
oForm.Items("OpBtn1").Specific.Selected = True
oForm.Items("Folder1").Specific.Select
End Sub
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, pVal As SAPbouiCOM.IItemEvent, BubbleEvent As Boolean)
If FormUID = "MyComplexForm" Then
Set oForm = SBO_Application.Forms(FormUID)
Select Case pVal.EventType
Case et_ITEM_PRESSED:
'//************************************************************
'// Check if the event was raised by one of the Folder items
'// and change the form's pane level
'//************************************************************
If pVal.ItemUID = "Folder1" Then
oForm.PaneLevel = 1
End If
If pVal.ItemUID = "Folder2" Then
oForm.PaneLevel = 2
End If
Case et_FORM_RESIZE:
'// first freeze the form so that all changes
'// would be updated at one batch
oForm.Freeze True
'// rearrange the the items according to the
'// new size of the form
RearrangeItems
'// unfreeze the form
oForm.Freeze False
'// update the changes
'// all changes will be updated in one batch
oForm.Update
Case et_FORM_CLOSE:
'// terminate the add on application
End
End Select
End If
End Sub
Private Sub SBO_Application_AppEvent(ByVal EventType As SAPbouiCOM.BoAppEventTypes)
Select Case EventType
Case aet_ShutDown:
'// Take care of terminating your AddOn application
SBO_Application.MessageBox ("A Shut Down Event has been caught" & _
vbNewLine & "Terminating 'Complex Form' Add On...")
End
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -