Guidance
指路人
g.yi.org
software / rapidq / Examples / Date & Time / Carnet v2 / fichiers.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'-- FILE AND DATA HANDLING
     $IFDEF FRANCAIS
      CONST wkfile="data\Carnet.txt"
     $ELSE
      CONST wkfile="data\Weeks.txt"
     $ENDIF

'----------------- 1 --- WEEK ORGANIZER

     DIM ljour AS INTEGER 'largeur d'un jour en pixels
     DIM hheure AS INTEGER 'hauteur d'une heure en pixels
     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

'-- HEURESTR: converts a screen y coordinate to a string describing time, in format hh:mm ex: 17:45
     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

'-- STRHEURE: does the reverse
     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
'return description string for event #i
      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, " # ") 'separator string forbidden in text -> replaced by " # " (or anything you want)
      thetext=REPLACESUBSTR$(thetext, crString, crSubst) 'substitute carriage returns
      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) 'sets Weekstartindex=event of first event of current week and nbeventsinweek=nb of events in this week
      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 'end of list, all events are before current week
       jouri=LEFT$(ev.item(index),10) 'date of event #index
       IF jouri<firstday THEN
        index++
       ELSE
        flag=false
       END IF
      WEND 'loop while date of event < start of week
      WeekStartIndex=index
      flag=true
      endofweek=advancedays(firstday,nbjours-1)
      WHILE flag
       IF index>= ev.itemcount THEN EXIT SUB 'end of list
       s=ev.item(index)  'description of event #index
       jouri=LEFT$(s,10) 'date of event
       IF jouri>endofweek THEN
        flag=false
       ELSE
        nbeventsinweek++:index++
       END IF
      WEND 'loop while date<= end of week
     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
掌柜推荐
 
 
¥860.00 ·
 
 
¥900.00 ·
 
 
¥810.00 ·
 
 
¥317.00 ·
 
 
¥1,370.00 ·
 
 
¥660.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:44:07