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 create data screen using (Data Window Child Class) template.
2 – Implementation steps
Fig. (1)
Create access database (sysdata.mdb) Create table Customers contains columns ID (AutoNumber) – Primary Key CustName (Text) CustAddress (Text) CustPhone (Text)
Fig. (2)
Create ODBC Data source Name : MyProjectData Type : Driver do Microsoft Access (*.mdb) Database : SysData.mdb
Fig. (3)
Fig. (4)
Open sysdata.mdb – Exclusive to set the database password
Fig. (5)
Database password = systemdatabase123
Fig. (6) Create new source file using the template (System Database – Parent Class)
Fig. (7) Source file name = Database.SSF
Fig. (8) Set the data source name to (MyProjectData)
Fig. (9)
Fig. (10)
Fig. (11)
Fig. (12) Run to generate the source code file (Database.PRG)
Fig. (13) Open Main.SSF
Fig. (14)
Use the component (Set procedure to ) to include the source file (Database.PRG)
Fig. (15)
Fig. (16)
Fig. (17) Create new source file using the template (Data Window –Child Class)
Fig. (18) Set class name = CustomersDataClass
Fig. (19)
Fig. (20)
Fig. (21)
Fig. (22) Set window name = CustomersDataWindow
Fig. (23)
Fig. (24)
Fig. (25)
Fig. (26) Set table name = Customers
Fig. (27)
Fig. (28)
Fig. (29) Add 3 attributes to our class using the component declare class data. We will add the attributes (cCustName, cCustAddress & cCustPhone).
Fig. (30)
Fig. (31)
Fig. (32)
Fig. (33)
Fig. (34)
Fig. (35) Add controls to our window
Fig. (36)
Fig. (37)
Fig. (38)
Fig. (39)
Fig. (40)
Fig. (41)
Fig. (42)
Fig. (43)
Fig. (44)
Fig. (45)
Fig. (46)
Fig. (46)
Fig. (47)
Fig. (48)
Fig. (49) Goto method UsetInterface2Class and generate steps to move the data from the use interface textboxes to class attributes.
Fig. (50)
Fig. (51)
Fig. (52)
Fig. (53)
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.
Fig. (55)
Fig. (56)
Fig. (57)
Fig. (58)
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
Fig. (60)
Fig. (61)
Fig. (62)
Fig. (63)
Fig. (64) Go to the method Class2Userinterface then generate steps to move the data from the class attributes to the window textboxes.
Fig. (65)
Fig. (66)
Fig. (67)
Fig. (68)
Fig. (69) Go to method ClearRecord then generate steps to set the initial values of class attributes
Fig. (70)
Fig. (71)
Fig. (72)
Fig. (73)
Fig. (74) Go to method setmode to generate steps the controls the enables/disabled status of controls.
Fig. (75)
Fig. (76)
Fig. (77)
Fig. (78)
Fig. (79)
Fig. (80) Generate the source code file (Customers.PRG)
Fig. (81) Open the file Main.SSF
Fig. (82) Use the component (Set procedure to ) to include the source code file Customers.PRG
Fig. (83) Create new object call CustomersDataObject of Class CustoemrsDataClass
Fig. (84)
Fig. (85)
Fig. (86) Add new menu item to open the customers window by calling the method ShowWindow()
Fig. (87)
Fig. (88)
Fig. (89) Move the step (Define item ("Customers”) ) up
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
Fig. (91)
Fig. (92)
|