Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.67 KB | None | 0 0
  1. #cs ----------------------------------------------------------------------------
  2. PW DB: root
  3. AutoIt Version: 3.3.6.1
  4. Author: Karavas Gustav
  5.  
  6. Script Function:
  7. Database connection
  8.  
  9.  
  10.  
  11.  
  12. #ce ----------------------------------------------------------------------------
  13.  
  14. #include <array.au3>
  15. #include "mysql.au3"
  16. #include <GUIConstantsEx.au3>
  17. #include <GUIConstants.au3>
  18. #include <EditConstants.au3>
  19. #include <GuiListView.au3>
  20. #include <ListviewConstants.au3>
  21. #include <WindowsConstants.au3>
  22. #include<StructureConstants.au3>
  23. #include<StaticConstants.au3>
  24.  
  25. Global $currentItem[2], $title, $currentOpt[2]
  26.  
  27. ; MYSQL starten, DLL im PATH (enthält auch @ScriptDir), sont Pfad zur DLL angeben. DLL muss libmysql.dll heißen.
  28. _MySQL_InitLibrary()
  29. If @error Then Exit MsgBox(0, '', "")
  30.  
  31. $MysqlConn = _MySQL_Init()
  32. ;$PW = InputBox("Logindaten", "Gib hier das Password ein", "", "*")
  33. $PW = "root"
  34. $connected = _MySQL_Real_Connect($MysqlConn, "localhost", "cash", $PW , "chipsy")
  35.  
  36. If $connected = 0 Then Exit MsgBox(16, 'Connection Error', _MySQL_Error($MysqlConn))
  37.  
  38. ;select auf alle daten
  39. $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"
  40.  
  41. ;auswertung des selects
  42. _MySQL_Real_Query($MysqlConn, $query)
  43. $res = _MySQL_Store_Result($MysqlConn)
  44. $fields = _MySQL_Num_Fields($res)
  45. $rows = _MySQL_Num_Rows($res)
  46. ;speichern in array
  47. $array = _MySQL_Fetch_Result_StringArray($res)
  48.  
  49. ;GUI erstellen
  50. $GUI = GUICreate("Verleihsystem", 600, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
  51. $button1 = GUICtrlCreateButton("Ändern", 10, 170, 70, 20)
  52. $button2 = GUICtrlCreateButton("Neuer Eintrag", 90, 170, 70, 20)
  53. $button3 = GUICtrlCreateButton("Eintrag löschen", 170, 170, 80, 20)
  54. $button2 = GUICtrlCreateButton("Suche", 260, 170, 70, 20)
  55. GUISetBkColor(0x00E0FFFF) ; Ändert die Hintergrundfarbe
  56.  
  57. ;spaltenüberschrift erstellen
  58. $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)
  59.  
  60. ;ergebnisse aus $array in einer Listview grafisch dartellen
  61. for $i = 1 to UBound($array) -1
  62. $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)
  63. ;$item2 = GUICtrlCreateListViewItem($array[$i][1], $listview)
  64. ;MsgBox(0,"",$array[$i])
  65. _GUICtrlListView_EditLabel($listview,0)
  66. next
  67.  
  68. ;Editbox einstellen zum ändern von einträgen
  69. $EditBox = GUICreate('', 200, 30, -1, -1, BitOR($WS_POPUP,$WS_BORDER), $WS_EX_TOPMOST)
  70. $hEdit = GUICtrlCreateInput('', 5, 5, 190, 20, $SS_CENTER)
  71. HotKeySet('{ESC}', '_EscEdit')
  72. GUISetState(@SW_SHOW, $GUI)
  73. GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
  74.  
  75. ;GUI Schleife, läuft solang bis sie beendet wird
  76. While True
  77. $msg = GUIGetMsg()
  78.  
  79. If $msg = $GUI_EVENT_CLOSE then Exit
  80. If $msg = $button1 Then
  81. Local $aItem ="", $sText = ""
  82. ;eintrag in variable speichern
  83. $aItem = _GUICtrlListView_GetItemTextArray($listview, $currentItem[0])
  84. $aItem2 = _GUICtrlListView_GetItemTextArray($listview, $currentItem[1])
  85. for $i = 1 To 1
  86. $sText &= StringFormat("%s", $aItem[$currentItem[1]+1]) & @LF
  87. Next
  88. $verg = StringCompare($sText,$Text, 1)
  89. if $verg < 0 Or $verg > 0 Then
  90. ;Tabelle setzen
  91. Select
  92. Case $currentItem[1]+1 = 1
  93. $tabelle = "vorgang"
  94. $spalte = "id"
  95.  
  96. Case $currentItem[1]+1 = 2
  97. $tabelle = "art"
  98. $spalte = "typ"
  99.  
  100. Case $currentItem[1]+1 = 3
  101. $tabelle = "gegenstand"
  102. $spalte = "autor"
  103.  
  104. Case $currentItem[1]+1 = 4
  105. $tabelle = "gegenstand"
  106. $spalte = "titel"
  107.  
  108. Case $currentItem[1]+1 = 5
  109. $tabelle = "person"
  110. $spalte = "vorname"
  111.  
  112. Case $currentItem[1]+1 = 6
  113. $tabelle = "person"
  114. $spalte = "nachname"
  115.  
  116. Case $currentItem[1]+1 = 7
  117. $tabelle = "vorgang"
  118. $spalte = "verleihdatum"
  119.  
  120. Case $currentItem[1]+1 = 8
  121. $tabelle = "vorgang."
  122. $spalte = "rueckgabedatum"
  123. EndSelect
  124. ;überschüssige leerzeichen und Enter entfernen
  125. StringStripCR ($Text)
  126. StringStripCR ($sText)
  127. StringStripCR ($sText)
  128. stringstripws($Text, 7)
  129. stringstripws($sText, 7)
  130. $vorgangID = $currentItem[0]+1
  131.  
  132. ;Update in die Datenbank mit den neuen Werten
  133. $query2 = "update " & $tabelle & " set " & $spalte & " = '" & $sText & "' where " & $spalte & " = '" & $Text & "'"
  134. _MySQL_Real_Query($MysqlConn, $query2)
  135.  
  136. ;Wenn fehler auftritt dann Errormessage! ansonsten wird der Befehl ausgeführt
  137. $Error = _MySQL_Errno($MysqlConn)
  138. If $Error == 0 Then
  139. MsgBox(0,"Erfolg","Eintrag wurde erfolgreich geändert.")
  140. Else
  141. MsgBox(0,"Fehler","Es ist ein fehler aufgetretten")
  142. EndIf
  143. Else
  144. msgbox(0,"","Eingaben sind gleich, nichts wird geändert!")
  145. EndIf
  146. EndIf
  147.  
  148. ;Button2 für Neuer Eintrag
  149. If $msg = $button2 Then
  150. $neuE= GUICreate("Neu", 670, 119, 196, 244)
  151. GUISetState(@SW_SHOW)
  152. While 1
  153. $msg = GUIGetMsg()
  154. Switch $nMsg
  155. Case $GUI_EVENT_CLOSE
  156. Exit
  157.  
  158. EndSwitch
  159. WEnd
  160. Else
  161. EndIf
  162.  
  163.  
  164.  
  165. WEnd
  166.  
  167.  
  168. #cs
  169. Do
  170. $msg = GUIGetMsg()
  171.  
  172. Select
  173. Case $msg = $button1
  174. ;Update in die Datenbank mit den neuen Werten
  175. MsgBox(0,"","test")
  176. $query2 = "update person set vorname = 'test' where Vorname = 'gustav'"
  177. _MySQL_Real_Query($MysqlConn, $query2)
  178. $res2 = _MySQL_Store_Result($MysqlConn)
  179. Case $GUI_EVENT_CLOSE
  180. Exit
  181.  
  182. EndSelect
  183. Until $msg = $GUI_EVENT_CLOSE
  184. #ce
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192. _MySQL_Free_Result($res)
  193. _MySQL_Close($MysqlConn)
  194. _MySQL_ShutDown()
  195.  
  196. Func _LeftDblClick($Info)
  197. If $Info[3] = -1 Then Return
  198. $currentOpt[0] = Opt('GUICoordMode', 1)
  199. $currentOpt[1] = Opt("GUIOnEventMode", 1)
  200. GUICtrlSetOnEvent($hEdit, '_EditEnter')
  201. _GUICtrlListView_SetSelectedColumn($Info[1], $Info[4])
  202. $title = WinGetTitle($GUI)
  203. Local $mouse = MouseGetPos(), $posEdit = WinGetPos($EditBox)
  204. Local $posGUI = WinGetPos($GUI), $posLV = ControlGetPos($GUI, '', $listview)
  205. Local $colInfo = _GUICtrlListView_GetColumn($Info[1], $Info[4]), $sumWidth = 0, $tmp
  206. WinSetTitle($GUI, '', 'Editiere: Zeile ' & $Info[3]+1 & ', ' & $colInfo[5])
  207. For $i = 0 To $Info[4]
  208. $tmp = _GUICtrlListView_GetColumn($Info[1], $i)
  209. $sumWidth += $tmp[4]
  210. Next
  211. $sumWidth -= $colInfo[4]
  212. Local $xPos = $posGUI[0]+$posLV[0]+$sumWidth
  213. If $xPos+$colInfo[4]+10 > @DesktopWidth Then $xPos = @DesktopWidth - ($colInfo[4] + 10)
  214. If $xPos < 0 Then $xPos = 0
  215. WinMove($EditBox, '', $xPos, $mouse[1]-$posEdit[3], $colInfo[4]+10)
  216. GUICtrlSetData($hEdit, _GUICtrlListView_GetItemText($Info[1], $Info[3], $Info[4]))
  217. $currentItem[0] = $Info[3]
  218. $currentItem[1] = $Info[4]
  219.  
  220. ;Alten spalteneintrag in variable $Text speichern
  221. global $Item = "" , $Text = ""
  222. $Item = _GUICtrlListView_GetItemTextArray($listview, $currentItem[0])
  223. $Item2 = _GUICtrlListView_GetItemTextArray($listview, $currentItem[1])
  224. ;for $i = 1 To 1
  225. $Text &= StringFormat("%s", $Item[$currentItem[1]+1])
  226. ;Next
  227.  
  228. GUISetState(@SW_SHOW, $EditBox)
  229.  
  230. EndFunc
  231.  
  232. Func _EscEdit()
  233. WinSetTitle($GUI, '', $title)
  234. Opt('GUICoordMode', $currentOpt[0])
  235. Opt("GUIOnEventMode", $currentOpt[1])
  236. GUISetState(@SW_HIDE, $EditBox)
  237. EndFunc
  238.  
  239. Func _EditEnter()
  240. WinSetTitle($GUI, '', $title)
  241. Opt('GUICoordMode', $currentOpt[0])
  242. Opt("GUIOnEventMode", $currentOpt[1])
  243. _GUICtrlListView_SetItemText($listview, $currentItem[0], GUICtrlRead($hEdit), $currentItem[1])
  244. GUISetState(@SW_HIDE, $EditBox)
  245. ;msgbox(0,"",$currentItem[0])
  246. EndFunc
  247.  
  248. Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
  249. Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
  250. $hWndListView = $listview ; ID des LV
  251. If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview) ; ID des LV
  252. $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
  253. $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
  254. $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
  255. $iCode = DllStructGetData($tNMHDR, "Code")
  256. Switch $hWndFrom
  257. Case $hWndListView
  258. Switch $iCode
  259. Case $NM_DBLCLK
  260. Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
  261. Local $aInfo[5] = [$hWndFrom, $iIDFrom, $iCode, DllStructGetData($tInfo, "Index"), _
  262. DllStructGetData($tInfo, "SubItem")]
  263. _LeftDblClick($aInfo)
  264. EndSwitch
  265. EndSwitch
  266. Return $GUI_RUNDEFMSG
  267. EndFunc ;==>WM_NOTIFY
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement