English
Source / code snippets

Json + TreeView (Wochenplan)

 

H.Brill
here time one Wochenplan with zusätzlicher list
for each action. where I the Reading the Wochennummer
and so a comparison of/ one File with the actually week,
here of Forum have. interestingly, for what the too
To use is.

Vielen Thanks for.
DEF GetFileAttributesEx(3) ! "Kernel32","GetFileAttributesExA"
DEF FileTimeToLocalFileTime(2) !"Kernel32","FileTimeToLocalFileTime"
DEF FileTimeToSystemTime(2) !"Kernel32","FileTimeToSystemTime"
Declare lever btn1, btn2, btn3, edit1, edit2, tv
Declare Long end, js, xs, item, subitem, obj, jtage[5]
Declare String File, week, ueberschrift, jitem, tvsubitem, name, txt, days[5]
Declare Long aweek, fweek, p, y, anz, tvitem, list
Window Title "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)
days[0] = "Montag"
days[1] = "Dienstag"
days[2] = "Mittwoch"
days[3] = "Donnerstag"
days[4] = "Freitag"
days[5] = "Samstag"
end = 0
File =  "Wochenplan.Json"

Ifnot FileExists(File)

    InitJson()
    InitTree()

Else

    ' so one each week a new plan has.
    week = GetAttribute(File)
    fweek = DT("GetWoY", DT("SetDate", subStr$(week,10,"|")))
    aweek = DT("GetWoY", !Now)

    If aweek = fweek

        js = Create("JSON", File)
        JsonInitTree()

    Else

        InitJson()
        InitTree()

    EndIf

EndIf

User Messages $10

WhileNot end

    WaitInput

    If Clicked(btn1)

        'Add on item

        If IndexOf(days[], jitem) > -1

            TreeView("InsertItem", tv, item, 0, GetText$(edit1))
            TreeView("SetChildren", tv, item, 1)
            obj = Json("GetObject", js, jitem)
            xs = Create("Json")
            list = Json("NewList")
            txt = GetText$(edit2)

            If Len(txt) > 0

                WhileLoop 0, GetCount(edit2) - 1

                    Json("AddString", list, GetString$(edit2, &LOOP))

                EndWhile

            EndIf

            Json("AddList", xs, "Liste", list)
            JSon("AddObject", obj, GetText$(edit1), xs)

        EndIf

    ElseIf Clicked(btn2)

        ' Print
        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, File)
        end = 1

    ElseIf Clicked(tv)

        item = TreeView("GetSelected", tv)
        TreeView("Expand", tv, item, 3)
        jitem = GetText$(tv, item)
        p = IndexOf(days[], 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)
            list = Json("GetList", subitem, "Liste")
            anz = Json("Count", list)
            SetText edit1, jitem

            If anz > 0

                Txt = ""
                SetText edit2, ""

                WhileLoop 0, anz - 1

                    txt = txt + Json("GetString", list, &LOOP) + Chr$(13) + Chr$(10)

                EndWhile

                SetText edit2, txt

            EndIf

        EndIf

    EndIf

    If %UMessage = $10

        Json("WRITE", js, File)
        end = 1

    EndIf

EndWhile

Proc InitJson

    js = Create("Json")

    WhileLoop 0, 5

        jtage[&LOOP] = Create("Json")
        Json("AddObject", js, days[&LOOP], jtage[&LOOP])

    EndWhile

ENDPROC

Proc InitTree

    WhileLoop 0, 5

        TreeView("InsertItem", tv, 0, 0, days[&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,monday,tuesday,wednesday,thursday,friday,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$ = stature$("###,###,###,###,###.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$=stature$("00",word(time#,6))+"."+stature$("00",word(time#,2))+"."+stature$("00",word(time#,0))'Last written date
        ctime$=stature$("00",word(time#,8))+":"+stature$("00",word(time#,10))+":"+stature$("00",word(time#,12))'last written time

    else

        cwrite$="00.00.00"
        ctime$="00:00:00"

    endif

    return$ = return$+cwrite$+"|"+ctime$+"|"
    '-----------------------------last grabbed
    FileTimeToLocalFileTime(info#+12,utc#)
    FileTimeToSystemTime(utc#,time#)
    awrite$=""
    atime$=""

    if word(time#,0) >= 1601

        aday$ = Getweekday(word(time#,4))
        return$ = return$+aday$+"|"
        awrite$=stature$("00",word(time#,6))+"."+stature$("00",word(time#,2))+"."+stature$("00",word(time#,0))'Last written date
        atime$=stature$("00",word(time#,8))+":"+stature$("00",word(time#,10))+":"+stature$("00",word(time#,12))'last written time

    else

        awrite$="00.00.00"
        atime$="00:00:00"

    endif

    return$ = return$+awrite$+"|"+atime$+"|"
    '--------------------------- lastly written
    FileTimeToLocalFileTime(info#+20,utc#)
    FileTimeToSystemTime(utc#,time#)
    wwrite$=""
    wtime$=""

    if word(time#,0) >= 1601

        wday$ = Getweekday(word(time#,4))
        return$ = return$+wday$+"|"
        wwrite$=stature$("00",word(time#,6))+"."+stature$("00",word(time#,2))+"."+stature$("00",word(time#,0))'Last written date
        wtime$=stature$("00",word(time#,8))+":"+stature$("00",word(time#,10))+":"+stature$("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
 
Benutze XPROFAN X3 + FREEPROFAN
Wir sind die XProfaner.
Sie werden von uns assimiliert.
Widerstand ist zwecklos!
Wir werden alle ihre Funktionen und Algorithmen den unseren hinzufügen.

Was die Borg können, können wir schon lange.
03/13/23  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

841 Views

Untitledvor 0 min.
Member 862464104/14/24
Manfred Barei12/09/23
H.Brill11/14/23
ecki07/28/23
More...

Themeninformationen

this Topic has 1 subscriber:

H.Brill (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie