#include #include #include "GUIListViewEx.au3" #include Global $cExitButton, $vData, $sMsg, $aLV_List_Left, $aRet, $iEditMode = 0, $cSearchInput, $cSearchButton, $sMySearch, $bSelect, $upd_array, $sItem Global $sFieldNames Global $FieldData Global $fieldCount Global $adOpenStatic = 3 Global $adLockOptimistic = 3 Global $adLockReadOnly = 1 Global $adOpenKeySet = 1 Global $ado, $adors Global $RunSQL Global $h, $i, $j Global $RowID = 0, $FieldName = 1, $OldData = 2, $NewData = 3, $Update = 4 Global $ChgData[1][5] Global $iEditCount = 0 Global $iLV_Index = 0 ;------------------------------------------------------------------------------ ;getdata() ; Simulate data retrieval $sFieldNames = "ID|SERVICE_NAME|DB_NAME|SID|SERVER_NAME|VERSION|PRODUCT" Global $aDataArray[] = ["1|MKDBT|MKDBT|MKDBT|CRLNXT1058|12.1.0.2.0|test", _ "2|MKDBM|MKDBM|MKDBM|CRLNXT1026|12.1.0.2.0|model", _ "3|IMDWBAT|IMDWBAT|IMDWBAT|CRACLP003|12.1.0.2.0|prod", _ "4|AWDLPT|AWDLPT|AWDLPT|CRLNXT1057|12.1.0.2.0|test", _ "5|IMDWUTL|IMDWUTL|IMDWUTL|CRLNXP261|11.2.0.4.0|prod", _ "6|CRWHRS|CRWHRS|CRWHRS|CRLNXP083|11.2.0.4.0|prod", _ "7|AFDBS|AFDBS|AFDBS|CRLNXT1053|19.0.0.0.0|dev", _ "8|AFDBSI|AFDBSI|AFDBSI|CRLNXT1053|19.0.0.0.0|asdfsdftest"] Global $iTotalRecs = UBound($aDataArray) ;------------------------------------------------------------------------------ ;msgbox(0,"","pos 0,0 = " & $All_Fields[0][1]) ; Create GUI Global $hGUI = GUICreate("Table Info", 800, 625) Global $cListView = GUICtrlCreateListView($sFieldNames, 30, 30, 500, 550, $LVS_SHOWSELALWAYS, $LVS_EX_GRIDLINES) _GUICtrlListView_SetExtendedListViewStyle($cListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) _GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE) Global $cRecords = GUICtrlCreateLabel("", 20, 10, 200, 20) Global $cExitButton = GUICtrlCreateButton("Exit", 175, 590, 70, 30) Global $cCommitButton = GUICtrlCreateButton("Commit", 75, 590, 70, 30) ;GUICtrlSetBkColor($cCommitButton, $COLOR_RED) ; Very bad idea <<<<<<<<<<<<<<<<< Global $cSearchButton = GUICtrlCreateButton("Query", 300, 590, 100, 25) Global $cSearchInput = GUICtrlCreateInput("", 425, 590, 300, 25) ;GUICtrlSetData($cSearchInput, "") ; Not needed GUICtrlSetState($cSearchInput, $GUI_FOCUS) ; Load ListView with loaded data $iLV_Index = _LoadLV($aDataArray) _GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE) ;Hide Rowid _GUICtrlListView_HideColumn($cListView, 0) _GUIListViewEx_MsgRegister() GUISetState() ;Local $B_DESCENDING[_GUICtrlListView_GetColumnCount ($cListView) ] While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $cExitButton Exit Case $cCommitButton If $ChgData[0][0] <> "" Then Update_Table() Global $ChgData[10][5] $iEditCount = 0 Else MsgBox(0, "", "Nothing to Change") EndIf Case $cSearchButton $sMySearch = StringUpper(GUICtrlRead($cSearchInput)) SearchFor($sMySearch) GUICtrlSetState($cSearchInput, $GUI_FOCUS) EndSwitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) ; Use combos to change EditMode If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error) EndIf Switch @extended Case 0 ; No event detected Case 1 If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF) Else If $iEditCount <> 0 Then ReDim $ChgData[UBound($ChgData) + 1][5] EndIf ; Read edited row $sItem = GUICtrlRead(GUICtrlRead($cListView)) ; Extract row number $iRowID = StringRegExpReplace($sItem, "^(\d*)\|.*", "$1") ; Search data array for this line For $i = 0 To UBound($aDataArray) - 1 If StringLeft($aDataArray[$i], StringLen($iRowID) + 1) = $iRowID & "|" Then ; And replace it $aDataArray[$i] = $sItem ; No pint in looking further ExitLoop EndIf Next #cs $sItem = StringTrimRight($sItem, 1) ; Will remove the pipe "|" from the end of the string ;Dim $RowID[$fieldCount] $RowID = StringSplit($sItem, "|") _ArrayDisplay($RowID, "Rowid") ;##Get the rowid from this## MsgBox(0, "Selected Item", $sItem) $ChgData[$iEditCount][$RowID] = $RowID[1] $ChgData[$iEditCount][$FieldName] = $FieldArray[$vRet[1][1] + 1] $ChgData[$iEditCount][$OldData] = $vRet[1][2] $ChgData[$iEditCount][$NewData] = $vRet[1][3] $ChgData[$iEditCount][$Update] = "update oracle_instance set " & $ChgData[$iEditCount][$FieldName] & _ " = '" & $ChgData[$iEditCount][$NewData] & _ "' where rowid = '" & $ChgData[$iEditCount][$RowID] & "'" _ArrayDisplay($ChgData, "Changed Data") MsgBox(0, "", "vRet = " & $vRet[1][0] & " " & $vRet[1][1] & " " & $vRet[1][2] & " " & $vRet[1][3]) For $j = 0 To UBound($aDataArray) - 1 If StringInStr($aDataArray[$j], $RowID[1]) Then MsgBox(0, "", "found rowid in row " & $j & " " & $All_Fields[$j][0]) ExitLoop EndIf Next $iEditCount = $iEditCount + 1 MsgBox(0, "", "sitem = " & $sItem) ;$aDataArray[$j] = $sItem Already done above MsgBox(0, "", "data array = " & $aDataArray[$j]) _ArrayDisplay($aDataArray, "data array") $upd_array = "" #ce EndIf EndSwitch WEnd Func GetData() Global $oError ; Initializes COM handler $oError = ObjEvent("AutoIt.Error", "ErrHandler") $ado = ObjCreate("ADODB.Connection") With $ado .ConnectionString = ("Provider='OraOLEDB.Oracle';Data Source='database';User Id='userid';Password='password';") .Open EndWith $adors = ObjCreate("ADODB.RecordSet") With $adors .ActiveConnection = $ado .LockType = $adLockOptimistic ; Set ODBC connection read only .CursorType = $adOpenKeySet .Source = "select rowid, oracle_instance.* from Oracle_Instance where rownum < 26" .Open If @error Then MsgBox(0, "", "Error running SQL GetData ") Exit EndIf EndWith $iTotalRecs = $adors.recordcount $fieldCount = $adors.Fields.Count Global $All_Fields[$iTotalRecs][$fieldCount] Global $aDataArray[$iTotalRecs] Global $FieldArray[$fieldCount] $j = 0 While Not $adors.EOF For $i = 0 To $adors.Fields.Count - 1 ;$FieldData = $FieldData & $adors.Fields($i).Value & "|" If $j = 0 Then $sFieldNames = $sFieldNames & $adors.Fields($i).Name & "|" $FieldArray[$i] = $adors.Fields($i).Name EndIf ;GUICtrlCreateListViewItem($adors.Fields(i$).Value, $cListView) $All_Fields[$j][$i] = $adors.Fields($i).Value ;msgbox (0, "Field count = ", "Field count = " & $adors.Fields.Count -1) $FieldData = $FieldData & $adors.Fields($i).Value & "|" Next $aDataArray[$j] = $FieldData $FieldData = "" $adors.MoveNext $j = $j + 1 WEnd $FieldArray = StringSplit($sFieldNames, "|") $adors.close EndFunc ;==>GetData Func _LoadLV($aArray) ; Close ListView in the UDF _GUIListViewEx_Close($iLV_Index) ; And clear current content _GUICtrlListView_DeleteAllItems($cListView) ; Fill LV with new array For $i = 0 To UBound($aArray) - 1 GUICtrlCreateListViewItem($aArray[$i], $cListView) Next ; And initalise $iLV_Index = _GUIListViewEx_Init($cListView, $aArray, 0, 0, True, 1 + 2) ; Sort columns on header click ; Set all fields editable _GUIListViewEx_SetEditStatus($iLV_Index, "*") GUICtrlSetData($cRecords, "Total Records = " & UBound($aArray)) Return $iLV_Index EndFunc ;==>_LoadLV Func SearchFor($sMySearch) If $sMySearch <> "" Then $aSearchArray = $aDataArray ; Now start the search from the bottom and delete all lines which do NOT hold the search term Local $iCount = $iTotalRecs For $j = $iTotalRecs - 1 To 0 Step -1 If Not StringInStr($aDataArray[$j], $sMySearch) Then _ArrayDelete($aSearchArray, $j) ; If the number of items is really large we can speed up the deletion by getting a list of the rows to delete and using the $vRange parameter <<<<<<<< $iCount -= 1 EndIf Next If $iCount = 0 Then ; No matches found MsgBox($MB_SYSTEMMODAL, "Search", "No items found to match: " & $sMySearch) Else ; We now an array of the relevant items, so reload the ListView $iLV_Index = _LoadLV($aSearchArray) EndIf Else ; No search term passed so show all records MsgBox($MB_SYSTEMMODAL, "Search", "No search term passed" & @CRLF & @CRLF & "All records displayed") $iLV_Index = _LoadLV($aDataArray) EndIf EndFunc ;==>SearchFor Func Update_Table() $j = 0 For $i = 0 To UBound($ChgData) - 1 MsgBox(0, "", "Update Statement = " & $ChgData[$i][$Update]) $RunSQL = $ChgData[$i][$Update] ; $UpdateSQL = $ChgData[$i][$Update] With $adors .ActiveConnection = $ado .LockType = $adLockOptimistic ; Set ODBC connection read only .CursorType = $adOpenKeySet .Source = $RunSQL .Open If @error Then MyErrFunc() Exit EndIf EndWith Next ; $dbsource = $adors.Fields(0).Value ; $adors.close EndFunc ;==>Update_Table ;******************************************************* Func MyErrFunc() $HexNumber = Hex($oError.number, 8) MsgBox(0, StringReplace($oError.windescription, "error", "COM Error #") & $oError.Number, _ $oError.Description & @CRLF & _ "Source: " & @TAB & $oError.source & @CRLF & _ "at Line #: " & $oError.ScriptLine & @TAB & _ "Last DllError: " & @TAB & $oError.lastdllerror & @CRLF & _ "Help File: " & @TAB & $oError.helpfile & @TAB & "Context: " & @TAB & $oError.helpcontext _ ) SetError(1) ; to check for after this function returns EndFunc ;==>MyErrFunc ;========================================================