Professional Documents
Culture Documents
Power Builder Training
Power Builder Training
Training
Session 1
Introduction To Powerbuilder
development tool.
Its strongest strength is
Database connectivity
Object Orientation Implementation.
In its initial releases, PowerBuilder was just used as a
client --talking to
the Database Server directly.
Powerbuilder applications can be deployed as client, as
a middle tier
application or both.
PowerBuilder supports SQL and stored procedures
using the Data
Window control
andbyembedded/dynamic
All rights reserved
Satyam Computers Services Ltd.SQL and
Powerbuilder Features
InfoMaker
Infomaker is a
subset of
PowerBuilder , used
by end for
generating reports.
PowerDesign
er
PowerDesigner
supports multi-user
database designing .
Adaptive
Server
Anywhere
ASA is full-featured
transaction
processing SQL
Database
Management
System.
Summary
Session 2
PowerBuilder
Environment
Prerequisites
Starting PowerBuilder
Powerbuilder Interface
PowerPanel
Window Painter In any application, Window is the main interface between a user and a
application.
Menu Painter A menu is a list of options or commands. Example your browser's menu.
Data Window object allows you to retrieve data from a database or other source for display .
A data window object consists of the following:
Data Source Definition : That is the data from where to bring i.e. database ,table, column etc.
Presentation Definition: Presentation style of the retrieved data from the database .
User Object allows you to reuse the code .It is nothing but a collection of one or more
Powerbuilder/Non PowerBuilder objects. Non PB Object includes objects from VB, Dlls ,OCX
and so on
Toolbars
What is a toolbar?
Answer: A toolbar is nothing but a collection of icons
associated with actions.
Types Of Toolbars
PowerBuilder comes with three
toolbars:
Powerbar
Painterbar
Stylebar
Powerbar
Powerbar is similar to PowerPanel in
terms of functionality and contains
all options available in PowerPanel.
Painterbar
Stylebar
Stylebar allows you to change the
text style - such as text's font, font
size, justification, etc.
Customizing Toolbar
The power of a PowerBuilder
toolbar is in its
flexibility. It
helps in adding or removing icons.
Script Editor
SUMMARY
In this session we have learnt about the
following
Ovetrview of the following Powerpanel
o Powerbar
o Painterbar
o Stylebar.
How to customize the Painterbars ?
How to access Script Editor ?
All rights reserved by Satyam Computers Services Ltd.
Session 3
Creating Library
To create a library need to invoke
the library painter by clicking on
icon.
To create a library, select
Library/Create from the menu or
click on icon.
Summary
In this session we have learnt the
following:
How to create a library ?
How to create a application object
Session 4
Window Painter
This session will help you to
understand the following:
Understand what a window is.
Understand about Window Controls and how
they work together.
Paint windows.
Preview/Run/Print the window.
Understand different types of windows.
Introduction to Window
Painter
Creating a Window
box.
Window Painter
Window Controls
The major window controls are :
SingleLineEdit
MultiLineEdit
Editmask
CommandButton
Picturebutton
ListBox etc.
Visisble
Enabled
Focus Rectangle
Visible
MultiLineEdit
DropDownPictureListBox
Picture EditMask
ListView
DataWindow Control
CommandButton
TreeView
UserObject
PictureButton
CheckBox
ListBox
RadioButton
Vertical Scrollbar
DropDownListBox GroupBox
Horizontal Scrollbar Tab Control Line Rectangle RoundRectangle Oval Graph
etc..
All rights reserved by Satyam
Computers Services Ltd.
Session 5
DataWindow controls
DataWindow technology is implemented in two
parts:
A DataWindow object The DataWindow object
defines the data source and presentation style for
the data.
A DataWindow control or component The control
or component is a container for the DataWindow
object in the application.
You write code that calls methods of the container
to manipulate the DataWindow object.
Presentation styles
A presentation style defines a typical style of report and handles how rows are
grouped on the page. You can customize the way the data is displayed in each
presentation style.
Important Presentation Styles include:
Tabular Data columns across the page and headers above each column. Several
rows are viewable at once.
Freeform Data columns going down the page with labels next to each
column. One row displayed at a time.
Grid Row-and-column format like a spreadsheet with grid Label Several labels
per page with one row for each label. Used for mailing and other labels.
Composite Several DataWindow objects grouped into a single presentation. Not
supported by the Web DataWindow
Graph Graphical presentation of data. Not supported by the Web
DataWindow
Crosstab Data summary in a row-and-column format.
RichText Paragraphs of text with embedded data columns. Not supported by
the Web DataWindow or the Sybase DataWindow Web control for ActiveX.
All rights reserved by Satyam
Computers Services Ltd.
Data Sources
The data source specifies the following:
DataWindow comes from
What data items are displayed.
Data can come from :
tables in a database, or
You can import data from a file or specify the data in code.
For databases, the Data specification is saved in a SQL statement.
In all cases, the DataWindow Object saves the names of the data items
to display, as well as their data types.
Other Functionalities
Of Data-Window Control
Programming Usage
You write scripts in the Window or User Object
painter to connect to the database, retrieve data,
process user input, and update data.
In PowerBuilder, you can take advantage of object
inheritance by defining a user object inherited
from a DataWindow control and adding your own
custom functionality. You can reuse the
customized DataWindow control throughout your
applications.
Naming Convention
The DataWindow object naming standards should
follow the following guidelines:
To avoid confusion, you should use different prefixes for
DataWindow objects and DataWindow controls.
The prefix d_ is commonly used for DataWindow objects.
For example, if the name of the DataWindow control is
dw_customer, you might want to name the
corresponding DataWindow object d_customer.
Limitations of
Internal Transaction Object
SetTransObject
Retrieval Arguments
Retrieval arguments qualify the SELECT
statement associated with the DataWindow
object, reducing the rows retrieved according to
some criteria.
For example, in the following SELECT statement,
Salary is a retrieval argument defined in the
DataWindow painter:
SELECT Name, emp.sal FROM Employee
WHERE emp.sal > :Salary
When you call the Retrieve method, you supply a
value for Salary. In PowerBuilder, the code looks
like this:
dw_emp.Retrieve( 50000 )
All rights reserved by Satyam
Computers Services Ltd.
Updating data
After users have made changes to data in a
DataWindow control, you can use the Update
method to save those changes in the database.
In PowerBuilder, the code looks like this:
dw_emp.Update()
Update sends to the database all inserts,
changes, and deletions made in the DataWindow
control since the last Update method.
Example
The following example gives an idea about
Updates:
// Connect to the database specified in the
Datawindow buffers
The Data Window Controls maintains
the following Buffers.
Primary: Data that has not been
deleted or filtered out (that is, the
rows that are
viewable)
Filter : Data that was filtered out
Delete : Data that was deleted by the
user or through code
All rights reserved by Satyam
Computers Services Ltd.
What Is Text ?
The contents of the edit control are
called text. Text is data that has not
yet been accepted by the
DataWindow control.
Data entered in the edit control is not
in a DataWindow buffer yet; it is
simply text in the edit control.
What Is Item?
When the user changes the contents of the edit
control and presses ENTER or leaves the cell (by
tabbing, using the mouse, or pressing UP ARROW
or DOWNARROW), the DataWindow processes the
data and either accepts or rejects it
It depends on whether it meets the requirements
specified for the column.
If the data is accepted, the text is moved to the
current row and column in the DataWindow
Primary buffer. The data in the Primary buffer for
a particular column is referred to as an item.
Action/Return Codes
You can affect the outcome of events
by specifying numeric values in the
events program code.
For example, step 3 above describes
how you can force data to be
rejected with a code of 1 in the
ItemChanged event.
To specify action/return codes:
PowerBuilder DataWindow Use a RETURN
statement
All rights reserved by Satyam
Computers Services Ltd.
ItemError event
The ItemError event is triggered if there is
a problem with the data. By default, it
rejects the data value and displays a
message box. You can write code for the
ItemError event to do some other processing.
For example, you can set a code to accept the
data value, or reject the data value but allow
focus to change.
GetItemDate,
GetItemDateTime,
GetItemDecimal,
GetItemNumber,
GetItemString,
GetItemTime
All rights reserved by Satyam
Computers Services Ltd.
SETITEM
This PowerBuilder statement sets the
value of the empname column in the
first row to the string Waters:
dw_1.SetItem(1, "empname", "Waters")
Expressions In PowerBuilder
Expressions in PowerBuilder The Object property
of the DataWindow control lets you specify
expressions that refer directly to the data of the
DataWindow object in the control.
Example Of Code:
dw_1.Object.jobtitle[3] = "Programmer
dw_1.Object.empname.Border = 1
Update
Update =1 Update succeeded.
Update = -1 Update failed; DBError event triggered.
Egs: IF dw_emp.Update() > 0 THEN
COMMIT USING EmpSQL;
ELSE
ROLLBACK USING EmpSQL;
END IF
All rights reserved by Satyam
Computers Services Ltd.
DBError Event
The DataWindow control triggers its
DBError event whenever there is an error
following a retrieval or update; that is, if
the Retrieve or Update methods return 1.
For example:
if you try to insert a row that does not
have values for allcolumns that have been
defined as not allowing NULL, the DBMS
rejects the row and the DBError event is
triggered.
All rights reserved by Satyam
Computers Services Ltd.
DBERROR MESSAGE
By default, the DataWindow control
displays a message box describing
the error message from the DBMS, as
shown here:
Sql Statement
NewModified!
DataModified!
INSERT
UPDATE
Original Status
New!
New! NewModified ! Yes
DataModified ! Yes
NotModified! No
NewModified!
New! No
NewModified!
DataModified! Yes!
NotModified! New!
DataModified!
New! NewModified!
NewModified! Yes
DataModified!
NotModified! Yes
NotModified!
New! Yes
NewModified! Yes
DataModified! Yes
NotModified! All rights reserved by Satyam
Computers Services Ltd.
Dynamically Changing
DataWindow Objects
Modifying a DataWindow
object
With some DataWindow properties, you
can assign a value through an
expression that the DataWindow
evaluates during execution, instead of
havingto assign a value directly.
For example, the following statement
displays a salary in red if it is less than
$12,000, and in black otherwise:
dw_1.Modify("salary.Color &= '0
~t if(salary <12000,255,0)' ")
All rights reserved by Satyam
Computers Services Ltd.
datastore lds_datastore
lds_datastore = CREATE datastore
lds_datastore.DataObject = "d_cust_list"
lds_datastore.SetTransObject (SQLCA)
lds_datastore.Retrieve()
/* Perform some processing on the data... */
All rights reserved by Satyam
Computers Services Ltd.
SESSION 6
Window Painter
There are six types of windows available in PowerBuilder. They are all created in the
same way, but each has a specific task for which it is used. You don't have to specify
the window type before you create the window. The default window type is "Main".
Window Types
Response WindowA Response Window is the PowerBuilder's
equivalent of a Windows dialog box; it is used to accept
response from the user, to display warnings and so on. A
response window demands action from the user and once
active remains active until the user answers.
Child WindowAs in Popup window, a Child Window can only
be opened from another window, its parent. Even though you
specify the window type as "child", it will behave like a main
window, when opened directly, i.e. not opened from another
window. "Directly" means from an application object, from a
menu option and so on.
MDI Frame Window A MDI Frame Window allows you to open
multiple windows as sheets inside it.
MDI Frame with MicroHelpThis window is exactly like an MDI
Frame, except that it has an additional feature of a status bar
at the bottom of the window.
All rights reserved by Satyam
Computers Services Ltd.
Menu Painter
PowerBuilder offers the ability to add your
custom menus to the application. In this
session you will learn about creating
menus, while retaining control over what
the user can and can't do. You will be
learning various techniques to create
menus, which you will be using in the
'Product Management System' and you will
also be looking at some of the other
options available in the Menu Painter.
All rights reserved by Satyam
Computers Services Ltd.
Types of Menus
You can create three different types
of menus in PowerBuilder:
DropDown menus
Cascading menus
Popup menus
DropDown Menus
DropDown menus are displayed when you select
an option from a menu bar that is on the topside
of a window.
The available options are grouped into logical
collections and the group names are displayed
horizontally on the menu bar.
The following picture illustrates a typical
DropDown menu.
Cascading Menus
A Cascading menu can display more menu
options than a DropDown menu.
In simple terms, if a menu option has a sub menu,
it is called a Cascading Menu.
The following pictures gives an idea about the
Cascading Menu.
Popup Menus
A Popup menu is displayed in response to a
specific event.
Unlike DropDown menus a Popup menu is not
displayed at a fixed place, but it pops up at the
current mouse position.
The following picture gives an idea about Popup
menu.
Creating A Menu
Invoke the New dialog box by selecting File >
New menu option and double-click on the Menu
icon located in Object tab page .
The following picture will provide a guideline to
you:
Properties Of menu
Some of the properties of the menu control
are:
Name
Microhelp
Accelerator Key etc
Name : PowerBuilder automatically assigns the name.
Microhelp: When using MDI windows, you can specify
the help text that is to be displayed on the status bar by
typing in the MicroHelp property.
Accelefrator Key : An accelerator key is the underlined
letter in the text of a menu item or a window object. User
can access the menu items or objects using the keyboard
instead of the mouse by pressing the specified key along
with the Alt key.
All rights reserved by Satyam
Computers Services Ltd.
Database Painter
PowerBuilder can talk to different
data sources, i.e.
Relational Databases, such as Sybase
SQL Server, Oracle, Informix, Microsoft
SQL Server, DB2, Adaptive Server
Anywhere (Watcom), etc.
Databases such as FoxPro tables.
Other sources such as Text Files, Excel
Spreadsheets, etc.
All rights reserved by Satyam
Computers Services Ltd.
Column Attributes
Each column in a table has a range of attributes, such as column
name, datatype, width, decimals, etc.
The following properties can be illustrated as below:
Name: This is the name that you use to refer to a column and it can
contain any alphanumeric characters, spaces and the underscore character.
Datatypes: This attribute defines the type of data that will be stored in the
column. For a database based upon the Adaptive Server Anywhere engine,
there are 14+ possible data types.
Width This defines the width, or the maximum number of characters a
column can contain. It is a good idea to limit the width of each column, so
as to limit the amount of memory assigned to data storage. This use of
memory can be wasteful if large amounts are allocated to store small
amounts of data.
Null Option This is a Yes/No option, which is used to determine whether or
not a column should accept a NULL value. A NULL is an empty undefined
value that shouldn't be confused with a zero-length string. The meaning of
NULL is "unknown value".
All rights reserved by Satyam
Computers Services Ltd.
Extended Attributes
What are extended attributes? They
define:
How data should be displayed.
How to accept data from the user.
What validations are to be done while
accepting the data.
The headings and labels for the column,
etc
The display and edit styles of the data
stored in the tables.
All rights reserved by Satyam
Computers Services Ltd.
Creating Indexes
Indexes are used to speed up data selection from
a table by restricting the number of rows that
have to be searched.
For example, if you had a table of contacts with a
gender field and assuming you had equal number
of male and female contacts, then indexing this
field would half the number of records that need
to be searched by a query.
Data Manipulation
To view the data that is stored in a table or to even alter/manipulate it, invoke popup menu on the
table title and select Edit Data > Appropriate Format option or click on one of the preview icons from
the Painterbar.
Importing Data At the moment PowerBuilder supports importing data from two file formats, namely
tab delimited text and the .DBF format. However, it is likely that in future releases more file formats
will be supported.
Exporting Data We've seen how to import data from a tab delimited text file. It may occur to you
that it would be useful to export data to some other format. To allow this PowerBuilder provides you
with tools to support several popular file formats.
Sorting Data When you are in the data manipulation pane, you can display the data in any sorted
order by selecting Rows > Sort... menu option.
Filtering DataIf you have a large table with a million rows and want to see only rows that belong to a
specific country, what you do? You put a WHERE clause in the SELECT statement to select only those
rows that you want to see.
Displaying Rows Description
While sorting, filtering, deleting and modifying data in the "Output (product) Units", you may find it
useful to see the summary of the things done to the rows. You can see it by selecting 'Rows >
Described...' menu option.
Print Previewing, Zooming & Printing the Data
You can print or preview the current display using the standard File menu options of 'Print...' and 'Print
Preview'. In Print Preview mode, you can turn on the Print Preview Rulers to let you adjust the margins
and using the 'Print Preview Zoom...' feature you can alter the magnification.
Commenting Code
You can comment the SQL code in any one
of the following styles.
Double Slash Method: '//' without
quotations make everything after that in
that line is considered as a comment. If you
place it in the middle of a line, everything
after that will be treated as comments.
//The following select everything from
units table.
Select * from units;
All rights reserved by Satyam
Computers Services Ltd.
Viewing Stored
Procedure Syntax
Database Profiles
Everything that was created is stored in
the product database. While creating a
database, there are few things that
happen behind the scenes.
PowerBuilder creates the database 'product'
using the appropriate database tool.
Creates an ODBC entry for product
Creates a database profile 'product' for the
product database.
Connects to the product database using the
database profile 'product'.
All rights reserved by Satyam
Computers Services Ltd.
Connection Options
Profile Name is the name given to a
profile and is used whenever you
want to connect to the database.
PowerBuilder creates a section with
this name in the pb.ini file.