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

2006-2019, 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 use the (Data/Browse window - Child Class) template.

2 - Implementation Steps

Create new file using the template (Data/Browse window – child class)

s1.JPG

Fig. 1

File name = CustDataBrowse.SSF

s2.JPG

Fig. 2

s3.JPG

Fig. 3

Set class name = CustDataBrowseClass

s4.JPG

Fig. 4

s5.JPG

Fig. 5

s6.JPG

Fig. 6

Set the window name = CustDataBrowseWindow

s7.JPG

Fig. 7

s8.JPG

Fig. 8

s9.JPG

Fig. 9

Set the tablename property = Customers

s10.JPG

Fig. 10

Set the column property = CustName

s11.JPG

Fig. 11

s12.JPG

Fig. 12

Set the columns attribute = {"ID”,”CustName”}

s13.JPG

Fig. 13

s14.JPG

Fig. 14

s15.JPG

Fig. 15

s16.JPG

Fig. 16

s17.JPG

Fig. 17

Open method (Class2ADO)

s18.JPG

Fig. 18

s19.JPG

Fig. 19

s20.JPG

Fig. 20

Open method (ADO2Class)

s21.JPG

Fig. 21

s22.JPG

Fig. 22

s23.JPG

Fig. 23

Save and run (press CTRL+R) to generate the source code file CustDataBrowse.PRG

s24.JPG

Fig. 24

Open file Main.SSF

s25.JPG

Fig. 25

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

s26.JPG

Fig. 26

s27.JPG

Fig. 27

Use the component (New Object) to create the object CustDataBrowseObject of CustDataBrowseClass

s28.JPG

Fig. 28

s29.JPG

Fig. 29

s30.JPG

Fig. 30

s31.JPG

Fig. 31

s32.JPG

Fig. 32

s33.JPG

Fig. 33

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"

                                Set Procedure to "CustomersBrowse.PRG"

                                Set Procedure to "CustDataBrowse.PRG"

                Create System Objects

                                Create Object AboutObject of Class AboutClass

                                Create Object CustomersDataObject of Class CustomersDataClass

                                Create Object CustomersBrowseObject of Class CustomersBrowseClass

                                Create Object CustDataBrowseObject of Class CustDataBrowseClass

                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 Data/Browse" )

                                                                                                                Define ITEM ( "Customers Browse" )

                                                                                                                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

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

CustDataBrowse.SSF

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

Set Class Name & Window Name

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

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

Class

                Define Class MyClassName From SystemDatabase

                                Declare Class Data

                                                Data cWindowName Init Value "CustDataBrowseWindow"

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

                                                Data TableName Init Value "Customers"

                                                Data column Init Value "CustName"

                                                Data PrimaryKey Init Value "id"

                                                Data columns Init Value {"ID","CustName"}

                                                Data nID Init Value 0

                                                Data cName Init Value ""

                                                Data ColTitles Init Value {"ID","Name"}

                                                Data ColWidths Init Value {100,200}

                                Declare Class Methods

                                                Method showwindow

                                                Method closewindow

                                                Method SetMode

                                                Method UserInterface2Class

                                                Method Class2ADO

                                                Method ADO2Class

                                                Method Class2UserInterface

                                                Method ClearRecord

                                                Method AutoGotoRecord

                                                Method OpenDataWindow

                                                Method showdatawindow

                                                Method myTimer

                                                Method BeforeSearch

                                                Method SearchAdd

                                                Method settimer

                                                Method GetSearchValue

                                End of Class

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

                                                Define Method showwindow Class MyClassName

                                                                Start Here

                                                                                myout = self.connect()

                                                                                myout = self.AutoGotoRecord()

                                                                                Define New Window ( MyWindowName ) , Title : "Data/Browse Window"

                                                                                                Window Events

                                                                                                                Event: ON INIT : Action self:Search()

                                                                                                Window Properties

                                                                                                Window Controls

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

                                                                                                                                Events

                                                                                                                                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

                                                                                                                Window Title

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

                                                                                                                                                Label Events

                                                                                                                                                Label Properties

                                                                                                                Item Class Name

                                                                                                                                Define Label ( lblAddress ) , Caption : "Name"

                                                                                                                                                Label Events

                                                                                                                                                Label Properties

                                                                                                                                Define TextBox ( textName )

                                                                                                                                                TextBox EVENTS

                                                                                                                                                TextBox Properties

                                                                                                                Browse

                                                                                                                                Define Label ( lbl1browse ) , Caption : "Name"

                                                                                                                                                Label Events

                                                                                                                                                Label Properties

                                                                                                                                Define TextBox ( textNamebrowse )

                                                                                                                                                TextBox EVENTS

                                                                                                                                                TextBox Properties

                                                                                                                                Define New Button ( btn1browse ) , Caption : "Search"

                                                                                                                                                Button Events

                                                                                                                                                                Event: ON CLICK : Action self:search()

                                                                                                                                                Button Properties

                                                                                                                                Define New Grid ( Grid1browse ) , HEADERS : self:ColTitles

                                                                                                                                                Events

                                                                                                                                                                Event: ON CHANGE : Action self:OpenDataWindow

                                                                                                                                                Properties

                                                                                                                Define Timer ( Timer1 )

                                                                                                End Of Window

                                                                                                MyWindowName.Center ( )

                                                                                                myout = self.showrecord()

                                                                                                myout = self.setmode(2)

                                                                                                MyWindowName.Timer1.Enabled := false

                                                                                                Activate window

                                                                End of Method (Return 0)

                                                Define Method UserInterface2Class Class MyClassName

                                                                Start Here

                                                                                self:cName = MyWindowName.textName.Value

                                                                End of Method (Return 0)

                                                Define Method Class2ADO Class MyClassName

                                                                Start Here

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

                                                                End of Method (Return 0)

                                                Define Method ADO2Class Class MyClassName

                                                                Start Here

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

                                                                End of Method (Return 0)

                                                Define Method Class2UserInterface Class MyClassName

                                                                Start Here

                                                                                MyWindowName.textName.Value := self:cName

                                                                End of Method (Return 0)

                                                Define Method ClearRecord Class MyClassName

                                                                Start Here

                                                                                self.cName = ""

                                                                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

                                                                                                                Search Controls

                                                                                                                                MyWindowName.textNameBrowse.Enabled := false

                                                                                                                                MyWindowName.btn1Browse.Enabled := false

                                                                                                                                MyWindowName.Grid1Browse.Enabled := false

                                                                                                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

                                                                                                                Search Controls

                                                                                                                                MyWindowName.textNameBrowse.Enabled := True

                                                                                                                                MyWindowName.btn1Browse.Enabled := True

                                                                                                                                MyWindowName.Grid1Browse.Enabled := True

                                                                                                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)

                                                Define Method BeforeSearch Class MyClassName

                                                                Start Here

                                                                                MyWindowName.grid1Browse.DeleteAllItems ( )

                                                                                MyWindowName.grid1Browse.Value := 0

                                                                End of Method (Return 0)

                                                Define Method SearchAdd(temp_array) Class MyClassName

                                                                Start Here

                                                                                MyWindowName.grid1Browse.AddItem ( temp_array )

                                                                End of Method (Return 0)

                                                Define Method SetTimer(p1) Class MyClassName

                                                                Start Here

                                                                                MyWindowName.Timer1.Enabled := p1

                                                                End of Method (Return 0)

                                                Define Method GetSearchValue Class MyClassName

                                                                Start Here

                                                                                cName = MyWindowName.textNameBrowse.Value

                                                                End of Method (Return cName)

                                                Define Method OpenDataWindow Class MyClassName

                                                                Start Here

                                                                                Local nvalue,myout

                                                                                nvalue = MyWindowName.grid1browse.Value

                                                                                IF ( nvalue > 0 )

                                                                                                Start Here

                                                                                                                myout = self.ShowDataWindow(nvalue)

                                                                                                                MyWindowName.Grid1Browse.SetFocus ( )

                                                                                                END OF IF STATEMENT

                                                                End of Method (Return 0)

                                                Define Method ShowDataWindow(nvalue) Class MyClassName

                                                                Start Here

                                                                                self.LFindRecord = true

                                                                                self.CFindExpr = self:primarykey+"= '"+self:resultprimarykeys[nvalue]+"' "

                                                                                myout = self.ShowWindow()

                                                                End of Method (Return 0)

                                                Define Method mytimer Class MyClassName

                                                                Start Here

                                                                                myout = self.search()

                                                                                MyWindowName.Timer1.Enabled := false

                                                                End of Method (Return 0)

4 - Application during the runtime

runtime1.JPG

Fig. 34

runtime2.JPG

Fig. 35

runtime3.JPG

Fig. 36