Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.11 KB | None | 0 0
  1. OnExit, CleanUp ; Runs the specified subroutine when the script closes
  2. #SingleInstance Force
  3. setbatchlines, -1
  4.  
  5. SetWorkingDir %A_ScriptDir%
  6. #include %A_ScriptDir%\Includes\XL.ahk
  7. #include %A_ScriptDir%\Includes\pArr.ahk
  8.  
  9. ; ==================================================
  10. ; GLOBAL VARIABLES
  11. ; ==================================================
  12.  
  13. GLOBAL cWB ;ActiveX Control for the HTML GUI
  14. global pWB
  15.  
  16. xl := XL_Check("Change-2019_25_03.xlsx - Excel")
  17. If(!isobject(xl))
  18. xl := Load(A_ScriptDir "\Change-2019_25_03.xlsx")
  19. xl.application.displayalerts := 0
  20. ; Excel is invisible by default. Once you have tested the script this line can be removed.
  21. ;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
  22.  
  23. Sheet_Name := "Change" ; Sheet name, may change in the future, depends on the extracted Excel file
  24. App_Name := "CMC Toolbox"
  25. Headers_Offset := 10
  26.  
  27.  
  28. ;Get the length of headers to loop through - im assuming headers start at A1 - and are always in Row 1
  29. HeaderColumns := xl.sheets(Sheet_Name).range("A1").end(xlright)["column"]
  30. Rows := xl.sheets(Sheet_Name).range("A1").end(xldown)["Row"]
  31. LastCol := ConverttoLetter(HeaderColumns)
  32.  
  33. ;Function to remove all duplicates from a range in Excel
  34. XL_RemoveDuplicates(xl,Sheet_Name,"A1:" LastCol Rows,1)
  35.  
  36. ; ==================================================
  37. ; GUI
  38. ; ==================================================
  39. Gui, Main:New
  40. Gui, Main:+OwnDialogs
  41. Gui, Main:Margin,5,5
  42. Gui, Main:Add, ActiveX, vcWB w1340 h325 -Caption, Shell.Explorer
  43.  
  44. ;Display HTML Page and Attach Event Listeners
  45. cWB.silent := 1
  46. fileread,html, % A_ScriptDir "\HTML\Base.html"
  47. Display(cWB,HTML)
  48.  
  49. BuildGui(xl,Sheet_name)
  50.  
  51. Gui,Main:Show,Autosize
  52. cWB.document.parentWindow.ahk_Hoverin := Func("hoverTitlein")
  53. cWB.document.parentWindow.ahk_Hoverout := Func("hoverTitleout")
  54. cWB.document.parentWindow.ahk_changeNumClick := Func("ChangeNumClick")
  55. cWB.document.parentWindow.ahk_submitDateFilter := Func("DateFilter")
  56. cWB.document.parentWindow.ahk_submitOutlook := Func("ItemstoOutlook")
  57.  
  58. pWB := ComObjCreate("InternetExplorer.Application")
  59. pWB.visible := true
  60. pWB.Navigate("http://servicecenter.scania.com")
  61. return
  62.  
  63. ; ==================================================
  64. ; LABELS
  65. ; ==================================================
  66.  
  67. Load(path) {
  68. ;xl := ComObjCreate("Excel.Application")
  69. ;xl.Visible := true
  70.  
  71. Run, % path
  72. winwait,Change-2019_25_03.xlsx - Excel
  73. xl := XL_Check("Change-2019_25_03.xlsx - Excel")
  74.  
  75. ;MyWorkbook := xl.Workbooks.Open(path) ; Open the file in Excel
  76. Return % xl
  77. }
  78.  
  79.  
  80. ; ==================================================
  81. ; HOTKEYS
  82. ; ==================================================
  83. ESC::
  84. Cleanup:
  85. GuiEscape:
  86. MainGuiClose:
  87. try{
  88. pWB.quit()
  89. pWB:=
  90.  
  91. xl.activeworkbook.close
  92. xl.quit
  93. xl:=
  94. }
  95. ExitApp
  96. return
  97.  
  98. ; ==================================================
  99. ; FUNCTIONS
  100. ; ==================================================
  101.  
  102. ItemsToOutlook()
  103. {
  104. TableRows := cWB.document.querySelectorAll("#dataTable1x tbody tr")
  105. Loop % TableRows.Length
  106. {
  107. RowChecked := TableRows[A_Index-1].getElementsByClassName("include")[0].checked
  108. IF(RowChecked = -1)
  109. {
  110. Row := TableRows[A_Index-1]
  111. Subject := Row.getElementsByClassName("title")[0].value
  112. Clients := Row.getElementsByClassName("clients")[0] .value
  113. ChangeNum := Row.getElementsByClassName("changenum")[0] .value
  114. changetype := Row.getElementsByClassName("changetype")[0].value
  115. mainaltered := Row.getElementsByClassName("mainaltered")[0] .value
  116. start := Row.getElementsByClassName("plannedstart")[0].value
  117. RegExMatch(Start, "(\d+)/(\d+)/(\d+)", part)
  118. cStart := part3 "/" part2 "/" part1
  119. body := "Clients: " clients "`nChange Number: " changenum "`nChange Type: " changetype "`n Main Altered CI: " mainaltered
  120. createAppointment(Subject,Body,cStart,cstart)
  121. }
  122. }
  123. }
  124.  
  125. createAppointment(pSubject,pBody,pStart,pEnd){
  126. olMailItem := 1 ; 1 for Calendar Item 0 for Mail item
  127. Outlook := comobjactive("outlook.application").CreateItem(olMailItem)
  128. if !IsObject(OutLook)
  129. OutLook := ComObjCreate("outlook.application").CreateItem(olMailItem)
  130.  
  131. OutLook.subject := pSubject
  132. Outlook.body := pBody
  133. Outlook.Start := pStart " 12:00:00 PM"
  134. Outlook.AllDayEvent := 1
  135. Outlook.save
  136. }
  137.  
  138. BuildGui(xl,Sheet_Name) {
  139. Static Classlist = {0:"title",1:"changenum",2:"changetype",3:"plannedstart",4:"plannedend",5:"mainaltered"}
  140. Not_Wanted_Columns := "C,E,H,I,J,K,M,N,O,P,Q"
  141. fileread,RawRow, % A_ScriptDir "\HTML\RawRow.txt"
  142. ;Get Total # of rows again, after we remove duplicate rows
  143. HeaderColumns := xl.sheets(Sheet_Name).range("A1").end(xlright)["column"]
  144. LastCol := ConverttoLetter(HeaderColumns)
  145. Rows := xl.sheets(Sheet_Name).range("A1").end(xldown)["Row"]
  146. Loop % Rows
  147. {
  148. Table := cwb.document.getElementById("dataTable1x").getElementsByTagName("tbody")[0]
  149.  
  150. RowIdx := A_Index
  151. If(A_Index = 1)
  152. continue ;Skip Header Row in Excel - we hardcoded it in the html
  153.  
  154. tableRow := cwb.Document.createElement("tr")
  155. tableRow.innerhtml := RawRow
  156. table.appendChild(tableRow)
  157.  
  158. CurrentRow := XL_RangeToObj(xl,Sheet_Name,"A" A_Index ":" LastCol A_Index,"Value")
  159. i=0
  160. for Column, Value in CurrentRow
  161. {
  162. list := Not_Wanted_Columns ;list of unwanted columns
  163. If Column in %list%
  164. continue
  165. Cell := Table.querySelector("tr:nth-child(" RowIdx-1 ")").getElementsByClassName(ClassList[i])[0]
  166. Cell.value := Value[RowIdx]
  167. if(i=1){
  168. str := "ahk_changeNumClick(this," RowIdx-1 ")"
  169. Cell.setAttribute("onClick",str)
  170. }
  171. i++
  172. }
  173. }
  174. }
  175.  
  176. DateFilter() {
  177. Start := cWB.document.getElementById("sDate").value
  178. End := cWB.document.getElementById("eDate").value
  179. RegExMatch(Start, "(\d+)-(\d+)-(\d+)", part)
  180. cStart := part1 part3 part2 0000000
  181. RegExMatch(End, "(\d+)-(\d+)-(\d+)", part)
  182. cEnd := part1 part3 part2 0000000
  183.  
  184.  
  185. TableRows := cWB.document.querySelectorAll("#dataTable1x tbody tr")
  186. Loop % TableRows.Length
  187. {
  188. DateStart := TableRows[A_Index-1].getElementsByClassName("plannedstart")[0].value
  189. RegExMatch(DateStart, "(\d+)/(\d+)/(\d+)", part)
  190. dStart := part1 part3 part2 0000000
  191.  
  192. If((dStart >= cStart) AND (dStart <= cEnd)) OR ((cStart="0000000") AND (cEnd="0000000"))
  193. TableRows[A_Index-1].style.display := "table-row"
  194. else
  195. TableRows[A_Index-1].style.display := "none"
  196. }
  197.  
  198. }
  199.  
  200. hoverTitlein(t){
  201. tooltip % t.innerText
  202. }
  203. hoverTitleout(t){
  204. tooltip,
  205. }
  206.  
  207. ChangeNumClick(t,idk)
  208. {
  209. Row := cWB.document.getElementById("dataTable1x").querySelector("tbody tr:nth-of-type(" idk ")")
  210. change_num := Row.getElementsByClassName("changenum")[0].value
  211. 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
  212. msgbox % change_url "`n Now Browsing to GOOGLE! PLEASE!"
  213. pWB.Navigate("www.google.com")
  214. return
  215. }
  216.  
  217. Display(WB,html_str) {
  218. Count:=0
  219. while % FileExist(f:=A_Temp "\" A_TickCount A_NowUTC "-tmp" Count ".DELETEME.html")
  220. Count+=1
  221. FileAppend,%html_str%,%f%
  222. WB.Navigate("file://" . f)
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement