#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=random generator.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_Run_Tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

;~ Opt("GUICoordMode", 1)

$Teilnehmer = 0
$artangegeben = 0
Local $name[1]


#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Gerechter verteilen", 626, 339, 193, 126)
GUICtrlCreateGroup("Teilnehmer", 16, 16, 169, 233)
$box1 = GUICtrlCreateCheckbox("", 29, 41, 20, 17)
$box2 = GUICtrlCreateCheckbox("", 29, 81, 20, 17)
$box3 = GUICtrlCreateCheckbox("", 29, 121, 20, 17)
$box4 = GUICtrlCreateCheckbox("", 29, 161, 20, 17)
$box5 = GUICtrlCreateCheckbox("", 29, 201, 20, 17)
$Input1 = GUICtrlCreateInput("", 56, 41, 121, 21)
$Input2 = GUICtrlCreateInput("", 56, 81, 121, 21)
$Input3 = GUICtrlCreateInput("", 56, 121, 121, 21)
$Input4 = GUICtrlCreateInput("", 56, 161, 121, 21)
$Input5 = GUICtrlCreateInput("", 56, 201, 121, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("Ausgeloster Teilnehmer", 420, 48, 168, 28)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Welcher Artikel", 420, 158, 168, 28)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("Artikel", 212, 16, 169, 233)
$radio1 = GUICtrlCreateRadio("", 225, 41, 20, 17)
$radio2 = GUICtrlCreateRadio("", 225, 71, 20, 17)
$radio3 = GUICtrlCreateRadio("", 225, 101, 20, 17)
$radio4 = GUICtrlCreateRadio("", 225, 131, 20, 17)
$radio5 = GUICtrlCreateRadio("", 225, 161, 20, 17)
$radio6 = GUICtrlCreateRadio("", 225, 191, 20, 17)
$radio7 = GUICtrlCreateRadio("", 225, 221, 20, 17)
$Input6 = GUICtrlCreateInput("", 252, 41, 121, 21)
$Input7 = GUICtrlCreateInput("", 252, 71, 121, 21)
$Input8 = GUICtrlCreateInput("", 252, 101, 121, 21)
$Input9 = GUICtrlCreateInput("", 252, 131, 121, 21)
$Input10 = GUICtrlCreateInput("", 252, 161, 121, 21)
$Input11 = GUICtrlCreateInput("", 252, 191, 121, 21)
$Input12 = GUICtrlCreateInput("", 252, 221, 121, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Ruettel = GUICtrlCreateButton("Aleae iacent", 16, 272, 585, 49)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$gewinnt = GUICtrlCreateLabel("gewinnt", 420, 102, 168, 28)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Ruettel
			_auslosung()
	EndSwitch
WEnd

Func _auslosung()
	If BitAND(GUICtrlRead($box1), $GUI_CHECKED) = $GUI_CHECKED Then
		$Teilnehmer = $Teilnehmer + 1
		_ArrayAdd($name, GUICtrlRead($Input1))
	EndIf
	If BitAND(GUICtrlRead($box2), $GUI_CHECKED) = $GUI_CHECKED Then
		$Teilnehmer = $Teilnehmer + 1
		_ArrayAdd($name, GUICtrlRead($Input2))
	EndIf
	If BitAND(GUICtrlRead($box3), $GUI_CHECKED) = $GUI_CHECKED Then
		$Teilnehmer = $Teilnehmer + 1
		_ArrayAdd($name, GUICtrlRead($Input3))
	EndIf
	If BitAND(GUICtrlRead($box4), $GUI_CHECKED) = $GUI_CHECKED Then
		$Teilnehmer = $Teilnehmer + 1
		_ArrayAdd($name, GUICtrlRead($Input4))
	EndIf
	If BitAND(GUICtrlRead($box5), $GUI_CHECKED) = $GUI_CHECKED Then
		$Teilnehmer = $Teilnehmer + 1
		_ArrayAdd($name, GUICtrlRead($Input5))
	EndIf

	$gewinner = Random(1, $Teilnehmer, 1)
	If $gewinner = 1 Then
		$name = $name[1]
	EndIf
	If $gewinner = 2 Then
		$name = $name[2]
	EndIf
	If $gewinner = 3 Then
		$name = $name[3]
	EndIf
	If $gewinner = 4 Then
		$name = $name[4]
	EndIf
	If $gewinner = 5 Then
		$name = $name[5]
	EndIf

	If BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED Then
		$artikel = GUICtrlRead($Input6)
		GUICtrlSetData($Label2, $artikel)
		$artangegeben = 1
	EndIf
	If BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED Then
		$artikel = GUICtrlRead($Input7)
		GUICtrlSetData($Label2, $artikel)
		$artangegeben = 1
	EndIf
	If BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED Then
		$artikel = GUICtrlRead($Input8)
		GUICtrlSetData($Label2, $artikel)
		$artangegeben = 1
	EndIf
	If BitAND(GUICtrlRead($radio4), $GUI_CHECKED) = $GUI_CHECKED Then
		$artikel = GUICtrlRead($Input9)
		GUICtrlSetData($Label2, $artikel)
		$artangegeben = 1
	EndIf
	If BitAND(GUICtrlRead($radio5), $GUI_CHECKED) = $GUI_CHECKED Then
		$artikel = GUICtrlRead($Input10)
		GUICtrlSetData($Label2, $artikel)
		$artangegeben = 1
	EndIf
	If BitAND(GUICtrlRead($radio6), $GUI_CHECKED) = $GUI_CHECKED Then
		$artikel = GUICtrlRead($Input11)
		GUICtrlSetData($Label2, $artikel)
		$artangegeben = 1
	EndIf
	If BitAND(GUICtrlRead($radio7), $GUI_CHECKED) = $GUI_CHECKED Then
		$artikel = GUICtrlRead($Input12)
		GUICtrlSetData($Label2, $artikel)
		$artangegeben = 1
	EndIf

	If $Teilnehmer > 0 And $artangegeben = 1 Then
		GUICtrlSetData($Label1, $name)
		GUICtrlSetFont($Label1, 15, 400, 0, "MS Sans Serif")
		GUICtrlSetData($gewinnt, "gewinnt")
		GUICtrlSetFont($gewinnt, 10, 400, 0, "MS Sans Serif")
		GUICtrlSetFont($Label2, 15, 400, 0, "MS Sans Serif")
		$Label3 = GUICtrlCreateLabel("Glückwunsch", 420, 224, 168, 28)
		GUICtrlSetFont($Label3, 20, 400, 0, "MS Sans Serif")
		GUICtrlSetData($Ruettel, "Alea iacta est")
		$fenster = WinGetHandle($Form1)
		_ScreenCapture_CaptureWnd(@WorkingDir & "\" & $name & " " & $artikel & ".jpg", $fenster)
	Else
		If $Teilnehmer < 1 Then
			GUICtrlSetData($Label1, "Teilnehmer")
			GUICtrlSetFont($Label1, 15, 400, 0, "MS Sans Serif")
			GUICtrlSetData($gewinnt, "auswählen")
			GUICtrlSetFont($gewinnt, 15, 400, 0, "MS Sans Serif")
			GUICtrlSetData($Label2, "")

		ElseIf $artangegeben <> 1 Then
			GUICtrlSetData($Label1, "Artikel")
			GUICtrlSetFont($Label1, 15, 400, 0, "MS Sans Serif")
			GUICtrlSetData($gewinnt, "auswählen")
			GUICtrlSetFont($gewinnt, 15, 400, 0, "MS Sans Serif")
			GUICtrlSetData($Label2, "")
		EndIf
	EndIf

	$Teilnehmer = 0
	$artangegeben = 0
	Dim $name[1]
EndFunc   ;==>_auslosung
