;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; AutoIt Version: 3.1.1
; Author:Andrew Calcutt 	Date:09/10/2005
; Script Function: Installs Datatel
;-----------------------------------------------------------------------------
Dim $settings = (@ScriptDir & "\settings.ini")
;-----------------------------------------------------------------------------

Run(@ScriptDir & "\Setup.exe")

WinWaitActive("Welcome", "&Next >", 120)
While WinExists("Datatel: UI Desktop")
	If WinExists("Welcome", "&Next >") Then
		WinActivate("Welcome", "&Next >")
		ControlClick("Welcome", "", "Button1")
	EndIf
	If WinExists("Datatel Software Licensing", "&Yes") Then
		WinActivate("Datatel Software Licensing", "&Yes")
		ControlClick("Datatel Software Licensing", "", "Button2")
	EndIf
	If WinExists("Datatel Installation - DMI Transaction", "Next>>") Then
		WinActivate("Datatel Installation - DMI Transaction", "Next>>")
		ControlSetText("Datatel Installation - DMI Transaction", "", "Edit1", IniRead($settings, "Datatel", "OrganisationName", "")) ;organisation name
		ControlSetText("Datatel Installation - DMI Transaction", "", "Edit2", IniRead($settings, "Datatel", "OrganisationCode", "")) ;organisation code 
		ControlSetText("Datatel Installation - DMI Transaction", "", "Edit3", IniRead($settings, "Datatel", "OrganisationPassword", "")) ;organisation Password
		ControlClick("Datatel Installation - DMI Transaction", "", "Button1")
	EndIf
	If WinExists("Datatel Installation", "User ID:") Then
		WinActivate("Datatel Installation", "User ID:")
		ControlSetText("Datatel Installation", "", "Edit1", IniRead($settings, "Datatel", "UserID", "")) ;User ID
		ControlSetText("Datatel Installation", "", "Edit2", IniRead($settings, "Datatel", "HostName", "")) ;Host Name
		If IniRead($settings, "Datatel", "type", "") = 1 Then ControlClick("Datatel Installation", "", "Button1") ;Unix
		If IniRead($settings, "Datatel", "type", "") = 2 Then ControlClick("Datatel Installation", "", "Button2") ;Windows Nt
		ControlSetText("Datatel Installation", "", "Edit3", IniRead($settings, "Datatel", "Database", "")) ;Database
		ControlSetText("Datatel Installation", "", "Edit4", IniRead($settings, "Datatel", "DatabasePath", "")) ;DataBase Path
		ControlSetText("Datatel Installation", "", "Edit5", IniRead($settings, "Datatel", "UserInterfacePath", "")) ;User Interface path
		ControlClick("Datatel Installation", "", "Button3")
	EndIf
	If WinExists("Setup") Then WinActive("Setup")
	If WinExists("Datatel Installation - Install Information", "Next>>") Then
		WinActivate("Datatel Installation - Install Information", "Next>>")
		ControlClick("Datatel Installation - Install Information", "", "Button1")
	EndIf
	If WinExists("Setup Complete", "Finish") Then
		WinActivate("Setup Complete", "Finish")
		ControlClick("Setup Complete", "", "Button4")
	EndIf
	If WinExists("Datatel: UI Desktop", "") = 0 Then
		ExitLoop
	EndIf
WEnd

RunWait("datatel.bat")
Exit