I have no problem showing you, but there are just quite a few pieces to it. Here is the main Script.
Obviously, i wrote alot of CSS/HTML for it as well.
The ahk is really just displaying my HTML/CSS and using Chrome.ahk to display and attach to it so i can 'Control' Everything with AHK. Most of the page logic is actually done with javascript.
AHK is only used to trigger external functions. Function call back to main ahk script -> Calls external ahk script, connects to chrome instance [Does stuff] -> return.
Code: Select all
SetBatchLines, -1
#persistent
#SingleInstance, Off
#NoEnv
#Include, %A_ScriptDir%\Includes\pArr.ahk
#include, %A_ScriptDir%\Includes\XL.ahk
#Include, %A_ScriptDir%\chrome\Chrome.ahk
Onexit, GarbageCollect
gui, message:new, hwndMyhwnd
;Global Variable Definitions
GLOBAL port, profile, UpdateData, XL, GUID, PageInst ;gPageInst
GLOBAL Manufacturer, RepOrDist, OrderEntryDetails, OrderPrin
;Connect to the calling Excel Workbook
XL := XL_Check().Activeworkbook
If(!isObject(XL))
{
msgbox, Order form cannot connect to Excel.
exitapp
}
;Global References to Quote page and Qform
Q := xla.sheets("Quote")
QF := xla.sheets("Qform")
ThisScriptsHWND := Format("{:i}", Myhwnd)
XL.OFhwnd := ThisScriptsHWND
;Get the Workbook name so we can pull custom configs for each principal (Config.ini and /Manufacturer/xxx.txt files)
xlname := StrSplit(XL.name,".").1
If (SubStr(xlname,StrLen(xlname),1) < "9")
xlname:=SubStr(xlname,1,StrLen(xlname)-1)
IniRead, RepOrDist, %A_ScriptDir%\Config.ini, %xlname%, Rep
IniRead, Manufacturer, %A_ScriptDir%\Config.ini, %xlname%, Manufacturer
IniRead, OrderPrin, %A_ScriptDir%\Config.ini, %xlname%, Principal
;Update CSS Files in users temp folder
IniRead, NewVer, %A_ScriptDir%\Config.ini, OrderVer, Ver
IniRead, CurVer, %A_Temp%\ver.ini, OrderVer, Ver
if(NewVer > CurVer) OR (CurVer = "ERROR"){
fileread, css, % A_ScriptDir "\form2css.css"
filedelete, % A_Temp "\form2css.css"
fileappend, % css, % A_Temp "\form2css.css"
fileread, css, % A_ScriptDir "\form2Ack.css"
filedelete, % A_Temp "\form2Ack.css"
fileappend, % css, % A_Temp "\form2Ack.css"
IniWrite, % NewVer, % A_Temp "\ver.ini", OrderVer, Ver
}
OrderEntryDetails := GetEntryDetails(Manufacturer)
If(OrderEntryDetails = -1){
msgbox, Order Entry Failed (Exit Code -15)
return
}
; --- Create a new Chrome instance ---
path := A_Scriptdir "\form2.html"
Port := 9222
if (Chromes := Chrome.FindInstances()).HasKey(Port){
port := chromes.maxIndex() + 1
profile := A_Temp "\ChromeProfile" Port
}else{
profile := A_Temp "\ChromeProfile"
}
;Create a chrome profile directory if one doesnt exist
if !FileExist(profile)
FileCreateDir, % profile
ChromeInst := new Chrome(profile,"--app=" path, "--window-size=970,1000 --disable-web-security --bwsi --disable-component-extensions-with-background-pages",,port)
BoundCallback := Func("Callback").Bind()
WinWaitActive, Order Form,, 10
if ErrorLevel
goto, GarbageCollect
if !(PageInst := ChromeInst.GetPageByTitle("", "contains",,BoundCallBack))
{
MsgBox, Could not retrieve page ""!
ChromeInst.Kill()
ExitApp
}
;On first load - fill out document title, and user information
PageInst.WaitForLoad()
PageInst.Call("Console.enable",,false)
PageInst.WaitforLoad()
PageInst.Evaluate("document.title = '" XL.name "';")
LogoPath := A_scriptdir "\Images\" Manufacturer ".png"
stringreplace, LogoPath, LogoPath, \, \\, All
rdy := WaitEval("document.getElementById('prinIMG').src")
if(rdy = -1)
{
PageInst.Evaluate("alert('Order form will close - please reopen. If you continue to get this message multiple times, let MD know.')")
ExitApp
}
PageInst.Evaluate("document.getElementById('prinIMG').src = '" LogoPath "';")
;Pull Information from Excel initially to populate Order Form
FillQformData()
PopulateItemList(Manufacturer)
return
ESC::
GarbageCollect:
try{
ChromeInst.Kill()
PageInst.Disconnect()
}
xl.OFhwnd := 0
exitapp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;BELOW HERE IS FOR THE CHROME INSTANCE FUNCTIONS AND PAGES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FillQformData() {
;PageInst := gPageInst
Q := xl.sheets("Quote")
QF := xl.sheets("Qform")
envget, firstlast, first.last
envget, testmail, testmail
envget, testphon, testphon
rTime :=
rTime += 7, Days
FormatTime, fTime, A_Now, ShortDate
FormatTime, rTimeFinal, % rTime, ShortDate
bCitStaZip := trim(qf.range("_bCitStaZip").text)
sCitStaZip := trim(qf.range("_sCitStaZip").text)
bZipPos := RegExMatch(bCitStaZip, "i)([0-9]{0,5}(?:-[0-9]{4})?$)", bZip)
bCitSta_NoZip := trim(StrReplace(bCitStaZip,bZip))
bStatePos := RegExMatch(bCitSta_NoZip, "i)(\b\w{2}\b$)", bState)
bCity := Trim(StrReplace(bCitSta_NoZip,bState))
sZipPos := RegExMatch(sCitStaZip, "i)([0-9]{0,5}(?:-[0-9]{4})?$)", sZip)
sCitSta_NoZip := trim(StrReplace(sCitStaZip,sZip))
sStatePos := RegExMatch(sCitSta_NoZip, "i)(\b\w{2}\b$)", sState)
sCity := Trim(StrReplace(sCitSta_NoZip,sState))
OnGList = 4600,4920
MiningList = 1241,1000,1221,1400,2895,3532,3200
EnvironList = 4300,4941,4950,4953
ChemList = 2813,2800,2821,2834,2879,2891,2895,2900,2910,3000
FnBList = 2000,2010,2040,2100
try
{
Sic := qf.range("_sicCode").text
If Sic in %OnGList%
BJSText := "document.getElementById('indType').value = 'Industrial';"
else if Sic in %MiningList%
BJSText := "document.getElementById('indType').value = 'Mining and Aggregates';"
else if Sic in %EnvironList%
BJSText := "document.getElementById('indType').value = 'Environmental';"
else if Sic in %ChemList%
BJSText := "document.getElementById('indType').value = 'Industrial';"
else if Sic in %FnBList%
BJSText := "document.getElementById('indType').value = 'Food & Beverage';"
else
BJSText := "document.getElementById('indType').value = 'Industrial';"
}
cpnum := (qf.range("_slsnum").value < 80) AND (qf.range("_slsnum").value > 69) ? "831" : "931"
ph := RegexMatch(Format("{:T}",qf.range("_bPhone").Text),"[2-9]\d{2}-\d{3}-\d{4}",onlyphone)
bJSText .= "document.getElementById('eDate').value = '" fTime "'; document.getElementById('submitName').value = '" firstlast "'; document.getElementById('submitPhone').value = '" testphon "'; document.getElementById('submitEmail').value = '" testmail "';"
. "document.getElementById('bName').value = '" trim(Format("{:T}",qf.range("_bName").Text)) "';"
. "document.getElementById('bAdd1').value = '" trim(Format("{:T}",qf.range("_bAdd1").Text)) "';"
. "document.getElementById('bAdd2').value = '" trim(Format("{:T}",qf.range("_bAdd2").Text)) "';"
. "document.getElementById('bAdd3').value = '" trim(Format("{:T}",qf.range("_bAdd3").Text)) "';"
. "document.getElementById('bCit').value = '" Format("{:T}",bCity) "';"
. "document.getElementById('bSta').value = '" Format("{:U}",bState) "';"
. "document.getElementById('bZip').value = '" SubStr(bZip,1,5) "';"
. "document.getElementById('bContact').value = '" Format("{:T}",qf.range("_bContact").Text) "';"
. "document.getElementById('bPhone').value = '" onlyphone "';"
. "document.getElementById('bEmail').value = '" Format("{:T}",qf.range("_bEmail").Text) "';"
. ""
. "document.getElementById('sName').value = '" trim(Format("{:T}",qf.range("_sName").Value)) "';"
. "document.getElementById('sAdd1').value = '" trim(Format("{:T}",qf.range("_sAdd1").Text)) "';"
. "document.getElementById('sAdd2').value = '" trim(Format("{:T}",qf.range("_sAdd2").Text)) "';"
. "document.getElementById('sAdd3').value = '" trim(Format("{:T}",qf.range("_sAdd3").Text)) "';"
. "document.getElementById('sCit').value = '" Format("{:T}",sCity) "';"
. "document.getElementById('sSta').value = '" Format("{:U}",sState) "';"
. "document.getElementById('sZip').value = '" SubStr(sZip,1,5) "';"
. "document.getElementById('sContact').value = '" Format("{:T}",qf.range("_bContact").Text) "';"
. "document.getElementById('sPhone').value = '" onlyphone "';"
. "document.getElementById('sEmail').value = '" Format("{:T}",qf.range("_bEmail").Text) "';"
BJSText.= "document.getElementById('AccNum').value = '" Format("{:T}",trim(qf.range("_gesAccNum").text)) "';"
. "document.getElementById('acct1').value = '" Format("{:T}",trim(qf.range("_gesAccNum").text)) "';"
. "document.getElementById('ContactID').value = '" StrReplace(qf.range("_contactID").text,"\","\\") "';"
. "document.getElementById('sman').value = '" Format("{:T}",qf.range("_slsinitials").Text) "';"
. "document.getElementById('smanNumber').value = '" Format("{:T}",qf.range("_slsnum").text) "';"
. "document.getElementById('qNumber').value = '" Format("{:T}",qf.range("_qNum").text) "';"
. "document.getElementById('qRef').value = '" Format("{:T}",q.range("_qRef").text) "';"
. "document.getElementById('cpRef').value = '" Format("{:T}",qf.range("_qNum").text) "';"
. "document.getElementById('billComp').value = '" Format("{:T}",qf.range("_bName").text) "';"
. "document.getElementById('prinNum').value = '" OrderPrin "';"
. "document.getElementById('repID').value = '" cpnum "';"
. "document.getElementById('sls1').value = '" Format("{:T}",qf.range("_slsnum").text) "';"
. "document.getElementById('csrNum').value = '" Format("{:T}",qf.range("_CSR").text) "';"
. "document.getElementById('sprNum').value = '" Format("{:T}",qf.range("_SPR").text) "';"
. "document.getElementById('Manufact').value = '" Manufacturer "';"
. "document.getElementById('appReview').value = '" Format("{:T}",qf.range("A308").text) "';"
. "document.getElementById('sameShip').checked = true;"
. "document.getElementById('rDelivery').value = '" rTimeFinal "';"
. "sameAsShip(document.getElementById('sameShip'));"
. "readTextFile();"
PageInst.Evaluate(bJSText)
}
PopulateItemList(Manufacturer,AdditionalFuncs:="0")
{
local col1,col2,col3,col4,col5,col6,col7
ChromeObjn := {"base": Chrome, "DebugPort": Port}
nPageInst := ChromeObjn.GetPageByurl("file:///" StrReplace(Path,"\","/"), "startswith")
try {
DeleteLines := "var table = document.getElementById('tablelineItems');for(var i = table.rows.length - 3; i > 0; i--){table.deleteRow(i);}"
nPageInst.Evaluate(DeleteLines)
}
AddLineItemsJS := "var table = document.getElementById('tablelineItems').getElementsByTagName('tbody')[0];"
lineitems := []
Items := XL_RangeFindAll(XL,"Qform","N1:N299","1", "N299", xlValues, xlwhole, xlbyrows, xlnext,"Row")
For i,Row in Items
{
description :=
Index := A_Index
itemrow := XL_RangeToObj(xl,"qform","E" Row ":Q" Row)
Qty := itemrow["O"][Row]
Desc := itemrow["E"][Row]
DiscList := itemrow["M"][Row]
Disc := itemrow["P"][Row]
Comm := itemrow["Q"][Row]
try {
ItemDesc := XL_RangeToObj(xl,"qform","E" Row+1 ":N" items[A_Index + 1] - 1)
for k,v in ItemDesc["E"] {
if(ItemDesc["N"][Row + A_Index] = "")
description .= v "`n"
}
}catch{
ItemDesc :=
ItemDesc := XL_RangeToObj(xl,"qform","E" Row+1 ":N" xl_getlast(xl,"qform","E299",xlup,"Row"))
for k,v in ItemDesc["E"] {
if(ItemDesc["N"][Row + A_Index] = "")
if(v = "Suitability and or performance of product:") or (v = "Net Total of All Items:")
break
description .= v "`n"
}
}
description := StrReplace(description,"'","\'")
if(trim(StrReplace(description,"`n","")) = trim(Desc))
description := ""
col1 := Index
col2 := Format("{:1d}",Qty)
col3 := trim(StrReplace(Desc,"'","\'"))
col4 := "$" Format("{:.02f}",DiscList/((100-Disc)/100))
if(RepOrDist = "1"){
;Rep Line Cost/Commision Calucations
col5 := "$" Format("{:.02f}",DiscList*Qty)
col6 := Format("{:.03f}",Disc) "%"
col7 := "$" Format("{:.02f}",strReplace(col5,"$") * Comm)
}else{
;Distributor Line Cost/Commision Calculations
GilsonCost := "$" Format("{:.02f}",(DiscList*(1-Comm))*qty)
CustomerCost := Format("{:.02f}",DiscList*Qty)
Profit := StrReplace(CustomerCost,"$","") - StrReplace(GilsonCost,"$","")
col5 := GilsonCost
col6 := "$" Format("{:.02f}",CustomerCost/Qty)
col7 := "$" CustomerCost
gComm := Format("{:.02f}",(1-((StrReplace(GilsonCost,"$","")/col2)/StrReplace(col4,"$",""))) * 100) "%"
Comm := Format("{:.02f}",Disc)
xtra := "SetCellProp();"
}
AddLineItemsJS .= "var row = table.insertRow(-1);"
. "var tArea = document.createElement('textarea');"
. "tArea.style.display = 'block';"
. "var eInput = document.createElement('input');"
. "var textdata, inputdata;"
. "var cell1 = row.insertCell(0);"
. "var cell2 = row.insertCell(1);"
. "var cell3 = row.insertCell(2);"
. "var cell4 = row.insertCell(3);"
. "var cell5 = row.insertCell(4);"
. "var cell6 = row.insertCell(5);"
. "var cell7 = row.insertCell(6);"
. "var cell8 = row.insertCell(7);"
. "var cell9 = row.insertCell(8);"
. "var cell10 = row.insertCell(9);"
. ""
. "cell1.innerHTML = '<img src=""Images\\RemoveItem.png"" id=""Row"" A_Index "">';"
. ""
. "cell2.innerText = '" col1 "';"
. ""
. "inputdata = cell3.appendChild(eInput);"
. "inputdata.setAttribute(""type"",""text"");"
. "inputdata.setAttribute(""value"",""" col2 """);"
. "inputdata.addEventListener(""change"", function() { QtyEdit(this);});"
. ""
. "var inputdata,eInput = document.createElement('textarea');"
. "inputdata = cell4.appendChild(eInput);"
. "inputdata.textContent = '" strreplace(Rtrim(col3,"`n"),"`n","\n") "';"
. "textdata = cell4.appendChild(tArea);textdata.textContent = '" strreplace(Rtrim(description,"`n"),"`n","\n") "';"
. ""
. "var inputdata,conformButton,eInput = document.createElement('input');"
. "var dConform = document.createElement('input');"
. "dConform.setAttribute(""type"",""button"");"
. "dConform.setAttribute(""value"",""*"");"
. "inputdata = cell5.appendChild(eInput);"
. "inputdata.setAttribute(""type"",""text"");"
. "inputdata.setAttribute(""value"",""" col4 """);"
. "conformButton = cell5.appendChild(dConform);"
. "conformButton.addEventListener(""click"", function() { DtoConform(this);});"
. "inputdata.addEventListener(""change"", function() { QtyEdit(this);});"
. ""
. "var inputdata,eInput = document.createElement('input');"
. "inputdata = cell6.appendChild(eInput);"
. "inputdata.setAttribute(""type"",""text"");"
. "inputdata.setAttribute(""readonly"",""true"");"
. "inputdata.setAttribute(""value"",""" col5 """);"
. ""
. "var inputdata,eInput = document.createElement('input');"
. "inputdata = cell7.appendChild(eInput);"
. "inputdata.setAttribute(""type"",""text"");"
. "inputdata.setAttribute(""readonly"",""true"");"
. "inputdata.setAttribute(""value"",""" col6 """);"
. "inputdata.addEventListener(""dblclick"", function() { ShowDConformModal(this);});"
. ""
. "cell8.innerHTML = '<input type=""text"" value=""" Comm """>';"
. ""
. "var inputdata,eInput = document.createElement('input');"
. "inputdata = cell9.appendChild(eInput);"
. "inputdata.setAttribute(""type"",""text"");"
. "inputdata.setAttribute(""readonly"",""true"");"
. "inputdata.setAttribute(""value"",""" col7 """);"
. "inputdata.addEventListener(""dblclick"", function() { ShowDConformModal(this);});"
. ""
. "cell10.style.display = 'none';"
. "cell10.innerHTML = '<input type=""text"" value=""" gComm """>';"
}
AddLineItemsJS .= "var row = table.insertRow(-1);"
. ""
. "var cell1 = row.insertCell(0);"
. "cell1.colSpan = 8;"
. "cell1.innerHTML = '<input type=""button"" value=""New Line"">';"
. "cell1.addEventListener(""click"", function() { NewLineItemRow();});"
. Xtra
AddLineItemsJS .= "var buttons = document.querySelectorAll('#tablelineItems tbody tr td:nth-of-Type(1)');for(i=0; i < buttons.length; ++i){buttons[i].addEventListener(""click"", function() { DeleteRow(this);});} var tareas = document.querySelectorAll('#tablelineItems tbody tr td textarea:nth-of-type(1)');for (i=0;i<tareas.length;++i){tareas[i].style.display = 'block';autoExpand(tareas[i]);}var tareas = document.querySelectorAll('#tablelineItems tbody tr td textarea:nth-of-type(2)');for (i=0;i<tareas.length;++i){autoExpand(tareas[i]);tareas[i].style.display = 'none';} document.getElementById('termsSelect').addEventListener(""change"", function() { ShowCreditCardFields('" Manufacturer "');});"
If(!AdditionalFuncs)
{
ExtraFormFunctions := StrSplit(OrderEntryDetails["FormFunctions"],"|")
for k,v in ExtraFormFunctions
{
fileread,file, % A_ScriptDir "\Scripts\FormTexts\" v
AddLineItemsJS .= file
}
}
nPageInst.Evaluate(AddLineItemsJS "subTotal();")
nPageInst.Disconnect()
}
SaveOrder(){
EmailOrder := OrderEntryDetails["EmailOrder"]
Functions := StrSplit(OrderEntryDetails["OrderFunctions"],",")
for k,v in Functions
{
funcname := StrReplace(StrSplit(v,"{").1,"}")
paramlist := StrReplace(StrSplit(v,"{").2,"}")
eParams := []
Params := StrSplit(paramlist,";")
for k,v in Params
eParams[A_Index] := %v%
ret := %Funcname%(eParams)
if(ret = -1)
break
}
}
BuyResell(){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\BuyResell.ahk """ XL.Name """ " A_ScriptDir " " Port,,UseErrorLevel
return % ErrorLevel
}
CheckFields(params*){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\CheckFields.ahk """ XL.Name """ " A_ScriptDir " " Manufacturer " " Port,,UseErrorLevel
return % ErrorLevel
}
Soap(params*){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\Soap.ahk """ XL.Name """ " A_ScriptDir " " Port,,UseErrorLevel
return % ErrorLevel
}
Print(params*){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\Print.ahk """ XL.Name """ " A_ScriptDir " " Port,,UseErrorLevel
return % ErrorLevel
}
OrderFile(params*){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\Ordertst.ahk """ XL.Name """ " A_ScriptDir " " Port,,UseErrorLevel
return % ErrorLevel
}
UpdateMcs(params*){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\UpdateMCS.ahk """ XL.Name """ " A_ScriptDir " " Port,,UseErrorLevel
return % ErrorLevel
}
JGBFiles(params*){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\PrintGilco.ahk """ XL.Name """ " A_ScriptDir " " Port,,UseErrorLevel
return % ErrorLevel
}
GetTaxCertData(Params*){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\GetTaxCert.ahk """ XL.Name """ " A_ScriptDir " " Port,,UseErrorLevel
return % ErrorLevel
}
CheckTemco(Params*){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\CheckTemco.ahk """ XL.Name """ " A_ScriptDir " " Port,,UseErrorLevel
return % ErrorLevel
}
Email(Params*){
runwait, % "F:\userfolders\md\autohotkey\autohotkey.exe " A_ScriptDir "\scripts\Email.ahk """ XL.Name """ " A_ScriptDir " " Params[1].2 " " Params[1].3 " " Port,,UseErrorLevel
return
}
RunWaitOne(command) {
shell := ComObjCreate("WScript.Shell").Exec(ComSpec " /C " command)
return shell.StdOut.ReadAll()
}
Callback(Event) {
; Filter for console messages starting with "AHK:"
if (Event.Method = "Console.messageAdded" && InStr(Event.params.message.text, "AHK:Print") == 1)
{
SaveOrder()
} else if(Event.Method = "Console.messageAdded" && InStr(Event.params.message.text, "AHK:buyresell") == 1){
BuyResell()
}else if(Event.Method == "Console.messageAdded" && InStr(Event.params.message.text, "AHK:notes") == 1){
msgbox, hello from callback AHK:notes
}else if (Event.Method == "Console.messageAdded" && InStr(Event.params.message.text, "AHK:FieldEdit") == 1){
If(InStr(Event.params.message.text, "CitStaZip"))
{
Parsed := StrSplit(StrReplace(Event.params.message.text,"AHK:FieldEdit:CitStaZip:"),"|")
qf := xl.sheets("qform")
If(SubStr(Parsed.1,1,1) = "b")
CitStaZip := qf.range("_bCitStaZip").text
else
CitStaZip := qf.range("_sCitStaZip").text
ZipPos := RegExMatch(CitStaZip, "i)([0-9]{0,5}(?:-[0-9]{4})?$)", Zip)
CitSta_NoZip := trim(StrReplace(CitStaZip,Zip))
StatePos := RegExMatch(CitSta_NoZip, "i)(\b\w{2}\b$)", State)
City := Trim(StrReplace(CitSta_NoZip,State))
If(InStr(Parsed.1, "Cit")){
If(City <> "")
NewStr := RegExReplace(CitStaZip, City,parsed.2)
else
NewStr := Parsed.2 " " State " " Zip
}else if(InStr(Parsed.1, "Sta")){
If(State <> "")
NewStr := RegExReplace(CitStaZip, state,parsed.2)
else
NewStr := City " " Parsed.2 " " Zip
}else if(InStr(Parsed.1, "Zip")){
If(Zip <> "")
NewStr := RegExReplace(CitStaZip, Zip,parsed.2)
else
NewStr := City " " State " " Parsed.2
}
xl.sheets("qform").range("_" SubStr(Parsed.1,1,1) "CitStaZip") := NewStr
}else{
Parsed := StrSplit(StrReplace(Event.params.message.text,"AHK:FieldEdit:"),"|")
xl.sheets("qform").range("_" Parsed.1) := Parsed.2
}
}else if(Event.Method == "Console.messageAdded" && InStr(Event.params.message.text, "AHK:itemRefresh") == 1){
PopulateItemList(Manufacturer,"1")
}else if(Event.Method == "Console.messageAdded" && InStr(Event.params.message.text, "AHK:ReqdFields") == 1){
hwndval:= StrSplit(Event.params.message.text,":").3
winget, sPID, PID, % "ahk_id" hwndval
process, close, % sPID
}else if(Event.Method == "Console.messageAdded" && InStr(Event.params.message.text, "AHK:SoapFail") == 1){
hwndval:= StrSplit(Event.params.message.text,":").3
winget, sPID, PID, % "ahk_id" hwndval
process, close, % sPID
}else if(Event.Method == "Console.messageAdded" && InStr(Event.params.message.text, "AHK:SiemensCC") == 1){
LaunchCCWindow()
}else if(Event.Method = "Inspector.Detached"){
ExitApp
}
}
LaunchCCWindow() {
;mainInst := gPageInst
if !FileExist(A_Temp "\ChromeProfileCC")
FileCreateDir, % A_Temp "\ChromeProfileCC"
CC_ChromeInst := new Chrome(A_Temp "\ChromeProfileCC", "--app=https://redacted.com"," --window-size=505,400",,"9600")
CCBoundCallBack := Func("CC_Callback").Bind(CC_ChromeInst)
WinWaitActive, Siemens CC Tokenization - Entry,,20
if ErrorLevel
{
PageInst.Evaluate("alert('Could not contact Siemens Credit Card Tokenization Form');")
CC_ChromeInst.Kill()
}
if !(CCPageInst := CC_ChromeInst.GetPageByTitle("Siemens CC Tokenization - Entry", "exact",,CCBoundCallBack))
{
PageInst.Evaluate("alert('Could not contact Siemens Credit Card Tokenization Form');")
CC_ChromeInst.Kill()
}
CCPageInst.Call("Console.enable",,false)
CCPageInst.WaitForLoad()
CCPageInst.Evaluate("document.querySelector('#iframewrapper > div > button').addEventListener(""click"", function() { CCSubmitClicked();}); function CCSubmitClicked(){console.log(""AHK:CC_Clicked"");}")
CCPageInst.WaitForLoad()
}
CC_Callback(Chrome,Event) {
if(Event.Method = "Inspector.Detached"){
try
{
Chrome.Kill()
}
}else if(Event.Method = "Console.messageAdded" && InStr(Event.params.message.text, "AHK:CC_Clicked") == 1){
;PageInst := gPageInst
WinWaitActive, Siemens CC Tokenization - Status,,5
if ErrorLevel
{
PageInst.Evaluate("alert('Could not contact Siemens Credit Card Tokenization Form');")
Chrome.Kill()
}
page := Chrome.getPageByTitle("Siemens CC Tokenization - Status", "exact")
JS =
(
var tokenstr = document.querySelector('span #CreditToken').value
var token = document.querySelector('table #CreditToken').value;
var Expr = document.getElementById('ExpirationDate').value;
var card = document.getElementById('CardType').value;
var returnstr = tokenstr + '|' + token + '|' + Expr + '|' + card
el = document.createElement('textarea');
document.body.appendChild(el);
el.textContent = returnstr;
document.getElementsByTagName('textarea')[0].value;
)
TokenFields := StrSplit(page.Evaluate(JS).value,"|")
Chrome.Kill()
etoken := TokenFields.1
type := TokenFields.4
ctoken := TokenFields.2
expr := TokenFields.3
JS =
(
document.getElementById('eToken').value = '%etoken%';
document.getElementById('tokencardType').value = '%type%';
document.getElementById('cToken').value = '%ctoken%';
document.getElementById('cExpire').value = '%expr%';
document.getElementById('cEDate').value = '%A_Now%';
)
PageInst.Evaluate(JS)
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;ABOVE HERE IS FOR THE CHROME INSTANCE FUNCTIONS AND PAGES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;--------------------------------
;ORDER ENTRY FUNCTIONS BELOW HERE
;--------------------------------
GetEntryDetails(ManufactName){
If !ManufactName
return, -1
OutArr := []
Loop, read, % A_ScriptDir "\Manufacturers\" ManufactName ".txt"
{
FieldData := StrSplit(A_LoopReadLine,"|")
OutArr[FieldData.1] := FieldData.2
}
return % OutArr
}
/*
ObjRegisterActive(Object, CLSID, Flags:=0)
Registers an object as the active object for a given class ID.
Requires AutoHotkey v1.1.17+; may crash earlier versions.
Object:
Any AutoHotkey object.
CLSID:
A GUID or ProgID of your own making.
Pass an empty string to revoke (unregister) the object.
Flags:
One of the following values:
0 (ACTIVEOBJECT_STRONG)
1 (ACTIVEOBJECT_WEAK)
Defaults to 0.
Related:
http://goo.gl/KJS4Dp - RegisterActiveObject
http://goo.gl/no6XAS - ProgID
http://goo.gl/obfmDc - CreateGUID()
*/
ObjRegisterActive(Object, CLSID, Flags:=0) {
static cookieJar := {}
if (!CLSID) {
if (cookie := cookieJar.Remove(Object)) != ""
DllCall("oleaut32\RevokeActiveObject", "uint", cookie, "ptr", 0)
return
}
if cookieJar[Object]
throw Exception("Object is already registered", -1)
VarSetCapacity(_clsid, 16, 0)
if (hr := DllCall("ole32\CLSIDFromString", "wstr", CLSID, "ptr", &_clsid)) < 0
throw Exception("Invalid CLSID", -1, CLSID)
hr := DllCall("oleaut32\RegisterActiveObject"
, "ptr", &Object, "ptr", &_clsid, "uint", Flags, "uint*", cookie
, "uint")
if hr < 0
throw Exception(format("Error 0x{:x}", hr), -1)
cookieJar[Object] := cookie
}
CreateGUID()
{
VarSetCapacity(pguid, 16, 0)
if !(DllCall("ole32.dll\CoCreateGuid", "ptr", &pguid)) {
size := VarSetCapacity(sguid, (38 << !!A_IsUnicode) + 1, 0)
if (DllCall("ole32.dll\StringFromGUID2", "ptr", &pguid, "ptr", &sguid, "int", size))
return StrGet(&sguid)
}
return ""
}
WaitEval(JS,timeout:=10) {
GLOBAL
tVar := ""
Start := A_TickCount
While(tVar = "")
{
tVar :=PageInst.Evaluate("try{" JS "}catch{var el = ''};").Value
If((A_TickCount - Start) > (timeout*1000))
return, -1
}
return
}