Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OnExit, CleanUp ; Runs the specified subroutine when the script closes
- #SingleInstance Force
- setbatchlines, -1
- SetWorkingDir %A_ScriptDir%
- #include %A_ScriptDir%\Includes\XL.ahk
- #include %A_ScriptDir%\Includes\pArr.ahk
- ; ==================================================
- ; GLOBAL VARIABLES
- ; ==================================================
- GLOBAL cWB ;ActiveX Control for the HTML GUI
- global pWB
- xl := XL_Check("Change-2019_25_03.xlsx - Excel")
- If(!isobject(xl))
- xl := Load(A_ScriptDir "\Change-2019_25_03.xlsx")
- xl.application.displayalerts := 0
- ; Excel is invisible by default. Once you have tested the script this line can be removed.
- ;Clients_List := "ALL||SFR|SFR+BENELUX|SFR+SFF+BENELUX|SFR+SFF|SFR+SFF+MA|SFR+SFF+SIT|SFR+MA|MA+SIT|MA|SIT|BENELUX" ; Will fill the DropDownList with clients IDs
- Sheet_Name := "Change" ; Sheet name, may change in the future, depends on the extracted Excel file
- App_Name := "CMC Toolbox"
- Headers_Offset := 10
- ;Get the length of headers to loop through - im assuming headers start at A1 - and are always in Row 1
- HeaderColumns := xl.sheets(Sheet_Name).range("A1").end(xlright)["column"]
- Rows := xl.sheets(Sheet_Name).range("A1").end(xldown)["Row"]
- LastCol := ConverttoLetter(HeaderColumns)
- ;Function to remove all duplicates from a range in Excel
- XL_RemoveDuplicates(xl,Sheet_Name,"A1:" LastCol Rows,1)
- ; ==================================================
- ; GUI
- ; ==================================================
- Gui, Main:New
- Gui, Main:+OwnDialogs
- Gui, Main:Margin,5,5
- Gui, Main:Add, ActiveX, vcWB w1340 h325 -Caption, Shell.Explorer
- ;Display HTML Page and Attach Event Listeners
- cWB.silent := 1
- fileread,html, % A_ScriptDir "\HTML\Base.html"
- Display(cWB,HTML)
- BuildGui(xl,Sheet_name)
- Gui,Main:Show,Autosize
- cWB.document.parentWindow.ahk_Hoverin := Func("hoverTitlein")
- cWB.document.parentWindow.ahk_Hoverout := Func("hoverTitleout")
- cWB.document.parentWindow.ahk_changeNumClick := Func("ChangeNumClick")
- cWB.document.parentWindow.ahk_submitDateFilter := Func("DateFilter")
- cWB.document.parentWindow.ahk_submitOutlook := Func("ItemstoOutlook")
- pWB := ComObjCreate("InternetExplorer.Application")
- pWB.visible := true
- pWB.Navigate("http://servicecenter.scania.com")
- return
- ; ==================================================
- ; LABELS
- ; ==================================================
- Load(path) {
- ;xl := ComObjCreate("Excel.Application")
- ;xl.Visible := true
- Run, % path
- winwait,Change-2019_25_03.xlsx - Excel
- xl := XL_Check("Change-2019_25_03.xlsx - Excel")
- ;MyWorkbook := xl.Workbooks.Open(path) ; Open the file in Excel
- Return % xl
- }
- ; ==================================================
- ; HOTKEYS
- ; ==================================================
- ESC::
- Cleanup:
- GuiEscape:
- MainGuiClose:
- try{
- pWB.quit()
- pWB:=
- xl.activeworkbook.close
- xl.quit
- xl:=
- }
- ExitApp
- return
- ; ==================================================
- ; FUNCTIONS
- ; ==================================================
- ItemsToOutlook()
- {
- TableRows := cWB.document.querySelectorAll("#dataTable1x tbody tr")
- Loop % TableRows.Length
- {
- RowChecked := TableRows[A_Index-1].getElementsByClassName("include")[0].checked
- IF(RowChecked = -1)
- {
- Row := TableRows[A_Index-1]
- Subject := Row.getElementsByClassName("title")[0].value
- Clients := Row.getElementsByClassName("clients")[0] .value
- ChangeNum := Row.getElementsByClassName("changenum")[0] .value
- changetype := Row.getElementsByClassName("changetype")[0].value
- mainaltered := Row.getElementsByClassName("mainaltered")[0] .value
- start := Row.getElementsByClassName("plannedstart")[0].value
- RegExMatch(Start, "(\d+)/(\d+)/(\d+)", part)
- cStart := part3 "/" part2 "/" part1
- body := "Clients: " clients "`nChange Number: " changenum "`nChange Type: " changetype "`n Main Altered CI: " mainaltered
- createAppointment(Subject,Body,cStart,cstart)
- }
- }
- }
- createAppointment(pSubject,pBody,pStart,pEnd){
- olMailItem := 1 ; 1 for Calendar Item 0 for Mail item
- Outlook := comobjactive("outlook.application").CreateItem(olMailItem)
- if !IsObject(OutLook)
- OutLook := ComObjCreate("outlook.application").CreateItem(olMailItem)
- OutLook.subject := pSubject
- Outlook.body := pBody
- Outlook.Start := pStart " 12:00:00 PM"
- Outlook.AllDayEvent := 1
- Outlook.save
- }
- BuildGui(xl,Sheet_Name) {
- Static Classlist = {0:"title",1:"changenum",2:"changetype",3:"plannedstart",4:"plannedend",5:"mainaltered"}
- Not_Wanted_Columns := "C,E,H,I,J,K,M,N,O,P,Q"
- fileread,RawRow, % A_ScriptDir "\HTML\RawRow.txt"
- ;Get Total # of rows again, after we remove duplicate rows
- HeaderColumns := xl.sheets(Sheet_Name).range("A1").end(xlright)["column"]
- LastCol := ConverttoLetter(HeaderColumns)
- Rows := xl.sheets(Sheet_Name).range("A1").end(xldown)["Row"]
- Loop % Rows
- {
- Table := cwb.document.getElementById("dataTable1x").getElementsByTagName("tbody")[0]
- RowIdx := A_Index
- If(A_Index = 1)
- continue ;Skip Header Row in Excel - we hardcoded it in the html
- tableRow := cwb.Document.createElement("tr")
- tableRow.innerhtml := RawRow
- table.appendChild(tableRow)
- CurrentRow := XL_RangeToObj(xl,Sheet_Name,"A" A_Index ":" LastCol A_Index,"Value")
- i=0
- for Column, Value in CurrentRow
- {
- list := Not_Wanted_Columns ;list of unwanted columns
- If Column in %list%
- continue
- Cell := Table.querySelector("tr:nth-child(" RowIdx-1 ")").getElementsByClassName(ClassList[i])[0]
- Cell.value := Value[RowIdx]
- if(i=1){
- str := "ahk_changeNumClick(this," RowIdx-1 ")"
- Cell.setAttribute("onClick",str)
- }
- i++
- }
- }
- }
- DateFilter() {
- Start := cWB.document.getElementById("sDate").value
- End := cWB.document.getElementById("eDate").value
- RegExMatch(Start, "(\d+)-(\d+)-(\d+)", part)
- cStart := part1 part3 part2 0000000
- RegExMatch(End, "(\d+)-(\d+)-(\d+)", part)
- cEnd := part1 part3 part2 0000000
- TableRows := cWB.document.querySelectorAll("#dataTable1x tbody tr")
- Loop % TableRows.Length
- {
- DateStart := TableRows[A_Index-1].getElementsByClassName("plannedstart")[0].value
- RegExMatch(DateStart, "(\d+)/(\d+)/(\d+)", part)
- dStart := part1 part3 part2 0000000
- If((dStart >= cStart) AND (dStart <= cEnd)) OR ((cStart="0000000") AND (cEnd="0000000"))
- TableRows[A_Index-1].style.display := "table-row"
- else
- TableRows[A_Index-1].style.display := "none"
- }
- }
- hoverTitlein(t){
- tooltip % t.innerText
- }
- hoverTitleout(t){
- tooltip,
- }
- ChangeNumClick(t,idk)
- {
- Row := cWB.document.getElementById("dataTable1x").querySelector("tbody tr:nth-of-type(" idk ")")
- change_num := Row.getElementsByClassName("changenum")[0].value
- Change_URL := "http://servicecenter.vw.vwg/jctsc/smp/index.do?ctx=docEngine&file=cm3r&query=header%2Cnumber%3D%22" Change_Num "%22&action=&title=Change%20" Change_Num
- msgbox % change_url "`n Now Browsing to GOOGLE! PLEASE!"
- pWB.Navigate("www.google.com")
- return
- }
- Display(WB,html_str) {
- Count:=0
- while % FileExist(f:=A_Temp "\" A_TickCount A_NowUTC "-tmp" Count ".DELETEME.html")
- Count+=1
- FileAppend,%html_str%,%f%
- WB.Navigate("file://" . f)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement