by jbrita » Thu Jul 29, 2010 4:31 pm
REDEFINE GET aGets[ 1] VAR FecPtoA ID 105 OF oFld:aDialogs[ 1 ] BITMAP "Bar_Ord" ;
ACTION (aRect := GetCoors(aGets[1]:hWnd),;
FecPtoA := FwxCalendar(FecPtoA,aRect[1],aRect[4],oFld:aDialogs[ 1 ]),;
aGets[1]:Refresh(),aGets[2]:SetFocus())
// --- Calendario de Jorge Mason --------------------------------------------
FUNCTION FwXCalendar(dDate,nRow,nCol,oDlg)
LOCAL oDlf, oBrf, aSem, nSem:=1, lSel:=.F.
LOCAL cMes, oMes, nMes, aMes, nAno, oAno, dSel
LOCAL aPos, nLen
DEFAULT dDate:=DATE()
dDate:=IF(Empty(dDate),Date(),dDate)
aMes:={"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio",;
"Agosto","Septiembre","Octubre","Noviembre","Diciembre" }
dSel:=dDate
cMes:=aMes[nMes:=MONTH(dDate)]
nAno:=YEAR(dDate)
aSem:=aSem(nMes,nAno)
IF ValType(oDlg)="O" // Idea tomada de M. Exposito
aPos:=oDlg:GetRect()
IF ValType(nRow)="N"
nRow+=aPos:nTop
nCol+=aPos:nLeft+5
ENDIF
IF (nLen:=(GetSysMetrics(1)-(nRow+254)))<0
nRow+=nLen
ENDIF
IF (nLen:=(GetSysMetrics(0)-(nCol+158)))<0
nCol+=nLen
END
ENDIF
DEFINE DIALOG oDlf RESOURCE "Calend"
REDEFINE COMBOBOX oMes VAR cMes ID 101 OF oDlf ITEMS aMes ;
ON CHANGE (aSem:=aSem(oMes:nAt,nAno) ,;
dSel:=RowColDate(DAY(dSel),oMes:nAt,nAno,oBrf,@nSem))
REDEFINE GET oAno VAR nAno ID 102 OF oDlf ;
SPINNER ON UP (++nAno,oAno:Refresh(),EVAL(oAno:bValid));
ON DOWN (--nAno,oAno:Refresh(),EVAL(oAno:bValid));
MIN 0 MAX 9999 PICTURE "9999";
VALID (aSem:=aSem(oMes:nAt,nAno) ,;
dSel:=RowColDate(DAY(dSel),oMes:nAt,nAno,oBrf,@nSem),.T.)
REDEFINE LISTBOX oBrf ;
FIELDS aSem[nSem][1],aSem[nSem][2],aSem[nSem][3],aSem[nSem][4],;
aSem[nSem][5],aSem[nSem][6],aSem[nSem][7] ;
HEADERS " D"," L"," M"," M"," J"," V"," S" ;
OF oDlf ;
ON CLICK dSel:=GetDate(VAL(aSem[nSem][oBrf:nColact]),oMes:nAt,nAno);
ON DBLCLICK IF(EMPTY(aSem[nSem][oBrf:nColAct]),;
(nMes:=oMes:nAt,;
IF(nSem=1,(--nMes,IF(nMes<1,(nMes:=12,--nAno),)),;
(++nMes,IF(nMes>12,(nMes:=1,++nAno),))),;
oMes:Set(aMes[nMes]),oAno:Refresh(),;
aSem:=aSem(nMes,nAno),dSel:=RowColDate(DAY(dSel),oMes:nAt,nAno,oBrf,@nSem)),;
(lSel:=.t.,oDlf:End())) ;
ID 100
REDEFINE SAY PROMPT "SiaWin-Pro©" ID 103 OF oDlf COLOR RGB( 68, 90,155)
oBrf:bGotop :={|| nSem:=MIN(EVAL(oBrf:bLogicLen),1)}
oBrf:bGoBottom :={|| nSem:=EVAL(oBrf:bLogicLen)}
oBrf:bSkip :={| nWant,nOld | nold:=nSem, nSem+=nWant,;
nSem:=MAX(1, MIN(nSem,EVAL(oBrf:bLogicLen))),nSem-nOld}
oBrf:lAdjLastCol:=.F.
oBrf:bLogicLen :={|| LEN(aSem)}
oBrf:cAlias :="Array"
oBrf:bKeydown :={|nKey| If(nKey==VK_RETURN,EVAL(oBrf:bLDblClick),EVAL(oBrf:bLClicked))}
oBrf:aColSizes :={20,20,20,20,20,20,20}
oBrf:lCellStyle :=.T.
oBrf:bTextColor :={|nRow,nCol,nStyle| IF(nCol=1 .AND. nStyle=0,CLR_HRED,)}
oDlf:lHelpIcon := .f.
REDEFINE BUTTON ID 104 OF oDlf ACTION (lSel:=.T.,oDlf:End())
ACTIVATE DIALOG oDlf ;
ON INIT (oDlf:Move(nRow,nCol), RowColDate(DAY(dDate),nMes,nAno,oBrf,@nSem))
RETURN IF(lSel,GetDate(VAL(aSem[nSem][oBrf:nColact]),oMes:nAt,nAno),dDate)
FUNCTION RowColDate(nDia,nMes,nAno,oBrf,nSem)
LOCAL dFecha :=GetDate(nDia,nMes,nAno)
LOCAL dFirstDay:=dFecha-Day(dFecha)+1
LOCAL nStep
oBrf:GoTop()
oBrf:nColPos=1
oBrf:nColAct=Dow(dFecha) //IF(Dow(dFecha)=1,7,Dow(dFecha))
nSem=INT((Day(dFecha)+Dow(dFirstDay)-oBrf:nColAct+8)/7)
oBrf:nRowPos=nSem
oBrf:Refresh()
oBrf:SetFocus()
RETURN (dFecha)
FUNCTION GetDate(nDia,nMes,nAno)
LOCAL dDate
DO WHILE EMPTY(dDate:=CToD(StrZero(nDia,2)+"/"+StrZero(nMes,2)+"/"+StrZero(nAno,4)))
--nDia
nDia=MAX(nDia,1)
ENDDO
RETURN (dDate)
FUNCTION aSem(nMes,nAno)
LOCAL aSemana:={{"","","","","","",""}}
LOCAL dFecha :=CToD("01/"+StrZero(nMes,2)+"/"+StrZero(nAno,4))
LOCAL nDia :=Dow(dFecha)
LOCAL nSem:=1
DO WHILE Month(dFecha)=nMes
IF nDia > 7
nDia=1
++nSem
AADD(aSemana,{"","","","","","",""})
ENDIF
aSemana[nSem][nDia]=PADL(STR(Day(dFecha)),3)
++dFecha
++nDia
ENDDO // oBrf:lHelpIcon := .f.
RETURN (aSemana)