#include #include #include "GUIListView.au3" #include "GUIListViewEx.au3" #include Global $Btn_Exit,$vData, $sMsg, $aLV_List_Left, $aRet, $iEditMode = 0, $Search, $bSearch, $mySearch, $bSelect, $upd_array, $sitem Global $FieldNames Global $FieldData Global $fieldCount Global $totrecs Global $adOpenStatic = 3 Global $adLockOptimistic = 3 Global $adLockReadOnly = 1 Global $adOpenKeySet = 1 Global $ado, $adors Global $RunSQL Global $h, $i, $j, $k=0 Global $ChgData[1][5] Global $RowID = 0, $FieldName = 1, $OldData = 2, $NewData = 3, $Update = 4 $hGUI = GUICreate("Table Info", 800, 625) getdata() msgbox(0,"","pos 0,0 = " & $All_Fields[0][1]) $ListView = GuiCtrlCreateListView($FieldNames, 30, 30, 500, 550,$LVS_SHOWSELALWAYS,$LVS_EX_GRIDLINES) _GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES)) _GUICtrlListView_SetColumnWidth($ListView,0,$LVSCW_AUTOSIZE) For $i = 0 to $totrecs - 1 GUICtrlCreateListViewItem($DataArray[$i], $ListView) Next $iLV_Index = _GUIListViewEx_Init($ListView, $DataArray, 0, 0, True, 2) _GUIListViewEx_SetEditStatus($iLV_Index, "*") _GUICtrlListView_SetColumnWidth($ListView,0,$LVSCW_AUTOSIZE) $Btn_Exit = GUICtrlCreateButton("Exit", 175, 590, 70, 30) $Commit = GUICtrlCreateButton("Commit", 75, 590, 70, 30) GUICtrlSetBkColor($Commit, $COLOR_RED) ;Setup Search area $bSearch = GUICtrlCreateButton ("Query", 300, 590, 100, 25) $Search = GuiCtrlCreateInput("", 425, 590, 300, 25) GuiCtrlSetData($Search,"") GUICtrlSetState ($Search,$GUI_FOCUS) ;End Search area ;Hide Rowid _GUICtrlListView_HideColumn($ListView, 0) _GUIListViewEx_MsgRegister() GUISetState() Local $B_DESCENDING[_GUICtrlListView_GetColumnCount ($listview) ] While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $Btn_Exit Exit Case $Commit if $ChgData[0][0] <> "" then Update_Table() Global $ChgData[10][5] $k=0 else msgbox(0,"","Nothing to Change") endif Case $bSearch $mySearch = StringUpper(GUICtrlRead($Search)) searchfor($mySearch) GuiCtrlCreateLabel("Total Records = " & $totrecs, 20, 10, 200, 20) GUICtrlSetState ($Search,$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 $k <> 0 then ReDim $ChgData[UBound($ChgData)+1][5] endif $sItem = GUICtrlRead(GUICtrlRead($listview)) $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[$k][$RowID] = $rowid[1] $ChgData[$k][$FieldName] = $FieldArray[$vRet[1][1]+1] $ChgData[$k][$OldData] = $vRet[1][2] $ChgData[$k][$NewData] = $vRet[1][3] $ChgData[$k][$Update] = "update oracle_instance set " &$ChgData[$k][$FieldName]& _ " = '"&$ChgData[$k][$NewData]& _ "' where rowid = '"&$ChgData[$k][$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($DataArray)-1 if StringInStr($DataArray[$j],$rowid[1]) then msgbox(0,"","found rowid in row " & $j &" "&$All_Fields[$j][0]) exitloop endif next $k = $k + 1 msgbox(0,"","sitem = " & $sitem) $DataArray[$j] = $sItem msgbox(0,"","data array = " & $DataArray[$j]) _arrayDisplay($DataArray,"data array") $upd_array = "" 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 $totrecs = $adors.recordcount $fieldCount = $adoRs.Fields.Count Global $All_Fields[$totrecs][$fieldCount] Global $DataArray[$totrecs] 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 $FieldNames = $FieldNames & $adoRs.Fields($i).Name & "|" $FieldArray[$i] = $adoRs.Fields($i).Name endif ;GUICtrlCreateListViewItem($adors.Fields(i$).Value, $listview) $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 $DataArray[$j] = $FieldData $FieldData="" $adors.MoveNext $j=$j+1 WEnd $FieldArray = stringsplit($FieldNames,"|") $adors.close EndFunc Func SearchFor($mySearch) $i = 0 if $mySearch <> "" then for $j = 0 to $totrecs-1 ;local $WhereisStr = StringInStr($DataArray[$j],$mySearch) if StringInStr($DataArray[$j],$mySearch) then ; msgbox(0,"","Found data = " & $mySearch &" at "& $WhereisStr) if $i = 0 then _GUICtrlListView_DeleteAllItems($listview) $i = $i + 1 endif GUICtrlCreateListViewItem($DataArray[$j], $listview) endif next if $i = 0 then msgbox(0,"","Data Not Found = " & $mySearch) endif else _GUICtrlListView_DeleteAllItems($listview) for $j = 0 to $totrecs-1 GUICtrlCreateListViewItem($DataArray[$j], $listview) next endif EndFunc 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 ;******************************************************* 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 ;========================================================