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 add combobox to our data window. 2 - Implementation Steps Open the data folder Fig. 1 Open file Sysdata.mdb Fig. 2 Create table Country ID : Autonumber Country : Text Fig. 3 Add column CountryID(Number) to the Customers table Fig. 4 Create new query using query designer. Fig. 5 Add tables Country & Customers to our query. Fig. 6 Fig. 7 Link the two tables using Country(ID) and Customers(CountryID) Fig. 8 Fig. 9 Fig. 10 Fig. 11 Fig. 12 Fig. 13 Fig. 14 Open file Customers.SSF using PWCT Fig. 15 Use the component (Declare class data) to add new attributes to our class nCountry (Number) CountryItems (Array) CountryItemsIDs (Array) Fig. 16 Fig. 17 Fig. 18 Fig. 19 Fig. 20 Fig. 21 Create new step called Country Fig. 22 Fig. 23 Fig. 24 Add new controls to our window (Country label & Country combobox) Fig. 25 Fig. 26 Fig. 27 Fig. 28 Fig. 29 Fig. 30 Load the data into self:CountryItems and self:CountryItemsIDs from the country table Using LoadLookupTable Method (Parent Class) Fig. 31 Fig. 32 Fig. 33 Fig. 34 Load combobox items from the array self:CountryItems Fig. 35 Open method (Userinterface2Class) Fig. 36 Fig. 37 Fig. 38 Fig. 39 Fig. 40 Fig. 41 Open method (Class2ADO) Fig. 42 Fig. 43 Fig. 44 Open method (Ado2Class) Fig. 45 Fig. 46 Fig. 47 Open method (Class2UserInterface) Fig. 48 Fig. 49 Fig. 50 Fig. 51 Fig. 52 Fig. 53 Fig. 54 Open method (ClearRecord) Fig. 55 Fig. 56 Fig. 57 Open method (SetMode) Fig. 58 Fig. 59 Fig. 60 Fig. 61 Fig. 62 Run to generate the source code file Customers.PRG Fig. 63 Open Main.SSF to run the application Fig. 64 3 - Final Steps Tree 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 {} 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 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 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] 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) 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 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 End of Method (Return 0) Define Method ClearRecord Class MyClassName Start Here self.cCustName = "" self.cCustAddress = "" self.cCustPhone = "" self.nCountry = 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 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 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. 65
|