SQLite Report Generator


SUBMITTED BY: Guest

DATE: May 29, 2013, 7:08 a.m.

FORMAT: Text only

SIZE: 91.3 kB

HITS: 2247

  1. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_Icon=SQLite2.ico
  3. #AutoIt3Wrapper_UseUpx=n
  4. #AutoIt3Wrapper_Compile_Both=y
  5. #AutoIt3Wrapper_UseX64=y
  6. #AutoIt3Wrapper_Res_Comment=SQL based Report Generator for SQLite databases
  7. #AutoIt3Wrapper_Res_Description=SQLite Report Generator
  8. #AutoIt3Wrapper_Res_Fileversion=1.0.0.6
  9. #AutoIt3Wrapper_Res_LegalCopyright=GreenCan
  10. #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
  11. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  12. #cs ----------------------------------------------------------------------------
  13. AutoIt Version: 3.3.8.1
  14. Author: GreenCan
  15. Other contributors:
  16. _ParseCSV: ProgAndy
  17. _DateCalc: Sean Hart <autoit@hartmail.ca>
  18. WM_NOTIFY() issue and some code optimization: jpm
  19. Script Function:
  20. SQL based Report Generator for SQLite databasess
  21. Known problem:
  22. None
  23. Updates:
  24. 1.0.0.6:
  25. Bug fixes (thanks jpm)
  26. Better GUI windows management
  27. Excel export optimized
  28. _COMError implemented
  29. #ce ----------------------------------------------------------------------------
  30. #include <Misc.au3>
  31. #include <SQLite.au3>
  32. #include <SQLite.dll.au3>
  33. #include <GUIConstantsEx.au3>
  34. #include <GuiListView.au3>
  35. #include <WindowsConstants.au3>
  36. #include <ButtonConstants.au3>
  37. #include <EditConstants.au3>
  38. #include <Date.au3>
  39. If _Singleton(@ScriptName, 1) = 0 Then Exit
  40. Opt("MustDeclareVars", 1)
  41. Opt("TrayIconHide", 1) ; hide the tray Icon
  42. ; Initializes COM handler
  43. ;~ Global $oAppError ; COM Error handler
  44. Global $oAppError = ObjEvent("AutoIt.Error", "_COMError")
  45. Global $iDebug = 1
  46. If Not @Compiled Then ConsoleWrite(@ScriptLineNumber & " Debug enabled" & @CR)
  47. #region Declare
  48. Const $iDark_Blue = 0x2601D3
  49. Const $iLight_Green = 0xEAFFE8
  50. ; postion of main window at startup
  51. Local $SM_VIRTUALWIDTH = 78
  52. Global $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
  53. $VirtualDesktopWidth = $VirtualDesktopWidth[0]
  54. Global $Menu_ListView, $DoubleClicked, $iIndex = 1 ; _ArrayMenu() requires $Menu_ListView and $DoubleClicked to be declared as Global variables.
  55. Global $ListDelimiter = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sList") ; Retrieve standard delimiter symbol
  56. Global $sDecimal = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sDecimal") ; decimal symbol
  57. ; GUI settings:
  58. ; _ArrayMenu
  59. Global $iAM_Width = 400, $iAM_Height = 400, $iAM_Left = -1, $iAM_Top = -1, $iAM_OffsetWidth = Default, $iAM_OffsetHeight = Default
  60. ; Multiline GUI
  61. Global $hGUI_Multiline, $View_Multiline, $ColName
  62. Global $MultiLine_Width = 300, $MultiLine_Height = 300, $MultiLine_OffsetWidth = Default, $MultiLine_OffsetHeight = Default, $MultiLine_Left = 0, $MultiLine_Top = 0
  63. ; $SQLResultWindow GUI
  64. Local $SQLResultWindow, $iLV_Width = 800, $iLV_Height = 400, $iLV_OffsetWidth = Default, $iLV_OffsetHeight = Default, $iLV_Left = -1, $iLV_Top = -1
  65. ; Vertical View
  66. Global $GUI_VerticalView, $aVertView, $VertView_hListView, $bVerticalView_Resize, $VertView_Width = 250, $VertView_Height = 480, $VertView_OffsetWidth = 0, $VertView_OffsetHeight = 0, $VertView_Left = $VirtualDesktopWidth - $VertView_Width - 15, $VertView_Top = 0, $VerticalView_Copy, $bVerticalView_GUI = False
  67. Global $iLastItem = -1, $iLastsubitemNR = -1 ; used in WM_NOTIfY2
  68. Global $aNames ; Column titles
  69. Global $Choice ; menu selected item
  70. Global $FileHandle, $hListView
  71. ; Menu Loop vars
  72. Local $aParameter, $Parameter1, $Parameter2, $lblParameter1, $lblParameter2, $TitleParams, $sSQL, $iIndex, $iKeeppreviousIndex = 0, $sRow, $size
  73. Local $BtSQL, $BtClose, $BtExport, $DataBase, $hQuery, $aRow, $aResult, $Result, $Active_win, $To_Clip
  74. #endregion Declare
  75. #region ini
  76. Local $iniFileName = @ScriptDir & "\SQLite Reports.ini"
  77. If Not FileExists($iniFileName) Then Exit MsgBox(48, "Error", $iniFileName & " not found") ; startup error, keep the message
  78. Global $Db = IniRead($iniFileName, "General", "Database", "-")
  79. If Not FileExists(@ScriptDir & "\" & $Db) Then Exit MsgBox(48, "Error", "Database not found:" & @CR & @ScriptDir & "\" & $Db)
  80. Global $sDbDateFormat = IniRead($iniFileName, "General", "DateFormat", "YYYY/MM/DD")
  81. Local $_DesktopWidth = IniRead($iniFileName, "General", "DesktopWidth", 0) ; Desktop width of the previous session
  82. If $_DesktopWidth = $VirtualDesktopWidth Then
  83. ; same desktop width so we can use the stored window coordinates
  84. ; _ArrayMenu
  85. $Result = IniRead($iniFileName, "General", "Menu", $iAM_Width & "," & $iAM_Height & "," & $iAM_Left & "," & $iAM_Top )
  86. $aResult = StringSplit($Result, ",")
  87. $iAM_Width = $aResult[1]
  88. $iAM_Height = $aResult[2]
  89. $iAM_Left = $aResult[3]
  90. $iAM_Top = $aResult[4]
  91. ; Vertical View
  92. $Result = IniRead($iniFileName, "General", "VerticalView", $VertView_Width & "," & $VertView_Height & "," & $VertView_Left & "," & $VertView_Top )
  93. $aResult = StringSplit($Result, ",")
  94. $VertView_Width = $aResult[1]
  95. $VertView_Height = $aResult[2]
  96. $VertView_Left = $aResult[3]
  97. $VertView_Top = $aResult[4]
  98. ; $SQLResultWindow (Listview)
  99. $Result = IniRead($iniFileName, "General", "SQLResultView", $iLV_Width & "," & $iLV_Height & "," & $iLV_Left & "," & $iLV_Top )
  100. $aResult = StringSplit($Result, ",")
  101. $iLV_Width = $aResult[1]
  102. $iLV_Height = $aResult[2]
  103. $iLV_Left = $aResult[3]
  104. $iLV_Top = $aResult[4]
  105. ; Multiline GUI
  106. $Result = IniRead($iniFileName, "General", "MultilineView", $MultiLine_Width & "," & $MultiLine_Height & "," & $MultiLine_Left & "," & $MultiLine_Top )
  107. $aResult = StringSplit($Result, ",")
  108. $MultiLine_Width = $aResult[1]
  109. $MultiLine_Height = $aResult[2]
  110. $MultiLine_Left = $aResult[3]
  111. $MultiLine_Top = $aResult[4]
  112. EndIf
  113. Global $aSQL = IniReadSection($iniFileName, "SQL")
  114. Global $aReportTitles = IniReadSection($iniFileName, "Titles")
  115. Global $aParameters = IniReadSection($iniFileName, "Parameters")
  116. ; make a single array out of the multi-dimentional array
  117. Dim $aMenu[$aReportTitles[0][0]]
  118. For $i = 0 To $aReportTitles[0][0] - 1
  119. $aMenu[$i] = $aReportTitles[$i + 1][1]
  120. Next
  121. #endregion ini
  122. #region SQL Startup
  123. ;~ If @AutoItX64 Then
  124. ;~ Local $sSQliteDll = _SQLite_Startup(@ScriptDir & "SQLite3_x64.dll")
  125. ;~ If @error > 0 Then Exit MsgBox(16, "SQLite Error", "SQLite3_x64.dll Can't be Loaded!")
  126. ;~ Else
  127. ;~ Local $sSQliteDll = _SQLite_Startup(@ScriptDir & "\SQLite3.dll")
  128. ;~ If @error > 0 Then Exit MsgBox(16, "SQLite Error", "SQLite3.dll Can't be Loaded!")
  129. ;~ EndIf
  130. Local $sSQliteDll = _SQLite_Startup()
  131. If Not @Compiled Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ") : SQLite3.dll Loaded " & $sSQliteDll & " (" & _SQLite_LibVersion() & ")" & @CRLF)
  132. #endregion SQL Startup
  133. While 1 ; Menu loop
  134. $Choice = _ArrayMenu($aMenu, "Reports", "Select", $iIndex - 1, $iAM_Width, $iAM_Height, $iAM_Left, $iAM_Top)
  135. If $Choice == "" Then _Exit()
  136. $iIndex = _ArraySearch($aReportTitles, $Choice, 1, 0, 0, 0, 1, 1) ; find selected element number
  137. ; If Not @Compiled Then ConsoleWrite(@ScriptLineNumber & " You selected: " & $Choice & " ==> " & $iIndex & " ==> " & $aSQL[$iIndex][1] & @CR)
  138. #region ini debug
  139. ; if debug is enabled, reread the essential SQL sections
  140. ; this will allow to modify the SQL sections, titles and parameters and run the report without having to restart the script
  141. If $iDebug Then
  142. $aSQL = IniReadSection($iniFileName, "SQL")
  143. $aReportTitles = IniReadSection($iniFileName, "Titles")
  144. $aParameters = IniReadSection($iniFileName, "Parameters")
  145. ; make a single array out of the multi-dimentional array
  146. Dim $aMenu[$aReportTitles[0][0] + 1]
  147. For $i = 0 To $aReportTitles[0][0] - 1
  148. $aMenu[$i] = $aReportTitles[$i + 1][1]
  149. Next
  150. EndIf
  151. #endregion ini debug
  152. #region Parameters
  153. ; string parameters, maximum 2: %1% and %2%
  154. ; date parameters: %d1% and %d2%
  155. If StringInStr($aSQL[$iIndex][1], "1%") > 0 Then ; capture if SQL contains dynamic parameters
  156. If $iIndex <> $iKeeppreviousIndex Then ; remember the parameter only if the selection does not change
  157. $Parameter1 = ""
  158. $Parameter2 = ""
  159. EndIf
  160. If StringInStr($aSQL[$iIndex][1], "%2%") > 0 Then
  161. ; 2 string parameters
  162. $lblParameter1 = StringTrimRight($aParameters[$iIndex][1], StringLen($aParameters[$iIndex][1]) - StringInStr($aParameters[$iIndex][1], ",") + 1)
  163. $lblParameter2 = StringTrimLeft($aParameters[$iIndex][1], StringLen($lblParameter1) + 1)
  164. $aParameter = _InputBox("Parameters", _
  165. StringTrimRight($lblParameter1, StringLen($lblParameter1) - StringInStr($lblParameter1, "|") + 1) & ": ", $Parameter1, "", StringTrimLeft($lblParameter1, StringInStr($lblParameter1, "|")), _
  166. StringTrimRight($lblParameter2, StringLen($lblParameter2) - StringInStr($lblParameter2, "|") + 1) & ": ", $Parameter2, "", StringTrimLeft($lblParameter2, StringInStr($lblParameter2, "|")), _
  167. Default , Default , $iAM_Left + ($iAM_Width - 250)/2, $iAM_Top + ($iAM_Height - 170)/2 )
  168. If @error = 1 Then ContinueLoop ; Escape
  169. $Parameter1 = $aParameter[0]
  170. $Parameter2 = $aParameter[1]
  171. $sSQL = StringReplace($aSQL[$iIndex][1], "%1%", $aParameter[0])
  172. $sSQL = StringReplace($sSQL, "%2%", $aParameter[1])
  173. $TitleParams = " - " & StringTrimRight($lblParameter1, StringLen($lblParameter1) - StringInStr($lblParameter1, "|") + 1) & " : " & $Parameter1 & " - " & _
  174. StringTrimRight($lblParameter2, StringLen($lblParameter2) - StringInStr($lblParameter2, "|") + 1) & " : " & $Parameter2 & " "
  175. ElseIf StringInStr($aSQL[$iIndex][1], "%1%") > 0 Then
  176. ; 1 string parameter
  177. $lblParameter1 = $aParameters[$iIndex][1]
  178. $aParameter = _InputBox("Parameter", StringTrimRight($lblParameter1, StringLen($lblParameter1) - StringInStr($lblParameter1, "|") + 1) & ": ", $Parameter1, "", StringTrimLeft($lblParameter1, StringInStr($lblParameter1, "|")), _
  179. "", "", "", "", _
  180. Default , Default , $iAM_Left + ($iAM_Width - 250)/2, $iAM_Top + ($iAM_Height - 170)/2 )
  181. If @error = 1 Then ContinueLoop ; Escape
  182. $Parameter1 = $aParameter[0]
  183. $sSQL = StringReplace($aSQL[$iIndex][1], "%1%", $aParameter[0])
  184. $TitleParams = " - " & StringTrimRight($lblParameter1, StringLen($lblParameter1) - StringInStr($lblParameter1, "|") + 1) & " : " & $Parameter1
  185. ElseIf StringInStr($aSQL[$iIndex][1], "%d2%") > 0 Then
  186. ; 2 date parameters
  187. $lblParameter1 = StringTrimRight($aParameters[$iIndex][1], StringLen($aParameters[$iIndex][1]) - StringInStr($aParameters[$iIndex][1], ",") + 1)
  188. $lblParameter2 = StringTrimLeft($aParameters[$iIndex][1], StringLen($lblParameter1) + 1)
  189. $aParameter = _InputDate($Parameter1, $Parameter2)
  190. If @error Then ContinueLoop ; Escape
  191. $Parameter1 = DateFormat($aParameter[1], $sDbDateFormat)
  192. $sSQL = StringReplace($aSQL[$iIndex][1], "%d1%", $Parameter1)
  193. $Parameter2 = DateFormat($aParameter[2], $sDbDateFormat)
  194. $sSQL = StringReplace($sSQL, "%d2%", $Parameter2)
  195. $TitleParams = " - From " & $Parameter1 & " to " & $Parameter2 & " [" & $aParameter[0] + 1 & " days] "
  196. Else
  197. ; 1 date parameters
  198. $lblParameter1 = $aParameters[$iIndex][1]
  199. $aParameter = _InputDate($Parameter1, Default, False)
  200. If @error Then ContinueLoop ; Escape
  201. $Parameter1 = DateFormat($aParameter[1], $sDbDateFormat)
  202. $sSQL = StringReplace($aSQL[$iIndex][1], "%d1%", $Parameter1)
  203. $TitleParams = " - On " & $Parameter1
  204. EndIf
  205. $iKeeppreviousIndex = $iIndex
  206. Else
  207. $TitleParams = ""
  208. $sSQL = $aSQL[$iIndex][1]
  209. EndIf
  210. ;If Not @Compiled Then ConsoleWrite ("SQL: " & $sSQL & @CRLF)
  211. #endregion Parameters
  212. ; first open a new file
  213. $FileHandle = FileOpen(@TempDir & "\" & $Choice & ".csv", 2)
  214. If $FileHandle = -1 Then
  215. MsgBox(16, "Error", "Can't open file:" & @LF & @TempDir & "\" & $Choice & ".csv" & @LF & "Please check if the file is not in use!")
  216. ContinueLoop
  217. EndIf
  218. ToolTip("Creating Report, please wait", $iLV_Left + ($iLV_Width)/2, $iLV_Top + ($iLV_Height)/2, "Reports", 0, 2)
  219. #region SQL Open
  220. $DataBase = _SQLite_Open(@ScriptDir & "\" & $Db, $SQLITE_OPEN_READWRITE)
  221. If @error Then Exit MsgBox(16, "_SQLite_Open Error " & @error, "Can't Load Database " & @ScriptDir & "\" & $Db & @LF & "@extended " & @extended)
  222. #endregion SQL Open
  223. ; Create Listview GUI
  224. $SQLResultWindow = GUICreate($Choice, $iLV_Width, $iLV_Height, $iLV_Left, $iLV_Top, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
  225. If $iLV_OffsetWidth = Default Then
  226. ; remember the difference between the result of WinGetClientSize and the initial Width and Height of the GUI
  227. $size = WinGetClientSize($SQLResultWindow)
  228. $iLV_OffsetWidth = $iLV_Width - $size[0]
  229. $iLV_OffsetHeight = $iLV_Height - $size[1]
  230. EndIf
  231. $BtSQL = GUICtrlCreateButton('SQL', 5, $iLV_Height - 28, 85, 25)
  232. GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM)
  233. $BtClose = GUICtrlCreateButton('Close', $iLV_Width - 90, $iLV_Height - 28, 85, 25)
  234. GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM)
  235. $BtExport = GUICtrlCreateButton('Export Excel', $iLV_Width - 180, $iLV_Height - 28, 85, 25)
  236. GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM)
  237. $hListView = GUICtrlCreateListView('', 0, 0, $iLV_Width, $iLV_Height - 30, Default, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP))
  238. GUICtrlSetResizing($hListView, $GUI_DOCKBORDERS)
  239. GUISetIcon("SQLite2.ico", 0)
  240. ; will display all records of an SQL
  241. $Result = _SQLite_Query(-1, $sSQL & ";", $hQuery)
  242. If $Result = $SQLITE_OK Then
  243. ;If Not @Compiled Then ConsoleWrite("SELECT success" & @LF & @LF)
  244. ; Set the Titles in the listview
  245. _SQLite_FetchNames($hQuery, $aNames) ; Read out Column Names
  246. If UBound($aNames) = 1 And $aNames[0] = "" Then
  247. ToolTip("")
  248. FileClose($FileHandle)
  249. GUIDelete($SQLResultWindow)
  250. MsgBox(64, "SQLite Info", "Command " & $sSQL & " performed")
  251. FileDelete(@TempDir & "\" & $Choice & ".csv")
  252. ContinueLoop
  253. Else
  254. ExportData($aNames)
  255. For $i = 0 To UBound($aNames) - 1
  256. _GUICtrlListView_InsertColumn($hListView, $i, $aNames[$i], 50)
  257. Next
  258. ; Rows
  259. While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
  260. ExportData($aRow)
  261. WEnd
  262. EndIf
  263. Else
  264. ToolTip("")
  265. FileClose($FileHandle)
  266. If _SQLite_ErrMsg() = "not an error" Then ; command that does not return results but has not to be considered as an error
  267. GUIDelete($SQLResultWindow)
  268. MsgBox(64, "SQLite Info", "Command " & $sSQL & " performed")
  269. FileDelete(@TempDir & "\" & $Choice & ".csv")
  270. ContinueLoop
  271. Else
  272. GUIDelete($SQLResultWindow)
  273. MsgBox(48, "SQLite Error", "Error: " & _SQLite_ErrMsg() & @CR & "Query: " & $sSQL)
  274. FileDelete(@TempDir & "\" & $Choice & ".csv")
  275. ContinueLoop
  276. EndIf
  277. EndIf
  278. #region SQL Close
  279. _SQLite_Close()
  280. #endregion SQL Close
  281. FileClose($FileHandle)
  282. $aResult = _ParseCSV(@TempDir & "\" & $Choice & ".csv", $ListDelimiter) ; convert csv into an array to populate the Listview
  283. If UBound($aResult) = 0 Then
  284. ToolTip("")
  285. GUIDelete($SQLResultWindow)
  286. MsgBox(64, "SQLite Info", "Command " & $sSQL & " performed")
  287. FileDelete(@TempDir & "\" & $Choice & ".csv")
  288. ContinueLoop
  289. EndIf
  290. WinSetTitle($Choice, '', $Choice & $TitleParams & " (" & UBound($aResult) - 1 & " rows)")
  291. GUISetState(@SW_SHOW, $SQLResultWindow)
  292. _GUICtrlListView_RegisterSortCallBack($hListView, True, True)
  293. _GUICtrlListView_BeginUpdate($hListView)
  294. ;_ArrayDisplay($aResult, @ScriptLineNumber)
  295. For $i = 1 To UBound($aResult) - 1 ; start at row 2 to skip titles
  296. $sRow = ""
  297. For $ii = 0 To UBound($aResult, 2) - 1
  298. $sRow &= $aResult[$i][$ii] & "|"
  299. Next
  300. $sRow = StringTrimRight($sRow, 1)
  301. GUICtrlCreateListViewItem($sRow, $hListView) ; create the listview elements
  302. Next
  303. For $i = 0 To UBound($aNames) - 1
  304. GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, $i, -1)
  305. GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, $i, -2) ; title
  306. Next
  307. _GUICtrlListView_EndUpdate($hListView)
  308. GUIRegisterMsg($WM_NOTIfY, "WM_NOTIfY2") ; new WM_NOTIfY2 to capture click and double click in this listview
  309. ToolTip("")
  310. While 1
  311. Switch GUIGetMsg()
  312. Case $GUI_EVENT_CLOSE
  313. ; Check If Active window closed is "Vertical View" , If correct, Then only close this GUI
  314. $Active_win = WinGetActive()
  315. If $Active_win[0] = "Vertical View" Then
  316. $size = WinGetPos($GUI_VerticalView)
  317. $VertView_Left = $size[0]
  318. $VertView_Top = $size[1]
  319. $size = WinGetClientSize($GUI_VerticalView)
  320. $VertView_Width = $size[0] + $VertView_OffsetWidth
  321. $VertView_Height = $size[1] + $VertView_OffsetHeight
  322. GUIDelete($GUI_VerticalView)
  323. $bVerticalView_GUI = False
  324. WinActivate($SQLResultWindow)
  325. ElseIf $Active_win[0] = "Cell Content" Then
  326. $size = WinGetPos($hGUI_Multiline)
  327. $MultiLine_Left = $size[0]
  328. $MultiLine_Top = $size[1]
  329. $size = WinGetClientSize($hGUI_Multiline)
  330. $MultiLine_Width = $size[0] + $MultiLine_OffsetWidth
  331. $MultiLine_Height = $size[1] + $MultiLine_OffsetHeight
  332. GUIDelete($hGUI_Multiline)
  333. WinActivate($SQLResultWindow)
  334. Else
  335. ExitLoop
  336. EndIf
  337. Case $BtClose
  338. ; Check If Active window closed is "Vertical View" , If correct, Then only close this GUI
  339. $Active_win = WinGetActive()
  340. If $Active_win[0] = "Vertical View" Then
  341. $size = WinGetPos($GUI_VerticalView)
  342. $VertView_Left = $size[0]
  343. $VertView_Top = $size[1]
  344. $size = WinGetClientSize($GUI_VerticalView)
  345. $VertView_Width = $size[0] + $VertView_OffsetWidth
  346. $VertView_Height = $size[1] + $VertView_OffsetHeight
  347. GUIDelete($GUI_VerticalView)
  348. $bVerticalView_GUI = False
  349. WinActivate($SQLResultWindow)
  350. ElseIf $Active_win[0] = "Cell Content" Then
  351. $size = WinGetPos($hGUI_Multiline)
  352. $MultiLine_Left = $size[0]
  353. $MultiLine_Top = $size[1]
  354. $size = WinGetClientSize($hGUI_Multiline)
  355. $MultiLine_Width = $size[0] + $MultiLine_OffsetWidth
  356. $MultiLine_Height = $size[1] + $MultiLine_OffsetHeight
  357. GUIDelete($hGUI_Multiline)
  358. WinActivate($SQLResultWindow)
  359. Else
  360. ExitLoop
  361. EndIf
  362. Case $bVerticalView_GUI And $VerticalView_Copy ; only allow copy to clipboard If Vertical Vew is open
  363. $To_Clip = ""
  364. For $i_I = 0 To UBound($aVertView) - 1
  365. ; exact column Order
  366. For $i_C = 0 To UBound($aVertView, 2) - 1
  367. $To_Clip = $To_Clip & $aVertView[$i_I][$i_C] & $ListDelimiter
  368. Next
  369. $To_Clip = StringTrimRight($To_Clip, 1) & @CRLF
  370. Next
  371. ; put to clipboard
  372. ClipPut($To_Clip)
  373. ;MsgBox(0, "_ArrayToClip() Test", ClipGet())
  374. Case $BtSQL
  375. View_SQL($sSQL, $Choice)
  376. Case $hListView ; clicked column header, thus sort
  377. If UBound($aResult) > 200 Then
  378. ToolTip("Sorting", Default, Default, "Please wait", 1, 2)
  379. EndIf
  380. _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
  381. ToolTip("")
  382. Case $BtExport
  383. $Result = FileMove(@TempDir & "\" & $Choice & ".csv", @MyDocumentsDir, 1)
  384. If $Result = 0 Then
  385. MsgBox(16, "Error", "Can't copy file:" & @LF & @TempDir & "\" & $Choice & ".csv to " & @MyDocumentsDir & @LF & "Please check if the file is not in use!")
  386. Else
  387. Local $oExcel = ObjCreate("Excel.Application")
  388. If Not IsObj($oExcel) Then ; Excel not found, another program maybe?
  389. ShellExecute(Chr(34) & @MyDocumentsDir & "\" & $Choice & ".csv" & Chr(34))
  390. Else
  391. ; any error will be intercepted by the Comm error handler
  392. With $oExcel
  393. .Visible = 1
  394. .WorkBooks.OpenText(Chr(34) & @MyDocumentsDir & "\" & $Choice & ".csv" & Chr(34), _
  395. Default, 1, 1, -4142, False, False, False, False, False, True, $ListDelimiter)
  396. .ActiveWorkbook.Sheets(1).Select()
  397. .ActiveSheet.Range(.Columns(1), .Columns(_GUICtrlListView_GetColumnCount($hListView))).AutoFit
  398. .ActiveSheet.Range(.Rows(1), .Rows(_GUICtrlListView_GetItemCount($hListView)+1)).AutoFit
  399. .Activesheet.Range("A2").Select
  400. .ActiveWindow.FreezePanes = True
  401. EndWith
  402. EndIf
  403. EndIf
  404. EndSwitch
  405. WEnd
  406. $size = WinGetPos($SQLResultWindow)
  407. $iLV_Left = $size[0]
  408. $iLV_Top = $size[1]
  409. $size = WinGetClientSize($SQLResultWindow)
  410. $iLV_Width = $size[0] + $iLV_OffsetWidth
  411. $iLV_Height = $size[1] + $iLV_OffsetHeight
  412. GUIDelete($SQLResultWindow)
  413. FileDelete(@TempDir & "\" & $Choice & ".csv")
  414. WEnd
  415. _Exit()
  416. #FUNCTION# ==============================================================
  417. Func _Exit()
  418. IniWrite($iniFileName, "General", "DesktopWidth", $VirtualDesktopWidth) ; remember desktop width
  419. ; write GUI coordinates
  420. IniWrite($iniFileName, "General", "Menu", $iAM_Width & "," & $iAM_Height & "," & $iAM_Left & "," & $iAM_Top )
  421. IniWrite($iniFileName, "General", "VerticalView", $VertView_Width & "," & $VertView_Height & "," & $VertView_Left & "," & $VertView_Top )
  422. IniWrite($iniFileName, "General", "SQLResultView", $iLV_Width & "," & $iLV_Height & "," & $iLV_Left & "," & $iLV_Top )
  423. IniWrite($iniFileName, "General", "MultilineView", $MultiLine_Width & "," & $MultiLine_Height & "," & $MultiLine_Left & "," & $MultiLine_Top )
  424. Exit
  425. EndFunc ;==>_Exit
  426. #FUNCTION# ==============================================================
  427. Func View_MultilineCell($Cell_content, $Column_name = "")
  428. Local $Msg2, $window_open, $size
  429. If $Cell_content = "" Then
  430. ; clicked on no-nmultiline cell, so close the window
  431. $window_open = WinList("Cell Content")
  432. If $window_open[0][0] > 0 Then
  433. $size = WinGetPos($hGUI_Multiline)
  434. $MultiLine_Left = $size[0]
  435. $MultiLine_Top = $size[1]
  436. $size = WinGetClientSize($hGUI_Multiline)
  437. $MultiLine_Width = $size[0] + $MultiLine_OffsetWidth
  438. $MultiLine_Height = $size[1] + $MultiLine_OffsetHeight
  439. GUIDelete($hGUI_Multiline)
  440. EndIf
  441. Return
  442. Else
  443. $window_open = WinList("Cell Content") ; check If window already exists
  444. If $window_open[0][0] = 0 Then
  445. ; If the window does not exist yet, create it
  446. Local Const $_ARRAYCONSTANT_WS_MAXIMIZEBOX = 0x00010000
  447. Local Const $_ARRAYCONSTANT_WS_MINIMIZEBOX = 0x00020000
  448. Local Const $_ARRAYCONSTANT_WS_SIZEBOX = 0x00040000
  449. $hGUI_Multiline = GUICreate("Cell Content", $MultiLine_Width, $MultiLine_Height, $MultiLine_Left, $MultiLine_Top, BitOR($_ARRAYCONSTANT_WS_SIZEBOX, $_ARRAYCONSTANT_WS_MINIMIZEBOX, $_ARRAYCONSTANT_WS_MAXIMIZEBOX), $WS_EX_TOPMOST, $SQLResultWindow);($WS_POPUPWINDOW), $WS_EX_TOPMOST,$SQLResultWindow) ;( $WS_POPUPWINDOW $WS_BORDER) $WS_EX_TOPMOST,$SQLResultWindow)
  450. $ColName = GUICtrlCreateLabel("Content of " & $Column_name, 5, 2, $MultiLine_Width, 20)
  451. $View_Multiline = GUICtrlCreateEdit($Cell_content, 5, 20, $MultiLine_Width - 10, $MultiLine_Height - 50, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL))
  452. GUICtrlSetResizing($View_Multiline, $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT + $GUI_DOCKLEFT)
  453. GUICtrlSetResizing($ColName, $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT)
  454. GUICtrlSetColor(-1, $iDark_Blue)
  455. GUICtrlSetBkColor(-1, $iLight_Green)
  456. GUICtrlCreateLabel("Click on any non-multiline cell to hide this pop-up", 35, $MultiLine_Height - 15, $MultiLine_Width)
  457. GUICtrlSetFont(-1, 7, 400)
  458. GUISetIcon("SQLite2.ico", 0)
  459. If $MultiLine_OffsetWidth = Default Then
  460. ; remember the difference between the result of WinGetClientSize and the initial Width and Height of the GUI
  461. $size = WinGetClientSize($hGUI_Multiline)
  462. $MultiLine_OffsetWidth = $MultiLine_Width - $size[0]
  463. $MultiLine_OffsetHeight = $MultiLine_Height - $size[1]
  464. EndIf
  465. Else
  466. ; window already exist so only change the content
  467. GUICtrlSetData($ColName, "Content of " & $Column_name) ; column title
  468. GUICtrlSetData($View_Multiline, $Cell_content) ; cell content
  469. EndIf
  470. GUISetState()
  471. Return
  472. EndIf
  473. EndFunc ;==>View_MultilineCell
  474. #FUNCTION# ==============================================================
  475. Func WinGetActive()
  476. ; Default Retrieving active window in AutoIt
  477. ; So I've had this problem for a long time and I've never figured out how to do it until now.
  478. ; This function returns an array with two values:
  479. ; $aWindow[0] returns the title of the window
  480. ; $aWindow[1] returns the window handle
  481. Dim $aWindow[2]
  482. Dim $aWinlist
  483. $aWinlist = WinList()
  484. For $i_I = 1 To $aWinlist[0][0]
  485. If $aWinlist[$i_I][0] <> "" And IsVisible($aWinlist[$i_I][1]) Then
  486. $aWindow[0] = $aWinlist[$i_I][0]
  487. $aWindow[1] = $aWinlist[$i_I][1]
  488. ExitLoop
  489. EndIf
  490. Next
  491. Return $aWindow
  492. EndFunc ;==>WinGetActive
  493. #FUNCTION# ==============================================================
  494. Func IsVisible($handle)
  495. If BitAND(WinGetState($handle), 2) Then
  496. Return 1
  497. Else
  498. Return 0
  499. EndIf
  500. EndFunc ;==>IsVisible
  501. #FUNCTION# ==============================================================
  502. ; #FUNCTION# ====================================================================================================================
  503. ; Name...........: _ParseCSV
  504. ; Description ...: Reads a CSV-file
  505. ; Syntax.........: _ParseCSV($sFile, $sDelimiters=',', $sQuote='"', $iFormat=0)
  506. ; Parameters ....: $sFile - File to read or string to parse
  507. ; $sDelimiters - [optional] Fieldseparators of CSV, mulitple are allowed (default: ,;)
  508. ; $sQuote - [optional] Character to quote strings (default: ")
  509. ; $iFormat - [optional] Encoding of the file (default: 0):
  510. ; |-1 - No file, plain data given
  511. ; |0 or 1 - automatic (ASCII)
  512. ; |2 - Unicode UTF16 Little Endian reading
  513. ; |3 - Unicode UTF16 Big Endian reading
  514. ; |4 or 5 - Unicode UTF8 reading
  515. ; Return values .: Success - 2D-Array with CSV data (0-based)
  516. ; Failure - 0, sets @error to:
  517. ; |1 - could not open file
  518. ; |2 - error on parsing data
  519. ; |3 - wrong format chosen
  520. ; Author ........: ProgAndy
  521. ; Modified.......:
  522. ; Remarks .......:
  523. ; Related .......: _WriteCSV
  524. ; Link ..........:
  525. ; Example .......:
  526. ; ===============================================================================================================================
  527. Func _ParseCSV($sFile, $sDelimiters = ',;', $sQuote = '"', $iFormat = 0)
  528. Local Static $aEncoding[6] = [0, 0, 32, 64, 128, 256]
  529. If $iFormat < -1 Or $iFormat > 6 Then
  530. Return SetError(3, 0, 0)
  531. ElseIf $iFormat > -1 Then
  532. Local $hFile = FileOpen($sFile, $aEncoding[$iFormat]), $sLine, $aTemp, $aCSV[1], $iReserved, $iCount
  533. If @error Then Return SetError(1, @error, 0)
  534. $sFile = FileRead($hFile)
  535. FileClose($hFile)
  536. EndIf
  537. If $sDelimiters = "" Or IsKeyword($sDelimiters) Then $sDelimiters = ',;'
  538. If $sQuote = "" Or IsKeyword($sQuote) Then $sQuote = '"'
  539. $sQuote = StringLeft($sQuote, 1)
  540. Local $srDelimiters = StringRegExpReplace($sDelimiters, '[\\\^\-\[\]]', '\\\0')
  541. Local $srQuote = StringRegExpReplace($sQuote, '[\\\^\-\[\]]', '\\\0')
  542. Local $sPattern = StringReplace(StringReplace('(?m)(?:^|[,])\h*(["](?:[^"]|["]{2})*["]|[^,\r\n]*)(\v+)?', ',', $srDelimiters, 0, 1), '"', $srQuote, 0, 1)
  543. Local $aREgex = StringRegExp($sFile, $sPattern, 3)
  544. If @error Then Return SetError(2, @error, 0)
  545. $sFile = '' ; save memory
  546. Local $iBound = UBound($aREgex), $iIndex = 0, $iSubBound = 1, $iSub = 0
  547. Local $aResult[$iBound][$iSubBound]
  548. For $i = 0 To $iBound - 1
  549. Select
  550. Case StringLen($aREgex[$i]) < 3 And StringInStr(@CRLF, $aREgex[$i])
  551. $iIndex += 1
  552. $iSub = 0
  553. ContinueLoop
  554. Case StringLeft(StringStripWS($aREgex[$i], 1), 1) = $sQuote
  555. $aREgex[$i] = StringStripWS($aREgex[$i], 3)
  556. $aResult[$iIndex][$iSub] = StringReplace(StringMid($aREgex[$i], 2, StringLen($aREgex[$i]) - 2), $sQuote & $sQuote, $sQuote, 0, 1)
  557. Case Else
  558. $aResult[$iIndex][$iSub] = $aREgex[$i]
  559. EndSelect
  560. $aREgex[$i] = 0 ; save memory
  561. $iSub += 1
  562. If $iSub = $iSubBound Then
  563. $iSubBound += 1
  564. ReDim $aResult[$iBound][$iSubBound]
  565. EndIf
  566. Next
  567. If $iIndex = 0 Then $iIndex = 1
  568. ReDim $aResult[$iIndex][$iSubBound]
  569. Return $aResult
  570. EndFunc ;==>_ParseCSV
  571. #FUNCTION# ==============================================================
  572. Func ExportData($aRow)
  573. ; will export all records fetched by SQL
  574. Local $Row = ""
  575. For $ColItem In $aRow
  576. If StringIsFloat($ColItem) Then
  577. $ColItem = StringReplace($ColItem, ".", $sDecimal) ; convert Floating Point with decimal separator compliant with Excel
  578. Else ; If StringInStr($ColItem,@LF)>0 Then
  579. $ColItem = Chr(34) & StringReplace($ColItem, Chr(34), "'") & Chr(34) ;Replace all " by ' before putting the string between double quotes to avoid Excel conflicts
  580. EndIf
  581. $Row &= $ColItem & $ListDelimiter
  582. Next
  583. $Row = StringTrimRight($Row, 1) & @CRLF
  584. FileWriteLine($FileHandle, $Row)
  585. Return
  586. EndFunc ;==>ExportData
  587. #FUNCTION# ==============================================================
  588. ; #FUNCTION# ====================================================================================================================
  589. ; Name ..........: _ArrayMenu
  590. ; Description ...: Creates a menu from Array items
  591. ; Syntax ........: _ArrayMenu($aMenu[, $sGUITitle= ""[, $sTitle = "Select"[, [$RowSelected = 1[, $iWidth = Default[, $iHeight = Default[, $iLeft = Default[, $iTop = Default]]]]]]])
  592. ; Parameters ....: $aMenu - A single dimension array containing the items to display as a menu
  593. ; $sGUITitle - [optional] Title for the selection
  594. ; $sTitle - [optional] The title of the selection box (default = "Select")
  595. ; $RowSelected - [optional] The Row that has focus in the selection box (default = 1)
  596. ; $iWidth - [optional] The width of the window.
  597. ; $iHeight - [optional] The height of the window.
  598. ; $iLeft - [optional] The left side of the dialog box. By default (-1), the window is centered. If defined, top must also be defined.
  599. ; $iTop - [optional] The top of the dialog box. Default (-1) is centered
  600. ;
  601. ; Return values .: Success (if a selection was made) - Returns Name of element
  602. ; Failure (if escape was pressed) - Returns an empty string
  603. ;
  604. ; Requirements ..: _ArrayMenu requires $Menu_ListView and $DoubleClicked to be declared as Global variables.
  605. ; Global $Menu_ListView, $DoubleClicked
  606. ; Author ........: Greencan
  607. ; Related .......:
  608. ; Remarks .......: _ArrayMenu always shows TOPMOST
  609. ; Link ..........;
  610. ; Example .......; Yes
  611. ; ===============================================================================================================================
  612. Func _ArrayMenu($aMenu, $sGUITitle = "", $sTitle = "Select", $RowSelected = 1, $iWidth = Default, $iHeight = Default, $iLeft = Default, $iTop = Default)
  613. $DoubleClicked = False ; Declared as Global var
  614. Local $mainmsg, $size
  615. ;~ Local $Menu_Window = GuiCreate(" " & $sGUITitle, $iWidth, $iHeight, $iLeft, $iTop, $WS_DLGFRAME, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
  616. ;~ Local $Menu_Window = GUICreate(" " & $sGUITitle, $iWidth, $iHeight, $iLeft, $iTop, Default, $WS_EX_TOPMOST)
  617. Local $Menu_Window = GUICreate(" " & $sGUITitle, $iWidth, $iHeight, $iLeft, $iTop, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX), $WS_EX_TOPMOST)
  618. Local $aSize = WinGetClientSize($Menu_Window)
  619. If $iLV_OffsetWidth = Default Then
  620. ; remember the difference between the result of WinGetClientSize and the initial Width and Height of the GUI
  621. $iAM_Width = $iWidth
  622. $iAM_Height = $iHeight
  623. $iAM_OffsetWidth = $iAM_Width - $aSize[0]
  624. $iAM_OffsetHeight = $iAM_Height - $aSize[1]
  625. EndIf
  626. Local $Menu_ListView = GUICtrlCreateListView($sTitle, 5, 30, $aSize[0] - 10, $aSize[1] - 65, BitOR($LVS_NOCOLUMNHEADER, $LVS_SHOWSELALWAYS, $LVS_SINGLESEL))
  627. GUICtrlCreateLabel($sTitle, 5, 10, $iWidth - 10, 15)
  628. For $i = 0 To UBound($aMenu) - 1
  629. GUICtrlCreateListViewItem($aMenu[$i], $Menu_ListView) ; Menu item
  630. Next
  631. Local $MainbuttonGo = GUICtrlCreateButton("Go", 5, $aSize[1] - 32, 100, 30, $BS_DEFPUSHBUTTON)
  632. Local $MainbuttonExit = GUICtrlCreateButton("Exit", $aSize[0] - 105, $aSize[1] - 32, 100, 30)
  633. GUISetIcon("SQLite2.ico", 0)
  634. ; Finished - Change the column width to fit the item text
  635. GUICtrlSendMsg($Menu_ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
  636. GUICtrlSendMsg($Menu_ListView, $LVM_SETCOLUMNWIDTH, 0, -2) ; title
  637. GUIRegisterMsg($WM_NOTIfY, "WM_NOTIFY") ; double click
  638. GUISetState(@SW_SHOW, $Menu_Window)
  639. _GUICtrlListView_ClickItem($Menu_ListView, $RowSelected)
  640. ; Run the GUI until the dialog is closed
  641. While 1
  642. $mainmsg = GUIGetMsg()
  643. Select
  644. Case $DoubleClicked Or $mainmsg = $MainbuttonGo
  645. $DoubleClicked = False
  646. $Choice = StringTrimRight(GUICtrlRead(GUICtrlRead($Menu_ListView)), 1)
  647. If $Choice <> "" Then
  648. $size = WinGetPos($Menu_Window)
  649. $iAM_Left = $size[0]
  650. $iAM_Top = $size[1]
  651. $size = WinGetClientSize($Menu_Window)
  652. $iAM_Width = $size[0] + $iAM_OffsetWidth
  653. $iAM_Height = $size[1] + $iAM_OffsetHeight
  654. GUIDelete($Menu_Window)
  655. Return $Choice
  656. EndIf
  657. Case $mainmsg = $GUI_EVENT_CLOSE Or $mainmsg = $MainbuttonExit; The End
  658. $size = WinGetPos($Menu_Window)
  659. $iAM_Left = $size[0]
  660. $iAM_Top = $size[1]
  661. $size = WinGetClientSize($Menu_Window)
  662. $iAM_Width = $size[0] + $iAM_OffsetWidth
  663. $iAM_Height = $size[1] + $iAM_OffsetHeight
  664. GUIDelete($Menu_Window)
  665. Return ""
  666. EndSelect
  667. WEnd ; Loop 1
  668. Return
  669. EndFunc ;==>_ArrayMenu
  670. #FUNCTION# ==============================================================
  671. ; #FUNCTION# ====================================================================================================================
  672. ; Name ..........: _InputBox
  673. ; Description ...: Alternative InputBox for one or two inputs
  674. ; Syntax ........: _InputBox($sTitle, $sPrompt1[, $sDefault1 = ""[, $sPwdChar1 = ""[, $sInputSetTip1 = ""[, $sPrompt2 = ""[, $sDefault2 = ""[, $sPwdChar2 = ""[, $sInputSetTip2 = ""[, $iWidth = Default[, $iHeight = Default[, $iLeft = Default[, $iTop = Default, $hwnd = Default]]]]]]]]]]])
  675. ; Parameters ....: $sTitle - The title of the input box.
  676. ; $sPrompt1 - Message to the user indicating what kind of input is expected.
  677. ; $sDefault1 - [optional] The value that the input box starts with (default = "")
  678. ; $sPwdChar1 - [optional] Password character if required, usualy '*' (default = "")
  679. ; $sInputSetTip1 - [optional] Tip text associated with the input (default = "")
  680. ; $sPrompt2 - [optional] Second Message to the user indicating what kind of input is expected.
  681. ; $sDefault2 - [optional] The value that the Second input box starts with (default = "")
  682. ; $sPwdChar2 - [optional] Password character if required, usualy '*' (default = "")
  683. ; $sInputSetTip2 - [optional] Tip text associated with the Second input (default = "")
  684. ; $iWidth - [optional] The width of the window.
  685. ; $iHeight - [optional] The height of the window.
  686. ; $iLeft - [optional] The left side of the dialog box. By default (-1), the window is centered. If defined, top must also be defined.
  687. ; $iTop - [optional] The top of the dialog box. Default (-1) is centered
  688. ; $hwnd - [optional] The window handle to use as the parent for this dialog
  689. ;
  690. ; Return values .: Success - Returns a single dimension array containing two elements:
  691. ; element 0 contains the value of input 1 and element 1 contains the value of input2
  692. ; If input 2 is not used, value of element 1 will be empty
  693. ; Failure - Returns @error 1
  694. ;
  695. ; Requirements ..:
  696. ; Author ........: Greencan
  697. ; Related .......:
  698. ; Remarks .......: The size of the dialog window will adapt dynamically to the number of required inputs
  699. ; Link ..........;
  700. ; Example .......; Yes
  701. ; ===============================================================================================================================
  702. Func _InputBox($sTitle, $sPrompt1, $sDefault1 = "", $sPwdChar1 = "", $sInputSetTip1 = "", $sPrompt2 = "", $sDefault2 = "", $sPwdChar2 = "", $sInputSetTip2 = "", $iWidth = Default, $iHeight = Default, $iLeft = Default, $iTop = Default, $hwnd = Default)
  703. Local $sInput1, $sInput2, $bOK, $bCancel, $msg, $avArray[2]
  704. ; ConsoleWrite(@ScriptLineNumber & " >" & $sInputSetTip1 & "< - >" & $sInputSetTip2 & "<" & @CR)
  705. If $iWidth = Default Then $iWidth = 250
  706. If $iHeight = Default Then
  707. If $sPrompt2 <> "" Then
  708. $iHeight = 170
  709. Else
  710. $iHeight = 130
  711. EndIf
  712. EndIf
  713. GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, $WS_SYSMENU, -1, $hwnd)
  714. GUICtrlCreateLabel($sPrompt1, 10, 10, $iWidth - 20, 20)
  715. If $sPwdChar1 <> "" Then
  716. $sInput1 = GUICtrlCreateInput($sDefault1, 15, 30, $iWidth - 30, 20, $ES_PASSWORD)
  717. Else
  718. $sInput1 = GUICtrlCreateInput($sDefault1, 15, 30, $iWidth - 30, 20)
  719. EndIf
  720. If $sInputSetTip1 <> "" Then GUICtrlSetTip(-1, $sInputSetTip1)
  721. If $sPrompt2 <> "" Then
  722. GUICtrlCreateLabel($sPrompt2, 10, 60, $iWidth - 20, 20)
  723. If $sPwdChar2 <> "" Then
  724. $sInput2 = GUICtrlCreateInput($sDefault2, 15, $iHeight - 90, $iWidth - 30, 20, $ES_PASSWORD)
  725. Else
  726. $sInput2 = GUICtrlCreateInput($sDefault2, 15, $iHeight - 90, $iWidth - 30, 20)
  727. EndIf
  728. If $sInputSetTip2 <> "" Then GUICtrlSetTip(-1, $sInputSetTip2)
  729. EndIf
  730. $bOK = GUICtrlCreateButton("OK", 30, $iHeight - 55, 77, 22, $BS_DEFPUSHBUTTON)
  731. $bCancel = GUICtrlCreateButton("Cancel", $iWidth - 107, $iHeight - 55, 77, 22)
  732. GUISetState()
  733. $msg = 0
  734. While 1
  735. $msg = GUIGetMsg()
  736. Select
  737. Case $msg = $bOK
  738. $avArray[0] = GUICtrlRead($sInput1)
  739. If $sPrompt2 <> "" Then $avArray[1] = GUICtrlRead($sInput2)
  740. GUIDelete()
  741. Return $avArray
  742. Case $msg = $bCancel Or $msg = $GUI_EVENT_CLOSE
  743. GUIDelete()
  744. Return SetError(1, 0, 0)
  745. EndSelect
  746. WEnd
  747. EndFunc ;==>_InputBox
  748. #FUNCTION# ==============================================================
  749. ; #FUNCTION# ====================================================================================================================
  750. ; Name ..........: _InputDate
  751. ; Description ...: Creates a Dialog for a single day or a period entry
  752. ; Syntax ........: _InputDate([$dFrom = Default[, $dTill = Default[, $bPeriod = Default[, $bLegality = Default]]]])
  753. ; Parameters ....: $dFrom - [optional] Date (if $bPeriod is True, starting the period ) (default = Default)
  754. ; $dTill - [optional] Date ending the Period, unused if $bPeriod is False (default = Default)
  755. ; $bPeriod - [optional] Bolean, if false, dialog will input one date (default = Default)
  756. ; $bLegality - [optional] Period Legality Check (default = Default)
  757. ;
  758. ; Return values .: Success - A single dimension array containing following elemnts:
  759. ; [0] - Number of days between From and Till ( is 0 if single date input)
  760. ; [1] - From date
  761. ; [2] - Till date ( is empty if single date input)
  762. ; Failure - Returns @error
  763. ; |1 - Escape pressed
  764. ; |2 - $bPeriod is not boolean
  765. ; |3 - $bLegality is not boolean
  766. ;
  767. ; Requirements ..:
  768. ; Author ........: Greencan
  769. ; Related .......:
  770. ; Remarks .......: Input dates Default to Date_Time_GetLocalTime() unless provided
  771. ; in 'yyyy/mm/dd' format
  772. ; Illegal formats will be replaced by Date_Time_GetLocalTime()
  773. ; function uses DateCalc.au3 (_DateCalc udf) from Sean Hart
  774. ; Link ..........;
  775. ; Example .......; Yes
  776. ; ===============================================================================================================================
  777. Func _InputDate($dFrom = Default, $dTill = Default, $bPeriod = Default, $bLegality = Default)
  778. If $dFrom = Default Then $dFrom = ""
  779. If $dTill = Default Then $dTill = ""
  780. If $bPeriod = Default Then $bPeriod = True
  781. If Not IsBool($bPeriod) Then Return SetError(2, 0, 0)
  782. If $bLegality = Default Then $bLegality = True
  783. If Not IsBool($bLegality) Then Return SetError(3, 0, 0)
  784. Local $_msg, $_ok, $Days_between, $sTitle, $iHeight
  785. Local $sDateFormat = RegRead("HKCU\Control Panel\International", "sShortDate") ; get system locale short Dateformat
  786. If $bPeriod Then
  787. $sTitle = "Set Period"
  788. $iHeight = 170
  789. Else
  790. $sTitle = "Set Date"
  791. $iHeight = 130
  792. EndIf
  793. ;~ Default , Default , $iAM_Left + (170 - 250)/2, $iAM_Top + ($iHeight - 170)/2 )
  794. ;~ $iAM_Width & "," & $iAM_Height & "," & $iAM_Left & "," & $iAM_Top
  795. ConsoleWrite(@ScriptLineNumber & " $iAM_Left:" & $iAM_Left & " $iAM_Top:" & $iAM_Top & " $iAM_Width:" & $iAM_Width & " $iAM_Height:" & $iAM_Height & " " & $iAM_Left + (172)/2 & " " & $iAM_Top + ( $iHeight)/2 & @CR)
  796. ;~ Local $input_Window = GUICreate($sTitle, 170, $iHeight, -1, -1, 0x00800000) ; $WS_BORDER = 0x00800000 requires #include <WindowsConstants.au3>
  797. Local $input_Window = GUICreate($sTitle, 170, $iHeight, $iAM_Left + ($iAM_Width - 172)/2, $iAM_Top + ($iAM_Height - $iHeight)/2, 0x00800000) ; $WS_BORDER = 0x00800000 requires #include <WindowsConstants.au3>
  798. If $bPeriod Then
  799. ; period
  800. GUICtrlCreateLabel("From:", 10, 22)
  801. $dFrom = GUICtrlCreateDate($dFrom, 50, 20, 100, 20, 0) ; $DTS_SHORTDATEFORMAT = 0 #include <DateTimeConstants.au3>
  802. GUICtrlCreateLabel("To:", 10, 52)
  803. $dTill = GUICtrlCreateDate($dTill, 50, 50, 100, 20, 0) ; $DTS_SHORTDATEFORMAT = 0 #include <DateTimeConstants.au3>
  804. Else
  805. ; Single date
  806. GUICtrlCreateLabel("Date:", 10, 22)
  807. $dFrom = GUICtrlCreateDate($dFrom, 50, 20, 100, 20, 0) ; $DTS_SHORTDATEFORMAT = 0 #include <DateTimeConstants.au3>
  808. EndIf
  809. $_ok = GUICtrlCreateButton("OK", 50, $iHeight - 60, 70, 20, 0x0001) ; $BS_DEFPUSHBUTTON = 0x0001 requires #include <ButtonConstants.au3>
  810. GUISetState()
  811. ; Run the GUI until the dialog is closed
  812. Do
  813. $_msg = GUIGetMsg()
  814. If $_msg = $_ok Then
  815. If $bPeriod Then
  816. $Days_between = _DateDiff('D', _DateCalc(GUICtrlRead($dFrom), $sDateFormat), _DateCalc(GUICtrlRead($dTill), $sDateFormat))
  817. ; period legality check
  818. If $bLegality = 1 And $Days_between < 0 Then
  819. GUICtrlCreateLabel("Incorrect Period", 48, 82, 120)
  820. GUICtrlSetColor(-1, 0xff0000)
  821. Beep(2000, 10)
  822. ContinueLoop
  823. Else
  824. Dim $Period[3]
  825. $Period[0] = $Days_between
  826. $Period[1] = GUICtrlRead($dFrom)
  827. $Period[2] = GUICtrlRead($dTill)
  828. GUIDelete($input_Window)
  829. Return $Period
  830. EndIf
  831. Else
  832. Dim $Period[3]
  833. $Period[0] = 0
  834. $Period[1] = GUICtrlRead($dFrom)
  835. $Period[2] = ""
  836. GUIDelete($input_Window)
  837. Return $Period
  838. EndIf
  839. GUISetState()
  840. EndIf
  841. Until $_msg = -3 ; $GUI_EVENT_CLOSE = -3 requires #include <GUIConstantsEx.au3>
  842. GUIDelete($input_Window)
  843. Return SetError(1, 0, 0)
  844. EndFunc ;==>_InputDate
  845. #FUNCTION# ==============================================================
  846. ; #FUNCTION# ====================================================================================================================
  847. ; Name ..........: _DateCalc
  848. ; Description ...: Returns the Date [and time] in format YYYY/MM/DD [HH:MM:SS],
  849. ; give the date / time in the system or specified format.
  850. ; Syntax ........: _DateCalc($sSysDateTime[, $dFormat = ""[, $tFormat = ""]])
  851. ; Parameters ....: $sSysDateTime - Input date [and time]
  852. ; $dFormat - [optional] Format of input date (default = "")
  853. ; $tFormat - [optional] Format of input time (default = "")
  854. ;
  855. ; Return values .: Success - Returns Date in in format YYYY/MM/DD [HH:MM:SS]
  856. ; Failure - Returns @error
  857. ; |1 - input date badly formatted
  858. ; |2 - input time badly formatted
  859. ;
  860. ; Requirements ..: None
  861. ; Author ........: Sean Hart <autoit@hartmail.ca>
  862. ; Related .......:
  863. ; Remarks .......: Date format can be provided without any separators only in
  864. ; the format YYYYMMDD.
  865. ; If system format is used it is current user format, NOT
  866. ; default user format (which may be different).
  867. ; 2 digit years converted: 81 - 99 -> 1981-1999
  868. ; 00 - 80 -> 2000-2080²
  869. ; Link ..........;
  870. ; Example .......; Yes
  871. ; ===============================================================================================================================
  872. Func _DateCalc($sSysDateTime, $dFormat = "", $tFormat = "")
  873. Local $sDay, $sMonth, $sYear, $sHour, $sMin, $sSec, $dSep, $tSep, $am, $pm, $split1[9], $split2[9], $sSysDate, $sSysTime, $isAM, $isPM, $sTestDate
  874. ;Local $dFormat, $tFormat
  875. ; Read default system time formats and separators from registry unless provided
  876. If $dFormat = "" Then
  877. $dFormat = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sShortDate")
  878. $dSep = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sDate")
  879. Else
  880. ; Extract separator from date format by finding first non recognised character
  881. For $x = 1 To StringLen($dFormat)
  882. If (Not (StringMid($dFormat, $x, 1) = "y")) And (Not (StringMid($dFormat, $x, 1) = "m")) And (Not (StringMid($dFormat, $x, 1) = "d")) Then
  883. $dSep = StringMid($dFormat, $x, 1)
  884. ExitLoop
  885. EndIf
  886. Next
  887. EndIf
  888. If $tFormat = "" Then
  889. $tFormat = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sShortDate")
  890. $tSep = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sDate")
  891. $am = RegRead("HKEY_CURRENT_USER\Control Panel\International", "s1159")
  892. $pm = RegRead("HKEY_CURRENT_USER\Control Panel\International", "s2359")
  893. Else
  894. ; Extract separator from time format by finding first non hour character
  895. For $x = 1 To StringLen($tFormat)
  896. If (Not (StringMid($tFormat, $x, 1) = "h")) Then
  897. $tSep = StringMid($tFormat, $x, 1)
  898. ExitLoop
  899. EndIf
  900. Next
  901. $am = "AM"
  902. $pm = "PM"
  903. EndIf
  904. ; Separate date and time if included (make break at first space)
  905. If StringInStr($sSysDateTime, " ") Then
  906. $sSysDate = StringLeft($sSysDateTime, StringInStr($sSysDateTime, " ") - 1)
  907. $sSysTime = StringStripWS(StringReplace($sSysDateTime, $sSysDate, ""), 1)
  908. Else
  909. $sSysDate = $sSysDateTime
  910. $sSysTime = ""
  911. EndIf
  912. ; Simple check of input date format (look for separators and unexpected non numeric characters)
  913. $sTestDate = StringReplace($sSysDate, $dSep, "")
  914. $sTestDate = "1" & $sTestDate
  915. If (String(Number($sTestDate)) <> $sTestDate) Then
  916. SetError(1)
  917. Return
  918. EndIf
  919. If (StringInStr($sSysDate, $dSep) = 0) And ($dSep <> "") Then
  920. SetError(1)
  921. Return
  922. EndIf
  923. If $sSysTime <> "" Then
  924. $sTestDate = StringReplace($sSysTime, $tSep, "")
  925. $sTestDate = StringReplace($sTestDate, $am, "")
  926. $sTestDate = StringReplace($sTestDate, $pm, "")
  927. $sTestDate = StringReplace($sTestDate, " ", "")
  928. $sTestDate = "1" & $sTestDate
  929. If (StringInStr($sSysTime, $tSep) = 0) Or (String(Number($sTestDate)) <> $sTestDate) Then
  930. SetError(2)
  931. Return
  932. EndIf
  933. EndIf
  934. ; Break up date components (using format as a template), unless format is YYYYMMDD
  935. If $dFormat = "YYYYMMDD" Then
  936. $sYear = StringMid($sSysDate, 1, 4)
  937. $sMonth = StringMid($sSysDate, 5, 2)
  938. $sDay = StringMid($sSysDate, 7, 2)
  939. Else
  940. $split1 = StringSplit($dFormat, $dSep)
  941. $split2 = StringSplit($sSysDate, $dSep)
  942. For $x = 1 To $split1[0]
  943. If StringInStr($split1[$x], "M") Then $sMonth = $split2[$x]
  944. If StringInStr($split1[$x], "d") Then $sDay = $split2[$x]
  945. If StringInStr($split1[$x], "y") Then $sYear = $split2[$x]
  946. Next
  947. EndIf
  948. ; Pad values with 0 if required and fix 2 digit year
  949. If StringLen($sMonth) = 1 Then $sMonth = "0" & $sMonth
  950. If StringLen($sDay) = 1 Then $sDay = "0" & $sDay
  951. If StringLen($sYear) = 2 Then
  952. If $sYear > 80 Then
  953. $sYear = "19" & $sYear
  954. Else
  955. $sYear = "20" & $sYear
  956. EndIf
  957. EndIf
  958. ; Break up time components (if given)
  959. If $sSysTime <> "" Then
  960. ; Look for AM/PM and note it, Then remove from the string
  961. $isPM = 0
  962. If StringInStr($sSysTime, $am) Then
  963. $sSysTime = StringReplace($sSysTime, " " & $am, "")
  964. $isPM = 1
  965. ElseIf StringInStr($sSysTime, $pm) Then
  966. $sSysTime = StringReplace($sSysTime, " " & $pm, "")
  967. $isPM = 2
  968. EndIf
  969. $split1 = StringSplit($tFormat, $tSep)
  970. $split2 = StringSplit($sSysTime, $tSep)
  971. $sSec = "00"
  972. For $x = 1 To $split2[0]
  973. If StringInStr($split1[$x], "h") Then $sHour = $split2[$x]
  974. If StringInStr($split1[$x], "m") Then $sMin = $split2[$x]
  975. If StringInStr($split1[$x], "s") Then $sSec = $split2[$x]
  976. Next
  977. ; Clean up time values (change hour to 24h and 0 pad values)
  978. If ($isPM = 1) And ($sHour = 12) Then $sHour = "00"
  979. If ($isPM = 2) And ($sHour < 12) Then $sHour = $sHour + 12
  980. If StringLen($sHour) = 1 Then $sHour = "0" & $sHour
  981. If StringLen($sMin) = 1 Then $sMin = "0" & $sMin
  982. If StringLen($sSec) = 1 Then $sSec = "0" & $sSec
  983. ; Return date with time
  984. Return $sYear & "/" & $sMonth & "/" & $sDay & " " & $sHour & ":" & $sMin & ":" & $sSec
  985. Else
  986. ; Return date only
  987. Return $sYear & "/" & $sMonth & "/" & $sDay
  988. EndIf
  989. EndFunc ;==>_DateCalc
  990. #FUNCTION# ==============================================================
  991. ; #FUNCTION# ====================================================================================================================
  992. ; Name ..........: DateFormat
  993. ; Description ...: Universal date format converter
  994. ; Converts the (default regional setting) PC Date format into any other specIfied date format:
  995. ; - convert date into another date format (for example ddd dd MMMM, yyyy)
  996. ; - convert date into day (d or dd)
  997. ; - convert date into month ( m, mm or mmm)
  998. ; - convert date into year (yy or yyyy)
  999. ; Syntax ........: DateFormat($InputDate[, $DateFmt = "mm/dd/yyyy"])
  1000. ; Parameters ....: $InputDate - Date to be converted
  1001. ; $DateFmt - [optional] Date format to convert to (default = "mm/dd/yyyy")
  1002. ;
  1003. ; Return values .: Success - Returns Date in in requested format
  1004. ; Failure (if escape was pressed) - Returns an empty string
  1005. ; Return values .: Success - A single dimension array containing following elemnts:
  1006. ; [0] - Number of days between From and Till ( is 0 if single date input)
  1007. ; [1] - From date
  1008. ; [2] - Till date ( is empty if single date input)
  1009. ; Failure - Returns @error
  1010. ; |1 - Input date badly formatted
  1011. ; |2 - Invalid Year in Date
  1012. ; |3 - Invalid Month in Date
  1013. ; |4 - Invalid Day in Date
  1014. ;
  1015. ; Requirements ..: _DateCalc() - The udf is included in this script
  1016. ; Author ........: Greencan
  1017. ; Related .......:
  1018. ; Remarks .......: Part of source code was borrowed from the Date conversion example provided by DaRam
  1019. ; http://www.autoitscript.com/forum/index.php?showtopic=76984&view=findpost&p=557834
  1020. ; DateCalc.au3 (_DateCalc udf) by Sean Hart
  1021. ; http://www.autoitscript.com/forum/index.php?showtopic=14084&view=findpost&p=96173
  1022. ; Link ..........;
  1023. ; Example .......; Yes
  1024. ; DateFormat( _NowCalcDate() , "dd-MM-yyyy" )
  1025. ; ===============================================================================================================================
  1026. Func DateFormat($InputDate, $DateFmt = "mm/dd/yyyy")
  1027. If StringLen($InputDate) < 6 Then Return SetError(1, 0, 0) ; Invalid Date ==> ddmmyy = 6
  1028. Local $sDateFormat = RegRead("HKCU\Control Panel\International", "sShortDate") ; get system locale short Dateformat
  1029. If $DateFmt = "" Then $DateFmt = "dd/mm/yyyy"
  1030. Local $DateValue = _DateCalc($InputDate, $sDateFormat) ; convert the date to yyyy/mm/dd
  1031. $DateValue = StringSplit($DateValue, "/")
  1032. ; error checking
  1033. If @error Then Return SetError(1, 0, 0) ; Invalid Input Date
  1034. If $DateValue[0] < 3 Then Return SetError(1, 0, 0) ; less than 3 parts in date not possible
  1035. If Int(Number($DateValue[1])) < 0 Then Return SetError(2, 0, 0) ; Invalid Year in Date
  1036. If Int(Number($DateValue[2])) < 1 Or Int(Number($DateValue[2])) > 12 Then Return SetError(3, 0, 0) ; Invalid Month in Date
  1037. If Int(Number($DateValue[3])) < 1 Or Int(Number($DateValue[3])) > 31 Then Return SetError(4, 0, 0) ; Invalid Day in Date
  1038. If Int(Number($DateValue[1])) < 100 Then $DateValue[1] = StringLeft(@YEAR, 2) & $DateValue[1]
  1039. $InputDate = $DateFmt
  1040. $InputDate = StringReplace($InputDate, "d", "@") ; Convert All Day References to @
  1041. $InputDate = StringReplace($InputDate, "m", "#") ; Convert All Month References to #
  1042. $InputDate = StringReplace($InputDate, "y", "&") ; Convert All Year References to &
  1043. $InputDate = StringReplace($InputDate, "&&&&", $DateValue[1]) ; Century and Year
  1044. $InputDate = StringReplace($InputDate, "&&", StringRight($DateValue[1], 2)) ; Year Only
  1045. $InputDate = StringReplace($InputDate, "&", "") ; Discard leftover Year Indicator
  1046. $InputDate = StringReplace($InputDate, "####", _DateToMonth($DateValue[2], 0)) ; Long Month Name
  1047. $InputDate = StringReplace($InputDate, "###", _DateToMonth($DateValue[2], 1)) ; Short Month Name
  1048. If StringLen($DateValue[1]) < 2 Then
  1049. $InputDate = StringReplace($InputDate, "##", "0" & $DateValue[2]) ; Month Number 2 Digit
  1050. Else
  1051. $InputDate = StringReplace($InputDate, "##", $DateValue[2]) ; Month Number 2 Digit
  1052. EndIf
  1053. $InputDate = StringReplace($InputDate, "#", Int($DateValue[2])) ; Month Number
  1054. Local $iPos = _DateToDayOfWeek($DateValue[1], $DateValue[2], $DateValue[3]) ; Day of Week Number
  1055. $InputDate = StringReplace($InputDate, "@@@@", _DateDayOfWeek($iPos, 0)) ; Long Weekday Name
  1056. $InputDate = StringReplace($InputDate, "@@@", _DateDayOfWeek($iPos, 1)) ; Short Weekday Name
  1057. $InputDate = StringReplace($InputDate, "@@", $DateValue[3]) ; Day Number 2 Digit
  1058. $InputDate = StringReplace($InputDate, "@", Int($DateValue[3])) ; Day Number
  1059. Return $InputDate
  1060. EndFunc ;==>DateFormat
  1061. #FUNCTION# ==============================================================
  1062. Func WM_NOTIFY($hwnd, $MsgID, $wParam, $lParam)
  1063. ; notify used for Double click in Main menu
  1064. Local $tagNMHDR, $code
  1065. $tagNMHDR = DllStructCreate("struct; hwnd hWndFrom;uint_ptr IDFrom;INT Code; endstruct", $lParam)
  1066. If @error Then Return 0
  1067. $code = DllStructGetData($tagNMHDR, 3)
  1068. ;If $wParam = $Menu_ListView And $code = -3 Then
  1069. If $code = -3 Then
  1070. $DoubleClicked = True
  1071. EndIf
  1072. ;If $wParam = $Menu_ListView Then $DoubleClicked = True
  1073. Return $GUI_RUNDEFMSG
  1074. EndFunc ;==>WM_NOTIFY
  1075. #FUNCTION# ==============================================================
  1076. Func WM_NOTIfY2($hwnd, $iMsg, $wParam, $lParam)
  1077. ; this udf will show a window with the content of a cell. Displays only If the data contains @CRLF (multiline)
  1078. ; the udf replaces WM_NOTIfY in Listviewer ($hListView)
  1079. Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $iItem, $subitemNR, $Column_attribute, $sToolTipData, $aTitle, $ColumnOrder, $aItem, $Position, $Rows_to_Clip
  1080. $hWndListView = $hListView
  1081. If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
  1082. $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
  1083. $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
  1084. $iCode = DllStructGetData($tNMHDR, "Code")
  1085. Switch $hWndFrom
  1086. Case $hWndListView
  1087. Switch $iCode
  1088. Case $NM_CLICK;
  1089. $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
  1090. $iItem = DllStructGetData($tInfo, "Item")
  1091. $subitemNR = DllStructGetData($tInfo, "SubItem")
  1092. $Column_attribute = _GUICtrlListView_GetColumn($hListView, $subitemNR)
  1093. If $iLastItem = $iItem And $iLastsubitemNR = $subitemNR Then Return 0
  1094. $iLastItem = $iItem
  1095. $iLastsubitemNR = $subitemNR
  1096. $sToolTipData = _GUICtrlListView_GetItemText($hListView, $iItem, $subitemNR)
  1097. ; Check LF, CR only
  1098. ; first check If LF in the memo
  1099. $Position = StringInStr($sToolTipData, @LF)
  1100. If $Position > 0 Then
  1101. ; Then check If @CRLF in the memo
  1102. $Position = StringInStr($sToolTipData, @CRLF)
  1103. If $Position > 0 Then ;can be displayed as is
  1104. View_MultilineCell($sToolTipData, $Column_attribute[5] & " Row " & $iItem + 1)
  1105. Else ; must convert @LF to @CRLF before displaying
  1106. View_MultilineCell(StringReplace($sToolTipData, @LF, @CRLF), $Column_attribute[5] & " Row " & $iItem + 1)
  1107. EndIf
  1108. Else
  1109. $Position = StringInStr($sToolTipData, @CR)
  1110. If $Position > 0 Then
  1111. ; Then check If @CRLF in the memo
  1112. $Position = StringInStr($sToolTipData, @CRLF)
  1113. If $Position > 0 Then ;can be displayed as is
  1114. View_MultilineCell($sToolTipData, $Column_attribute[5] & " Row " & $iItem + 1)
  1115. Else ; must convert @CR to @CRLF before displaying
  1116. View_MultilineCell(StringReplace($sToolTipData, @CR, @CRLF), $Column_attribute[5] & " Row " & $iItem + 1)
  1117. EndIf
  1118. Else
  1119. View_MultilineCell("")
  1120. EndIf
  1121. EndIf
  1122. Case $NM_DBLCLK
  1123. $ColumnOrder = _GUICtrlListView_GetColumnOrderArray($hListView) ; exact column order, required If the user changed the layout in the listview
  1124. ; exact column Order
  1125. ; titles first
  1126. $aTitle = $aNames
  1127. Dim $aVertView[UBound($aTitle) + 1][2]
  1128. $aVertView[0][0] = "Column title"
  1129. $aVertView[0][1] = "Content"
  1130. ; Set the titles according to column setting
  1131. For $i_C = 1 To UBound($ColumnOrder) - 1
  1132. ; only export the column If width > 0
  1133. If _GUICtrlListView_GetColumnWidth($hListView, $i_C - 1) > 0 Then $aVertView[$i_C][0] = $aTitle[$ColumnOrder[$i_C]]
  1134. Next
  1135. $Rows_to_Clip = StringSplit(_GUICtrlListView_GetSelectedIndices($hListView), "|")
  1136. For $i_I = 1 To UBound($Rows_to_Clip) - 1
  1137. ; exact column Order
  1138. For $i_C = 1 To UBound($ColumnOrder) - 1
  1139. $aItem = _GUICtrlListView_GetItem($hListView, $Rows_to_Clip[$i_I] + 0, $ColumnOrder[$i_C])
  1140. ; only export the column If width > 0
  1141. If _GUICtrlListView_GetColumnWidth($hListView, $i_C - 1) > 0 Then $aVertView[$i_C][1] = $aItem[3]
  1142. Next
  1143. Next
  1144. ; cleanup empty elements in array
  1145. For $i_C = UBound($aVertView) - 1 To 1 Step -1
  1146. If $aVertView[$i_C][0] = "" Then _ArrayDelete($aVertView, $i_C)
  1147. Next
  1148. _ArrayDisplay2($aVertView, "Vertical View", 2, -1, 0, ";")
  1149. EndSwitch
  1150. EndSwitch
  1151. Return $GUI_RUNDEFMSG
  1152. EndFunc ;==>WM_NOTIfY2
  1153. #FUNCTION# ==============================================================
  1154. Func View_SQL($sSQL, $sTitle)
  1155. Local $msg
  1156. ; get the coordiantes of $SQLResultWindow
  1157. $size = WinGetPos($SQLResultWindow)
  1158. $iLV_Left = $size[0]
  1159. $iLV_Top = $size[1]
  1160. $size = WinGetClientSize($SQLResultWindow)
  1161. $iLV_Width = $size[0] + $iLV_OffsetWidth
  1162. $iLV_Height = $size[1] + $iLV_OffsetHeight
  1163. Local $window_width = $iLV_Width - 100
  1164. Local $window_heigth = $iLV_Height - 100
  1165. ; format SQL script a bit
  1166. ; the formating does not consider UNION,
  1167. Local $stempSQL, $sSQLPart1, $sSQLPart2, $sSQLPart3, $sSQLPart4, $sSQLPart5, $sSQLPart6
  1168. $stempSQL = $sSQL
  1169. ; LIMIT - should be after FROM !
  1170. If StringInStr($stempSQL, "LIMIT", 0, -1) > 0 Then
  1171. If StringInStr($stempSQL, "LIMIT", 0, -1) > StringInStr($stempSQL, "FROM", 0, -1) Then
  1172. $sSQLPart6 = @CRLF & "LIMIT" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "LIMIT", 0, -1) + 5)
  1173. $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "LIMIT", 0, -1) + 1), 2)
  1174. EndIf
  1175. EndIf
  1176. ; ORDER BY - should be after FROM !
  1177. If StringInStr($stempSQL, "ORDER BY", 0, -1) > 0 Then
  1178. If StringInStr($stempSQL, "ORDER BY", 0, -1) > StringInStr($stempSQL, "FROM", 0, -1) Then
  1179. $sSQLPart5 = @CRLF & "ORDER BY" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "ORDER BY", 0, -1) + 8)
  1180. $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "ORDER BY", 0, -1) + 1), 2)
  1181. EndIf
  1182. EndIf
  1183. ; GROUP BY - should be after FROM !
  1184. If StringInStr($stempSQL, "GROUP BY", 0, -1) > 0 Then
  1185. If StringInStr($stempSQL, "GROUP BY", 0, -1) > StringInStr($stempSQL, "FROM", 0, -1) Then
  1186. $sSQLPart4 = @CRLF & "GROUP BY" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "GROUP BY", 0, -1) + 8)
  1187. $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "GROUP BY", 0, -1) + 1), 2)
  1188. EndIf
  1189. EndIf
  1190. ; WHERE - should be after FROM !
  1191. If StringInStr($stempSQL, "WHERE", 0, -1) > 0 Then
  1192. If StringInStr($stempSQL, "WHERE", 0, -1) > StringInStr($stempSQL, "FROM", 0, -1) Then
  1193. $sSQLPart3 = @CRLF & "WHERE" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "WHERE", 0, -1) + 5)
  1194. $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "WHERE", 0, -1) + 1), 2)
  1195. EndIf
  1196. EndIf
  1197. ; INNER JOIN
  1198. If StringInStr($stempSQL, "INNER JOIN", 0, -1) > 0 Then
  1199. $stempSQL = StringReplace($stempSQL, "INNER JOIN", @CRLF & @TAB & @TAB & "INNER JOIN")
  1200. EndIf
  1201. ; FROM
  1202. If StringInStr($stempSQL, "FROM", 0, -1) > 0 Then
  1203. $sSQLPart2 = @CRLF & "FROM" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "FROM", 0, -1) + 4)
  1204. $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "FROM", 0, -1) + 1), 2)
  1205. EndIf
  1206. ; SELECT
  1207. If StringInStr($stempSQL, "SELECT", 0, 1) > 0 Then
  1208. $sSQLPart1 = "SELECT" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "SELECT", 0, 1) + 6)
  1209. $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "SELECT", 0, 1) + 1), 2)
  1210. EndIf
  1211. Local $hGUI_View_SQL = GUICreate("SQL", $window_width, $window_heigth, $iLV_Left + 50, $iLV_Top + 50, $WS_CAPTION, $WS_EX_TOPMOST, $SQLResultWindow)
  1212. GUICtrlCreateLabel($sTitle, 10, 2, 600)
  1213. Local $ViewSQL = GUICtrlCreateEdit($sSQLPart1 & $sSQLPart2 & $sSQLPart3 & $sSQLPart4 & $sSQLPart5 & $sSQLPart6 & @CRLF, 5, 25, $window_width - 10, $window_heigth - 80, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL))
  1214. GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
  1215. GUICtrlSetColor(-1, $iDark_Blue)
  1216. GUICtrlSetBkColor(-1, $iLight_Green)
  1217. Local $buttonOK = GUICtrlCreateButton("OK", 10, $window_heigth - 35, 60, 20, $BS_DEFPUSHBUTTON)
  1218. #region Perforated Image
  1219. ; Perforated Image
  1220. # ==> Start
  1221. Local $_Left_pos, $_Top_pos, $_GUI_NAME
  1222. $_Left_pos = $window_width - 145; 338 ; Replace with correct position
  1223. $_Top_pos = $window_heigth - 20; 521 ; Replace with correct position
  1224. _GuiImageHole($hGUI_View_SQL, $_Left_pos, $_Top_pos, 136, 41)
  1225. # <== End
  1226. #endregion Perforated Image
  1227. GUISetState()
  1228. Do
  1229. $msg = GUIGetMsg()
  1230. Select
  1231. Case $msg = $buttonOK Or $msg = -3
  1232. GUIDelete($hGUI_View_SQL)
  1233. Return
  1234. EndSelect
  1235. Until $msg = $GUI_EVENT_CLOSE
  1236. EndFunc ;==>View_SQL
  1237. #FUNCTION# ==============================================================
  1238. #region Perforated Image
  1239. #comments-start
  1240. The lines below will generate the perforated image (bewteen start and end)
  1241. Move these lines into your GUI code, usually just before GUISetState()
  1242. Don't forget to fill in the correct coordinates for $Left_pos, $Top_pos
  1243. and enter the GUI Window Handle in the last line
  1244. # ==> Start
  1245. Local $_Left_pos, $_Top_pos, $_GUI_NAME
  1246. $_Left_pos = 10 ; Replace with correct position
  1247. $_Top_pos = 10 ; Replace with correct position
  1248. $_GUI_NAME = 'The name of your GUI window'
  1249. _GuiImageHole($_GUI_NAME, $_Left_pos, $_Top_pos, 136, 45)
  1250. # <== End
  1251. #comments-end
  1252. #FUNCTION# ==============================================================
  1253. ; #FUNCTION# ====================================================================================================
  1254. ; Name...........: _GuiImageHole
  1255. ; Description....: Create a perforated image in a GUI Window
  1256. ; Syntax.........: _GuiImageHole($window_handle, $pos_x, $pos_y,$Image_Width ,$Image_Height)
  1257. ; Parameters ....: $window_handle - Window Handle of the GU to be perforated
  1258. ; $pos_x - Upper left position of the perforation
  1259. ; $pos_y - Upper Top position of the perforation
  1260. ; $Image_Width - Image width
  1261. ; $Image_Height - Image heigth
  1262. ; Return values .: Success - Nothing returned
  1263. ; Failure - Function does not fail
  1264. ; Authors........: GreenCan
  1265. ; Modified ......:
  1266. ; Remarks .......:
  1267. ; Related .......:
  1268. ; Link ..........:
  1269. ; Example .......: Yes
  1270. ; ===============================================================================================================
  1271. Func _GuiImageHole($window_handle, $pos_x, $pos_y, $Image_Width, $Image_Height)
  1272. Local $aClassList, $aM_Mask, $aMask
  1273. #region picture array
  1274. Local $aPicture[262] = [ _
  1275. '3,1,48,1', '50,1,137,1', '3,2,48,2', '50,2,93,2', '94,2,137,2', '1,3,2,3', '4,3,47,3', '49,3,92,3', '95,3,137,3', '1,4,3,4', '5,4,25,4', '28,4,46,4', '48,4,92,4', '95,4,137,4', '1,5,3,5', '5,5,25,5', '29,5,45,5', '48,5,92,5', '95,5,137,5', '1,6,4,6', _
  1276. '6,6,24,6', '30,6,45,6', '47,6,92,6', '96,6,137,6', '1,7,5,7', '7,7,9,7', '10,7,23,7', '30,7,38,7', '42,7,44,7', '46,7,93,7', '96,7,137,7', '1,8,6,8', '11,8,24,8', '29,8,37,8', '45,8,66,8', '68,8,93,8', '96,8,137,8', '1,9,6,9', '13,9,24,9', '30,9,36,9', _
  1277. '44,9,66,9', '69,9,87,9', '91,9,93,9', '97,9,137,9', '1,10,6,10', '13,10,23,10', '31,10,37,10', '43,10,65,10', '71,10,86,10', '92,10,93,10', '97,10,137,10', '1,11,6,11', '12,11,22,11', '32,11,35,11', '42,11,65,11', '71,11,86,11', '92,11,93,11', '97,11,137,11', '1,12,6,12', '15,12,22,12', _
  1278. '32,12,34,12', '43,12,50,12', '54,12,65,12', '70,12,86,12', '97,12,137,12', '1,13,5,13', '18,13,21,13', '32,13,33,13', '44,13,49,13', '55,13,65,13', '72,13,86,13', '96,13,137,13', '1,14,5,14', '15,14,16,14', '44,14,48,14', '55,14,64,14', '73,14,86,14', '96,14,137,14', '1,15,4,15', '15,15,20,15', _
  1279. '45,15,48,15', '54,15,64,15', '74,15,85,15', '96,15,137,15', '1,16,4,16', '17,16,19,16', '46,16,48,16', '55,16,63,16', '75,16,84,16', '96,16,137,16', '1,17,5,17', '17,17,18,17', '46,17,47,17', '56,17,63,17', '76,17,84,17', '97,17,137,17', '1,18,5,18', '17,18,18,18', '46,18,47,18', '56,18,63,18', _
  1280. '77,18,84,18', '97,18,137,18', '1,19,6,19', '16,19,18,19', '33,19,34,19', '57,19,63,19', '77,19,84,19', '98,19,137,19', '1,20,6,20', '16,20,17,20', '32,20,34,20', '58,20,63,20', '77,20,84,20', '98,20,137,20', '1,21,6,21', '16,21,17,21', '32,21,34,21', '58,21,63,21', '78,21,83,21', '98,21,137,21', _
  1281. '1,22,6,22', '32,22,34,22', '58,22,63,22', '78,22,83,22', '98,22,137,22', '1,23,6,23', '57,23,64,23', '78,23,82,23', '98,23,137,23', '1,24,6,24', '57,24,65,24', '78,24,82,24', '98,24,137,24', '1,25,6,25', '58,25,65,25', '77,25,82,25', '99,25,137,25', '1,26,6,26', '58,26,64,26', '76,26,83,26', _
  1282. '99,26,137,26', '1,27,7,27', '32,27,33,27', '46,27,47,27', '58,27,64,27', '77,27,83,27', '100,27,137,27', '1,28,7,28', '31,28,33,28', '46,28,47,28', '58,28,65,28', '77,28,83,28', '99,28,137,28', '2,29,7,29', '31,29,33,29', '59,29,65,29', '78,29,84,29', '98,29,137,29', '7,30,8,30', '16,30,18,30', _
  1283. '31,30,33,30', '46,30,47,30', '59,30,65,30', '79,30,84,30', '96,30,137,30', '8,31,10,31', '15,31,18,31', '25,31,26,31', '31,31,34,31', '45,31,47,31', '60,31,62,31', '79,31,85,31', '95,31,137,31', '3,32,6,32', '8,32,10,32', '15,32,21,32', '25,32,26,32', '33,32,34,32', '42,32,48,32', '60,32,62,32', _
  1284. '78,32,85,32', '95,32,137,32', '34,33,35,33', '39,33,40,33', '42,33,49,33', '60,33,62,33', '76,33,86,33', '95,33,120,33', '125,33,130,33', '135,33,137,33', '38,34,39,34', '44,34,51,34', '76,34,88,34', '95,34,122,34', '125,34,129,34', '131,34,134,34', '135,34,137,34', '47,35,51,35', '55,35,60,35', '64,35,65,35', _
  1285. '76,35,88,35', '95,35,121,35', '123,35,124,35', '126,35,128,35', '130,35,134,35', '135,35,137,35', '49,36,51,36', '56,36,62,36', '65,36,66,36', '69,36,70,36', '76,36,81,36', '83,36,88,36', '95,36,120,36', '122,36,124,36', '126,36,127,36', '129,36,137,36', '56,37,58,37', '66,37,70,37', '76,37,78,37', '84,37,88,37', _
  1286. '95,37,120,37', '122,37,124,37', '126,37,127,37', '129,37,131,37', '135,37,137,37', '67,38,71,38', '77,38,79,38', '84,38,89,38', '95,38,119,38', '126,38,127,38', '129,38,132,38', '134,38,137,38', '32,39,33,39', '85,39,89,39', '95,39,118,39', '120,39,124,39', '126,39,127,39', '129,39,132,39', '134,39,137,39', '18,40,24,40', _
  1287. '26,40,41,40', '86,40,89,40', '95,40,117,40', '121,40,123,40', '127,40,128,40', '134,40,137,40', '14,41,46,41', '85,41,89,41', '95,41,137,41', '9,42,52,42', '88,42,89,42', '97,42,137,42', '7,43,55,43', '57,43,59,43', '62,43,65,43', '67,43,69,43', '70,43,73,43', '100,43,137,43', '6,44,79,44', '100,44,137,44', _
  1288. '4,45,81,45', '100,45,137,45']
  1289. #endregion picture array
  1290. ; get the size of the active window
  1291. Local $size = WinGetClientSize($window_handle)
  1292. Local $window_width = $size[0]
  1293. Local $Window_height = $size[1] + 33 ; including the title bar
  1294. ; First hide the window
  1295. $aClassList = StringSplit(_WinGetClassListEx($window_handle), @LF)
  1296. $aM_Mask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', 0, 'long', 0, 'long', 0, 'long', 0)
  1297. ; rectangle A - left side
  1298. $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', 0, 'long', 0, 'long', $pos_x, 'long', $Window_height)
  1299. DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
  1300. ; rectangle B - Top
  1301. $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', 0, 'long', 0, 'long', $window_width, 'long', $pos_y)
  1302. DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
  1303. ; rectangle C - Right side
  1304. $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', $pos_x + $Image_Width, 'long', 0, 'long', $window_width + 30, 'long', $Window_height)
  1305. DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
  1306. ; rectangle D - Bottom
  1307. $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', 0, 'long', $pos_y + $Image_Height, 'long', $window_width, 'long', $Window_height)
  1308. DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
  1309. ; now unhide all regions as defined in array $aPicture
  1310. For $i_I = 0 To (UBound($aPicture) - 1)
  1311. Local $Block_value = StringSplit($aPicture[$i_I], ',')
  1312. $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', $pos_x + $Block_value[1] - 1, 'long', $pos_y + $Block_value[2], 'long', $pos_x + $Block_value[3], 'long', $pos_y + $Block_value[4] - 1)
  1313. DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
  1314. Next
  1315. DllCall('user32.dll', 'long', 'SetWindowRgn', 'hwnd', $window_handle, 'long', $aM_Mask[0], 'int', 1)
  1316. $aPicture = '' ; empty array
  1317. EndFunc ;==>_GuiImageHole
  1318. #FUNCTION# ==============================================================
  1319. Func _WinGetClassListEx($sTitle)
  1320. Local $sClassList = WinGetClassList($sTitle)
  1321. Local $aClassList = StringSplit($sClassList, @LF)
  1322. Local $sRetClassList = '', $sHold_List = '|'
  1323. Local $aiInHold, $iInHold
  1324. For $i_I = 1 To UBound($aClassList) - 1
  1325. If $aClassList[$i_I] = '' Then ContinueLoop
  1326. If StringRegExp($sHold_List, '\|' & $aClassList[$i_I] & '~(\d+)\|') Then
  1327. $aiInHold = StringRegExp($sHold_List, '.*\|' & $aClassList[$i_I] & '~(\d+)\|.*', 1)
  1328. $iInHold = Number($aiInHold[UBound($aiInHold) - 1])
  1329. If $iInHold = 0 Then $iInHold += 1
  1330. $aClassList[$i_I] &= '~' & $iInHold + 1
  1331. $sHold_List &= $aClassList[$i_I] & '|'
  1332. $sRetClassList &= $aClassList[$i_I] & @LF
  1333. Else
  1334. $aClassList[$i_I] &= '~1'
  1335. $sHold_List &= $aClassList[$i_I] & '|'
  1336. $sRetClassList &= $aClassList[$i_I] & @LF
  1337. EndIf
  1338. Next
  1339. Return StringReplace(StringStripWS($sRetClassList, 3), '~', '')
  1340. EndFunc ;==>_WinGetClassListEx
  1341. #endregion Perforated Image
  1342. #FUNCTION# ==============================================================
  1343. ; #FUNCTION# ====================================================================================================================
  1344. ; Name...........: _ArrayDisplay2
  1345. ; Description ...: Displays given 1D or 2D array in a listview.
  1346. ; Syntax.........: _ArrayDisplay(Const ByRef $avArray[, $sTitle = "Array: ListView Display", [$iColumnTitle = 0][, $iItemLimit = -1[, $iTranspose = 0[, $sDelimiter = ""[, $sReplace = "|"]]]]])
  1347. ; Parameters ....: $avArray - Array to display
  1348. ; $sTitle - [optional] Title to use for window
  1349. ; $iColumnTitles - [optional]
  1350. ; 0 = Default 'Col x' (same as _ArrayDisplay)
  1351. ; 1 = Display Column Titles defined as Row 0 in $avArray
  1352. ; 2 = Display Column Titles, don't show Row numbers (not valid for $iTranspose <> 0)
  1353. ; $iItemLimit - [optional] Maximum number of listview items (rows) to show
  1354. ; $iTranspose - [optional] If set dIfferently than default, will transpose the array If 2D
  1355. ; $sDelimiter - [optional] Change Opt("GUIDataSeparatorChar") on-the-fly
  1356. ; $sReplace - [optional] String to replace any occurrence of $sDelimiter with in each array element
  1357. ; Return values .: Success - 1
  1358. ; Failure - 0, sets @error:
  1359. ; |1 - $avArray is not an array
  1360. ; |2 - $avArray has too many Dimensions (only up to 2D supported)
  1361. ; Author ........: randallc, Ultima
  1362. ; ModIfied.......: Gary Frost (gafrost) / Ultima: modIfied to be self-contained (no longer depends on "GUIListView.au3")
  1363. ; Greencan added optional Column Title / Hide Column numbers, correct positioning of ListView GUI on screen
  1364. ; Remarks .......:
  1365. ; Related .......:
  1366. ; Link ..........;
  1367. ; Example .......; Yes
  1368. ; ===============================================================================================================================
  1369. Func _ArrayDisplay2(Const ByRef $avArray, $sTitle = "Array: ListView Display", $iColumnTitle = 0, $iItemLimit = -1, $iTranspose = 0, $sDelimiter = "", $sReplace = "|")
  1370. If Not IsArray($avArray) Then Return SetError(1, 0, 0)
  1371. ; Dimension checking
  1372. Local $iDimension = UBound($avArray, 0), $iUBound = UBound($avArray, 1) - 1, $iSubMax = UBound($avArray, 2) - 1
  1373. If $iDimension > 2 Then Return SetError(2, 0, 0)
  1374. Local $size
  1375. ; Delimiter handling
  1376. If $sDelimiter = "" Then $sDelimiter = Chr(124)
  1377. ; Declare variables
  1378. Local $i_I, $i_J, $vTmp, $aItem, $avArrayText, $sHeader = "Row", $iBuffer = 64
  1379. Local $iColLimit = 250, $iLVIAddUDFThreshold = 4000;, $VertView_Width = 640, $VertView_Height = 480
  1380. Local $iOnEventMode = Opt("GUIOnEventMode", 0), $sDataDelimiterChar = Opt("GUIDataSeparatorChar", $sDelimiter)
  1381. ; Swap Dimensions If transposing
  1382. If $iSubMax < 0 Then $iSubMax = 0
  1383. If $iTranspose Then
  1384. $vTmp = $iUBound
  1385. $iUBound = $iSubMax
  1386. $iSubMax = $vTmp
  1387. EndIf
  1388. ; Set limits for Dimensions
  1389. If $iSubMax > $iColLimit Then $iSubMax = $iColLimit
  1390. If $iItemLimit = 1 Then $iItemLimit = $iLVIAddUDFThreshold
  1391. If $iItemLimit < 1 Then $iItemLimit = $iUBound
  1392. If $iUBound > $iItemLimit Then $iUBound = $iItemLimit
  1393. If $iLVIAddUDFThreshold > $iUBound Then $iLVIAddUDFThreshold = $iUBound
  1394. ; Column Titles
  1395. If $iColumnTitle = 0 Then
  1396. ; Set header up
  1397. For $i_I = 0 To $iSubMax
  1398. $sHeader &= $sDelimiter & "Col " & $i_I
  1399. Next
  1400. Local $StartRow = 0
  1401. Local $StartCol = 0
  1402. Else
  1403. ; no first column with row number
  1404. If $iColumnTitle = 2 Then $sHeader = ""
  1405. ; Set header with array row 0
  1406. For $i_I = 0 To $iSubMax
  1407. Local $StartCol
  1408. If $iTranspose Then
  1409. $sHeader = "Title"
  1410. For $i_I = 1 To $iSubMax
  1411. $sHeader &= $sDelimiter & "Col " & $i_I
  1412. Next
  1413. $StartCol = 1
  1414. Else
  1415. If $iDimension = 1 Then
  1416. $sHeader &= $sDelimiter & $avArray[$i_I]
  1417. Else
  1418. $sHeader &= $sDelimiter & $avArray[0][$i_I]
  1419. EndIf
  1420. $StartCol = 0
  1421. EndIf
  1422. Next
  1423. Local $StartRow = 1
  1424. If StringLeft($sHeader, 1) = $sDelimiter Then $sHeader = StringTrimLeft($sHeader, 1)
  1425. EndIf
  1426. ; Convert array into text for listview
  1427. Local $avArrayText[$iUBound + 1]
  1428. For $i_I = $StartRow To $iUBound + $StartCol
  1429. If $iColumnTitle <> 0 And $iTranspose Then
  1430. If $iDimension = 1 Then
  1431. $avArrayText[$i_I - $StartRow] = "[" & $avArray[$i_I - $StartRow] & "]"
  1432. Else
  1433. $avArrayText[$i_I - $StartRow] = "[" & $avArray[0][$i_I - $StartRow] & "]"
  1434. EndIf
  1435. Else
  1436. If $iColumnTitle < 2 Then
  1437. $avArrayText[$i_I - $StartRow] = "[" & $i_I & "]"
  1438. EndIf
  1439. EndIf
  1440. For $i_J = $StartCol To $iSubMax
  1441. ; Get current item
  1442. If $iDimension = 1 Then
  1443. If $iTranspose Then
  1444. $vTmp = $avArray[$i_J]
  1445. Else
  1446. $vTmp = $avArray[$i_I]
  1447. EndIf
  1448. Else
  1449. If $iTranspose Then
  1450. If $iColumnTitle <> 0 Then
  1451. $vTmp = $avArray[$i_J][$i_I - $StartRow]
  1452. Else
  1453. $vTmp = $avArray[$i_J][$i_I]
  1454. EndIf
  1455. Else
  1456. $vTmp = $avArray[$i_I][$i_J]
  1457. EndIf
  1458. EndIf
  1459. ; Add to text array
  1460. $vTmp = StringReplace($vTmp, $sDelimiter, $sReplace, 0, 1)
  1461. $avArrayText[$i_I - $StartRow] &= $sDelimiter & $vTmp
  1462. ; Set max buffer size
  1463. $vTmp = StringLen($vTmp)
  1464. If $vTmp > $iBuffer Then $iBuffer = $vTmp
  1465. Next
  1466. If StringLeft($avArrayText[$i_I - $StartRow], 1) = $sDelimiter Then $avArrayText[$i_I - $StartRow] = StringTrimLeft($avArrayText[$i_I - $StartRow], 1)
  1467. Next
  1468. $iBuffer += 1
  1469. ; GUI Constants
  1470. Local Const $_ARRAYCONSTANT_GUI_DOCKBORDERS = 0x66
  1471. Local Const $_ARRAYCONSTANT_GUI_DOCKBOTTOM = 0x40
  1472. Local Const $_ARRAYCONSTANT_GUI_DOCKHEIGHT = 0x0200
  1473. Local Const $_ARRAYCONSTANT_GUI_DOCKLEFT = 0x2
  1474. Local Const $_ARRAYCONSTANT_GUI_DOCKRIGHT = 0x4
  1475. Local Const $_ARRAYCONSTANT_GUI_EVENT_CLOSE = -3
  1476. Local Const $_ARRAYCONSTANT_LVIf_PARAM = 0x4
  1477. Local Const $_ARRAYCONSTANT_LVIf_TEXT = 0x1
  1478. Local Const $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH = (0x1000 + 29)
  1479. Local Const $_ARRAYCONSTANT_LVM_GETITEMCOUNT = (0x1000 + 4)
  1480. Local Const $_ARRAYCONSTANT_LVM_GETITEMSTATE = (0x1000 + 44)
  1481. Local Const $_ARRAYCONSTANT_LVM_INSERTITEMA = (0x1000 + 7)
  1482. Local Const $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE = (0x1000 + 54)
  1483. Local Const $_ARRAYCONSTANT_LVM_SETITEMA = (0x1000 + 6)
  1484. Local Const $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT = 0x20
  1485. Local Const $_ARRAYCONSTANT_LVS_EX_GRIDLINES = 0x1
  1486. Local Const $_ARRAYCONSTANT_LVS_SHOWSELALWAYS = 0x8
  1487. Local Const $_ARRAYCONSTANT_WS_EX_CLIENTEDGE = 0x0200
  1488. Local Const $_ARRAYCONSTANT_WS_MAXIMIZEBOX = 0x00010000
  1489. Local Const $_ARRAYCONSTANT_WS_MINIMIZEBOX = 0x00020000
  1490. Local Const $_ARRAYCONSTANT_WS_SIZEBOX = 0x00040000
  1491. Local Const $_ARRAYCONSTANT_tagLVITEM = "int Mask;int Item;int SubItem;int State;int StateMask;ptr Text;int TextMax;int Image;int Param;int Indent;int GroupID;int Columns;ptr pColumns"
  1492. Local $iAddMask = BitOR($_ARRAYCONSTANT_LVIf_TEXT, $_ARRAYCONSTANT_LVIf_PARAM)
  1493. Local $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]"), $pBuffer = DllStructGetPtr($tBuffer)
  1494. Local $tItem = DllStructCreate($_ARRAYCONSTANT_tagLVITEM), $pItem = DllStructGetPtr($tItem)
  1495. DllStructSetData($tItem, "Param", 0)
  1496. DllStructSetData($tItem, "Text", $pBuffer)
  1497. DllStructSetData($tItem, "TextMax", $iBuffer)
  1498. ; Set interface up
  1499. Local $window_open = WinList("Vertical View") ; check If window already exists
  1500. ;Local $GUI_VerticalView
  1501. ;~ ConsoleWrite ( @ScriptLineNumber & " $VertView_Width:" & $VertView_Width & " $VertView_Height:" & $VertView_Height & " $VertView_Left:" & $VertView_Left & " $VertView_Top:" & $VertView_Top & @CR)
  1502. If $window_open[0][0] > 0 Then
  1503. ;~ $bVerticalView_Resize = False
  1504. $bVerticalView_GUI = False
  1505. $size = WinGetPos($GUI_VerticalView)
  1506. $VertView_Left = $size[0]
  1507. $VertView_Top = $size[1]
  1508. $size = WinGetClientSize($GUI_VerticalView)
  1509. $VertView_Width = $size[0] + $VertView_OffsetWidth
  1510. $VertView_Height = $size[1] + $VertView_OffsetHeight
  1511. GUIDelete($GUI_VerticalView)
  1512. $GUI_VerticalView = GUICreate($sTitle, $VertView_Width, $VertView_Height, $VertView_Left, $VertView_Top, BitOR($_ARRAYCONSTANT_WS_SIZEBOX, $_ARRAYCONSTANT_WS_MINIMIZEBOX, $_ARRAYCONSTANT_WS_MAXIMIZEBOX), $WS_EX_TOPMOST, $SQLResultWindow)
  1513. Else
  1514. $GUI_VerticalView = GUICreate($sTitle, $VertView_Width, $VertView_Height, $VertView_Left, $VertView_Top, BitOR($_ARRAYCONSTANT_WS_SIZEBOX, $_ARRAYCONSTANT_WS_MINIMIZEBOX, $_ARRAYCONSTANT_WS_MAXIMIZEBOX), $WS_EX_TOPMOST, $SQLResultWindow)
  1515. $bVerticalView_GUI = True
  1516. If $VertView_OffsetWidth = 0 Then
  1517. ; remember the difference between the result of WinGetClientSize and the initial Width and Height of the GUI
  1518. $size = WinGetClientSize($GUI_VerticalView)
  1519. $VertView_OffsetWidth = $VertView_Width - $size[0]
  1520. $VertView_OffsetHeight = $VertView_Height - $size[1]
  1521. EndIf
  1522. EndIf
  1523. ;~ ConsoleWrite ( @ScriptLineNumber & " $VertView_Width:" & $VertView_Width & " $VertView_Height:" & $VertView_Height & " $VertView_Left:" & $VertView_Left & " $VertView_Top:" & $VertView_Top & @CR)
  1524. Local $aiGUISize = WinGetClientSize("Vertical View")
  1525. Local $VertView_hListView = GUICtrlCreateListView($sHeader, 0, 0, $aiGUISize[0], $aiGUISize[1] - 26, $_ARRAYCONSTANT_LVS_SHOWSELALWAYS)
  1526. $VerticalView_Copy = GUICtrlCreateButton("Copy to Clipboard", 3, $aiGUISize[1] - 23, $aiGUISize[0] - 6, 20)
  1527. GUICtrlSetResizing($VertView_hListView, $_ARRAYCONSTANT_GUI_DOCKBORDERS)
  1528. GUICtrlSetResizing($VerticalView_Copy, $_ARRAYCONSTANT_GUI_DOCKLEFT + $_ARRAYCONSTANT_GUI_DOCKRIGHT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT)
  1529. GUICtrlSendMsg($VertView_hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_GRIDLINES, $_ARRAYCONSTANT_LVS_EX_GRIDLINES)
  1530. GUICtrlSendMsg($VertView_hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT)
  1531. GUICtrlSendMsg($VertView_hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE)
  1532. GUISetIcon("DATABASE.ICO", 0)
  1533. ; Fill listview
  1534. For $i_I = 0 To $iLVIAddUDFThreshold
  1535. GUICtrlCreateListViewItem($avArrayText[$i_I], $VertView_hListView)
  1536. Next
  1537. For $i_I = ($iLVIAddUDFThreshold + 1) To $iUBound
  1538. $aItem = StringSplit($avArrayText[$i_I], $sDelimiter)
  1539. DllStructSetData($tBuffer, "Text", $aItem[1])
  1540. ; Add listview item
  1541. DllStructSetData($tItem, "Item", $i_I)
  1542. DllStructSetData($tItem, "SubItem", 0)
  1543. DllStructSetData($tItem, "Mask", $iAddMask)
  1544. GUICtrlSendMsg($VertView_hListView, $_ARRAYCONSTANT_LVM_INSERTITEMA, 0, $pItem)
  1545. ; Set listview subitem text
  1546. DllStructSetData($tItem, "Mask", $_ARRAYCONSTANT_LVIf_TEXT)
  1547. For $i_J = 2 To $aItem[0]
  1548. DllStructSetData($tBuffer, "Text", $aItem[$i_J])
  1549. DllStructSetData($tItem, "SubItem", $i_J - 1)
  1550. GUICtrlSendMsg($VertView_hListView, $_ARRAYCONSTANT_LVM_SETITEMA, 0, $pItem)
  1551. Next
  1552. Next
  1553. ; calibrate columns
  1554. ;~ $VertView_Width = 0
  1555. For $i_I = 0 To $iSubMax + 1
  1556. GUICtrlSendMsg($VertView_hListView, 0x1000 + 30, $i_I, -2) ; added this to calibrate column width correctly
  1557. ;~ If $bVerticalView_Resize Then $VertView_Width += GUICtrlSendMsg($VertView_hListView, $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH, $i_I, 0)
  1558. Next
  1559. ;~ If $bVerticalView_Resize Then
  1560. ;~ ; postion of main window at startup
  1561. ;~ ;Local $VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 78)
  1562. ;~ Local $iCentre = (@DesktopWidth - $VertView_Width - 20) / 2
  1563. ;~ If $VertView_Width + 20 > $VirtualDesktopWidth Then ; If Listview larger than $VirtualDesktopWidth limit to the visible size
  1564. ;~ $VertView_Width = $VirtualDesktopWidth - 20
  1565. ;~ $iCentre = ($VirtualDesktopWidth - $VertView_Width - 20) / 2
  1566. ;~ ElseIf $VertView_Width + 20 <= @DesktopWidth Then ; If Listview smaller than @DesktopWidth center on first screen
  1567. ;~ $iCentre = (@DesktopWidth - $VertView_Width - 20) / 2
  1568. ;~ ElseIf $VertView_Width < 250 Then ; Minimal size of Listview is 250
  1569. ;~ $VertView_Width = 250
  1570. ;~ $iCentre = (@DesktopWidth - $VertView_Width - 20) / 2
  1571. ;~ EndIf
  1572. ;~ $VertView_Left = $VirtualDesktopWidth - $VertView_Width - 20
  1573. ;~ WinMove($GUI_VerticalView, "", $VertView_Left, Default, $VertView_Width + 20)
  1574. ;~ EndIf
  1575. ;~ ConsoleWrite ( @ScriptLineNumber & " $VertView_Width:" & $VertView_Width & " $VertView_Height:" & $VertView_Height & " $VertView_Left:" & $VertView_Left & " $VertView_Top:" & $VertView_Top & @CR)
  1576. ; Show dialog
  1577. GUISetState(@SW_SHOW, $GUI_VerticalView)
  1578. Opt("GUIOnEventMode", $iOnEventMode)
  1579. Opt("GUIDataSeparatorChar", $sDataDelimiterChar)
  1580. Return 1
  1581. EndFunc ;==>_ArrayDisplay2
  1582. #FUNCTION# ==============================================================
  1583. Func _COMError()
  1584. Local $bHexNumber = Hex($oAppError.number, 8)
  1585. Local $sError = "COM Error Encountered in " & @ScriptName & @CRLF & _
  1586. "@AutoItVersion = " & @AutoItVersion & @CRLF & _
  1587. "@AutoItX64 = " & @AutoItX64 & @CRLF & _
  1588. "@Compiled = " & @Compiled & @CRLF & _
  1589. "@OSArch = " & @OSArch & @CRLF & _
  1590. "@OSVersion = " & @OSVersion & @CRLF & _
  1591. "Scriptline = " & $oAppError.scriptline & @CRLF & _
  1592. "NumberHex = " & $bHexNumber & @CRLF & _
  1593. "Number = " & $oAppError.number & @CRLF & _
  1594. "WinDescription = " & StringStripWS($oAppError.WinDescription, 2) & @CRLF & _
  1595. "Description = " & StringStripWS($oAppError.description, 2) & @CRLF & _
  1596. "Source = " & $oAppError.Source & @CRLF & _
  1597. "HelpFile = " & $oAppError.HelpFile & @CRLF & _
  1598. "HelpContext = " & $oAppError.HelpContext & @CRLF & _
  1599. "LastDllError = " & $oAppError.LastDllError
  1600. If $iDebug > 0 Then
  1601. If $iDebug = 1 Then ConsoleWrite($sError & @CRLF & "========================================================" & @CRLF)
  1602. If $iDebug = 2 Then MsgBox(64, "SQLite Reports - Debug Info", $sError)
  1603. EndIf
  1604. Return SetError(999, $oAppError.number, 0)
  1605. EndFunc ;==>_COMError
  1606. #FUNCTION# ==============================================================

comments powered by Disqus