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 (Master Details Child Class) template - part (2) . In this part of our lesson we are going to add a combobox So we can select a customer name when we add new orders. 2 - Implementation Steps Open MasterDetailsTest.SSF Fig. 1 Fig. 2 Fig. 3 Fig. 4 Fig. 5 Fig. 6 Fig. 7 Fig. 8 Fig. 9 Fig. 10 Fig. 11 Fig. 12 Open method UserInterface2Class Fig. 13 Fig. 14 Fig. 15 Fig. 16 Open method Class2Ado Fig. 17 Fig. 18 Fig. 19 Open method Ado2Class Fig. 20 Fig. 21 Fig. 22 Open method Class2UserInterface Fig. 23 Fig. 24 Fig. 25 Fig. 26 Open method ClearRecord Fig. 27 Fig. 28 Fig. 29 Open method SetMode Fig. 30 Fig. 31 Fig. 32 Fig. 33 Fig. 34 Fig. 35 3 - Final Steps Tree ============================ MasterDetailsTest.SSF ============================ Set Class Name & Window Name PWCT-Code Generator: Replace String (MyClassName) with (OrdersClass) PWCT-Code Generator: Replace String (MyWindowName) with (&(self:cWindowName)) Classes Define Class MyClassName From SystemDatabase Declare Class Data Data cWindowName Init Value "OrdersWindow" ************************** Record Data Here ************************** Data TableName Init Value "Orders_All" Data nID Init Value 0 Data column Init Value "OrderNumber" Data PrimaryKey Init Value "id" Data columns Init Value {"OrderNumber","CustName"} Item Data nItem Init Value 0 Data itemitems Init Value {} Data itemitemsids Init Value {} Data nOrderNumber Init Value "" detailstable Data TableName2 Init Value "OrderItems_All" Data column2 Init Value "ItemName" Data PrimaryKey2 Init Value "id" Data columns2 Init Value {"ItemName"} Data ResultPrimaryKeys2 Init Value {} Join Table Data TableName3 Init Value "OrderItems" Data PrimaryKey3 Init Value "id" Data linkmasterkey Init Value "OrderNumber" Data linkchildkey Init Value "ItemNumber" Counter Table Data TableName4 Init Value "SystemCounter" Data CounterColumn Init Value "OrderNumber" Items Table Data itemstable Init Value "items" Data Itemscolumn Init Value "itemname" Customers Data nCustomer Init Value 0 Data CustomerItems Init Value {} Data CustomerItemsIDs Init Value {} 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 itemchange Method OnAfterAddEdit Method OnBeforeDelete Method onbeforeedit Method onAddClick Method search2 Method delrecord2 Method addrecord2 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 : "Enter Orders" 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 : Master/Details" Label Events Label Properties Browse Define Label ( lbl1browse ) , Caption : "Order Number" 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 : {"Order Number","Customer Name"} Events Event: ON CHANGE : Action self:OpenDataWindow Properties Define Timer ( Timer1 ) Item items myout = self.LoadLookupTable(self:itemstable,self:itemscolumn,@self:ItemItems,"id",@self:ItemItemsIDS) Define Label ( lblitems ) , Caption : "Item" Label Events Label Properties Define Combobox ( comboitem ) , Items : self:itemitems Combobox Events Event: ON CHANGE : Action self:itemchange() Combobox Properties Order Number Define Label ( lblOrdernumber ) , Caption : "Order Number" Label Events Label Properties Define TextBox ( textOrderNumber ) TextBox EVENTS TextBox Properties Browse Order Items Define Label ( lbl1browse2 ) , Caption : "Item Name" Label Events Label Properties Define TextBox ( textNamebrowse2 ) TextBox EVENTS TextBox Properties Define New Button ( btn1browse2 ) , Caption : "Search" Button Events Event: ON CLICK : Action self:search2() Button Properties Define New Grid ( Grid1browse2 ) , HEADERS : {"Item Name"} Events Properties Data Buttons 2 Define New Button ( btnDel2 ) , Caption : "Delete Item" Button Events Event: ON CLICK : Action self:delrecord2() Button Properties Define New Button ( btnadd2 ) , Caption : "Add Item" Button Events Event: ON CLICK : Action self:addrecord2() Button Properties Customers myout = self.LoadLookupTable("Customers","CustName",@self:CustomerItems,"ID",@self:CustomerItemsIDs) Define Label ( lbl13 ) , Caption : "Customer" Label Events Label Properties Define Combobox ( comboCustomer ) , Items : self:CustomerItems Combobox Events Combobox Properties End Of Window MyWindowName.Center ( ) myout = self.showrecord() myout = self.setmode(2) MyWindowName.Timer1.Enabled := false MyWindowName.textOrderNumber.Enabled := false Activate window End of Method (Return 0) Define Method UserInterface2Class Class MyClassName Start Here Customers self:nCustomer = MyWindowName.comboCustomer.Value self.nCustomer = self:CustomerItemsIDs[self:nCustomer] End of Method (Return 0) Define Method Class2ADO Class MyClassName Start Here ADODB RecordSet (self:oRS) Set Field (self:linkmasterkey) Value To (self:nOrderNumber) ADODB RecordSet (self:oRS) Set Field ("CustomerID") Value To (self:nCustomer) End of Method (Return 0) Define Method ADO2Class Class MyClassName Start Here self:nOrderNumber = ADODB RecordSet (self:oRS) Get Field (self:linkmasterkey) Value self:nCustomer = ADODB RecordSet (self:oRS) Get Field ("CustomerID") Value End of Method (Return 0) Define Method Class2UserInterface Class MyClassName Start Here MyWindowName.textOrderNumber.Value := alltrim(str(self:nOrderNumber)) myout = self.search2() Customer self:nCustomer = self.LookupIDtoIndex(self:nCustomer,@self:customeritemsIDs) MyWindowName.ComboCustomer.Value := self:nCustomer End of Method (Return 0) Define Method ClearRecord Class MyClassName Start Here IF ( self:addrec = false ) Start Here self:nOrderNumber = 0 END OF IF STATEMENT self.nCustomer = 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.btnadd2.Enabled := false MyWindowName.btndel2.Enabled := false Search Controls MyWindowName.textNameBrowse.Enabled := false MyWindowName.btn1Browse.Enabled := false MyWindowName.Grid1Browse.Enabled := false MyWindowName.ComboCustomer.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.btnadd2.Enabled := true MyWindowName.btndel2.Enabled := true Search Controls MyWindowName.textNameBrowse.Enabled := True MyWindowName.btn1Browse.Enabled := True MyWindowName.Grid1Browse.Enabled := True MyWindowName.ComboCustomer.Enabled := False END OF IF STATEMENT self:OperationMode = p1 End of Method (Return 0) Define Method OnBeforeDelete Class MyClassName Start Here myout = self:oCon.execute("delete from "+self:tablename3+" where "+self:linkmasterkey+" = " + str(self:nOrderNumber)) End of Method (Return myout) Define Method onAddClick Class MyClassName Start Here Local myRS,nValue nvalue = 0 get new order number myRS = Create New ADODB RecordSet Object Open Recordset myRS , Connection self:oCon , CursorType 1 , SQL Statement "Select * from " + self:tablename4 nValue = ADODB RecordSet (myRS) Get Field (self:countercolumn) Value nvalue = nvalue+1 ADODB RecordSet (myRS) Set Field (self:countercolumn) Value To (nvalue) ADODB RecordSet myRS - Update Record Close ADODB RecordSet myRS self:nOrderNumber = nValue MyWindowName.textOrderNumber.Value := alltrim(str(self:nOrderNumber)) End of Method (Return 0) Define Method search2 Class MyClassName Start Here Local oRS,cName,myMax,x,x2,mymax2,vname,vname2,vid cName = MyWindowName.textNamebrowse2.Value oRS = Create New ADODB RecordSet Object Open Recordset oRS , Connection self:oCon , CursorType 1 , SQL Statement "Select * from "+self:tableName2 +" where "+self:linkmasterkey+"= "+str(self:nOrderNumber)+" and "+self:column2+" like '" + cName + "%'" mymax := ADODB RecordSet (oRS) , Get Records Count MyWindowName.grid1browse2.DeleteAllItems ( ) self:ResultPrimaryKeys2 = {} MyWindowName.grid1browse2.Value := 0 IF ( mymax > 0 ) Start Here FOR LOOP ( From x = 1 To mymax Step 1) Start Here vname = ADODB RecordSet (oRS) Get Field (self:column2) Value temp_array = {} mymax2 = Get Length of String/Variable/Array self:columns2 FOR LOOP ( From x2 = 1 To mymax2 Step 1) Start Here vname2 = ADODB RecordSet (oRS) Get Field (self:columns2[x2]) Value IF ( valtype(vname2) = "N" ) Start Here VNAME2 = CONVERT VNAME2 TO STRING VNAME2 = All Trim VNAME2 END OF IF STATEMENT Add item vname2 To Array temp_array End of For Loop MyWindowName.grid1browse2.AddItem ( temp_array ) vid = ADODB RecordSet (oRS) Get Field (self:PrimaryKey2) Value vid = CONVERT vid TO STRING Add item vid To Array self:ResultPrimaryKeys2 ADODB RecordSet oRS - Goto Next Record End of For Loop END OF IF STATEMENT Close ADODB RecordSet oRS End of Method (Return 0) Define Method DelRecord2 Class MyClassName Start Here Local nvalue,myout nvalue = MyWindowName.grid1browse2.Value IF ( nvalue > 0 ) Start Here nvalue = self:resultprimarykeys2[nvalue] myout = self:oCon.execute("delete from "+self:tablename3+" where "+self:primarykey3+" = " + nvalue) myout = self.search2() ELSE Start Here Show Message "You should Create/Select Item First" Title "Sorry" Type: Message Box END OF IF STATEMENT End of Method (Return 0) Define Method AddRecord2 Class MyClassName Start Here Local oRS,nValue IF ( self:nOrderNumber > 0 ) Start Here Item self:nItem = MyWindowName.ComboItem.Value self:nItem = self:ItemItemsids[self:nItem] oRS = Create New ADODB RecordSet Object Open Recordset oRS , Connection self:oCon , CursorType 1 , SQL Statement "Select * from "+self:tablename3 ADODB RecordSet oRS - Add New Record save data ADODB RecordSet (oRS) Set Field (self:linkchildkey) Value To (self:nItem) ADODB RecordSet (oRS) Set Field (self:linkmasterkey) Value To (self:nOrderNumber) ADODB RecordSet oRS - Update Record Close ADODB RecordSet oRS myout = self.Search2() ELSE Start Here Show Message "You should Create/Select Order First" Title "Sorry" Type: Message Box END OF IF STATEMENT End of Method (Return 0) Define Method itemchange Class MyClassName Start Here Local myrs,MYVALUE TVALUE = MyWindowName.Comboitem.Value IF ( TVALUE = 0 ) Start Here Return 0 END OF IF STATEMENT MYVALUE = self:ItemItemsids[TVALUE] myrs = Create New ADODB RecordSet Object MYVALUE = CONVERT MYVALUE TO STRING Do Task based on item change 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) Define Method OnBeforeEdit Class MyClassName Start Here End of Method (Return myout) Define Method OnAfterAddEdit Class MyClassName Start Here End of Method (Return myout) 4 - Application during the runtime Fig. 36
|