Code: Select all
on updateTop5WelderMonth
put revOpenDatabase("MySQL",dbAddr,dbName,dbUser,dbPass) into tResult
if tResult is a number then
put tResult into gConnectionID
else
put empty into gConnectionID
answer error "Unable to connect to the database:" & cr & tResult
BREAK
end if
put "SELECT cworker, Count(*) FROM nonc WHERE cworker REGEXP '^[0-9]+$' and cat = 'welder' and errordate > DATE_SUB(NOW(), INTERVAL 1 MONTH) group by cworker order by count(Cworker) desc" into tSQL
put revDataFromQuery(comma, cr, gConnectionID, tSQL) into Top5WMonth
put 1 into Top5M
put "0" into AllTimeAvg
put "0" into TotalEmp
repeat for each line tLine in Top5WMonth
put item 2 of tLine into TopAvg
put AllTimeAvg + TopAvg into AllTimeAvg
put TotalEmp + "1" into TotalEmp
end repeat
put AllTimeAvg / TotalEmp into aAvg
put the round of aAvg into aAvg
put "Avg/Emp = " & aAvg & " pink slips" into fld "Top10MWA"
repeat for each line tLine in Top5WMonth
put item 1 of tLine into Top51M
put item 2 of tLine into Top52M
switch Top5M
case "1"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top1MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top1MW" to green
else
set the backgroundColor of fld "Top1MW" to red
end if
if aAvg = Top25M then
set the backgroundColor of fld "Top1MW" to yellow
end if
break
case "2"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top2MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top2MW" to green
else
set the backgroundColor of fld "Top2MW" to red
end if
if aAvg = Top25M then
set the backgroundColor of fld "Top2MW" to yellow
end if
break
case "3"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top3MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top3MW" to green
else
set the backgroundColor of fld "Top3MW" to red
end if
if aAvg = Top25M then
set the backgroundColor of fld "Top3MW" to yellow
end if
break
case "4"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top4MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top4MW" to green
else
set the backgroundColor of fld "Top4MW" to red
end if
put aAvg into fld "Field1"
put Top52M after fld "Field1"
if aAvg = Top25M then
set the backgroundColor of fld "Top4MW" to yellow
end if
break
case "5"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top5MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top5MW" to green
else
set the backgroundColor of fld "Top5MW" to red
end if
if aAvg = Top25M then
set the backgroundColor of fld "Top5MW" to yellow
end if
break
case "6"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top6MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top6MW" to green
else
set the backgroundColor of fld "Top6MW" to red
end if
if aAvg = Top25M then
set the backgroundColor of fld "Top6MW" to yellow
end if
break
case "7"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top7MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top7MW" to green
else
set the backgroundColor of fld "Top7MW" to red
end if
if aAvg = Top25M then
set the backgroundColor of fld "Top7MW" to yellow
end if
break
case "8"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top8MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top8MW" to green
else
set the backgroundColor of fld "Top8MW" to red
end if
if aAvg = Top25M then
set the backgroundColor of fld "Top8MW" to yellow
end if
break
case "9"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top9MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top9MW" to green
else
set the backgroundColor of fld "Top9MW" to red
end if
if aAvg = Top25M then
set the backgroundColor of fld "Top9MW" to yellow
end if
break
case "10"
put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top10MW"
if aAvg > Top52M then
set the backgroundColor of fld "Top10MW" to green
else
set the backgroundColor of fld "Top10MW" to red
end if
if aAvg = Top25M then
set the backgroundColor of fld "Top10MW" to yellow
end if
break
end switch
put Top5M + 1 into Top5M
end repeat
if gConnectionID is a number then
revCloseDatabase gConnectionID
put empty into gConnectionID
end if
end updateTop5WelderMonth