Fix API to set pctypeid when inserting new PCs

- Added GetPCTypeIdFromPCType() function to map pcType strings to pctypeid
- INSERT now includes pctypeid column (was missing, causing PCs to not be
  properly identified as PCs in Phase 2 schema)
- pctypeid mapping: Standard=1, Engineer=2, Shopfloor=3, CMM=5, Wax/Trace=6,
  Keyence=7, Genspect/EAS1000=8, Heat Treat=9, Part Marker=10
- WJPRT* pattern override now sets both machinetypeid and pctypeid
- Fixed EAS1000/GENSPECT to map to same pctypeid (8)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-12-09 07:33:04 -05:00
parent 81f905f0b0
commit adeff46d80

63
api.asp
View File

@@ -828,15 +828,18 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
Set rsModel = Nothing
End If
' Step 4: Get machine type ID
' Step 4: Get machine type ID and PC type ID
machineTypeId = GetMachineTypeIdFromPCType(pcType)
Dim pctypeId
pctypeId = GetPCTypeIdFromPCType(pcType)
' Override machineTypeId based on machinenumber pattern
' WJPRT* = Wax Trace PC (42)
' Override types based on machinenumber pattern
' WJPRT* = Wax Trace PC (machinetypeid 42, pctypeid 6)
If machinenumber <> "" Then
If UCase(Left(machinenumber, 5)) = "WJPRT" Then
machineTypeId = 42 ' PC - Wax Trace
LogToFile "Detected WJPRT pattern in machinenumber, setting machineTypeId to 42 (PC - Wax Trace)"
pctypeId = 6 ' Wax / Trace
LogToFile "Detected WJPRT pattern in machinenumber, setting machineTypeId to 42, pctypeid to 6"
End If
End If
@@ -844,8 +847,9 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
If Not IsNumeric(vendorId) Or vendorId = "" Then vendorId = 0
If Not IsNumeric(modelId) Or modelId = "" Then modelId = 1 ' TBD model
If Not IsNumeric(machineTypeId) Or machineTypeId = "" Then machineTypeId = 36 ' PC - Standard
If Not IsNumeric(pctypeId) Or pctypeId = "" Then pctypeId = 1 ' Standard
LogToFile "Vendor ID: " & vendorId & ", Model ID: " & modelId & ", Machine Type ID: " & machineTypeId
LogToFile "Vendor ID: " & vendorId & ", Model ID: " & modelId & ", Machine Type ID: " & machineTypeId & ", PC Type ID: " & pctypeId
' Check if PC already exists (Phase 2: identify PCs by pctypeid IS NOT NULL)
Dim strSQL, rsResult, safeHostname
@@ -964,7 +968,7 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
' Build SQL in parts to isolate error
Dim sqlPart1, sqlPart2, sqlPart3
sqlPart1 = "INSERT INTO machines (hostname, serialnumber, modelnumberid, machinetypeid, loggedinuser, machinenumber, osid, machinestatusid, isactive, lastupdated) VALUES ("
sqlPart1 = "INSERT INTO machines (hostname, serialnumber, modelnumberid, machinetypeid, pctypeid, loggedinuser, machinenumber, osid, machinestatusid, isactive, lastupdated) VALUES ("
sqlPart2 = "'" & safeHostname & "', '" & safeSerial & "', "
If modelId > 0 Then
@@ -973,8 +977,8 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
sqlPart2 = sqlPart2 & "NULL, "
End If
' machinetypeid is required for PCs (33=Standard, 34=Engineering, 35=Shopfloor)
sqlPart2 = sqlPart2 & CLng(machineTypeId) & ", "
' machinetypeid and pctypeid are required for PCs
sqlPart2 = sqlPart2 & CLng(machineTypeId) & ", " & CLng(pctypeId) & ", "
If safeUser <> "" Then
sqlPart2 = sqlPart2 & "'" & safeUser & "', "
@@ -1870,8 +1874,8 @@ Function GetMachineTypeIdFromPCType(pcTypeString)
GetMachineTypeIdFromPCType = 42 ' PC - Wax Trace (runs Formtracepak, FormStatusMonitor)
Case "KEYENCE"
GetMachineTypeIdFromPCType = 43 ' PC - Measuring Tool - Keyence (runs Keyence VR Series)
Case "EAS1000"
GetMachineTypeIdFromPCType = 43 ' PC - Measuring Tool - EAS1000 (runs GageCal, NI Software)
Case "EAS1000", "GENSPECT"
GetMachineTypeIdFromPCType = 43 ' PC - Measuring Tool - EAS1000/Genspect (runs GageCal, NI Software)
Case "PART MARKER", "PARTMARKER"
GetMachineTypeIdFromPCType = 43 ' PC - Measuring Tool - Part Marker (0615 machines)
Case "MEASURING", "MEASURING TOOL"
@@ -1886,6 +1890,45 @@ Function GetMachineTypeIdFromPCType(pcTypeString)
LogToFile "Mapped pcType '" & pcTypeString & "' to machinetypeid: " & GetMachineTypeIdFromPCType
End Function
Function GetPCTypeIdFromPCType(pcTypeString)
On Error Resume Next
' Map pcType parameter to pctypeid (from pctype table)
' pctypeid values: 1=Standard, 2=Engineer, 3=Shopfloor, 4=Uncategorized,
' 5=CMM, 6=Wax/Trace, 7=Keyence, 8=Genspect, 9=Heat Treat, 10=Part Marker
Dim pcTypeClean
pcTypeClean = Trim(UCase(pcTypeString))
Select Case pcTypeClean
Case "ENGINEER", "ENGINEERING"
GetPCTypeIdFromPCType = 2
Case "SHOPFLOOR", "SHOP FLOOR"
GetPCTypeIdFromPCType = 3
Case "CMM"
GetPCTypeIdFromPCType = 5
Case "WAX TRACE", "WAXTRACE", "WAX", "WAX / TRACE"
GetPCTypeIdFromPCType = 6
Case "KEYENCE"
GetPCTypeIdFromPCType = 7
Case "GENSPECT", "EAS1000"
GetPCTypeIdFromPCType = 8 ' Genspect / EAS1000
Case "HEAT TREAT", "HEATTTREAT"
GetPCTypeIdFromPCType = 9
Case "PART MARKER", "PARTMARKER"
GetPCTypeIdFromPCType = 10
Case "MEASURING", "MEASURING TOOL"
GetPCTypeIdFromPCType = 7 ' Default other measuring tools to Keyence
Case "STANDARD", ""
GetPCTypeIdFromPCType = 1
Case Else
LogToFile "Unknown pcType '" & pcTypeString & "' for pctypeid, defaulting to Standard (1)"
GetPCTypeIdFromPCType = 1
End Select
LogToFile "Mapped pcType '" & pcTypeString & "' to pctypeid: " & GetPCTypeIdFromPCType
End Function
' ============================================================================
' HELPER FUNCTIONS - JSON PARSING (Simple)
' ============================================================================