* Program..: Scope.prg * Author...: Jeremy Suiter * Date.....: 26/03/2003 * * Notice...: Copyright (c) 2003, Jeremy Suiter, All Rights Reserved * Notes....: Visual DbEditor Scope functions #Include "Font.ch" #Include "Gra.ch" #Include "Xbp.ch" #Include "Appevent.ch" #Include "Common.ch" #Include "Dmlb.ch" #Include "Dbstruct.ch" #Include "Inkey.ch" #Include "DbEditor.ch" #Include "Resources.ch" ************* Func SetScope() ************* * scope function Local nEvent:=Nil, mp1:=Nil, mp2:=Nil, aPos:={}, lSet:=.F., cTopScope:=Space(90), cBottomScope:=Space(90), cFilter:=Space(512), lRetVal:=.F., bFilter:="" Local oDlg:=Nil, oXbp:=Nil, drawingArea:=Nil, oGroup1:=Nil, oGroup2:=Nil, oGroup3:=Nil, oBegScope:=Nil, oEndScope:=Nil, oFilter:=Nil Local oBTRB:=Nil, oSVRB:=Nil, oETRB:=Nil, oEVRB:=Nil, oSFCB:=Nil, oController:=Nil Begin Sequence If oFocusBrowse==Nil Break EndIf aPos:=CenterPos({477,251},AppDesktop():currentSize()) oDlg:=XbpDialog():new(AppDesktop(), SetAppWindow(), aPos, {477,251}, , .F.) oDlg:icon:=ICON_MAIN oDlg:taskList:=.F. oDlg:border:=XBPDLG_RAISEDBORDERTHIN_FIXED oDlg:title:="Set Scope/Filter" oDlg:close:={|mp1,mp2,obj| PostAppEvent(xbeP_Close+1000) } oDlg:create() oDlg:setModalState(XBP_DISP_APPMODAL) oDlg:keyBoard:={| nKeyCode, uNIL, self | Iif(nKeyCode==xbeK_ESC,PostAppEvent(xbeP_Close+1000),Nil) } drawingArea:=oDlg:drawingArea drawingArea:setFontCompoundName("8.Helv") // beginning of scope group oGroup1:=XbpStatic():new(drawingArea, , {12,120}, {216,84}) oGroup1:caption:="Starting Scope" oGroup1:clipSiblings:=.T. oGroup1:type:=XBPSTATIC_TYPE_GROUPBOX oGroup1:create() // beginning of table radiobutton oBTRB:=XbpRadiobutton():new(oGroup1, , {12,36}, {120,24}) oBTRB:caption:="Beginning of Table" If DbScope(SCOPE_TOP)==Nil oBTRB:selection:=.T. Else oBTRB:selection:=.F. EndIf oBTRB:tabStop:=.T. oBTRB:setInputFocus:={| uNil1,uNil2,self | XbpBorder(self,GRA_CLR_BLUE) } oBTRB:killInputFocus:={| uNil1,uNil2,self | XbpBorder(self, GRA_CLR_BACKGROUND) } oBTRB:create() oBTRB:selected:={|| BegScopeSet(oBegScope,.T.) } // start value selection radiobutton oSVRB:=XbpRadiobutton():new(oGroup1, , {12,12}, {84,24}) oSVRB:caption:="Start Value" oSVRB:tabStop:=.T. If !DbScope(SCOPE_TOP)==Nil oSVRB:selection:=.T. Else oSVRB:selection:=.F. EndIf oSVRB:setInputFocus:={| uNil1,uNil2,self | XbpBorder(self,GRA_CLR_BLUE) } oSVRB:killInputFocus:={| uNil1,uNil2,self | XbpBorder(self, GRA_CLR_BACKGROUND) } oSVRB:create() oSVRB:selected:={|| BegScopeSet(oBegScope,.F.) } If OrdNumber()==0 oSVRB:disable() EndIf // start value entry field oBegScope:=XbpGet():new(oGroup1, , {96,12}, {108,24}, { { XBP_PP_BGCLR, XBPSYSCLR_ENTRYFIELD } }) oBegScope:tabStop:=.T. oBegScope:picture:="" oBegScope:datalink:={|x| IIf(x==Nil,x:=cTopScope,cTopScope:=x) } If !DbScope(SCOPE_TOP)==Nil oBegScope:editable:=.T. Else oBegScope:editable:=.F. EndIf oBegScope:bufferLength:=90 oBegScope:setInputFocus:={| uNil1,uNil2,self | XbpBorder(self,GRA_CLR_BLUE) } oBegScope:killInputFocus:={| uNil1,uNil2,self | XbpBorder(self, GRA_CLR_BACKGROUND) } oBegScope:create() If OrdNumber()==0 oBegScope:disable() EndIf If !DbScope(SCOPE_TOP)==Nil oBegScope:setData(DbScope(SCOPE_TOP)) EndIf // end of scope group oGroup2:=XbpStatic():new(drawingArea, , {240,120}, {216,84}) oGroup2:caption:="Ending Scope" oGroup2:clipSiblings:=.T. oGroup2:type:=XBPSTATIC_TYPE_GROUPBOX oGroup2:create() // end of table radiobutton oETRB:=XbpRadiobutton():new(oGroup2, , {12,36}, {120,24}) oETRB:caption:="End of Table" If DbScope(SCOPE_BOTTOM)==Nil oETRB:selection:=.T. Else oETRB:selection:=.F. EndIf oETRB:tabStop:=.T. oETRB:setInputFocus:={| uNil1,uNil2,self | XbpBorder(self,GRA_CLR_BLUE) } oETRB:killInputFocus:={| uNil1,uNil2,self | XbpBorder(self, GRA_CLR_BACKGROUND) } oETRB:create() oETRB:selected:={|| EndScopeSet(oEndScope,.T.) } // select end value radiobutton oEVRB:=XbpRadiobutton():new(oGroup2, , {12,12}, {84,24}) oEVRB:caption:="End Value" oEVRB:tabStop:=.T. If !DbScope(SCOPE_BOTTOM)==Nil oEVRB:selection:=.T. Else oEVRB:selection:=.F. EndIf oEVRB:setInputFocus:={| uNil1,uNil2,self | XbpBorder(self,GRA_CLR_BLUE) } oEVRB:killInputFocus:={| uNil1,uNil2,self | XbpBorder(self, GRA_CLR_BACKGROUND) } oEVRB:create() oEVRB:selected:={|| EndScopeSet(oEndScope,.F.) } If OrdNumber()==0 oEVRB:disable() EndIf // select end value entry field oEndScope:=XbpGet():new(oGroup2, , {96,12}, {108,24}, { { XBP_PP_BGCLR, XBPSYSCLR_ENTRYFIELD } }) oEndScope:tabStop:=.T. oEndScope:picture:="" oEndScope:datalink:={|x| IIf(x==Nil,x:=cBottomScope,cBottomScope:=x) } If !DbScope(SCOPE_BOTTOM)==Nil oEndScope:editable:=.T. Else oEndScope:editable:=.F. EndIf oEndScope:bufferLength:=90 oEndScope:setInputFocus:={| uNil1,uNil2,self | XbpBorder(self,GRA_CLR_BLUE) } oEndScope:killInputFocus:={| uNil1,uNil2,self | XbpBorder(self, GRA_CLR_BACKGROUND) } oEndScope:create() If OrdNumber()==0 oEndScope:disable() EndIf If !DbScope(SCOPE_BOTTOM)==Nil oEndScope:setData(DbScope(SCOPE_BOTTOM)) EndIf // filter group box oGroup3:=XbpStatic():new(drawingArea, , {12,48}, {444,60}) oGroup3:caption:="Filter" oGroup3:clipSiblings:=.T. oGroup3:type:=XBPSTATIC_TYPE_GROUPBOX oGroup3:create() // set filter checkbox oSFCB:=XbpCheckbox():new(oGroup3, , {12,12}, {84,24}) oSFCB:caption:="Filter:" oSFCB:tabStop:=.T. If !Empty(DbFilter()) oSFCB:selection:=.T. Else oSFCB:selection:=.F. EndIf oSFCB:setInputFocus:={| uNil1,uNil2,self | XbpBorder(self,GRA_CLR_BLUE) } oSFCB:killInputFocus:={| uNil1,uNil2,self | XbpBorder(self, GRA_CLR_BACKGROUND) } oSFCB:create() oSFCB:selected:={|| FilterSet(oFilter) } // filter entry field oFilter:=XbpGet():new(oGroup3, , {72,12}, {360,24}, { { XBP_PP_BGCLR, XBPSYSCLR_ENTRYFIELD } }) oFilter:tabStop:=.T. oFilter:picture:="" oFilter:datalink:={|x| IIf(x==Nil,x:=cFilter,cFilter:=x) } If !Empty(DbFilter()) oFilter:editable:=.T. Else oFilter:editable:=.F. EndIf oFilter:bufferLength:=512 oFilter:setInputFocus:={| uNil1,uNil2,self | XbpBorder(self,GRA_CLR_BLUE) } oFilter:killInputFocus:={| uNil1,uNil2,self | XbpBorder(self, GRA_CLR_BACKGROUND) } oFilter:create() If !Empty(DbFilter()) oFilter:setData(DbFilter()) Else oFilter:setData("") EndIf oXbp:=XbpPushButton():new(drawingArea, , {240,12}, {96,24}, { { XBP_PP_BGCLR, XBPSYSCLR_BUTTONMIDDLE }, { XBP_PP_FGCLR, -58 } }) oXbp:caption:="Set" oXbp:tabStop:=.T. oXbp:create() oXbp:activate:={|| lSet:=.T., PostAppEvent(xbeP_Close+1000) } oXbp:=XbpPushButton():new(drawingArea, , {360,12}, {96,24}, { { XBP_PP_BGCLR, XBPSYSCLR_BUTTONMIDDLE }, { XBP_PP_FGCLR, -58 } }) oXbp:caption:=GEN_CLOSE oXbp:tabStop:=.T. oXbp:create() oXbp:activate:={|| lSet:=.F., PostAppEvent(xbeP_Close+1000) } oController:=XbpGetController():new(oDlg):create() oController:read(,.F.) oDlg:show() SetAppFocus(oBTRB) nEvent:=xbe_None Do While nEvent<>xbeP_Close+1000 nEvent:=AppEvent(@mp1, @mp2, @oXbp) oXbp:handleEvent(nEvent, mp1, mp2) if nEvent == xbeP_Keyboard .and.; mp1 == xbeK_ESC exit endif EndDo If lSet // set scope and/or filter If OrdNumber()>0 //set scope If Empty(cTopScope) .And. !Empty(DbScope(SCOPE_TOP)) DbClearScope(SCOPE_TOP) DbGoTop() lRetVal:=.T. EndIf If Empty(cBottomScope) .And. !Empty(DbScope(SCOPE_BOTTOM)) DbClearScope(SCOPE_BOTTOM) DbGoTop() lRetVal:=.T. EndIf If !Empty(cTopScope) .Or. !Empty(cBottomScope) If !Empty(cTopScope) DbSetScope(SCOPE_TOP,cTopScope) EndIf If !Empty(cBottomScope) DbSetScope(SCOPE_BOTTOM,cBottomScope) EndIf DbGoTop() If Eof() Errm(ERR_ERRM39) DbClearScope(SCOPE_BOTH) DbGoTop() lRetVal:=.T. Else lRetVal:=.T. EndIf EndIf EndIf // set filter If !Empty(cFilter) .And. TestCondition(cFilter) bFilter:=&('{||'+cFilter+'}') DbSetFilter(bFilter,cFilter) DbGoTop() If Eof() Errm(ERR_ERRM40) DbClearFilter() DbGoTop() lRetVal:=.T. Else lRetVal:=.T. EndIf ElseIf !Empty(DbFilter()) DbClearFilter() DbGoTop() lRetVal:=.T. EndIf EndIf If lRetVal oFocusBrowse:goTop() oFocusBrowse:refreshAll() oFocusBrowse:forceStable() EndIf oDlg:destroy() SetAppFocus(oFocusBrowse) End Return lRetVal **************** Func BegScopeSet(oBegScope,lBeginning) **************** Begin Sequence If lBeginning oBegScope:setData(Space(90)) oBegScope:editable:=.F. oBegScope:configure() Else oBegScope:editable:=.T. oBegScope:configure() SetAppFocus(oBegScope) EndIf End Return Nil **************** Func EndScopeSet(oEndScope,lEnd) **************** Begin Sequence If lEnd oEndScope:setData(Space(90)) oEndScope:editable:=.F. oEndScope:configure() Else oEndScope:editable:=.T. oEndScope:configure() SetAppFocus(oEndScope) EndIf End Return Nil ************** Func FilterSet(oFilter) ************** Begin Sequence If oFilter:editable oFilter:setData(Space(512)) oFilter:editable:=.F. oFilter:configure() Else oFilter:editable:=.T. oFilter:configure() SetAppFocus(oFilter) EndIf End Return Nil