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 do arithmetic operations on records.

2 - Implementation Steps

Open database sysdata.mdb

Add column balance to customers table

s1.JPG

Fig. 1

s2.JPG

Fig. 2

s3.JPG

Fig. 3

s4.JPG

Fig. 4

s5.JPG

Fig. 5

s6.JPG

Fig. 6

s7.JPG

Fig. 7

s8.JPG

Fig. 8

s9.JPG

Fig. 9

s10.JPG

Fig. 10

s11.JPG

Fig. 11

s12.JPG

Fig. 12

s13.JPG

Fig. 13

s14.JPG

Fig. 14

s15.JPG

Fig. 15

s16.JPG

Fig. 16

s17.JPG

Fig. 17

s18.JPG

Fig. 18

s19.JPG

Fig. 19

s20.JPG

Fig. 20

s21.JPG

Fig. 21

s22.JPG

Fig. 22

s23.JPG

Fig. 23

s24.JPG

Fig. 24

s25.JPG

Fig. 25

s26.JPG

Fig. 26

s27.JPG

Fig. 27

s28.JPG

Fig. 28

s29.JPG

Fig. 29

s30.JPG

Fig. 30

s31.JPG

Fig. 31

s32.JPG

Fig. 32

s33.JPG

Fig. 33

s34.JPG

Fig. 34

s35.JPG

Fig. 35

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

Open customers.SSF

Add balance to customers data

s47.JPG

Fig. 47

s48.JPG

Fig. 48

s49.JPG

Fig. 49

s50.JPG

Fig. 50

s51.JPG

Fig. 51

s52.JPG

Fig. 52

s53.JPG

Fig. 53

s54.JPG

Fig. 54

s55.JPG

Fig. 55

s56.JPG

Fig. 56

s57.JPG

Fig. 57

s58.JPG

Fig. 58

s59.JPG

Fig. 59

s60.JPG

Fig. 60

s61.JPG

Fig. 61

s62.JPG

Fig. 62

s63.JPG

Fig. 63

s64.JPG

Fig. 64

s65.JPG

Fig. 65

s66.JPG

Fig. 66

s67.JPG

Fig. 67

s68.JPG

Fig. 68

s69.JPG

Fig. 69

s70.JPG

Fig. 70

s71.JPG

Fig. 71

s72.JPG

Fig. 72

s73.JPG

Fig. 73

s74.JPG

Fig. 74

s75.JPG

Fig. 75

s76.JPG

Fig. 76

s77.JPG

Fig. 77

s78.JPG

Fig. 78

s79.JPG

Fig. 79

s80.JPG

Fig. 80

s81.JPG

Fig. 81

s82.JPG

Fig. 82

s83.JPG

Fig. 83

s84.JPG

Fig. 84

s85.JPG

Fig. 85

s86.JPG

Fig. 86

s87.JPG

Fig. 87

s88.JPG

Fig. 88

s89.JPG

Fig. 89

s90.JPG

Fig. 90

s91.JPG

Fig. 91

s92.JPG

Fig. 92

s93.JPG

Fig. 93

s94.JPG

Fig. 94

s95.JPG

Fig. 95

s96.JPG

Fig. 96

s97.JPG

Fig. 97

Declare and define the method GetTotalBalance

s98.JPG

Fig. 98

s99.JPG

Fig. 99

s100.JPG

Fig. 100

s101.JPG

Fig. 101

s102.JPG

Fig. 102

s103.JPG

Fig. 103

s104.JPG

Fig. 104

s105.JPG

Fig. 105

s106.JPG

Fig. 106

s107.JPG

Fig. 107

s108.JPG

Fig. 108

s109.JPG

Fig. 109

s110.JPG

Fig. 110

s111.JPG

Fig. 111

s112.JPG

Fig. 112

s113.JPG

Fig. 113

s114.JPG

Fig. 114

s115.JPG

Fig. 115

s116.JPG

Fig. 116

s117.JPG

Fig. 117

s118.JPG

Fig. 118

s119.JPG

Fig. 119

s120.JPG

Fig. 120

s121.JPG

Fig. 121

s122.JPG

Fig. 122

s123.JPG

Fig. 123

s124.JPG

Fig. 124

s125.JPG

Fig. 125

s126.JPG

Fig. 126

s127.JPG

Fig. 127

s128.JPG

Fig. 128

s129.JPG

Fig. 129

s130.JPG

Fig. 130

s131.JPG

Fig. 131

s132.JPG

Fig. 132

s133.JPG

Fig. 133

s134.JPG

Fig. 134

s135.JPG

Fig. 135

s136.JPG

Fig. 136

s137.JPG

Fig. 137

s138.JPG

Fig. 138

s139.JPG

Fig. 139

s140.JPG

Fig. 140

s141.JPG

Fig. 141

s142.JPG

Fig. 142

s143.JPG

Fig. 143

s144.JPG

Fig. 144

s145.JPG

Fig. 145

s146.JPG

Fig. 146

s147.JPG

Fig. 147

s148.JPG

Fig. 148

s149.JPG

Fig. 149

s150.JPG

Fig. 150

s151.JPG

Fig. 151

s152.JPG

Fig. 152

s153.JPG

Fig. 153

s154.JPG

Fig. 154

s155.JPG

Fig. 155

s156.JPG

Fig. 156

s157.JPG

Fig. 157

s158.JPG

Fig. 158

s159.JPG

Fig. 159

s160.JPG

Fig. 160

s161.JPG

Fig. 161

s162.JPG

Fig. 162

s163.JPG

Fig. 163

s164.JPG

Fig. 164

s165.JPG

Fig. 165

s166.JPG

Fig. 166

s167.JPG

Fig. 167

s168.JPG

Fig. 168

s169.JPG

Fig. 169

s170.JPG

Fig. 170

s171.JPG

Fig. 171

s172.JPG

Fig. 172

s173.JPG

Fig. 173

s174.JPG

Fig. 174

s175.JPG

Fig. 175

s176.JPG

Fig. 176

s177.JPG

Fig. 177

s178.JPG

Fig. 178

s179.JPG

Fig. 179

s180.JPG

Fig. 180

s181.JPG

Fig. 181

3 - Final Steps Tree

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

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 ""

                                                Country

                                                                Data nCountry Init Value 0

                                                                Data CountryItems Init Value {}

                                                                Data CountryItemsIDs Init Value {}

                                                Data dDateOfBirth Init Value date()

                                                Data nBalance Init Value 0

                                Declare Class Methods

                                                Method showwindow

                                                Method closewindow

                                                Method SetMode

                                                Method UserInterface2Class

                                                Method Class2ADO

                                                Method ADO2Class

                                                Method Class2UserInterface

                                                Method ClearRecord

                                                Method AutoGotoRecord

                                                Method CheckData

                                                Method GetTotalBalance

                                End of Class

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

                                                Define Method showwindow Class MyClassName

                                                                Start Here

                                                                                Check Permission

                                                                                                IF ( UsersObject:CheckPermission(1) = False )

                                                                                                                Start Here

                                                                                                                                Show Message "You don't have permission to access this window" Title "Sorry" Type: Message Info

                                                                                                                                Return 0

                                                                                                                END OF IF STATEMENT

                                                                                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

                                                                                                                Country

                                                                                                                                myout = Self.LoadLookupTable("country","country",@self:countryitems,"id",@self:countryitemsids)

                                                                                                                                Define Label ( lblCountry ) , Caption : "Country"

                                                                                                                                                Label Events

                                                                                                                                                Label Properties

                                                                                                                                Define Combobox ( comboCountry ) , Items : self:CountryItems

                                                                                                                                                Combobox Events

                                                                                                                                                Combobox Properties

                                                                                                                Define Label ( lbl5 ) , Caption : "Date of Birth"

                                                                                                                                Label Events

                                                                                                                                Label Properties

                                                                                                                Define New DatePicker ( DateOfBirth )

                                                                                                                                Events

                                                                                                                                Properties

                                                                                                                Define Label ( lblBalance ) , Caption : "Balance"

                                                                                                                                Label Events

                                                                                                                                Label Properties

                                                                                                                Define TextBox ( textBalance )

                                                                                                                                TextBox EVENTS

                                                                                                                                TextBox Properties

                                                                                                                Define New Button ( btnTotalBalance ) , Caption : "Get Total Balance"

                                                                                                                                Button Events

                                                                                                                                                Event: ON CLICK : Action self:GetTotalBalance()

                                                                                                                                Button 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

                                                                                Country

                                                                                                self:nCountry = MyWindowName.ComboCountry.Value

                                                                                                self:nCountry = self:CountryItemsIDs[self:nCountry]

                                                                                self:dDateOfBirth = MyWindowName.DateofBirth.Value

                                                                                self:nBalance = MyWindowName.textBalance.Value

                                                                                self:nBalance = CONVERT self:nBalance TO Numeric

                                                                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)

                                                                                ADODB RecordSet (self:oRS) Set Field ("CountryID") Value To (self:nCountry)

                                                                                ADODB RecordSet (self:oRS) Set Field ("DateOfBirth") Value To (self:dDateOfBirth)

                                                                                ADODB RecordSet (self:oRS) Set Field ("Balance") Value To (self:nBalance)

                                                                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

                                                                                self:nCountry = ADODB RecordSet (Self:oRS) Get Field ("CountryID") Value

                                                                                self:dDateOfBirth = ADODB RecordSet (self:oRS) Get Field ("DateOfBirth") Value

                                                                                self:nBalance = ADODB RecordSet (self:oRS) Get Field ("Balance") 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

                                                                                Country

                                                                                                self:nCountry = self.LookupIDToIndex(self:nCountry,@self:CountryItemsIDs)

                                                                                                MyWindowName.ComboCountry.Value := self:nCountry

                                                                                MyWindowName.DateOfBirth.Value := self:dDateofBirth

                                                                                cBalance = CONVERT self:nBalance TO STRING

                                                                                cBalance = All Trim cBalance

                                                                                MyWindowName.textBalance.Value := cBalance

                                                                End of Method (Return 0)

                                                Define Method ClearRecord Class MyClassName

                                                                Start Here

                                                                                self.cCustName = ""

                                                                                self.cCustAddress = ""

                                                                                self.cCustPhone = ""

                                                                                self.nCountry = 0

                                                                                self.dDateOfBirth = Date()

                                                                                self.nBalance = 0

                                                                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

                                                                                                                MyWindowName.ComboCountry.Enabled := True

                                                                                                                MyWindowName.DateOfBirth.Enabled := True

                                                                                                                MyWindowName.textBalance.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

                                                                                                                MyWindowName.ComboCountry.Enabled := False

                                                                                                                MyWindowName.DateOfBirth.Enabled := False

                                                                                                                MyWindowName.textBalance.Enabled := False

                                                                                                END OF IF STATEMENT

                                                                                self:OperationMode = p1

                                                                End of Method (Return 0)

                                                Define Method CheckData Class MyClassName

                                                                Start Here

                                                                                Local myret,cName,nCountry

                                                                                myret = True

                                                                                Check Name

                                                                                                cName = MyWindowName.textName.Value

                                                                                                cName = All Trim cName

                                                                                                IF ( cName == "" )

                                                                                                                Start Here

                                                                                                                                Show Message "Enter Customer Name" Title "Sorry" Type: Message Info

                                                                                                                                myret = False

                                                                                                                END OF IF STATEMENT

                                                                                Check Country

                                                                                                nCountry = MyWindowName.ComboCountry.Value

                                                                                                IF ( nCountry = 0 )

                                                                                                                Start Here

                                                                                                                                Show Message "Please select the country" Title "Sorry" Type: Message Info

                                                                                                                                Check Permission

                                                                                                                END OF IF STATEMENT

                                                                End of Method (Return myret)

                                                Define Method GetTotalBalance Class MyClassName

                                                                Start Here

                                                                                The First Method

                                                                                                myoRS = Create New ADODB RecordSet Object

                                                                                                Open Recordset myoRS , Connection self:oCon , CursorType 1 , SQL Statement "Select * from TotalBalance"

                                                                                                nBalance = ADODB RecordSet (myoRS) Get Field ("SumOfBalance") Value

                                                                                                cBalance = CONVERT nBalance TO STRING

                                                                                                Show Message cBalance Title "Total Balance" Type: Message Box

                                                                                                Close ADODB RecordSet myoRS

                                                                                The Second Method

                                                                                                myoRS = Create New ADODB RecordSet Object

                                                                                                Open Recordset myoRS , Connection self:oCon , CursorType 1 , SQL Statement "SELECT Sum(Customers.balance) AS SumOfbalance from Customers"

                                                                                                nBalance = ADODB RecordSet (myoRS) Get Field ("SumOfBalance") Value

                                                                                                cBalance = CONVERT nBalance TO STRING

                                                                                                Show Message cBalance Title "Total Balance" Type: Message Box

                                                                                                Close ADODB RecordSet myoRS

                                                                                The Third Method

                                                                                                myoRS = Create New ADODB RecordSet Object

                                                                                                Open Recordset myoRS , Connection self:oCon , CursorType 1 , SQL Statement "Select * from Customers"

                                                                                                nBalance = 0

                                                                                                nMax := ADODB RecordSet (myoRS) , Get Records Count

                                                                                                IF ( nMax > 0 )

                                                                                                                Start Here

                                                                                                                                FOR LOOP ( From x = 1 To nMax Step 1)

                                                                                                                                                Start Here

                                                                                                                                                                custBalance = ADODB RecordSet (myoRS) Get Field ("Balance") Value

                                                                                                                                                                nBalance = nBalance + custBalance

                                                                                                                                                                ADODB RecordSet myoRS - Goto Next Record

                                                                                                                                                End of For Loop

                                                                                                                END OF IF STATEMENT

                                                                                                cBalance = CONVERT nBalance TO STRING

                                                                                                Show Message cBalance Title "Total Balance" Type: Message Box

                                                                                                Close ADODB RecordSet myoRS

                                                                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

runtime1.JPG

Fig. 182

runtime2.JPG

Fig. 183

runtime3.JPG

Fig. 184