#include <Array.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>


Global $aSpalte1[21], $aSpalte2[21], $aSpalte3[21]
Global $DataINI = 'data.ini'
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1050, 596, 257, 234)
$Button1 = GUICtrlCreateButton("Exit", 144, 552, 105, 25)
$Button2 = GUICtrlCreateButton("Speichern", 24, 552, 105, 25)
$Group1 = GUICtrlCreateGroup("", 8, 536, 257, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 8, 96, 1025, 425)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("", 8, 48, 249, 41)
$Label1 = GUICtrlCreateLabel("Lagerort:", 16, 64, 46, 17)
$Input1 = GUICtrlCreateInput("", 72, 64, 177, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("", 8, 8, 249, 33)
$Combo1 = GUICtrlCreateCombo("", 72, 16, 177, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData($Combo1,_setCombo())
$Label2 = GUICtrlCreateLabel("Eintrag", 16, 16, 37, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
_generateLagerSpalte($aSpalte1,20)
_generateLagerSpalte($aSpalte2,360)
_generateLagerSpalte($aSpalte3,720)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Combo1
			_LoadData()
	EndSwitch
WEnd


Func _generateLagerSpalte(ByRef $ArrayToUse,$left)
    $Abstand = 19
    For $i = 1 To UBound($ArrayToUse)-1
        GUICtrlCreateLabel(' Lagerplatz ' & $i,$left,100+$Abstand,90)
        $ArrayToUse[$i] = GUICtrlCreateInput("",80+$left,100+$Abstand,170)
        $Abstand +=19
    Next
EndFunc

Func _LoadData()
	For $i = 1 To UBound($aSpalte1)-1
		$return = GUICtrlSetData($aSpalte1[$i],IniRead($DataINI,GUICtrlRead($Combo1),1&$i,''))
	Next
	For $i = 1 To UBound($aSpalte2)-1
		$return = GUICtrlSetData($aSpalte2[$i],IniRead($DataINI,GUICtrlRead($Combo1),2&$i,''))
	Next
	For $i = 1 To UBound($aSpalte3)-1
		$return = GUICtrlSetData($aSpalte3[$i],IniRead($DataINI,GUICtrlRead($Combo1),3&$i,''))
	Next
EndFunc

Func _setCombo()
	Local $Sections = IniReadSectionNames($DataINI)
	Local $SectionString = _ArrayToString($Sections,'|',1,UBound($Sections)-1)
	Return($SectionString)
EndFunc

