Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs ----------------------------------------------------------------------------
- PW DB: root
- AutoIt Version: 3.3.6.1
- Author: Karavas Gustav
- Script Function:
- Database connection
- #ce ----------------------------------------------------------------------------
- #include <array.au3>
- #include "mysql.au3"
- #include <GUIConstantsEx.au3>
- #include <GUIConstants.au3>
- #include <EditConstants.au3>
- #include <GuiListView.au3>
- #include <ListviewConstants.au3>
- #include <WindowsConstants.au3>
- #include<StructureConstants.au3>
- #include<StaticConstants.au3>
- Global $currentItem[2], $title, $currentOpt[2]
- ; MYSQL starten, DLL im PATH (enthält auch @ScriptDir), sont Pfad zur DLL angeben. DLL muss libmysql.dll heißen.
- _MySQL_InitLibrary()
- If @error Then Exit MsgBox(0, '', "")
- $MysqlConn = _MySQL_Init()
- ;$PW = InputBox("Logindaten", "Gib hier das Password ein", "", "*")
- $PW = "root"
- $connected = _MySQL_Real_Connect($MysqlConn, "localhost", "cash", $PW , "chipsy")
- If $connected = 0 Then Exit MsgBox(16, 'Connection Error', _MySQL_Error($MysqlConn))
- ;select auf alle daten
- $query = "select vorgang.id, art.typ, gegenstand.Autor, gegenstand.titel,person.vorname, person.nachname, vorgang.verleihdatum, vorgang.rueckgabedatum FROM vorgang, art, gegenstand, person where gegenstand.id = vorgang.gegenstand_id and art.id = vorgang.art_id and person.id = vorgang.person_id order by vorgang.id"
- ;auswertung des selects
- _MySQL_Real_Query($MysqlConn, $query)
- $res = _MySQL_Store_Result($MysqlConn)
- $fields = _MySQL_Num_Fields($res)
- $rows = _MySQL_Num_Rows($res)
- ;speichern in array
- $array = _MySQL_Fetch_Result_StringArray($res)
- ;GUI erstellen
- $GUI = GUICreate("Verleihsystem", 600, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
- $button1 = GUICtrlCreateButton("Ändern", 10, 170, 70, 20)
- $button2 = GUICtrlCreateButton("Neuer Eintrag", 90, 170, 70, 20)
- $button3 = GUICtrlCreateButton("Eintrag löschen", 170, 170, 80, 20)
- $button2 = GUICtrlCreateButton("Suche", 260, 170, 70, 20)
- GUISetBkColor(0x00E0FFFF) ; Ändert die Hintergrundfarbe
- ;spaltenüberschrift erstellen
- $listview = GUICtrlCreateListView($array[0][0] &"|"& $array[0][1] &"|"& $array[0][2] &"|"& $array[0][3] &"|"& $array[0][4] &"|"& $array[0][5] &"|"& $array[0][6] &"|"& $array[0][7], 10, 10, 580, 150);,$LVS_SORTDESCENDING)
- ;ergebnisse aus $array in einer Listview grafisch dartellen
- for $i = 1 to UBound($array) -1
- $item1 = GUICtrlCreateListViewItem($array[$i][0] &"|"& $array[$i][1] &"|"& $array[$i][2] &"|"& $array[$i][3] &"|"& $array[$i][4] &"|"& $array[$i][5] &"|"& $array[$i][6] &"|"& $array[$i][7], $listview)
- ;$item2 = GUICtrlCreateListViewItem($array[$i][1], $listview)
- ;MsgBox(0,"",$array[$i])
- _GUICtrlListView_EditLabel($listview,0)
- next
- ;Editbox einstellen zum ändern von einträgen
- $EditBox = GUICreate('', 200, 30, -1, -1, BitOR($WS_POPUP,$WS_BORDER), $WS_EX_TOPMOST)
- $hEdit = GUICtrlCreateInput('', 5, 5, 190, 20, $SS_CENTER)
- HotKeySet('{ESC}', '_EscEdit')
- GUISetState(@SW_SHOW, $GUI)
- GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
- ;GUI Schleife, läuft solang bis sie beendet wird
- While True
- $msg = GUIGetMsg()
- If $msg = $GUI_EVENT_CLOSE then Exit
- If $msg = $button1 Then
- Local $aItem ="", $sText = ""
- ;eintrag in variable speichern
- $aItem = _GUICtrlListView_GetItemTextArray($listview, $currentItem[0])
- $aItem2 = _GUICtrlListView_GetItemTextArray($listview, $currentItem[1])
- for $i = 1 To 1
- $sText &= StringFormat("%s", $aItem[$currentItem[1]+1]) & @LF
- Next
- $verg = StringCompare($sText,$Text, 1)
- if $verg < 0 Or $verg > 0 Then
- ;Tabelle setzen
- Select
- Case $currentItem[1]+1 = 1
- $tabelle = "vorgang"
- $spalte = "id"
- Case $currentItem[1]+1 = 2
- $tabelle = "art"
- $spalte = "typ"
- Case $currentItem[1]+1 = 3
- $tabelle = "gegenstand"
- $spalte = "autor"
- Case $currentItem[1]+1 = 4
- $tabelle = "gegenstand"
- $spalte = "titel"
- Case $currentItem[1]+1 = 5
- $tabelle = "person"
- $spalte = "vorname"
- Case $currentItem[1]+1 = 6
- $tabelle = "person"
- $spalte = "nachname"
- Case $currentItem[1]+1 = 7
- $tabelle = "vorgang"
- $spalte = "verleihdatum"
- Case $currentItem[1]+1 = 8
- $tabelle = "vorgang."
- $spalte = "rueckgabedatum"
- EndSelect
- ;überschüssige leerzeichen und Enter entfernen
- StringStripCR ($Text)
- StringStripCR ($sText)
- StringStripCR ($sText)
- stringstripws($Text, 7)
- stringstripws($sText, 7)
- $vorgangID = $currentItem[0]+1
- ;Update in die Datenbank mit den neuen Werten
- $query2 = "update " & $tabelle & " set " & $spalte & " = '" & $sText & "' where " & $spalte & " = '" & $Text & "'"
- _MySQL_Real_Query($MysqlConn, $query2)
- ;Wenn fehler auftritt dann Errormessage! ansonsten wird der Befehl ausgeführt
- $Error = _MySQL_Errno($MysqlConn)
- If $Error == 0 Then
- MsgBox(0,"Erfolg","Eintrag wurde erfolgreich geändert.")
- Else
- MsgBox(0,"Fehler","Es ist ein fehler aufgetretten")
- EndIf
- Else
- msgbox(0,"","Eingaben sind gleich, nichts wird geändert!")
- EndIf
- EndIf
- ;Button2 für Neuer Eintrag
- If $msg = $button2 Then
- $neuE= GUICreate("Neu", 670, 119, 196, 244)
- GUISetState(@SW_SHOW)
- While 1
- $msg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- EndSwitch
- WEnd
- Else
- EndIf
- WEnd
- #cs
- Do
- $msg = GUIGetMsg()
- Select
- Case $msg = $button1
- ;Update in die Datenbank mit den neuen Werten
- MsgBox(0,"","test")
- $query2 = "update person set vorname = 'test' where Vorname = 'gustav'"
- _MySQL_Real_Query($MysqlConn, $query2)
- $res2 = _MySQL_Store_Result($MysqlConn)
- Case $GUI_EVENT_CLOSE
- Exit
- EndSelect
- Until $msg = $GUI_EVENT_CLOSE
- #ce
- _MySQL_Free_Result($res)
- _MySQL_Close($MysqlConn)
- _MySQL_ShutDown()
- Func _LeftDblClick($Info)
- If $Info[3] = -1 Then Return
- $currentOpt[0] = Opt('GUICoordMode', 1)
- $currentOpt[1] = Opt("GUIOnEventMode", 1)
- GUICtrlSetOnEvent($hEdit, '_EditEnter')
- _GUICtrlListView_SetSelectedColumn($Info[1], $Info[4])
- $title = WinGetTitle($GUI)
- Local $mouse = MouseGetPos(), $posEdit = WinGetPos($EditBox)
- Local $posGUI = WinGetPos($GUI), $posLV = ControlGetPos($GUI, '', $listview)
- Local $colInfo = _GUICtrlListView_GetColumn($Info[1], $Info[4]), $sumWidth = 0, $tmp
- WinSetTitle($GUI, '', 'Editiere: Zeile ' & $Info[3]+1 & ', ' & $colInfo[5])
- For $i = 0 To $Info[4]
- $tmp = _GUICtrlListView_GetColumn($Info[1], $i)
- $sumWidth += $tmp[4]
- Next
- $sumWidth -= $colInfo[4]
- Local $xPos = $posGUI[0]+$posLV[0]+$sumWidth
- If $xPos+$colInfo[4]+10 > @DesktopWidth Then $xPos = @DesktopWidth - ($colInfo[4] + 10)
- If $xPos < 0 Then $xPos = 0
- WinMove($EditBox, '', $xPos, $mouse[1]-$posEdit[3], $colInfo[4]+10)
- GUICtrlSetData($hEdit, _GUICtrlListView_GetItemText($Info[1], $Info[3], $Info[4]))
- $currentItem[0] = $Info[3]
- $currentItem[1] = $Info[4]
- ;Alten spalteneintrag in variable $Text speichern
- global $Item = "" , $Text = ""
- $Item = _GUICtrlListView_GetItemTextArray($listview, $currentItem[0])
- $Item2 = _GUICtrlListView_GetItemTextArray($listview, $currentItem[1])
- ;for $i = 1 To 1
- $Text &= StringFormat("%s", $Item[$currentItem[1]+1])
- ;Next
- GUISetState(@SW_SHOW, $EditBox)
- EndFunc
- Func _EscEdit()
- WinSetTitle($GUI, '', $title)
- Opt('GUICoordMode', $currentOpt[0])
- Opt("GUIOnEventMode", $currentOpt[1])
- GUISetState(@SW_HIDE, $EditBox)
- EndFunc
- Func _EditEnter()
- WinSetTitle($GUI, '', $title)
- Opt('GUICoordMode', $currentOpt[0])
- Opt("GUIOnEventMode", $currentOpt[1])
- _GUICtrlListView_SetItemText($listview, $currentItem[0], GUICtrlRead($hEdit), $currentItem[1])
- GUISetState(@SW_HIDE, $EditBox)
- ;msgbox(0,"",$currentItem[0])
- EndFunc
- Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
- Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
- $hWndListView = $listview ; ID des LV
- If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview) ; ID des LV
- $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
- $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
- $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
- $iCode = DllStructGetData($tNMHDR, "Code")
- Switch $hWndFrom
- Case $hWndListView
- Switch $iCode
- Case $NM_DBLCLK
- Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
- Local $aInfo[5] = [$hWndFrom, $iIDFrom, $iCode, DllStructGetData($tInfo, "Index"), _
- DllStructGetData($tInfo, "SubItem")]
- _LeftDblClick($aInfo)
- EndSwitch
- EndSwitch
- Return $GUI_RUNDEFMSG
- EndFunc ;==>WM_NOTIFY
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement