Sign in to follow this  
Followers 0
danusko

GUI - script Menu

5 posts in this topic

Hi,

please can you help me? One of member this forum helps me a lot with this little program. Now is this program almost done, but some funcionality i need improve but i don know how.

What this program does:

There are menus for each working day. Each day has 5 types of meals. Source of this meal is in file "recepty1.txt" (1,2,3). After the program is launched it shows menus for each day. Every meal can be used only once. After all the menus have been used, they can be used again for menu creation

What I need to do:

- after the program is started I can load the first meals from source files (for each types in each day)

- meals loading doesn't work automatically at this moment. The user has to manually select a meal he/she wants to choose for creating a menu. I would prefer to load the first unused meal for each day and each type after the program is lanched

- The work should be saved after I click the "OK" button not during the menu creation (as it is at the present)

thanks for help

DATA.ZIP

Share this post


Link to post
Share on other sites



Here is first optimization:

#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>

Opt('GUIOnEventMode',1)

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=c:\documents and settings\daniel\plocha\ondro menu\menu2.kxf
$Form2 = GUICreate("Recepty", 801, 660, -1, -1)
GUISetBkColor(0xA6CAF0)
$Group1 = GUICtrlCreateGroup("Pondelok", 8, 80, 777, 97)
$Label1 = GUICtrlCreateLabel("A)", 32, 104, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("B)", 32, 130, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("C)", 32, 155, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("P)", 412, 104, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("V)", 413, 130, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label26 = GUICtrlCreateLabel("Recept 1", 72, 104, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label27 = GUICtrlCreateLabel("Recept 2", 72, 130, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label28 = GUICtrlCreateLabel("Recept 3", 72, 155, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label29 = GUICtrlCreateLabel("Recept 4", 457, 104, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label30 = GUICtrlCreateLabel("Recept 5", 457, 130, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Utorok", 8, 186, 777, 97)
$Label6 = GUICtrlCreateLabel("A)", 32, 210, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label7 = GUICtrlCreateLabel("B)", 32, 236, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label8 = GUICtrlCreateLabel("C)", 32, 261, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label9 = GUICtrlCreateLabel("P)", 412, 210, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel("V)", 413, 236, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label31 = GUICtrlCreateLabel("Recept 2", 67, 239, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label32 = GUICtrlCreateLabel("Recept 1", 67, 213, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label33 = GUICtrlCreateLabel("Recept 3", 67, 264, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label34 = GUICtrlCreateLabel("Recept 4", 452, 213, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label35 = GUICtrlCreateLabel("Recept 5", 452, 239, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Streda", 8, 293, 777, 97)
$Label11 = GUICtrlCreateLabel("A)", 32, 317, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label12 = GUICtrlCreateLabel("B)", 32, 343, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label13 = GUICtrlCreateLabel("C)", 32, 368, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label14 = GUICtrlCreateLabel("P)", 412, 317, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label15 = GUICtrlCreateLabel("V)", 413, 343, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label36 = GUICtrlCreateLabel("Recept 2", 68, 346, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label37 = GUICtrlCreateLabel("Recept 1", 68, 320, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label38 = GUICtrlCreateLabel("Recept 3", 68, 371, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label39 = GUICtrlCreateLabel("Recept 4", 453, 320, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label40 = GUICtrlCreateLabel("Recept 5", 453, 346, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("Štvrtok", 7, 399, 777, 97)
$Label16 = GUICtrlCreateLabel("A)", 31, 423, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label17 = GUICtrlCreateLabel("B)", 31, 449, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label18 = GUICtrlCreateLabel("C)", 31, 474, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label19 = GUICtrlCreateLabel("P)", 411, 423, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label20 = GUICtrlCreateLabel("V)", 412, 449, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label41 = GUICtrlCreateLabel("Recept 2", 70, 453, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label42 = GUICtrlCreateLabel("Recept 1", 70, 427, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label43 = GUICtrlCreateLabel("Recept 3", 70, 478, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label44 = GUICtrlCreateLabel("Recept 4", 455, 427, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label45 = GUICtrlCreateLabel("Recept 5", 455, 453, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("Piatok", 8, 505, 777, 97)
$Label21 = GUICtrlCreateLabel("A)", 32, 529, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label22 = GUICtrlCreateLabel("B)", 32, 555, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label23 = GUICtrlCreateLabel("C)", 32, 580, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label24 = GUICtrlCreateLabel("P)", 412, 529, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label25 = GUICtrlCreateLabel("V)", 413, 555, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label46 = GUICtrlCreateLabel("Recept 2", 72, 558, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label47 = GUICtrlCreateLabel("Recept 1", 72, 532, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label48 = GUICtrlCreateLabel("Recept 3", 72, 583, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label49 = GUICtrlCreateLabel("Recept 4", 457, 532, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label50 = GUICtrlCreateLabel("Recept 5", 457, 558, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$MyButton1 = GUICtrlCreateButton("OK", 184, 616, 284, 30, $BS_FLAT)
GUICtrlSetOnEvent(-1,'CloseEvent')
GUICtrlSetCursor (-1, 2)
$MyButton2 = GUICtrlCreateButton("Zruš", 520, 616, 100, 30, $BS_FLAT)
GUICtrlSetOnEvent(-1,'CloseEvent')
$Label51 = GUICtrlCreateLabel("Recepty šéfkuchára", 288, 24, 227, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0000FF)
GUISetOnEvent($GUI_EVENT_CLOSE,'CloseEvent')
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$cesta = @ScriptDir & '\DATA\'
$dnes = '|' & @YEAR & '-' & @MON & '-' & @MDAY & '|'

 $File1 = $cesta & "recepty1.txt"
 $File2 = $cesta & "recepty2.txt"
 $File3 = $cesta & "recepty3.txt"
 $File4 = $cesta & "recepty4.txt"
 $File5 = $cesta & "recepty5.txt"
  
; If @Error Then 
    ; $pocet_souboru = 0
; Else
    ; $pocet_souboru = UBound($FileList) - 1
; EndIf

; automaticky nacist nove recepty pri otevreni
AutoNacteni()

While 1
    Sleep(100)
WEnd

Func AutoNacteni()
    LabelEvent_Main($File1, $Label26)
    LabelEvent_Main($File1, $Label32)
    LabelEvent_Main($File1, $Label37)
    LabelEvent_Main($File1, $Label42)
    LabelEvent_Main($File1, $Label47)

    LabelEvent_Main($File2, $Label27)
    LabelEvent_Main($File2, $Label31)
    LabelEvent_Main($File2, $Label36)
    LabelEvent_Main($File2, $Label41)
    LabelEvent_Main($File2, $Label46)
#cs
    ; doplnit ostatni odpovidajici cisla labelu ...
    LabelEvent_Main($File3, $Labelxx)
    LabelEvent_Main($File3, $Labelxx)
    LabelEvent_Main($File3, $Labelxx)
    LabelEvent_Main($File3, $Labelxx)
    LabelEvent_Main($File3, $Labelxx)

    LabelEvent_Main($File4, $Labelxx)
    LabelEvent_Main($File4, $Labelxx)
    LabelEvent_Main($File4, $Labelxx)
    LabelEvent_Main($File4, $Labelxx)
    LabelEvent_Main($File4, $Labelxx)

    LabelEvent_Main($File5, $Labelxx)
    LabelEvent_Main($File5, $Labelxx)
    LabelEvent_Main($File5, $Labelxx)
    LabelEvent_Main($File5, $Labelxx)
    LabelEvent_Main($File5, $Labelxx)
#ce
EndFunc

Func LabelEvent1()
    LabelEvent_Main($File1, @GUI_CtrlId)
EndFunc

Func LabelEvent2()
    LabelEvent_Main($File2, @GUI_CtrlId)
EndFunc

Func LabelEvent3()
    LabelEvent_Main($File3, @GUI_CtrlId)
EndFunc

Func LabelEvent4()
    LabelEvent_Main($File4, @GUI_CtrlId)
EndFunc

Func LabelEvent5()
    LabelEvent_Main($File5, @GUI_CtrlId)
EndFunc

; jako vst. parametry jsou nazev souboru z nehoz nacitat recepty
; a ControlID labelu jenz se bude aktualizovat
Func LabelEvent_Main($soubor, $control)
;~  MsgBox(0,'',GUICtrlRead($control))
;~  ConsoleWrite($dnes & @CRLF)
    $pokus = 0
        While 1
        $pokus += 1
;~   ConsoleWrite($i & @CRLF)
        $pocet_radku = _FileCountLines($soubor)
        $j = Random(1,$pocet_radku,1) ; nahodne cislo radku v souboru
;~   ConsoleWrite($j & @CRLF)
        $radek = FileReadLine($soubor, $j)
;~   ConsoleWrite($radek & @CRLF)
                ; |2007-05-28|
        If StringLeft($radek,1) <> '|' Then
            _FileWriteToLine($soubor, $j, $dnes & $radek, 1)
            GUICtrlSetData($control,$radek)
            ExitLoop
        ElseIf StringLeft($radek,12) <> $dnes Then
            _FileWriteToLine($soubor, $j, $dnes & StringTrimLeft($radek,12), 1)
            GUICtrlSetData($control,StringTrimLeft($radek,12))
            ExitLoop
        EndIf
            ; pozn: pokud je na nalezenem nahodnem radku dnesni datum tak hledat znovu (jiny nahodny radek)
        If $pokus > 100 Then ; maximalne 100 pokusu
          MsgBox(48,'POZOR','Všetky recepty tohto druhu už boli použité. Začínam znovu.')
FileCopy("C:\Documents and Settings\Daniel\Desktop\old desktop\ondro menu\DATA\origi\*.txt", "C:\Documents and Settings\Daniel\Desktop\old desktop\ondro menu\DATA\*.*",1)
            ExitLoop
        EndIf
    WEnd
EndFunc

Func CloseEvent()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Hi Zedna,

i look on it only very quick but it looks very good. I try some action and it seems, thats all works as i want.

Later I am going to look on it a little better.

Zedna i am very very thankeful.

Here is first optimization:

#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>

Opt('GUIOnEventMode',1)

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=c:\documents and settings\daniel\plocha\ondro menu\menu2.kxf
$Form2 = GUICreate("Recepty", 801, 660, -1, -1)
GUISetBkColor(0xA6CAF0)
$Group1 = GUICtrlCreateGroup("Pondelok", 8, 80, 777, 97)
$Label1 = GUICtrlCreateLabel("A)", 32, 104, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("B)", 32, 130, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("C)", 32, 155, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("P)", 412, 104, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("V)", 413, 130, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label26 = GUICtrlCreateLabel("Recept 1", 72, 104, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label27 = GUICtrlCreateLabel("Recept 2", 72, 130, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label28 = GUICtrlCreateLabel("Recept 3", 72, 155, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label29 = GUICtrlCreateLabel("Recept 4", 457, 104, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label30 = GUICtrlCreateLabel("Recept 5", 457, 130, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Utorok", 8, 186, 777, 97)
$Label6 = GUICtrlCreateLabel("A)", 32, 210, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label7 = GUICtrlCreateLabel("B)", 32, 236, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label8 = GUICtrlCreateLabel("C)", 32, 261, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label9 = GUICtrlCreateLabel("P)", 412, 210, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel("V)", 413, 236, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label31 = GUICtrlCreateLabel("Recept 2", 67, 239, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label32 = GUICtrlCreateLabel("Recept 1", 67, 213, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label33 = GUICtrlCreateLabel("Recept 3", 67, 264, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label34 = GUICtrlCreateLabel("Recept 4", 452, 213, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label35 = GUICtrlCreateLabel("Recept 5", 452, 239, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Streda", 8, 293, 777, 97)
$Label11 = GUICtrlCreateLabel("A)", 32, 317, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label12 = GUICtrlCreateLabel("B)", 32, 343, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label13 = GUICtrlCreateLabel("C)", 32, 368, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label14 = GUICtrlCreateLabel("P)", 412, 317, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label15 = GUICtrlCreateLabel("V)", 413, 343, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label36 = GUICtrlCreateLabel("Recept 2", 68, 346, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label37 = GUICtrlCreateLabel("Recept 1", 68, 320, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label38 = GUICtrlCreateLabel("Recept 3", 68, 371, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label39 = GUICtrlCreateLabel("Recept 4", 453, 320, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label40 = GUICtrlCreateLabel("Recept 5", 453, 346, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("tvrtok", 7, 399, 777, 97)
$Label16 = GUICtrlCreateLabel("A)", 31, 423, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label17 = GUICtrlCreateLabel("B)", 31, 449, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label18 = GUICtrlCreateLabel("C)", 31, 474, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label19 = GUICtrlCreateLabel("P)", 411, 423, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label20 = GUICtrlCreateLabel("V)", 412, 449, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label41 = GUICtrlCreateLabel("Recept 2", 70, 453, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label42 = GUICtrlCreateLabel("Recept 1", 70, 427, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label43 = GUICtrlCreateLabel("Recept 3", 70, 478, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label44 = GUICtrlCreateLabel("Recept 4", 455, 427, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label45 = GUICtrlCreateLabel("Recept 5", 455, 453, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("Piatok", 8, 505, 777, 97)
$Label21 = GUICtrlCreateLabel("A)", 32, 529, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label22 = GUICtrlCreateLabel("B)", 32, 555, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label23 = GUICtrlCreateLabel("C)", 32, 580, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label24 = GUICtrlCreateLabel("P)", 412, 529, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label25 = GUICtrlCreateLabel("V)", 413, 555, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label46 = GUICtrlCreateLabel("Recept 2", 72, 558, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label47 = GUICtrlCreateLabel("Recept 1", 72, 532, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label48 = GUICtrlCreateLabel("Recept 3", 72, 583, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label49 = GUICtrlCreateLabel("Recept 4", 457, 532, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label50 = GUICtrlCreateLabel("Recept 5", 457, 558, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$MyButton1 = GUICtrlCreateButton("OK", 184, 616, 284, 30, $BS_FLAT)
GUICtrlSetOnEvent(-1,'CloseEvent')
GUICtrlSetCursor (-1, 2)
$MyButton2 = GUICtrlCreateButton("Zru", 520, 616, 100, 30, $BS_FLAT)
GUICtrlSetOnEvent(-1,'CloseEvent')
$Label51 = GUICtrlCreateLabel("Recepty éfkuchára", 288, 24, 227, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0000FF)
GUISetOnEvent($GUI_EVENT_CLOSE,'CloseEvent')
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$cesta = @ScriptDir & '\DATA\'
$dnes = '|' & @YEAR & '-' & @MON & '-' & @MDAY & '|'

 $File1 = $cesta & "recepty1.txt"
 $File2 = $cesta & "recepty2.txt"
 $File3 = $cesta & "recepty3.txt"
 $File4 = $cesta & "recepty4.txt"
 $File5 = $cesta & "recepty5.txt"
  
; If @Error Then 
    ; $pocet_souboru = 0
; Else
    ; $pocet_souboru = UBound($FileList) - 1
; EndIf

; automaticky nacist nove recepty pri otevreni
AutoNacteni()

While 1
    Sleep(100)
WEnd

Func AutoNacteni()
    LabelEvent_Main($File1, $Label26)
    LabelEvent_Main($File1, $Label32)
    LabelEvent_Main($File1, $Label37)
    LabelEvent_Main($File1, $Label42)
    LabelEvent_Main($File1, $Label47)

    LabelEvent_Main($File2, $Label27)
    LabelEvent_Main($File2, $Label31)
    LabelEvent_Main($File2, $Label36)
    LabelEvent_Main($File2, $Label41)
    LabelEvent_Main($File2, $Label46)
#cs
    ; doplnit ostatni odpovidajici cisla labelu ...
    LabelEvent_Main($File3, $Labelxx)
    LabelEvent_Main($File3, $Labelxx)
    LabelEvent_Main($File3, $Labelxx)
    LabelEvent_Main($File3, $Labelxx)
    LabelEvent_Main($File3, $Labelxx)

    LabelEvent_Main($File4, $Labelxx)
    LabelEvent_Main($File4, $Labelxx)
    LabelEvent_Main($File4, $Labelxx)
    LabelEvent_Main($File4, $Labelxx)
    LabelEvent_Main($File4, $Labelxx)

    LabelEvent_Main($File5, $Labelxx)
    LabelEvent_Main($File5, $Labelxx)
    LabelEvent_Main($File5, $Labelxx)
    LabelEvent_Main($File5, $Labelxx)
    LabelEvent_Main($File5, $Labelxx)
#ce
EndFunc

Func LabelEvent1()
    LabelEvent_Main($File1, @GUI_CtrlId)
EndFunc

Func LabelEvent2()
    LabelEvent_Main($File2, @GUI_CtrlId)
EndFunc

Func LabelEvent3()
    LabelEvent_Main($File3, @GUI_CtrlId)
EndFunc

Func LabelEvent4()
    LabelEvent_Main($File4, @GUI_CtrlId)
EndFunc

Func LabelEvent5()
    LabelEvent_Main($File5, @GUI_CtrlId)
EndFunc

; jako vst. parametry jsou nazev souboru z nehoz nacitat recepty
; a ControlID labelu jenz se bude aktualizovat
Func LabelEvent_Main($soubor, $control)
;~  MsgBox(0,'',GUICtrlRead($control))
;~  ConsoleWrite($dnes & @CRLF)
    $pokus = 0
        While 1
        $pokus += 1
;~   ConsoleWrite($i & @CRLF)
        $pocet_radku = _FileCountLines($soubor)
        $j = Random(1,$pocet_radku,1) ; nahodne cislo radku v souboru
;~   ConsoleWrite($j & @CRLF)
        $radek = FileReadLine($soubor, $j)
;~   ConsoleWrite($radek & @CRLF)
                ; |2007-05-28|
        If StringLeft($radek,1) <> '|' Then
            _FileWriteToLine($soubor, $j, $dnes & $radek, 1)
            GUICtrlSetData($control,$radek)
            ExitLoop
        ElseIf StringLeft($radek,12) <> $dnes Then
            _FileWriteToLine($soubor, $j, $dnes & StringTrimLeft($radek,12), 1)
            GUICtrlSetData($control,StringTrimLeft($radek,12))
            ExitLoop
        EndIf
            ; pozn: pokud je na nalezenem nahodnem radku dnesni datum tak hledat znovu (jiny nahodny radek)
        If $pokus > 100 Then ; maximalne 100 pokusu
          MsgBox(48,'POZOR','Vetky recepty tohto druhu u boli pouité. Začínam znovu.')
FileCopy("C:\Documents and Settings\Daniel\Desktop\old desktop\ondro menu\DATA\origi\*.txt", "C:\Documents and Settings\Daniel\Desktop\old desktop\ondro menu\DATA\*.*",1)
            ExitLoop
        EndIf
    WEnd
EndFunc

Func CloseEvent()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Here is next version (not tested):

#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>

Opt('GUIOnEventMode',1)

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=c:\documents and settings\daniel\plocha\ondro menu\menu2.kxf
$Form2 = GUICreate("Recepty", 801, 660, -1, -1)
GUISetBkColor(0xA6CAF0)
$Group1 = GUICtrlCreateGroup("Pondelok", 8, 80, 777, 97)
$Label1 = GUICtrlCreateLabel("A)", 32, 104, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("B)", 32, 130, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("C)", 32, 155, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("P)", 412, 104, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("V)", 413, 130, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label26 = GUICtrlCreateLabel("Recept 1", 72, 104, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label27 = GUICtrlCreateLabel("Recept 2", 72, 130, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label28 = GUICtrlCreateLabel("Recept 3", 72, 155, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label29 = GUICtrlCreateLabel("Recept 4", 457, 104, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label30 = GUICtrlCreateLabel("Recept 5", 457, 130, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Utorok", 8, 186, 777, 97)
$Label6 = GUICtrlCreateLabel("A)", 32, 210, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label7 = GUICtrlCreateLabel("B)", 32, 236, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label8 = GUICtrlCreateLabel("C)", 32, 261, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label9 = GUICtrlCreateLabel("P)", 412, 210, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel("V)", 413, 236, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label31 = GUICtrlCreateLabel("Recept 2", 67, 239, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label32 = GUICtrlCreateLabel("Recept 1", 67, 213, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label33 = GUICtrlCreateLabel("Recept 3", 67, 264, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label34 = GUICtrlCreateLabel("Recept 4", 452, 213, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label35 = GUICtrlCreateLabel("Recept 5", 452, 239, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Streda", 8, 293, 777, 97)
$Label11 = GUICtrlCreateLabel("A)", 32, 317, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label12 = GUICtrlCreateLabel("B)", 32, 343, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label13 = GUICtrlCreateLabel("C)", 32, 368, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label14 = GUICtrlCreateLabel("P)", 412, 317, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label15 = GUICtrlCreateLabel("V)", 413, 343, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label36 = GUICtrlCreateLabel("Recept 2", 68, 346, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label37 = GUICtrlCreateLabel("Recept 1", 68, 320, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label38 = GUICtrlCreateLabel("Recept 3", 68, 371, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label39 = GUICtrlCreateLabel("Recept 4", 453, 320, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label40 = GUICtrlCreateLabel("Recept 5", 453, 346, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("Štvrtok", 7, 399, 777, 97)
$Label16 = GUICtrlCreateLabel("A)", 31, 423, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label17 = GUICtrlCreateLabel("B)", 31, 449, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label18 = GUICtrlCreateLabel("C)", 31, 474, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label19 = GUICtrlCreateLabel("P)", 411, 423, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label20 = GUICtrlCreateLabel("V)", 412, 449, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label41 = GUICtrlCreateLabel("Recept 2", 70, 453, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label42 = GUICtrlCreateLabel("Recept 1", 70, 427, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label43 = GUICtrlCreateLabel("Recept 3", 70, 478, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label44 = GUICtrlCreateLabel("Recept 4", 455, 427, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label45 = GUICtrlCreateLabel("Recept 5", 455, 453, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("Piatok", 8, 505, 777, 97)
$Label21 = GUICtrlCreateLabel("A)", 32, 529, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label22 = GUICtrlCreateLabel("B)", 32, 555, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label23 = GUICtrlCreateLabel("C)", 32, 580, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label24 = GUICtrlCreateLabel("P)", 412, 529, 17, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label25 = GUICtrlCreateLabel("V)", 413, 555, 16, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label46 = GUICtrlCreateLabel("Recept 2", 72, 558, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent2')
$Label47 = GUICtrlCreateLabel("Recept 1", 72, 532, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent1')
$Label48 = GUICtrlCreateLabel("Recept 3", 72, 583, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent3')
$Label49 = GUICtrlCreateLabel("Recept 4", 457, 532, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent4')
$Label50 = GUICtrlCreateLabel("Recept 5", 457, 558, 305, 17)
GUICtrlSetOnEvent(-1,'LabelEvent5')
GUICtrlCreateGroup("", -99, -99, 1, 1)
$MyButton1 = GUICtrlCreateButton("OK", 184, 616, 284, 30, $BS_FLAT)
GUICtrlSetOnEvent(-1,'OKEvent')
GUICtrlSetCursor (-1, 2)
$MyButton2 = GUICtrlCreateButton("Zruš", 520, 616, 100, 30, $BS_FLAT)
GUICtrlSetOnEvent(-1,'CloseEvent')
$Label51 = GUICtrlCreateLabel("Recepty šéfkuchára", 288, 24, 227, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0000FF)
GUISetOnEvent($GUI_EVENT_CLOSE,'CloseEvent')
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$datum = @YEAR & '-' & @MON & '-' & @MDAY
$dnes = '|' & $datum & '|'
$dnes_prizn = '*' & $datum & '*'

$cesta = @ScriptDir & '\DATA\'
$File1 = $cesta & "recepty1.txt"
$File2 = $cesta & "recepty2.txt"
$File3 = $cesta & "recepty3.txt"
$File4 = $cesta & "recepty4.txt"
$File5 = $cesta & "recepty5.txt"

; automaticky nacist nove recepty pri otevreni
AutoNacteni()

While 1
    Sleep(100)
WEnd

Func AutoNacteni()
    NactiRecept($File1, $Label26)
    NactiRecept($File1, $Label32)
    NactiRecept($File1, $Label37)
    NactiRecept($File1, $Label42)
    NactiRecept($File1, $Label47)

    NactiRecept($File2, $Label27)
    NactiRecept($File2, $Label31)
    NactiRecept($File2, $Label36)
    NactiRecept($File2, $Label41)
    NactiRecept($File2, $Label46)
#cs
    ; doplnit ostatni odpovidajici cisla labelu ...
    NactiRecept($File3, $Labelxx)
    NactiRecept($File3, $Labelxx)
    NactiRecept($File3, $Labelxx)
    NactiRecept($File3, $Labelxx)
    NactiRecept($File3, $Labelxx)

    NactiRecept($File4, $Labelxx)
    NactiRecept($File4, $Labelxx)
    NactiRecept($File4, $Labelxx)
    NactiRecept($File4, $Labelxx)
    NactiRecept($File4, $Labelxx)

    NactiRecept($File5, $Labelxx)
    NactiRecept($File5, $Labelxx)
    NactiRecept($File5, $Labelxx)
    NactiRecept($File5, $Labelxx)
    NactiRecept($File5, $Labelxx)
#ce
EndFunc

Func LabelEvent1()
    NactiRecept($File1, @GUI_CtrlId)
EndFunc

Func LabelEvent2()
    NactiRecept($File2, @GUI_CtrlId)
EndFunc

Func LabelEvent3()
    NactiRecept($File3, @GUI_CtrlId)
EndFunc

Func LabelEvent4()
    NactiRecept($File4, @GUI_CtrlId)
EndFunc

Func LabelEvent5()
    NactiRecept($File5, @GUI_CtrlId)
EndFunc

; jako vst. parametry jsou nazev souboru z nehoz nacitat recept
; a ControlID labelu jenz se bude aktualizovat
; nastavi se jen priznak *, az tl. OK to potvrdi
Func NactiRecept($soubor, $control)
    $pokus = 0
        While 1
        $pokus += 1
        $pocet_radku = _FileCountLines($soubor)
        $j = Random(1,$pocet_radku,1) ; nahodne cislo radku v souboru
        $radek = FileReadLine($soubor, $j)
                ; *2007-05-28* --> priznak dnesniho datumu
        ; |2007-05-28| --> potvrzene dnesni datum

        If StringLeft($radek,1) <> '|' And StringLeft($radek,1) <> '*' Then
                        ; pokud jeste neni na danem radku zapsane zadne datum, zapsat dnesni datum s priznakem a vybrat ho
            _FileWriteToLine($soubor, $j, $dnes_prizn & $radek, 1)
                    GUICtrlSetData($control,$radek)
        ElseIf StringLeft($radek,12) <> $dnes And StringLeft($radek,12) <> $dnes_prizn Then
                        ; pokud je na danem radku zapsane jine nez dnesni datum, zapsat dnesni datum s priznakem a vybrat ho
            _FileWriteToLine($soubor, $j, $dnes_prizn & StringTrimLeft($radek,12), 1)
            GUICtrlSetData($control,StringTrimLeft($radek,12))
            ExitLoop
        EndIf

            ; pozn: pokud je na nalezenem nahodnem radku dnesni datum tak hledat znovu (jiny nahodny radek)
        If $pokus > 100 Then ; maximalne 100 pokusu
          MsgBox(48,'POZOR','Všetky recepty tohto druhu už boli použité. Začínam znovu.')
FileCopy("C:\Documents and Settings\Daniel\Desktop\old desktop\ondro menu\DATA\origi\*.txt", "C:\Documents and Settings\Daniel\Desktop\old desktop\ondro menu\DATA\*.*",1)
            ExitLoop
        EndIf
    WEnd
EndFunc

Func OKEvent()
    ; u vsech souboru nahradi priznak *
    NahradPriznak($File1, $dnes)
    NahradPriznak($File2, $dnes)
    NahradPriznak($File3, $dnes)
    NahradPriznak($File4, $dnes)
    NahradPriznak($File5, $dnes)
EndFunc

; zameni priznak * u vsech radku daneho souboru
Func NahradPriznak($soubor, $novy_priznak)
    $text = FileRead($soubor)
    $text = StringReplace($text, $dnes_prizn, $novy_priznak)
    FileDelete($soubor)
    FileWrite($soubor,$text)
EndFunc

Func CloseEvent()
    ; u vsech souboru nahradi priznak *
    NahradPriznak($File1, '')
    NahradPriznak($File2, '')
    NahradPriznak($File3, '')
    NahradPriznak($File4, '')
    NahradPriznak($File5, '')
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0