|
Home Up Database Steps Objects & Tools PB Window Steps Event Scripts
| |
|
 | Create a New Folder (subdirectory) for your
project & make sure everything gets into it as you work.
I've used the Windows Explorer to create a new folder named according
to the class naming convention as gs9191. This will be my
'working folder', where the application to be submitted will be built.

Keep everything that will be submitted for your
project in this Working Folder so that all you need to do to submit
your projects is to zip this folder up and attach it to me in
email.
If you're working in the labs, please work directly
on a Zip disk and do not leave copies of your application on the hard
drives of any machine. This will protect you against the honor
violation of 'facilitating academic dishonesty'.
Make frequent backup copies of the contents of this
working folder, perhaps by zipping the folder and saving it in email
to yourself or at one of the on-line storage services. Your
software is of considerable value and keeping copies of it on multiple
media is the best way to protect it.
Proactive Systems Administration steps will protect
against losing your work because of media failure, PB blowing up on
you, or just klutzing your work (which is probably the #1 cause of
lost projects). 'My application was eaten by the
dog', 'was blown away by PB', or other lame excuses get little
grace (a day) when projects come due.
|
 | Setup a new Powerbuilder Workspace
If you're working with a brand-new install of PB
you'll get a wizard at startup that offers the option of creating a
new Workspace and a new Target application at the same time. If
you get this dialog, take it and the screens will look the same.
I've already had PB running on my desktop, so the IDE looks like this,
with an improperly named couple of Target Applications under the
Workspace:
|

Choose File -> New from the top menu and PB's
multi-tabbed New Object dialog pops up. Choose the Workspace tab,
then double-click on the Workspace icon.

In the New Workspace dialog that pops up,
navigate
to the newly created folder. Name the Workspace appropriately
(mine might be gs9191) in the FileName text box.

Clicking the Save button gets you into PB
with the newly created Workspace Open. Only one Workspace can be
open at a time, so the new one just created replaces any existing
Workspace in the
IDE:

 | Create a new Target Application Object Right-clicking
on the little blue Workspace icon at the upper left of the Workspace
Window gets you to a popup menu where the New choice gets you to a New
Object dialog, where the Target tab is chosen this time:
|

At this point we want to add a New Application, so
highlight the Application icon & double-click it, or click the OK
button.

This gets to the Specify New Application
and Library dialog where the appropriate name (gs9191 for me) is
put into the Application Name box at the top.

Click on the 'browse' button, which is
usually identified
in PB with ellipses (3 dots), to the right of the Library text box and browse
to the new directory that you've made for your software, where it should
already be parked by virtue of having chosen the new directory for the
Workspace in a prior step. PB will name the Library & the
Application Object the same as the name entered for the Application
& place both these files into the same directory by default.
When you click OK, you're returned to the
PB IDE where you can click on the little +s to open up the Workspace and
you'll see the new Target , pbl, & Application Object in the
Workspace:

If you click on _all_ the + marks, you'll
see the built-in Properties, Events, and Functions of an Application
Object. Don't worry, we only use a few of the dozens that are
available.
Next, X out of PB and go looking for the
important pieces in the new directory. You should find three
files: pbw, pbt, and pbl; for Workspace, Target, and Library,
respectively.

Open up PB again & it should return
to the Workspace we just left. Then, we're ready to get into
setting up a new database for your project...
 | Database Issues & Cautions:
|
Always say No to 'database logging' when you create the database -- we don't
need it and relocating the log file can cause hassles. It's
unfortunate that the default option is Yes since we don't need the
logs and they keep the projects from being easily Portable. Points
will be deducted for days late from projects that arrive at my
desk with their database set to log its activity and which are
referred back to the student for removal of the offending database
logging option.
Take care not to open the Database Painter more
than once in the IDE. Although PB allows more than one
instance of the Database Painter, having more than one open can at
best lead to
confusion and at worst may corrupt your database. Always use the Window menu to move back to the
Database Painter from other Painters, checking for an already open Database Painter before clicking on those little tanks of
data to open a new instance of the Painter.
Keep in mind that these databases are somewhat inflexible once cast,
so practice with the absolute minimum tables needed to use Foreign Keys:
Ledger Accounts, and Goods & Services.
You might find it helpful to stop building the
tables after building the first two: Ledger Accounts and Goods
& Services. Then take the steps with
the Window & DataWindow Painters so that you can see how all
the parts work together, especially the edit styles for columns
with foreign keys, before inheriting the other windows for
maintaining the other tables.
The Database Painter is a 'Right-Click' kind
of environment. When you want to Save Changes,
right-click in the window in which the changes were made. If
you don't see a menu choice or icon for what you need to do next,
the choice is probably on a right-click popup menu.
 | Steps to make a new ASA database: Start
PB and get to your Workspace if it's not already open. Click the Database Painter icon
and its Painter will appear & show Installed Database Interfaces, of which we're interested in the
ODBC variety. Most PB installations have the EAS Demo database
already installed for the tutorial in the Getting Started
manual. We need to create a new one, named according the the
naming convention for the course.

Double-click on the Utilities folder under ODBC,
or click it's + mark, and double-click on
Create ASA Database folder. Choose the Adaptive Server Anywhere
7.0 Database as the driver for the new database. Click
Finish.
This gets you to the Create Adaptive Server Anywhere
dialog, where these choices are essential:
Leave the default DBA and *** (sql) for User ID and password for the
database. Don't check Prompt for Password on Connect.
Use the Browse button to find the
exact Folder you created to hold the
Project. Name the database using the same convention as the Application Object's
name, in the required format, for me this is gs9191.
Uncheck Use Transaction Logging since we don't need
it and it will hamper portability of your project.
This should get you a dialog box that filled in like
this:

When you click OK, the database is created on the
disk & added to the ODBC Database collection for the computer
where you create the database. The process takes a few moments,
during which you should see the little Orange & Red SQL which
indicates that the ASA is doing its work
If all goes well, the Object View of the
Database Painter now shows the new database with a green check
indicating that PB has automatically connected to the new
database:

It's wise to make sure that all
the files are in the expected place now: Use the Windows
Explorer to check it out:

|
 | When you get back to your Workspace and open the
Database Painter, the new database displayed is empty now, except
for the two tables PB put there. These next steps are for
creating the tables, columns, edit styles, & validation rules that
are referenced by your project's DataWindows.
|
 | For each Table in your database design, or
just the
first two for the time being, Ledger Accounts and Goods &
Services:
 | Click the sparkling New Table button in
the powerbar, or right click on the Tables
folder and choose New, then use the Columns forms to enter the columns for the table.
Take care as each column is entered to
properly define its name, data type, width, and any default
such as autoincrement. These cannot be easily modified
later, so it is important to have a complete and accurate Data
Dictionary before you get into building tables. When you get
done with the Goods & Services table it should look something
like this:

|
 | When you've got the columns defined OK, right click in the columns
form and choose Save to give the new table a name.
|
 | The new table will show up under the Tables folder in the Database
window. Click on the little plus sign to show the folders PB maintains for you
about tables. Right click on the Primary Key folder to
assign the ID column for the table as the primary key by checking its box in the Primary
Key form. When you've checked the correct primary key, right click on the Primary Key window
and Save Changes.
|
 | For each of any Foreign Keys:
Right click on the Foreign Keys folder in the
Database Painters Object View for the desired table, and choose New Foreign Key to get to the Foreign Keys window.
In
Goods & Services, there are Foreign keys for the Ledger
Accounts for Sales & Purchase, and later for Primary Supplier
Id. Follow your Data Dictionary carefully as you use the
Database Painter.
In the pane that appears for Foreign Key definition, make sure the
expected Table appears in the Table: field.
Add a descriptive
name in the Foreign Key: field -- using the same name as the column
is appropriate. PB only uses this name for
documentation & display purposes.
On the General tab, Check on the column in the table
that you are defining that holds a
foreign key, ledacc_sale for example.
Then choose the Primary Key tab and choose the
table referenced by the Foreign Key: Touching the
first characters of the table name will zoom this screen to the
right place.
Make sure the ID field for
this table is checked. The Primary Key of the
foreign table is the default.
Right click in the Foreign Keys window and Save Changes.
Repeat these steps for each Foreign
Key.
|
 | Use the Object Layout view of the Database Painter to see a graphic of
your database's tables, primary keys, and relationships of foreign keys.
If your Layout pane is empty, drag each table from the object list
into the layout pane and PB will draw the lines connecting the foreign keys to their
tables from what you've defined.
With the Ledger Accounts and Goods & Services tables built it
should look like this:

Notice that the Primary &
Foreign Keys are all nominated appropriately.
|
 | Close the Table, by right clicking
on one of the table's panes, and save changes when it all looks OK.
|
 | Repeat these steps for each table. |
|
 | Make sure you can find the database again with
PowerBuilder. Get all the way out of Powerbuilder & make sure it's in the right place by looking for it with the
Windows Explorer in the folder where you expect it to be. Check
that the time agrees with the little clock in the system tray. Start
PB back up & use the Database Painter to open your database,
open each table, and graphically display the tables, their keys, and their foreign keys.
These are important steps since PB uses this 'metadata' to enforce referential
integrity for us. We need this because the normalization of the
prototype's database uses "the key, the whole
key, and nothing but the key".
|
 | At this point the databases can be populated
with a row or two of appropriate data:
Start with the
Ledger Accounts table and add enough accounts to test the foreign
keys in the Goods & Services table.
Never use junk
data,
always choosing test data carefully according to the plan for your
Enterprise, submitted for Quiz #1, is a good idea.
Right click on the
Ledger Accounts Table and choose Edit
Data & Grid. When the table is opened in the Data Manipulation window's
Retrieve, Save Changes, and Insert Row buttons are enabled and you can put records
directly into the database by clicking in the Grid window & clicking on
the Insert Row in the painter's button bar at the top. Add a few
valid Ledger Details, Cash and Equity as a minimum.
Click Save Changes to write the Ledger Details
table to the database. Then right click your Goods &
Services table and add new records, probably for Cash &
Equity.
At this point, if you have saved some Ledger
Details, the LDetPurch and LDetSales columns of the Goods &
Service table should not accept a value that is not a key in the
Ledger Details table.

The next steps are about
DropDownListBoxes and DropDownDataWindows that do this.
|
 | Add Edit Styles & Validations to
the columns that require them:
This is easier if you have
some good, clean sample data in the tables involved.
Edit
styles used here are:
|
a DropDownListBox, valid_class, used to supply
a valid GS Class;
DropDownDataWindows, ledger_accounts
& entities, are used to edit for valid ledger account coding
and primary supplier entity
ids in GS records.
Drop Down Data Lists can be defined easily at design
time, but require programmer attention to make changes. They
are good for Static tables that are defined in the system's
architecture.
Drop Down Data Windows are dynamic, are
populated with the current contents of a table, & require construction of DataWindows
to complete the style, so we'll look at these DDDWs after the
simpler DDDLs.
 | To add a DropDownListBox edit style make
sure that the Extended Attributes pane is showing in the
Database Painter.

Right click on the icon for Edit
Style. In the panel that appears, name the edit style and
choose its style from the DropDownListBox provided.

Fill
in the Display & Data values for each code & text
combination. The Data value is what is stored in the table
-- the Display value is what is displayed in its place.
Use the Add button to add each row of display
and data values. Don't leave a blank row, or use the
Delete button if you do.
Click OK to save the edit style, this one is
named valid_class, and you'll see
it appear in the list of edit styles on the Extended Attributes
pane.
To add the edit style to the column in the
database, find the table in the Object pane of the database
painter, open its folder, and open the Columns folder under
it. Right click on the column name & choose properties
from the popup menu. Choose the Edit Style tab in the
properties box, highlight the appropriate Edit Style. Then
right click on the properties window and choose Save Changes.
If you refresh the tables (right click on the
Tables folder and choose Refresh)
|
 | DropDownDataWindows use a DataWindow
to populate the DropDown list from the database instead of keying in static
values at design time.
There are several steps in creating
a Data Window with the DataWindow Painter, then placing the dw into an Edit Style, which is
then put into the Edit Style Property of the Column that it
edits.
There are a lots of steps & options. Plan
to replace your prototype with newly constructed objects after you've
seen how all the parts work together & have decided what style to
impress into your software.
|
 |
First, create an Edit Style
called valid_ledacc which will be used to supply a list of
Ledger Detail ids for ledacc_purch & ledacc_sales in the Goods
& Services table. Use similar steps to define other
DropDownDataWindows later in the project.
Click the sparkling New object box just under
the File menu choice. Choose Data Window as the type of
object to create. Tabular is the appropriate presentation
style for DDDW & also for the Lookup windows in the
prototype.
Choose SQL Select on the Data Source
dialog,
and make sure that Retrieve on Preview is checked. Click
Next.
When the Select Tables dialog appears
highlight ledacc (or the name of your Ledger Accounts table) and
click Open. This brings up a little box for the Ledger
Account table
with its columns for selection.
Notice that the Selection List at the top of
the panel is empty. Click id, then text, and these column
names will appear in the Selection List in the order they were
selected. These are the two columns that will display in
the DDDW that uses this DataWindow.
Click on the Sort tab at the bottom of the
window and drag id to the right pane. This will result in
the DDDW being sorted in Account# sequence, which is appropriate
for our project. The ASA database puts records wherever is
most convenient for itself so rows may be displayed at random
if the ORDER BY tab is left blank.
Click on the Return icon, at the right of the
DataSource/SQL view's speedbar. At the Select Color &
Border dialog box choose whatever color & border that
suits your style.
Click Next to display a list of the characteristics
generated by the Data Window Wizard. This is text that
describes what the Data Window Painter's builder wizard is about to do
next.
Click Finish and you
should be rewarded with a DataWindow definition window where you
can do the rest of the work on the DataWindow just
created. This is where Prompts are made appropriate for
users, where rows can be positioned exactly, and where other
elements of PB style may be imparted by a programmer.

When you X out of this window name it
appropriately. Our first one is dw_ldet_lookup. This
DataWindow will be used for the ledger_details Edit Style and
also for the lookup window in the window used to maintain the
Ledger Details table.
|
 |
To put the new DataWindow into a DDDW Edit
Style right click on the Edit Styles icon in the Extended
Properties panel and choose New.

In the Edit Style panel that displays enter
the name, ledger_accounts, and choose DropDownDW for the style of
edit. Choose dw_lacc_lookup (or the name of your
datawindow for lookup) in the DataWindow field, the
choose text and id for the Display and Data columns.
Leave
the other fields at default for now.
Click OK and the new Edit
Style should appear in the list of Edit Styles.
Add the new Edit Style to the columns that use
it (ledacc_purch & ledacc_sale) by finding each under the Goods
& Services table in the object pane, right clicking on it,
choosing the Edit Style tab, highlighting valid_ledacc (or
whatever you've named it), and
right clicking to Save Changes.
|
 | Validation Rules should also be placed in
the database where appropriate. This keeps bad data out of
the database without the Programmer needing to code the
validation in scripts. Use PB on-line help to fill in the
details of syntax about Validation Rules.
The Activity and Ledger Detail tables need
Validation Rules on their keys. Activity ids are integers
from 100 - 999. Ledger Details are integers from 1000 -
5999. When a Validation rule is in place on a column in a
table no process can
put an invalid key into the database.
Two other 'startup'
tables, Goods & Services and Entity, use autoincremented
integers as keys so don't need validation.
|
 |
Here is an example of for the Validation Rule
for Activity Ids. Right Clicking on the Validation Rule icon in
the Extended Attributes tab and choosing New gets this
screen. Notice that @col holds the data that was entered
so that it can be used in the error message and in the
validation rule:

Here you name the rule and define the error message
that will be delivered to the user if the rule is not met for
the data entered.
The Definition tab is where the rule is
spelled out:

When you have filled in the
General and Definition tabs, right click in the properties box
and Save Changes, giving the new Validation Rule its name.
Make a Validation Rule for Ledger
Detail Ids, too. Place these new Validation Rules into the
id columns for Activities and Ledger Details by right clicking
on each column's icon in the Object View under its table,
choosing Properties, and choosing the correct Validation Id from
the list box on the Validation tab. Right click the
properties box and Save Changes for each.
|
 | Revisit the Goods & Services
table using the Data Manipulation Painter and you should find
the DDDW on the columns ledacc_purch & ledacc_sales. Make
sure that the validation rules are correct.
|
 |
Take similar steps with the other tables,
Business Entities & Activity Codes and make
sure that they have good data and work properly.
|
 | When you're done with the database, X out of
the Database Painter and resolve to leave the database details
alone as much as possible after you've started building the GUI.
|
 | Only proceed to the next steps about Objects
& Tools after
you've got the database working properly and populated with one
or two rows of data.
|
[ Up ] [ Database Steps ] [ Objects & Tools ] [ PB Window Steps ] [ Event Scripts ]
|
|