diff --git a/api.asp b/api.asp index cea3c21..39fa407 100644 --- a/api.asp +++ b/api.asp @@ -55,6 +55,8 @@ Select Case action GetShopfloorPCs() Case "getRecordedIP" GetRecordedIP() + Case "updateMachinePositions" + UpdateMachinePositions() Case Else SendError "Invalid action: " & action End Select @@ -2412,4 +2414,69 @@ Sub UpdateWinRMStatus() Response.Write "{""success"":true,""message"":""WinRM status updated"",""hostname"":""" & hostname & """,""iswinrm"":" & winrmValue & "}" End Sub +' ============================================================================ +' UPDATE MACHINE POSITIONS - Bulk update mapleft/maptop for machines +' ============================================================================ +Sub UpdateMachinePositions() + On Error Resume Next + + Dim changesJson, changes, i, updateCount, errorCount + changesJson = Request.Form("changes") + + If changesJson = "" Then + SendError "Missing changes parameter" + Exit Sub + End If + + LogToFile "UpdateMachinePositions: Received " & Len(changesJson) & " bytes" + + ' Parse JSON array + changes = ParseJSONArray(changesJson) + + If Not IsArray(changes) Then + SendError "Invalid changes format" + Exit Sub + End If + + updateCount = 0 + errorCount = 0 + + ' Update each machine position + For i = 0 To UBound(changes) + Dim machineId, newLeft, newTop, updateSQL + + machineId = GetJSONValue(changes(i), "id") + newLeft = GetJSONValue(changes(i), "newLeft") + newTop = GetJSONValue(changes(i), "newTop") + + If machineId <> "" And IsNumeric(machineId) And IsNumeric(newLeft) And IsNumeric(newTop) Then + updateSQL = "UPDATE machines SET mapleft = " & CLng(newLeft) & ", maptop = " & CLng(newTop) & _ + " WHERE machineid = " & CLng(machineId) + objConn.Execute updateSQL + + If Err.Number = 0 Then + updateCount = updateCount + 1 + LogToFile " Updated machineid " & machineId & " to (" & newLeft & ", " & newTop & ")" + Else + errorCount = errorCount + 1 + LogToFile " Error updating machineid " & machineId & ": " & Err.Description + Err.Clear + End If + Else + errorCount = errorCount + 1 + LogToFile " Invalid data for change " & i + End If + Next + + LogToFile "UpdateMachinePositions: Updated " & updateCount & ", Errors " & errorCount + + ' Send response + Response.ContentType = "application/json" + If errorCount = 0 Then + Response.Write "{""success"":true,""message"":""Updated " & updateCount & " position(s)"",""updated"":" & updateCount & "}" + Else + Response.Write "{""success"":true,""message"":""Updated " & updateCount & ", " & errorCount & " error(s)"",""updated"":" & updateCount & ",""errors"":" & errorCount & "}" + End If +End Sub + %> diff --git a/machine_map.asp b/machine_map.asp index 2447386..92aae54 100644 --- a/machine_map.asp +++ b/machine_map.asp @@ -128,7 +128,7 @@ Do While Not rsLegend.EOF Case Else: legendColor = "#FFC107" End Select Response.Write("