#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Func.au3>




;********************************************GUI 1 ********************************************
$gui1=GUICreate ("Kamerabildspeicher",500,300,500,260)
GUISetOnEvent(-3, "_Exit")
GUISetState (@sw_show)
$Group = GUICtrlCreateGroup ("Bild",8,8,370,280)
$Zeit = GUICtrlCreateLabel ("Zeit" , 15,23,180,20)
Global $Rand = 1
$Buttonaendern        = GUICtrlCreateButton ("Nächstes Bild",  400,20,90,35)
$Buttonvorher         = GUICtrlCreateButton ("Vorheriges Bild",400,60,90,35)
$ButtonBildAufnehmen  = GUICtrlCreateButton ("Bild Aufnahmen", 400,100,90,35)
$Buttoeinstellung     = GUICtrlCreateButton ("Einstellung",   400,140,90,35)


;*****************************************GUI Einstellung****************************************
$hConfigGui = GUICreate("Edit Connection", 300, 200)
GUISetOnEvent(-4, "_CancelConfigGui")
GUICtrlCreateLabel("Geben Sie die URL Adresse der Kamera an",20,10,250,20)
GLOBAL $GUIPfad = GUICtrlCreateInput ("Datenpfad",20,30,250,20)
GUICtrlCreateLabel("Geben Sie die Anzahl der zu Speichernden Bilder an",20,70,250,20)
GLOBAL $GUIAnzahl   = GUICtrlCreateInput ("10",20,90,100,20,$ES_NUMBER)
$Buttonspeichern = GUICtrlCreateButton ("Speichern",100,150,100,35)

;Zeige GUI 1 an
GUISetState (@sw_show,$gui1)


;*********************************************************************************************
 RandPic ()
 LoadConfigGui()

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1] ; window-handle
        Case $gui1
            Switch $msg[0] ; event/control-handle
			   Case $Buttoeinstellung
			        LoadConfigGui()
                    GUISetState(@SW_SHOW, $hConfigGui)
					;GUISetState(@SW_HIDE, $gui1)
			   Case $Buttonaendern 
				  IF $Rand > $Anzahl-1 Then
					 $Rand = 1
				  Else
				  $Rand = $Rand +1
				  EndIf
				  RandPic ()
				  
				  
			   Case  $Buttonvorher
				  IF $Rand < 2 Then
					 $Rand = 1
				  ELSE 
				  $Rand = $Rand -1
				  EndIf
				  RandPic ()
				  
				  
			   Case $ButtonBildAufnehmen
				  _BildAufnahmen()
				  RandPic ()				  
			   Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $hConfigGui
            Switch $msg[0]
                
                Case $GUI_EVENT_CLOSE  
                    GUISetState(@SW_SHOW, $gui1)
                    GUISetState(@SW_HIDE, $hConfigGui)
				 Case $Buttonspeichern
					SaveConfigGui()
					LoadConfigGui()
                    GUISetState(@SW_SHOW, $gui1)
                    GUISetState(@SW_HIDE, $hConfigGui)	
			   
            EndSwitch
    EndSwitch
WEnd




Func RandPic ()
 
GUICtrlCreatePic ( @ScriptDir & "\Bilder\Bild"&$Rand&".jpg",15,24,350,250)
Local $t = FileGetTime(@ScriptDir & "\Bilder\Bild"&$Rand&".jpg", 2)
If Not @error Then
    Local $yyyymd = "    Tag  "& $t[2] & "." & $t[1]&"." & $t[0] & "  Zeit:  " & $t[3]& ":" & $t[4] & ":" & $t[5]
    GUICtrlSetData ($Group,"Bild"&$Rand&"."&$yyyymd)
 EndIf
  
EndFunc


;Werte Speicherin 
Func SaveConfigGui()
   $Pfad = GUICtrlRead ($GUIPfad)
   $Anzahl = GUICtrlRead ($GUIAnzahl)
   _SaveConfigGui()
	
EndFunc

;Werte Laden
Func LoadConfigGui()
   _LoadConfigGui()
   GUICtrlSetData ($GUIPfad,$Pfad)
   GUICtrlSetData ($GUIAnzahl,$Anzahl)
		
 EndFunc
 
 