/* * MDI filter * badikprg@mail.ru * only database -> all window -> unique filter * v00.03 23/07/2004 */ #include "minigui.ch" Function Main local xT,i,xR:=100,xC:=100 public xThisName:="" public iWin:=0 SET BROWSESYNC ON SET MULTIPLE ON Set Delete on /* //debug filter Set printer to dd Set printer on Set console off */ DEFINE WINDOW Form_Main ; AT 0,0 ; WIDTH 600 ; HEIGHT 70 ; TITLE 'MDI Filter' ; MAIN ; ON GOTFOCUS {||ll(.t.)} ; FONT "ARIAL" SIZE 09 ; ON INIT OpenTables() ; ON RELEASE CloseTables() @ 5,10 TEXTBOX tb_01 VALUE "Noy" @ 5,135 TEXTBOX tb_02 VALUE "" @ 5,260 BUTTON CH_1 CAPTION "new Window" ; ON CLICK {||DoMethod(My_child(),"activate")} @ 5,365 BUTTON CH_2 CAPTION "minimize All" ; ON CLICK {||my_zoom(iWin,"minimize")} @ 5,475 BUTTON CH_3 CAPTION "restore All" ; ON CLICK {||my_zoom(iWin,"restore")} END WINDOW aW:={"Form_Main"} FOR I:=1 TO 7 aadd(aw,My_child()) NEXT _ActivateWindow (aW) END WINDOW Return Function My_zoom(nWin,metod) Local xT , i for i:=1 to nWin xT:="Fw_"+Padl(i,5,"0") If _IsWIndowDefined(xT) DoMethod(xT,metod) end next Function My_child() Static xR:=100,xC:=10,lUnique:=.t. local xT,i,xWhile,aW While !lunique inkey(0.1) end lUnique:=.f. iWin++ xT:="Fw_"+Padl(iWin,5,"0") xWhile:=Str(random(99),2) DEFINE WINDOW &xT; AT xR,xC ; WIDTH 350 ; HEIGHT 480 ; TITLE 'Win '+Padl(iWin,3,"0"); CHILD; ON GOTFOCUS {||ll()} ; ON INIT {||init_filter(thiswindow.name)} ; ON RELEASE {||my_delete()} my_browse() @280,20 FRAME F_1 WIDTH 300 HEIGHT 50 CAPTION "query While" @300,25 LABEL L_1 WIDTH 120 HEIGHT 20 ; VALUE "group between Min" FONT "ARIAL" SIZE 09 @300,140 TEXTBOX T_1 WIDTH 20 HEIGHT 20 ; VALUE xWhile MAXLENGTH 2 FONT "ARIAL" SIZE 09 @300,170 LABEL L_2 WIDTH 50 HEIGHT 20 ; VALUE "and Max" FONT "ARIAL" SIZE 09 @300,235 TEXTBOX T_2 WIDTH 20 HEIGHT 20 ; VALUE xWhile MAXLENGTH 2 FONT "ARIAL" SIZE 09 @340,20 FRAME F_2 WIDTH 200 HEIGHT 50 CAPTION "query For" @360,25 LABEL L_3 WIDTH 60 HEIGHT 20 VALUE "numer" FONT "ARIAL" SIZE 09 @360,70 COMBOBOX Combo_1 WIDTH 100 HEIGHT 80 ; ITEMS { " <> "," = "," >= "," <= " } ; VALUE 1 FONT 'Courier' SIZE 09 @360,180 TEXTBOX T_4 WIDTH 30 HEIGHT 20 ; VALUE "500" MAXLENGTH 3 FONT "ARIAL" SIZE 09 @355,230 CHECKBUTTON CH_1 CAPTION "filter" VALUE .T. ; ON CHANGE init_filter(thiswindow.name,.t.) @380,230 BUTTON CH_2 CAPTION "delete" ON Click f_delete() DEFINE STATUSBAR STATUSITEM "" STATUSITEM "" WIDTH 100 CLOCK DATE END STATUSBAR END WINDOW //xC+=75 if iWin % 9 = 0 xR:=100+int(iWin/9)*15 xC:=10 else xR+=160 if iWin %9 % 3 = 0 xR:=100+int(iWin/9)*15 xC:=10+int(iWin%9/3)*250 endif endif lUnique:=.t. Return xT function ll(Code) xThisName:=_HMG_THISFORMNAME Form_Main.tb_01.value:=GetProperty ( _HMG_THISFORMNAME , "Title" ) If code==nil Form_Main.tb_02.value:="Recno "+padl(GetProperty( _HMG_THISFORMNAME ,"Browse_1","Value" ),7,"0") endif my_filter(,,,_HMG_THISFORMNAME,.t.) return nil function my_ll(xName) if xName==nil //xName:=_HMG_THISFORMNAME error ? xName:=xThisName endif if xName="Fw" Form_Main.tb_02.value:="Recno "+padl(Recno(),7,"0") SetProperty( xNAME ,"StatusBar","Item",1,Str(GetProperty( xNAME ,"Browse_1","Value" ))) SetProperty( xNAME ,"StatusBar","Item",2,Str(OrdKeyNo())) endif return recno() function my_delete() my_filter(,,,xThisName) return Function my_browse() DEFINE BROWSE Browse_1 ROW 10 COL 20 WIDTH 300 HEIGHT 250 VALUE 0 WIDTHS {100,100,100} HEADERS {'Grup',"Numer","Recno_r"} WORKAREA d_filter FIELDS {'Grup',"Numer","Recno_r"} ON CHANGE my_ll() VSCROLLBAR .F. LOCK .T. End Browse //EDIT INPLACE APPEND Function init_filter(xName,linit) if xName==nil xName:=_HMG_THISFORMNAME endif if GetProperty ( xName , "CH_1","Value") my_filter(GetProperty ( xName , "T_1","Value"), ; GetProperty ( xName , "T_2","Value"), ; " numer "+GetProperty ( xName , "Combo_1","DisplayValue")+; GetProperty ( xName , "T_4","Value"), ; xName) else my_filter(,,,xName) dbskip(1) my_ll() endif Set filter to my_filter() dbgotop() if linit <>nil SetProperty ( xName , "Browse_1","Value",Recno()) DoMethod( xName , "Browse_1","SetFocus") else my_ll(xName) endif Return Function my_filter(x_Min,x_Max,x_for,xWindow,xVisible) Static log:=.t. Static aQuery:={} local xMin,xMax,xfor local db_step:=procname(2),i:=2,bn /* //debug filter ?"========"+Str(Recno())+"========",log while !empty(procname(i)) ?Str(i,3)+"."+PROCNAME(i)+" "+Str(procline(i),6) i++ end */ if xWindow <>nil if (bn:=Ascan(aQuery,{|x| x[4]==xWindow}))= 0 aadd(aQuery,{0,99,".t.",xWindow}) bn:=len(aQuery) endif if x_min<>nil aQuery[bn,1]:=Val(x_min) aQuery[bn,2]:=Val(x_max) aQuery[bn,3]:=x_for else if xVisible==nil aDel(aQuery,bn) i:=len(aQuery) aQuery:=aSize(aQuery,i-1) else endif endif return .t. endif bn:=Ascan(aQuery,{|x| x[4]==xThisName}) if bn=0 return .t. endif if log if bn > len(aQuery) msginfo("error "+ Str(bn)+" > array len "+Str(len(aQuery))+" !?!?!") endif if grup >= aQuery[bn,1] .and.grup <=aQuery[bn,2] Return &(aQuery[bn,3]) else if db_step="DBSKIP" log :=.f. if grup < aQuery[bn,1] log :=.f. dbseek(Str(aQuery[bn,1],2),.t.) While !&(aQuery[bn,3]) dbskip(1) end log :=.t. else dbGobottom() skip(1) end log :=.t. Elseif db_step="DBGOBOTTOM" log :=.f. if aQuery[bn,2]=99 dbgotop() else dbseek(Str(aQuery[bn,2]+1,2),.t.) dbskip(-1) endif While !&(aQuery[bn,3]) dbskip(-1) end log :=.t. Elseif db_step="DBGOTOP" log :=.f. dbseek(Str(aQuery[bn,1],2),.t.) While !&(aQuery[bn,3]) dbskip(1) end log :=.t. endif return .t. endif endif if !log return .t. endif rETURN grup >= aQuery[bn,1] .and.grup <=aQuery[bn,2] .and. &(aQuery[bn,3]) Procedure OpenTables() Create_New() use d_filter new shared index_file("d_filter.ntx","Str(grup,2,0)+Str(numer,3,0)") Set index to d_filter Return Nil Procedure CloseTables() Use Return Nil function create_new() local aDBF:={},i if !file("d_filter.dbf") aDbf:={; {"Grup","n",2,0},; {"numer","n",3,0},; {"Recno_R","n",6,0}; } DbCreate("d_filter",aDbf) use d_filter new DEFINE WINDOW ind_file ; AT 200,10 ; WIDTH 440 HEIGHT 60; TITLE "Create test DataBaseFile d_filter.dbf" ; MODAL NOSIZE NOSYSMENU; ON INIT my_create() @ 5,10 PROGRESSBAR Progress_1 RANGE 0,100 WIDTH 400 HEIGHT 18 END WINDOW ind_file.center ind_file.ACTIVATE use endif Return function my_create() local i ,rMax:=100000 for i:=1 to rMax d_filter->(dbappend()) d_filter->grup:=random(99) d_filter->numer:=random(999) d_filter->Recno_r:=recno() ind_file.Progress_1.Value := INT((RECNO()/rMax) * 100) next ind_file.release return function index_file(xFile,xKey) if !file(xFile) DEFINE WINDOW ind_file ; AT 200,10 ; WIDTH 440 HEIGHT 60; TITLE "IndexFile "+xFile ; MODAL NOSIZE NOSYSMENU; ON INIT my_ind_file(xFile,xKey) @ 5,14 PROGRESSBAR Progress_1 RANGE 0,100 WIDTH 400 HEIGHT 18 END WINDOW ind_file.center ind_file.ACTIVATE endif Return function my_ind_file(xFile,xKey) INDEX ON &xKey TO &xFile EVAL my_ind_eval() EVERY LASTREC() /20 ind_file.Release Return function my_ind_eval() ind_file.Progress_1.Value := INT((RECNO()/LASTREC()) * 100) Return .t. //nil-error 13.01.2004 FUNCTION f_delete xName:=xThisName dbgoto(GetProperty( xNAME ,"Browse_1","Value" )) While !rlock();end dbdelete() dbunlock() dbSkip(1) SetProperty( xNAME ,"Browse_1","Value" ,Recno()) RETURN NIL