PWCT 1.9 Art Documentation ( http://doublesvsoop.sourceforge.net )

2006-2013, Mahmoud Fayed ( msfclipper@users.sourceforge.net )

_____________________________________________________________________________________

Table of contents

1 - Introduction

2 - Implementation steps

3 - Final Steps Tree

4 – Application during the runtime

1 - Introduction

In this lesson we are going to learn how to create data screen using (Data Window Child Class) template.

 

 2 – Implementation steps

 

s1.JPG

 

Fig. (1)

 

Create access database (sysdata.mdb)

Create table Customers contains columns

ID (AutoNumber) – Primary Key

CustName (Text)

CustAddress (Text)

 CustPhone (Text)

 

s2.JPG

Fig. (2)

 

Create ODBC Data source

Name : MyProjectData

Type : Driver do Microsoft Access (*.mdb)

Database : SysData.mdb

s3.JPG

Fig. (3)

s4.JPG

Fig. (4)

 

Open sysdata.mdb – Exclusive to set the database password

s5.JPG

Fig. (5)

 

Database password = systemdatabase123

s6.JPG

Fig. (6)

Create new source file using the template (System Database – Parent Class)

s7.JPG

Fig. (7)

Source file name = Database.SSF

s8.JPG

Fig. (8)

Set the data source name to (MyProjectData)

s9.JPG

Fig. (9)

s10.JPG

Fig. (10)

s11.JPG

Fig. (11)

s12.JPG

Fig. (12)

Run to generate the source code file (Database.PRG)

s13.JPG

Fig. (13)

Open Main.SSF

s14.JPG

Fig. (14)

 

Use the component (Set procedure to ) to include the source file (Database.PRG)

s15.JPG

Fig. (15)

s16.JPG

Fig. (16)

s17.JPG

Fig. (17)

Create new source file using the template (Data Window –Child Class)

s18.JPG

Fig. (18)

Set class name = CustomersDataClass

s19.JPG

Fig. (19)

s20.JPG

Fig. (20)

s21.JPG

Fig. (21)

s22.JPG

Fig. (22)

Set window name = CustomersDataWindow

s23.JPG

Fig. (23)

s24.JPG

Fig. (24)

s25.JPG

Fig. (25)

s26.JPG

Fig. (26)

Set table name = Customers

s27.JPG

Fig. (27)

s28.JPG

Fig. (28)

s29.JPG

Fig. (29)

Add 3 attributes to our class using the component declare class data.

We will add the attributes (cCustName, cCustAddress & cCustPhone).

 

s30.JPG

Fig. (30)

s31.JPG

Fig. (31)

s32.JPG

Fig. (32)

s33.JPG

Fig. (33)

s34.JPG

Fig. (34)

s35.JPG

Fig. (35)

Add controls to our window

s36.JPG

Fig. (36)

s37.JPG

Fig. (37)

s38.JPG

Fig. (38)

s39.JPG

Fig. (39)

s40.JPG

Fig. (40)

s41.JPG

Fig. (41)

s42.JPG

Fig. (42)

s43.JPG

Fig. (43)

s44.JPG

Fig. (44)

s45.JPG

Fig. (45)

s46.JPG

Fig. (46)

s47.JPG

Fig. (46)

s48.JPG

Fig. (47)

s49.JPG

Fig. (48)

s50.JPG

Fig. (49)

Goto method UsetInterface2Class and generate steps to move the data from the use interface textboxes to class attributes.

s51.JPG

Fig. (50)

s52.JPG

Fig. (51)

s53.JPG

Fig. (52)

s54.JPG

Fig. (53)

s55.JPG

Fig. (54)

Go to method Class2Ado and use the component Ado set field value to move the data from the class attributes to the recordset.

s56.JPG

Fig. (55)

s57.JPG

Fig. (56)

s58.JPG

Fig. (57)

s59.JPG

Fig. (58)

s60.JPG

Fig. (59)

Go to the method ADO2Class then use the component Ado Get field value to move the data from the record set to the class attributes

s61.JPG

Fig. (60)

s62.JPG

Fig. (61)

s63.JPG

Fig. (62)

s64.JPG

Fig. (63)

s65.JPG

Fig. (64)

Go to the method Class2Userinterface then generate steps to move the data from the class attributes to the window textboxes.

s66.JPG

Fig. (65)

s67.JPG

Fig. (66)

s68.JPG

Fig. (67)

s69.JPG

Fig. (68)

s70.JPG

Fig. (69)

Go to method ClearRecord then generate steps to set the initial values of class attributes

s71.JPG

Fig. (70)

s72.JPG

Fig. (71)

s73.JPG

Fig. (72)

s74.JPG

Fig. (73)

s75.JPG

Fig. (74)

Go to method setmode to generate steps the controls the enables/disabled status of controls.

s76.JPG

Fig. (75)

s77.JPG

Fig. (76)

s78.JPG

Fig. (77)

s79.JPG

Fig. (78)

s80.JPG

Fig. (79)

s81.JPG

Fig. (80)

Generate the source code file (Customers.PRG)

s82.JPG

Fig. (81)

Open the file Main.SSF

s83.JPG

Fig. (82)

Use the component (Set procedure to ) to include the source code file Customers.PRG

s84.JPG

Fig. (83)

Create new object call CustomersDataObject of Class CustoemrsDataClass

s85.JPG

Fig. (84)

s86.JPG

Fig. (85)

s87.JPG

Fig. (86)

Add new menu item to open the customers window by calling the method ShowWindow()

s88.JPG

Fig. (87)

s89.JPG

Fig. (88)

s90.JPG

Fig. (89)

Move the step (Define item ("Customers”) ) up

s91.JPG

Fig. (90)

We can now run our application.

 

3 – Final Steps Tree

 

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

Main.SSF

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

 

The First Step

                Load System Modules

                                Set Procedure to "About.PRG"

                                Set Procedure to "Database.PRG"

                                Set Procedure to "Customers.PRG"

                Create System Objects

                                Create Object AboutObject of Class AboutClass

                                Create Object CustomersDataObject of Class CustomersDataClass

                Define New Window  ( win1 ) , Title : "System"

                                Window Events

                                Window Properties

                                Window Controls

                                                START OF MAIN MENU

                                                                MENU POPUPS

                                                                                DEFINE POPUP "File"

                                                                                                POPUP ITEMS

                                                                                                                Define ITEM ( "Customers" )

                                                                                                                Define ITEM ( "About" )

                                                                                                                Define ITEM ( "Close System" )

                                                                                                END OF POPUP

                                                                END OF MAIN MENU

                                                Define New Statusbar

                                                                Items

                                                                                Define New StatusItem ( "Ready" )

                                                                                                Events

                                                                                                Properties

                                                                                Keyboard

                                                                                                Events

                                                                                                Properties

                                                                                Clock

                                                                                                Events

                                                                                                Properties

                                                                End Statusbar

                                End Of Window

                                win1.Maximize ( )

                                Activate window

Procedures

                Define Procedure closesystem

                                Start Here

                                                win1.Release ( )

                                End of Procedure

 

 

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

Customers.SSF

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

 

Set Class Name & Window Name

                PWCT-Code Generator: Replace String (MyClassName) with (CustomersDataClass)

                PWCT-Code Generator: Replace String (MyWindowName) with (&(self:cWindowName))

Class

                Define Class MyClassName From SystemDatabase

                                Declare Class Data

                                                Data cWindowName Init Value "CustomersDataWindow"

                                ************************** Record Data Here  **************************

                                                Data TableName Init Value "Customers"

                                                Data cCustName Init Value ""

                                                Data cCustAddress Init Value ""

                                                Data cCustPhone Init Value ""

                                Declare Class Methods

                                                Method showwindow

                                                Method closewindow

                                                Method SetMode

                                                Method UserInterface2Class

                                                Method Class2ADO

                                                Method ADO2Class

                                                Method Class2UserInterface

                                                Method ClearRecord

                                                Method AutoGotoRecord

                                End of Class

                                *******************************  Methods to Customize  *****************************

                                                Define Method showwindow Class MyClassName

                                                                Start Here

                                                                                myout = self.connect()

                                                                                myout = self.AutoGotoRecord()

                                                                                Define New Window  ( MyWindowName ) , Title : "Customers Data"

                                                                                                Window Events

                                                                                                Window Properties

                                                                                                Window Controls

                                                                                                                Define New Image ( image1 ) , Image : "image\Back.jpg"

                                                                                                                                Events

                                                                                                                                Properties

                                                                                                                Window Title

                                                                                                                                Define Label ( lblTitle ) , Caption : "Customers Data Window"

                                                                                                                                                Label Events

                                                                                                                                                Label Properties

                                                                                                                Data Buttons

                                                                                                                                Define New Button ( btnFirst ) , Caption : "First"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:firstrecord()

                                                                                                                                                Button Properties

                                                                                                                                Define New Button ( btnNext ) , Caption : "Next"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:nextrecord()

                                                                                                                                                Button Properties

                                                                                                                                Define New Button ( btnLast ) , Caption : "Last"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:lastrecord()

                                                                                                                                                Button Properties

                                                                                                                                Define New Button ( btnClose ) , Caption : "Close"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:closewindow()

                                                                                                                                                Button Properties

                                                                                                                                Define New Button ( btnPrev ) , Caption : "Prev "

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:prevrecord()

                                                                                                                                                Button Properties

                                                                                                                                Define New Button ( btnDel ) , Caption : "Delete"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:delrecord()

                                                                                                                                                Button Properties

                                                                                                                                Define New Button ( btnsave ) , Caption : "Save"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:saverecord()

                                                                                                                                                Button Properties

                                                                                                                                Define New Button ( btncancel ) , Caption : "Cancel"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:cancelrecord()

                                                                                                                                                Button Properties

                                                                                                                                Define New Button ( btnedit ) , Caption : "Edit"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:editrecord()

                                                                                                                                                Button Properties

                                                                                                                                Define New Button ( btnadd ) , Caption : "Add"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:addrecord()

                                                                                                                                                Button Properties

                                                                                                                Define Label ( lbl1 ) , Caption : "Name"

                                                                                                                                Label Events

                                                                                                                                Label Properties

                                                                                                                Define Label ( lbl2 ) , Caption : "Address"

                                                                                                                                Label Events

                                                                                                                                Label Properties

                                                                                                                Define Label ( lbl3 ) , Caption : "Phone"

                                                                                                                                Label Events

                                                                                                                                Label Properties

                                                                                                                Define TextBox  ( textName  )

                                                                                                                                TextBox EVENTS

                                                                                                                                TextBox Properties

                                                                                                                Define TextBox  ( textAddress  )

                                                                                                                                TextBox EVENTS

                                                                                                                                TextBox Properties

                                                                                                                Define TextBox  ( textPhone  )

                                                                                                                                TextBox EVENTS

                                                                                                                                TextBox Properties

                                                                                                End Of Window

                                                                                                MyWindowName.Center ( )

                                                                                                myout = self.showrecord()

                                                                                                myout = self.setmode(2)

                                                                                                Activate window

                                                                End of Method (Return 0)

                                                Define Method UserInterface2Class Class MyClassName

                                                                Start Here

                                                                                self:cCustName = MyWindowName.textName.Value

                                                                                self:cCustAddress = MyWindowName.textAddress.Value

                                                                                self:cCustPhone = MyWindowName.textPhone.Value

                                                                End of Method (Return 0)

                                                Define Method Class2ADO Class MyClassName

                                                                Start Here

                                                                                ADODB RecordSet (self:oRS) Set Field ("CustName") Value To (self:cCustName)

                                                                                ADODB RecordSet (self:oRS) Set Field ("CustAddress") Value To (self:cCustAddress)

                                                                                ADODB RecordSet (self:oRS) Set Field ("CustPhone") Value To (self:cCustPhone)

                                                                End of Method (Return 0)

                                                Define Method ADO2Class Class MyClassName

                                                                Start Here

                                                                                self:cCustName = ADODB RecordSet (self:oRS) Get Field ("CustName") Value

                                                                                self:cCustAddress = ADODB RecordSet (self:oRS) Get Field ("CustAddress") Value

                                                                                self:cCustPhone = ADODB RecordSet (self:oRS) Get Field ("CustPhone") Value

                                                                End of Method (Return 0)

                                                Define Method Class2UserInterface Class MyClassName

                                                                Start Here

                                                                                MyWindowName.textName.Value := self:cCustName

                                                                                MyWindowName.textAddress.Value := self:cCustAddress

                                                                                MyWindowName.textPhone.Value := self:cCustPhone

                                                                End of Method (Return 0)

                                                Define Method ClearRecord Class MyClassName

                                                                Start Here

                                                                                self.cCustName = ""

                                                                                self.cCustAddress = ""

                                                                                self.cCustPhone = ""

                                                                End of Method (Return 0)

                                                Define Method setmode(p1) Class MyClassName

                                                                Start Here

                                                                                IF ( p1 = 1 )

                                                                                                Start Here

                                                                                                                MyWindowName.btnfirst.Enabled := false

                                                                                                                MyWindowName.btnnext.Enabled := false

                                                                                                                MyWindowName.btnprev.Enabled := false

                                                                                                                MyWindowName.btnlast.Enabled := false

                                                                                                                MyWindowName.btndel.Enabled := false

                                                                                                                MyWindowName.btnclose.Enabled := false

                                                                                                                MyWindowName.btnsave.Enabled := true

                                                                                                                MyWindowName.btncancel.Enabled := true

                                                                                                                MyWindowName.btnedit.Enabled := false

                                                                                                                MyWindowName.btnadd.Enabled := false

                                                                                                                MyWindowName.textName.Enabled := true

                                                                                                                MyWindowName.textAddress.Enabled := true

                                                                                                                MyWindowName.textPhone.Enabled := true

                                                                                                END OF IF STATEMENT

                                                                                IF ( p1 = 2 )

                                                                                                Start Here

                                                                                                                MyWindowName.btnfirst.Enabled := true

                                                                                                                MyWindowName.btnnext.Enabled := true

                                                                                                                MyWindowName.btnprev.Enabled := true

                                                                                                                MyWindowName.btnlast.Enabled := true

                                                                                                                MyWindowName.btndel.Enabled := true

                                                                                                                MyWindowName.btnclose.Enabled := true

                                                                                                                MyWindowName.btnsave.Enabled := false

                                                                                                                MyWindowName.btncancel.Enabled := false

                                                                                                                MyWindowName.btnedit.Enabled := true

                                                                                                                MyWindowName.btnadd.Enabled := true

                                                                                                                MyWindowName.textName.Enabled := False

                                                                                                                MyWindowName.textAddress.Enabled := False

                                                                                                                MyWindowName.textPhone.Enabled := False

                                                                                                END OF IF STATEMENT

                                                                                self:OperationMode = p1

                                                                End of Method (Return 0)

                                Class Methods

                                                Define Method closewindow Class MyClassName

                                                                Start Here

                                                                                myout = self.disconnect()

                                                                                MyWindowName.Release ( )

                                                                End of Method (Return 0)

                                                Define Method AutoGotoRecord Class MyClassName

                                                                Start Here

                                                                                IF ( self:LFindRecord = true .and. self:OperationMode = 2 )

                                                                                                Start Here

                                                                                                                ADODB RecordSet (self:oRS) Find , Cirteria self:CFindExpr

                                                                                                                mycheck = ADODB RecordSet self:oRS , Check EOF

                                                                                                                IF ( mycheck = true )

                                                                                                                                Start Here

                                                                                                                                                ADODB RecordSet self:oRS - Goto Previous Record

                                                                                                                                END OF IF STATEMENT

                                                                                                                IF ( iswindowdefined( MyWindowName ) )

                                                                                                                                Start Here

                                                                                                                                                myout = self.showrecord()

                                                                                                                                                MyWindowName.SetFocus ( )

                                                                                                                                END OF IF STATEMENT

                                                                                                END OF IF STATEMENT

                                                                                self:LFindRecord = false

                                                                                self:CFindExpr = ""

                                                                End of Method (Return 0)

 

 

4 – Application during the runtime

 

s92.JPG

Fig. (91)

 

 

s93.JPG

Fig. (92)