//------------------------------------------------------------------------- // Author: Chris Carmac 5/3/2011 3:43:24 PM // Add items to Napa quote using Prolink web site - Internet Exlorer version // // PARAMETERS //------------------------------------------------------------------------- METHOD fscNapa2:addQuoteItems(oDlg) LOCAL oIE, oDocument, xVal, oError LOCAL bOldError := ERRORBLOCK() LOCAL nHwnd := 0 LOCAL cResult := '' LOCAL nHandle := 0 LOCAL lDone := .F. LOCAL oOldFocus := fsAppFocus() LOCAL nXml := 0 LOCAL cNode := "//Item" // LOCAL cNewUrl := '' IF IsCanada(oMainDlg:cStoreKey) ::cURL := 'https://test.napapunchout.ca/prolinkppse/punchout.aspx' ELSE ::cURL := 'https://www.napapunchout.com/punchout.aspx' ENDIF ::cURL := ::cURL + '?uid='+::cUserId IF !EMPTY(::cEngineVIN) ::cURL := ::cURL + '&VIN='+::cEngineVIN ENDIF IF IsCanada(oMainDlg:cStoreKey) ::cURL := ::cURL + '&Email='+Store->(Quickseek(oMainDlg:cStoreKey,{||ALLTRIM(Store->Email)},'KEY')) ENDIF oIE := CreateObject("InternetExplorer.Application") IF VALTYPE(oIE) == 'O' oIE:RegisterAsBrowser := .T. oIE:navigate(::cURL) oIE:Visible := .T. // oIE:Fullscreen := .T. *** Get window handle and force the browser window to the foreground nHwnd := oIE:HWND BringWindowToTop( nHWnd ) SetForegroundWindow( nHWnd ) *** Wait here while page loads DO WHILE oIE:Busy ENDDO oDocument := oIE:document BEGIN SEQUENCE ERRORBLOCK( {|oError| Break(oError) } ) DO WHILE !lDone //.AND. !EMPTY(oIE) *** Wait here while page loads DO WHILE oIE:Busy ENDDO xVal := oDocument:getElementById('partXMLHidden') // Retrieve result value IF !EMPTY(xVal) *** Pause and reload the data to make sure we get it all xVal := nil cResult := nil SLEEP(30) xVal := oDocument:getElementById('partXMLHidden') // Retrieve result value cResult := xVal:getAttribute('value') IF !EMPTY(cResult) IF IsDebugMode() nHandle := FCREATE('c:\temp\napa\response.xml') IF EMPTY(FERROR()) FWRITE(nHandle,cResult) FCLOSE(nHandle) ENDIF // fsalert(TextToArray(cResult,65)) ENDIF nXml := XMLDocOpenString(cResult) // Open XML result file *** Build array of part information from XML data IF nXml > 0 XMLDocResetAction( nXml ) XMLDocSetAction( nXml, cNode, { |cName,xContent,xAttribute,nHandle| ::ProlinkLookupResponse( nHandle ) } ) XMLDocProcess( nXml ) XMLDocResetAction( nXml ) XMLDocClose( nXml ) ENDIF ::loadPart() // Create temporary part file IF NapaPart->(LASTREC()) > 0 ::quoteAddItem(.T.,.T.) // Add item to quote oDlg:oBrow:goBottom() oDlg:oBrow:refreshall() ENDIF IF iniValue('NAPA_Transfer_Reset','settings','L') oIE:navigate(::cURL) // Navigate back to original URL so you can transfer more than one part ENDIF ENDIF xVal:setAttribute('value','') // Clear result contents ENDIF ENDDO oIE:stop() oIE:quit() RECOVER USING oError // fsWarn({'!!! NAPA ERROR ENCOUNTERED !!!'}) // fsWarn({'!!! NAPA ERROR ENCOUNTERED !!!',,'Error Code: '+ALLTRIM(STR(COMLASTERROR())),COMLASTMESSAGE(),'valtype '+valtype(oIe)}) END SEQUENCE oIE:destroy() ENDIF ERRORBLOCK(bOldError) // Reset old error handler fsAppFocus(oOldFocus) RETURN(self)