$IFDEF FRANCAIS
CONST wkfile="data\Carnet.txt"
$ELSE
CONST wkfile="data\Weeks.txt"
$ENDIF
DIM ljour AS INTEGER
DIM hheure AS INTEGER
DEFINT nbevent=0
DEFINT currentev=0
DIM ev AS QSTRINGLIST
ev.sorted=true
DIM edcadre(1) AS QPANEL
DIM ed(1) AS QRICHEDIT
DIM edicon(1) AS QIMAGE
DIM edrect(1) AS QCANVAS
FUNCTION heurestr(dd AS DOUBLE) AS STRING
d=dd/hheure
heure=INT(d)+heure1
minute=ROUND(FRAC(d)*60)
heurestr=format$("%2.2d",heure)+":"+format$("%2.2d",minute)
END FUNCTION
FUNCTION strheure(s AS STRING) AS DOUBLE
DIM hh AS STRING, mm AS STRING
hh=FIELD$(s,":",1)
mm=FIELD$(s,":",2)
strheure=VAL(hh)+VAL(mm)/60
END FUNCTION
FUNCTION eventstring(i AS INTEGER) AS STRING
DIM s AS STRING,ss AS STRING, queljour AS STRING, thetext AS STRING
joursem=INT(edcadre(i).left/ljour)
queljour=advancedays(lundi,joursem)
gauche=(edcadre(i).left)/ljour+firstdaydisplayed
droite=(edcadre(i).left+edcadre(i).width)/ljour+firstdaydisplayed
thetext=ed(i).text
thetext=REPLACESUBSTR$(thetext, separ, " # ")
thetext=REPLACESUBSTR$(thetext, crString, crSubst)
ss= format$("%-.2g",gauche) + " "+ format$("%-.2g",droite) +" "+ _
heurestr(edcadre(i).top) +" "+ heurestr(edcadre(i).top+edcadre(i).height)
eventstring=queljour+separ+thetext+separ+ss+separ+edicon(i).hint
END FUNCTION
SUB closeweek
FOR i=1 TO nbevent
IF ed(i).text<>"[[deleted]]" THEN
ev.additems(eventstring(i))
END IF
NEXT
END SUB
SUB opencarnet
DIM icone AS STRING,icone2 AS STRING,s AS STRING, posInfo AS STRING, posInfo2 AS STRING
DIM x1 AS DOUBLE, x2 AS DOUBLE, time AS STRING
DIM backwardcompatibilityoffset AS INTEGER
CHDIR appdir
IF FILEEXISTS(wkfile)=false THEN
ev.clear
EXIT SUB
END IF
ev.sorted=false
ev.loadfromfile(wkfile)
s=ev.item(0)
IF s="[Agenda]" THEN
ev.delitems(0)
backwardcompatibilityoffset=0
ELSE
backwardcompatibilityoffset=1
END IF
icondir=LTRIM$(ev.item(0)):ev.delitems(0)
FOR i=0 TO ev.itemcount-1
s=ev.item(i)
icone=FIELD$(s,separ,4)
IF LEFT$(icone,1)="\" THEN
icone2=icondir+icone
ev.item(i)=REPLACESUBSTR$(s,icone,icone2)
END IF
NEXT
IF backwardcompatibilityoffset THEN
FOR i=0 TO ev.itemcount-1
s=ev.item(i)
posInfo=FIELD$(s,separ,3)
x1=VAL(FIELD$(posInfo," ",1))
x2=VAL(FIELD$(posInfo," ",2))
time=FIELD$(posInfo," ",3)+" "+FIELD$(posInfo," ",4)
posInfo2=STR$(x1+backwardcompatibilityoffset)+" "+STR$(x2+backwardcompatibilityoffset)+" "+time
ev.item(i)=REPLACESUBSTR$(s,posInfo,posInfo2)
NEXT
END IF
ev.sort
ev.sorted=true
END SUB
DIM WeekStartIndex AS INTEGER, nbeventsinweek AS INTEGER
SUB findweek(firstday AS STRING)
DIM jouri AS STRING, endofweek AS STRING, s AS STRING
nbeventsinweek=0 : index=0 : flag=true
WeekStartIndex=-1
WHILE flag
IF index>= ev.itemcount THEN EXIT SUB
jouri=LEFT$(ev.item(index),10)
IF jouri<firstday THEN
index++
ELSE
flag=false
END IF
WEND
WeekStartIndex=index
flag=true
endofweek=advancedays(firstday,nbjours-1)
WHILE flag
IF index>= ev.itemcount THEN EXIT SUB
s=ev.item(index)
jouri=LEFT$(s,10)
IF jouri>endofweek THEN
flag=false
ELSE
nbeventsinweek++:index++
END IF
WEND
END SUB
SUB savecarnet
DIM icone AS STRING,icone2 AS STRING,s AS STRING
DIM saveev AS QSTRINGLIST
closeweek
saveev.clear
saveev.additems("[Agenda]")
saveev.additems(icondir)
FOR i=0 TO ev.itemcount-1
s=ev.item(i)
icone=FIELD$(s,separ,4)
IF LEFT$(icone,LEN(icondir))=icondir THEN
icone2=MID$(icone,LEN(icondir)+1,LEN(icone))
s=REPLACESUBSTR$(s,icone,icone2)
END IF
saveev.additems(s)
NEXT
CHDIR appdir
saveev.savetofile(wkfile)
END SUB
|
|