>*---------------------- Location Section ------------------------ >* Library: CContrls.vcx >* Class: CGrid >* Method: SetOrder() >*----------------------- Usage Section -------------------------- >*) Description: >*) This method checks if there is a tag for the current >*) column's RowSource (specified in tcControlSource), >*) and if so, sets the order to it AND sets cGrid.cTagName >*) to the tag name of the index. If the optional second >*) parameter is passed, it simply issues a SET ORDER >*) on the tag. >* >* Scope: Public >* Parameters: >* 1. tcControlSource - Name of the ControlSource >* 2. tcTagName - (optional)Name of an index tag to >* be used to SET ORDER >* >*$ Usage: Typically called from the Click() method of >* a grid header. >* >* Returns: Logical .T. by default >*--------------------- Maintenance Section ---------------------- >* Change Log: >* MODIFIED 10/27/97 - KJM >* Moved this method up the hierarchy from CSetOrderGrid >* to CGrid so that SetOrder functionality is available >* to all grids in the framework. CSetOrderGrid, although >* no longer necessary is left in the framework for >* backward compatibility. >* Also enhanced the code to allow for index expressions >* that are simply surrounded by an UPPER() statement. >* MODIFIED 04/16/98 - KJM >* Added a second tcTagName parameter. If a value has >* been passed ignore the tcControlSource parameter for >* now (may be used in the future) and set the ORDER >* to the specified tag. >* MODIFIED 07/10/99 - KJM >* Enhanced this method so that clicking on a column >* header toggles the ascending/descending order of >* the currently selected column. >* MODIFIED 11/01/99 - KJM >* Check if RECCOUNT() > 0 before issuing GOTO lnRecNo >* MODIFIED 10/05/00 - KJM >* Added a call to ThisForm.SetFilePos() so the >* navigation toolbar gets properly refreshed. >* MODIFIED 06/25/02 - KJM >* Changed "IF NOT tcTagName == UPPER(This.cTagName)" >* to "IF NOT UPPER(tcTagName) == UPPER(This.cTagName)" >*----------------------------------------------------------------- >* MODIFIED 01/25/2005 - NN - >* Added two new grid properties to not refresh toolbars and to go top after sorting >* Also do not sort in empty grid >*---------------------------------------------------------------- >LPARAMETERS tcControlSource, tcTagName >LOCAL lnCount, lcField, lcIndexExpr, lcCursor, lnIndexes, ; > lcAscDesc, lnRecNo, loSelect >LOCAL ARRAY laIndex[1] > >*---------------------------------------------------------- >*-- Get the field, cursor name for the ControlSource cursor >*---------------------------------------------------------- >lcField = SUBSTR(tcControlSource, AT(".", tcControlSource) + 1) >lcCursor = JUSTSTEM(tcControlSource) > >* Change by NN >IF RECCOUNT(m.lcCursor) = 0 && empty cursor, why bother? > RETURN >ENDIF > >lnRecNo = RECNO(lcCursor) > >loSelect = CREATEOBJ('CSelect', lcCursor) > >IF PCOUNT() < 2 > >*---------------------------------------------- >*--- A tag name was not passed. Try to find a >*--- tag for the current column's ControlSource >*--- Get the number of indexes for the cursor. >*---------------------------------------------- > lnIndexes = AIndexes(@laIndex, lcCursor) >*---------------------------------------------------------------- >*-- See if the field name is in the leftmost part of an index >*-- expression OR simply within an UPPER() statement. >*-- If so, SET ORDER TO the index. >*---------------------------------------------------------------- > FOR lnCount = 1 TO lnIndexes > lcIndexExpr = UPPER(SYS(14, lnCount, lcCursor)) > >*-------------------------------------------------- >*--- Allow for character indexes that are simply >*--- surrounded by "UPPER()". Remove "UPPER()". >*-------------------------------------------------- > IF LEFT(lcIndexExpr,6) = 'UPPER(' > lcIndexExpr = SUBSTR(lcIndexExpr,7) > lcIndexExpr = SUBSTR(lcIndexExpr,1,LEN(lcIndexExpr)-1) > ENDIF > > IF lcIndexExpr = UPPER(lcField) > tcTagName = TAG(lnCount, lcCursor) >*--- Index found...exit ---* > EXIT > ENDIF > ENDFOR > >ENDIF > >*---------------------------------- >*--- Determine ASCENDING/DESCENDING >*---------------------------------- >IF NOT EMPTY(tcTagName) > IF NOT UPPER(tcTagName) == UPPER(THIS.cTagName) >*--- Default to ascending ---* > THIS.lAscending = .T. > ELSE >*--- Toggle ascending/descending ---* > THIS.lAscending = NOT THIS.lAscending > ENDIF > >*------------------------ >*--- SET ORDER to the tag >*------------------------ > THIS.cTagName = tcTagName > lcAscDesc = IIF(THIS.lAscending, 'ASCENDING', 'DESCENDING') > SET ORDER TO tcTagName IN (lcCursor) &lcAscDesc > >*--------------------------------------------------- >*--- Refresh the grid and restore the record pointer >*--- If done in the reverse order (GOTO, Refresh), >*--- the grid is visually on the wrong record. >*--------------------------------------------------- > THIS.REFRESH() > >*-- CHANGE - NN - January 25, 2005 - 09:37:53 > IF THIS.lGoTopAfterSorting > GO TOP IN (m.lcCursor) > ELSE > IF RECCOUNT(m.lcCursor) > 0 > GOTO m.lnRecNo IN (m.lcCursor) > ENDIF > ENDIF > >*-- CHANGE - NN - January 25, 2005 - 09:38:59 - added a new property > IF THIS.lUpdateToolbar > THISFORM.SetFilePos() && Note, that this code assumes existance of the SetFilePos method > ENDIF >ENDIF>
>*---------------------- Location Section ------------------------ >* Library: Acustomcontrols.vcx >* Class: Grdsorting >* Method: Headerclick() >*----------------------- Usage Section -------------------------- >*) Description: Custom method which fires when Header is clicked (idea from Barbara Peisch) >*) >* Scope: Public >* Parameters: >*$ Usage: >*$ >* Returns: >*--------------------- Maintenance Section ---------------------- >* Change Log: >* CREATED 01/06/2005 - NN >* MODIFIED >*---------------------------------------------------------------- >LOCAL loCalledBy AS OBJECT > >AEVENTS[aCurEvent,0] >loCalledBy = aCurEvent[1] && should be a Header object > >IF VARTYPE(m.loCalledBy)= "O" AND NOT EMPTY(m.loCalledBy.PARENT.CONTROLSOURCE) > LOCAL lcOrder > lcOrder = SET('order') && Save current tag > THIS.SetOrder(m.loCalledBy.PARENT.CONTROLSOURCE) > IF this.lShowSortingArrows AND NOT SET('order')== m.lcOrder >** Clear the picture of the previously sorted column > this.ClearHeaderPictures() > this.SetHeaderPicture(m.loCalledBy) > endif >ENDIF>
>*---------------------- Location Section ------------------------ >* Library: Acustomcontrols.vcx >* Class: Grdsorting >* Method: Clearheaderpictures() >*----------------------- Usage Section -------------------------- >*) Description: >*) > >* Scope: Public >* Parameters: >*$ Usage: >*$ >* Returns: >*--------------------- Maintenance Section ---------------------- >* Change Log: >* CREATED 01/24/2005 - NN >* MODIFIED >*---------------------------------------------------------------- >LOCAL loColumn, loControl >FOR EACH loColumn IN THIS.COLUMNS > FOR EACH loControl IN loColumn.CONTROLS > IF UPPER(loControl.BASECLASS) = "HEADER" > loControl.resettodefault('picture') > ENDIF > ENDFOR >ENDFOR>