H.Brill | Hier mal ein Wochenplan mit zusätzlicher Liste für jede Aktion. Wobei ich das Auslesen der Wochennummer und damit einen Vergleich einer Datei mit der aktuellen Woche, auch hier vom Forum habe. Interessant, für was das auch zu gebrauchen ist.
Vielen Dank dafür.
DEF GetFileAttributesEx(3) ! "Kernel32","GetFileAttributesExA"
DEF FileTimeToLocalFileTime(2) !"Kernel32","FileTimeToLocalFileTime"
DEF FileTimeToSystemTime(2) !"Kernel32","FileTimeToSystemTime"
Declare Handle btn1, btn2, btn3, edit1, edit2, tv
Declare Long ende, js, xs, item, subitem, obj, jtage[5]
Declare String datei, week, ueberschrift, jitem, tvsubitem, name, txt, Tage[5]
Declare Long aweek, fweek, p, y, anz, tvitem, liste
WindowTitle "Wochen - Liste"
Window 600, 500
btn1 = Create("Button", %HWnd, "Add", 10, 10, 60, 25)
btn2 = Create("Button", %HWnd, "Drucken", 380, 10, 60, 25)
btn3 = Create("Button", %HWnd, "Ende", 160, 10, 60, 25)
Create("Text", %HWnd, "Aktion", 10, 50, 60, 25)
edit1 = Create("Edit", %HWnd, "", 100, 50, 180, 25)
Create("Text", %HWnd, "Liste", 300, 10, 50, 25)
edit2 = Create("MultiEdit", %HWnd, "", 300, 40, 240, 130)
tv = Create("TreeView", %HWnd, 0, 10, 150, 240, 150)
Tage[0] = "Montag"
Tage[1] = "Dienstag"
Tage[2] = "Mittwoch"
Tage[3] = "Donnerstag"
Tage[4] = "Freitag"
Tage[5] = "Samstag"
ende = 0
datei = "Wochenplan.Json"
IfNot FileExists(datei)
InitJson()
InitTree()
Else
' Damit man jede Woche einen neuen Plan hat.
week = GetAttribute(datei)
fweek = DT("GetWoY", DT("SetDate", subStr$(week,10,"|")))
aweek = DT("GetWoY", !Now)
If aweek = fweek
js = Create("JSON", datei)
JsonInitTree()
Else
InitJson()
InitTree()
EndIf
EndIf
UserMessages $10
WhileNot ende
WaitInput
If Clicked(btn1)
'Add an item
If IndexOf(Tage[], jitem) > -1
TreeView("InsertItem", tv, item, 0, GetText$(edit1))
TreeView("SetChildren", tv, item, 1)
obj = Json("GetObject", js, jitem)
xs = Create("Json")
liste = Json("NewList")
txt = GetText$(edit2)
If Len(txt) > 0
WhileLoop 0, GetCount(edit2) - 1
Json("AddString", liste, GetString$(edit2, &LOOP))
EndWhile
EndIf
Json("AddList", xs, "Liste", liste)
JSon("AddObject", obj, GetText$(edit1), xs)
EndIf
ElseIf Clicked(btn2)
' Drucken
anz = GetCount(edit2)
y = 10
StartPrint
DrawText 10, y, ueberschrift
Inc y, 14
DrawText 10, y, "-----------------------"
Inc y, 14
WhileLoop 0, anz - 1
DrawText 10, y, GetString$(edit2, &LOOP)
Inc y, 14
EndWhile
EndPrint
ElseIf Clicked(btn3)
Json("WRITE", js, datei)
ende = 1
ElseIf Clicked(tv)
item = TreeView("GetSelected", tv)
TreeView("Expand", tv, item, 3)
jitem = GetText$(tv, item)
p = IndexOf(tage[], jitem)
If p = -1
tvsubitem = GetText$(tv, Treeview("GetSelected", tv))
ueberschrift = tvsubitem
jitem = GetText$(tv, TreeView("GetParent", tv, Treeview("GetSelected", tv)))
obj = Json("GetObject", js, jitem)
subitem = Json("GetObject", obj, tvsubitem)
liste = Json("GetList", subitem, "Liste")
anz = Json("Count", liste)
SetText edit1, jitem
If anz > 0
Txt = ""
SetText edit2, ""
WhileLoop 0, anz - 1
txt = txt + Json("GetString", liste, &LOOP) + Chr$(13) + Chr$(10)
EndWhile
SetText edit2, txt
EndIf
EndIf
EndIf
If %UMessage = $10
Json("WRITE", js, datei)
ende = 1
EndIf
EndWhile
Proc InitJson
js = Create("Json")
WhileLoop 0, 5
jtage[&LOOP] = Create("Json")
Json("AddObject", js, Tage[&LOOP], jtage[&LOOP])
EndWhile
EndProc
Proc InitTree
WhileLoop 0, 5
TreeView("InsertItem", tv, 0, 0, Tage[&LOOP])
TreeView("SetChildren", tv, 0, 1)
EndWhile
EndProc
Proc JsonInitTree
Declare Long x, i, h
anz = Json("Count", js)
WhileLoop 0, anz - 1
name = Json("Name", js, &LOOP)
h = TreeView("InsertItem", tv, 0, 0, name)
obj = Json("GetObject", js, name)
x = Json("Count", obj)
For i, 0, x - 1
If Json("Type", obj, i) <> 5
TreeView("InsertItem", tv, h, 0, Json("Name", obj, i))
TreeView("SetChildren", tv, h, 1)
EndIf
EndFor
EndWhile
EndProc
Proc Getweekday
Parameters day&
Return substr$("Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag",day& + 1,",")
endproc
proc GetAttribString
parameters attrib&
return if(testbit(attrib&,4),"<DIR> ","") \
+ if(testbit(attrib&,0),"r","-") \
+ if(testbit(attrib&,5),"a","-") \
+ if(testbit(attrib&,1),"h","-") \
+ if(testbit(attrib&,2),"s","-")
endproc
proc GetAttribute
parameters File$
Declare info#,file#,utc#,time#,Attrib&,size!,cwrite$,ctime$,awrite$,atime$,wwrite$,wtime$,size$,Attrib$
Declare cday$,aday$,wday$,return$
dim info#,36
dim file#, len(file$)+1
String file#,0 = file$
DIM utc#,8
DIM time#,16
GetFileAttributesEx(file#,0,info#)
Attrib& = long(info#,0)'Attribut
Attrib$ = GetAttribString(attrib&)
size! = (long(info#,28) * 65536 * 65536) + long(info#,32)'Filesize
Size$ = Format$("###,###,###,###,###.00",size!)
return$ = size$+"|"+attrib$
'-------------------------Erstellzeit
FileTimeToLocalFileTime(info#+4,utc#)
FileTimeToSystemTime(utc#,time#)
cwrite$=""
ctime$=""
if word(time#,0) >= 1601
cday$ = Getweekday(word(time#,4))
return$ = return$+"|"+cday$+"|"
cwrite$=Format$("00",word(time#,6))+"."+Format$("00",word(time#,2))+"."+Format$("00",word(time#,0))'Last written date
ctime$=Format$("00",word(time#,8))+":"+Format$("00",word(time#,10))+":"+Format$("00",word(time#,12))'last written time
else
cwrite$="00.00.00"
ctime$="00:00:00"
endif
return$ = return$+cwrite$+"|"+ctime$+"|"
'-----------------------------letzter Zugriff
FileTimeToLocalFileTime(info#+12,utc#)
FileTimeToSystemTime(utc#,time#)
awrite$=""
atime$=""
if word(time#,0) >= 1601
aday$ = Getweekday(word(time#,4))
return$ = return$+aday$+"|"
awrite$=Format$("00",word(time#,6))+"."+Format$("00",word(time#,2))+"."+Format$("00",word(time#,0))'Last written date
atime$=Format$("00",word(time#,8))+":"+Format$("00",word(time#,10))+":"+Format$("00",word(time#,12))'last written time
else
awrite$="00.00.00"
atime$="00:00:00"
endif
return$ = return$+awrite$+"|"+atime$+"|"
'--------------------------- Zuletzt geschrieben
FileTimeToLocalFileTime(info#+20,utc#)
FileTimeToSystemTime(utc#,time#)
wwrite$=""
wtime$=""
if word(time#,0) >= 1601
wday$ = Getweekday(word(time#,4))
return$ = return$+wday$+"|"
wwrite$=Format$("00",word(time#,6))+"."+Format$("00",word(time#,2))+"."+Format$("00",word(time#,0))'Last written date
wtime$=Format$("00",word(time#,8))+":"+Format$("00",word(time#,10))+":"+Format$("00",word(time#,12))'last written time
else
wwrite$="00.00.00"
wtime$="00:00:00"
endif
return$ = return$+wwrite$+"|"+wtime$
Dispose info#
Dispose file#
Dispose UTC#
Dispose time#
return return$
endproc
End
|
|