Moin zusammen.
In den Zeilen 216 bis 225 möchte ich folgendes erreichen:
Ich wähle in der Listview einen Datensatz aus. Er ist dann ja blau hinterlegt. Nun sollen, wenn ich den Datensatz ausgewählt haben und ich auf Button19 (Löschbutton) drücke, der Datensatz gelöscht und das Listview neu eingelesen werden.
Wie bekomme ich die ID von dem Datensatz, um damit zu arbeiten???
AutoIt
#Region ;************ Includes ************
#Include <SQLite.au3>
#Include <GuiListView.au3>
#EndRegion ;************ Includes ************
;Opt
Opt("GUIOnEventMode", 0) ; Du benutzt den MsgLoop-Modus also muss hier "0" stehen oder die Zeile gleich ganz weglassen, weil "0" der Standardwert ist
Global $hQuery, $aNames, $aRow
;GUI Titel
$Buchverwaltung = GUICreate("Buchverwaltung erstellt mit AutoIt", 1121, 629, 280, 183)
; Titel oben Mitte
$Label1 = GUICtrlCreateLabel("~ ~ ~ B U C H V E R W A L T U N G ~ ~ ~", 304, 8, 516, 28)
GUICtrlSetFont(-1, 16, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
; ListView
$listview = GUICtrlCreateListView("ID |Titel|Autor|Verlag|Erscheinungsdatum|Genre|Preis|Einband|ISBN|Seiten|Lagerplatz|Serie|Bestellt|Gelesen|Note|Zusatz|Information|Ausgeliehen_an|Ausgeliehen_am|Ausgeliehen_bis|LfdNr", 10, 40, 1105, 220)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
; Hauptbereich
$Label2 = GUICtrlCreateLabel("Titel: ", 10, 274, 45, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input1 = GUICtrlCreateInput("", 160, 272, 361, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label3 = GUICtrlCreateLabel("Autor:", 10, 305, 45, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input2 = GUICtrlCreateInput("", 160, 302, 361, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label4 = GUICtrlCreateLabel("Verlag: ", 10, 335, 58, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input3 = GUICtrlCreateInput("", 160, 332, 361, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label5 = GUICtrlCreateLabel("Genre: ", 10, 365, 55, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input4 = GUICtrlCreateInput("", 160, 362, 361, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label6 = GUICtrlCreateLabel("Erscheinungsdatum: ", 10, 395, 149, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input5 = GUICtrlCreateInput("2016.01.31", 160, 392, 100, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label7 = GUICtrlCreateLabel("Serie: ", 267, 395, 50, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input6 = GUICtrlCreateInput("", 313, 392, 208, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label8 = GUICtrlCreateLabel("Preis: ", 10, 424, 146, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input7 = GUICtrlCreateInput("", 160, 422, 81, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label9 = GUICtrlCreateLabel("Lagerplatz: ", 267, 424, 85, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input8 = GUICtrlCreateInput("", 354, 422, 165, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label10 = GUICtrlCreateLabel("Einband: ", 10, 455, 70, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input9 = GUICtrlCreateInput("", 160, 452, 361, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label11 = GUICtrlCreateLabel("ISBN", 10, 485, 40, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input10 = GUICtrlCreateInput("", 160, 482, 361, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label12 = GUICtrlCreateLabel("Seiten: ", 10, 514, 57, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input11 = GUICtrlCreateInput("", 160, 512, 81, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label13 = GUICtrlCreateLabel("ausgeliehen an: ", 624, 272, 117, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input12 = GUICtrlCreateInput("", 760, 272, 121, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label14 = GUICtrlCreateLabel("ausgeliehen am: ", 624, 302, 122, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input13 = GUICtrlCreateInput("", 760, 302, 121, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label15 = GUICtrlCreateLabel("ausgeliehen bis: ", 624, 332, 121, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input14 = GUICtrlCreateInput("", 760, 334, 121, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label16 = GUICtrlCreateLabel("Bestellt: J/N", 624, 384, 86, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input15 = GUICtrlCreateInput("", 760, 384, 121, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label17 = GUICtrlCreateLabel("gelesen: J/N", 624, 414, 90, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input16 = GUICtrlCreateInput("", 760, 414, 121, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label18 = GUICtrlCreateLabel("Note: 1 - 6", 624, 444, 76, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input17 = GUICtrlCreateInput("", 760, 444, 121, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label19 = GUICtrlCreateLabel("Zusatz:", 624, 474, 53, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input18 = GUICtrlCreateInput("", 760, 472, 121, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label20 = GUICtrlCreateLabel("Information:", 896, 384, 84, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Edit1 = GUICtrlCreateEdit("AA_info", 896, 408, 217, 89)
$Label24 = GUICtrlCreateLabel("Lfd.-Nr:", 350, 515, 55, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input20 = GUICtrlCreateInput("", 415, 512, 105, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetData(-1, "")
$Label22 = GUICtrlCreateLabel("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", 10, 256, 1110, 17)
$Label23 = GUICtrlCreateLabel("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", 10, 544, 1110, 17)
;Suche
$Button16 = GUICtrlCreateButton("S U C H E N", 621, 509, 132, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input19 = GUICtrlCreateInput("Suchbegriff hier eingeben", 760, 507, 347, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
; unterer Bereich
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label26 = GUICtrlCreateLabel("Büchermenge: ", 13, 595, 113, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input22 = GUICtrlCreateInput("", 128, 592, 81, 26) ; hier soll die ges. Bücheranzahl eingefügt werden und nicht veränderbar durch Anwender
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label27 = GUICtrlCreateLabel("Ges. Seitenzahl:", 270, 596, 117, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Input23 = GUICtrlCreateInput(" ", 394, 592, 81, 26) ; hier soll die ges. Seitenzahl eingefügt werden und nicht veränderbar durch Anwender
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Label28 = GUICtrlCreateLabel("Ges. Buch NP:", 572, 595, 106, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlCreateInput("", 680, 592, 121, 26) ; hier soll der ges. Bücherwert eingefügt werden und nicht veränderbar durch Anwender
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Button20 = GUICtrlCreateButton("Speichern", 991, 592, 121, 26)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
; Ausleihbutton
$Button17 = GUICtrlCreateButton("Ausleihen", 888, 272, 227, 25)
; DK 1 / 2 / 3
$Button18 = GUICtrlCreateButton("Update", 894, 334, 99, 26)
; D 1 / 2
$Button19 = GUICtrlCreateButton("Löschen", 1012, 334, 99, 25)
; GUI anzeigen
GUISetState(@SW_SHOW)
; !!! Datei lösche ich hier nur, damit ich sie nicht manuell löschen muss in der Übungsphase !!!
FileDelete(@ScriptDir & "\buchverwaltung.db")
; DLL Pfad
_SQLite_Startup(@ScriptDir & "\sqlite3.dll", False, 1) ; BugFix Idee, da DLL ja nicht mehr mitgeliefert wird
; gibt die SQL Version in die Console aus
ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF)
; Datenbank öffnen, ggf. erstellen
Global $g_db_Database = _SQLite_Open(@ScriptDir & "\buchverwaltung.db")
; Datenbanktabelle
_SQLite_Exec($g_db_Database, "CREATE TABLE IF NOT EXISTS Buchverwaltung(ID INTEGER PRIMARY KEY AUTOINCREMENT,Titel,Autor,Verlag,Erscheinungsdatum,Genre,Preis,Einband,ISBN,Seiten,Lagerplatz,Serie,Bestellt,Gelesen,Note,Zusatz,Information,Ausgeliehen_an,Ausgeliehen_am,Ausgeliehen_bis,LfdNr);")
; jeweils ein Datensatz wird dazu geschrieben, Daten sind von Enno Jüders zur Verfügung gestellt.
_SQLite_Exec(-1, "INSERT INTO Buchverwaltung VALUES(NULL,'13 Tage','Giambanco, Valentina','Droemer Knaur','2014.03.03','Thriller','14.99','Hardcover','9783426513996','576','R1-F2','','','N','','','','','..','..','..');")
_SQLite_Exec(-1, "INSERT INTO Buchverwaltung VALUES(NULL,'Abgründe','Strobel, Arno','Loewe','2014.03.10','Thriller-J','9.95','Taschenbuch','9783785578643','240','R1-F2','','','N','','','','','..','..','..');")
_SQLite_Exec(-1, "INSERT INTO Buchverwaltung VALUES(NULL,'Agent 6','Smith, Tom Rob','Goldmann','2011.09.14','Thriller','9.99','Taschenbuch','9783442546770','540','R1-F2','Leo Demidow Bd.3','','N','','','','','..','..','..');")
_SQLite_Exec(-1, "INSERT INTO Buchverwaltung VALUES(NULL,'Bedroht','Koppen, Hans','Heyne','2013.03.27','Thriller','14.99','Taschenbuch','9783453268012','411','R1-F2','','','J','1','','','','..','..','..');")
_SQLite_Exec(-1, "INSERT INTO Buchverwaltung VALUES(NULL,'Belladonna','Slaughter, Karin','rororo','2003.03.03','Thriller','6.00','Taschenbuch','9783499239140','413','R1-F1','Grant County Bd.1','','J','1','','','','..','..','..');")
_SQLite_Exec(-1, "INSERT INTO Buchverwaltung VALUES(NULL,'Bis zum letzten Atemzug','Baldacci, David','Bastei Lübbe','2011.04.01','Thriller','9.99','Taschenbuch','9783404165537','574','R1-F2','King & Maxwell Bd. 4','austauschen','N','','','','','..','..','..');")
_SQLite_Exec(-1, "INSERT INTO Buchverwaltung VALUES(NULL,'Bittere Wunden','Slaughter, Karin','blanvalet','2014.09.01','Thriller','19.99','Hardcover','9783764505172','576','R1-F1','Georgia Bd.4','','J','2','','','','..','..','..');")
_ListViewFill()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
_Exit() ; Ende
Case $listview ; Sortieren v. ListView
_GUICtrlListView_SortItems($listview, GUICtrlGetState($listview))
Case $Button20 ; Speichern (erledigt)
_DsInset()
Case $Button19 ; Löschen (offen in Arbeit)
_DsDelete()
Case $Button18 ; Update (offen)
_DsUpdate()
Case $Button16 ; Search (offen)
_search()
Case $Button17 ; Ausleihen (offen und für später gedacht, wenn ich mit SQLite besser klar komme und es besser verstehe; Idee: eine extra DB fürs ausleihen.)
_ausleihen()
EndSwitch
WEnd
Func _Exit() ; Datenbank schließen und down.
_GUICtrlListView_UnRegisterSortCallBack($listview)
_SQLite_Close($g_db_Database)
_SQLite_Shutdown()
Exit
EndFunc ;==>_Exit
Func _ausleihen()
MsgBox(0,"","Noch nicht gescriptet")
EndFunc
Func _search()
MsgBox(0,"","Noch nicht gescriptet")
EndFunc
Func _DsUpdate()
MsgBox(0,"","Noch nicht gescriptet")
EndFunc
; DS löschen
Func _DsDelete()
Local $aworte
GUICtrlSetData($Input1,"") ; Titel
GUICtrlSetData($Input2,"") ; Autor
GUICtrlSetData($Input3,"") ; Verlag
GUICtrlSetData($Input4,"") ; Genre
GUICtrlSetData($Input5,"") ; Erscheinungsjahr
GUICtrlSetData($Input6,"") ; Serie
GUICtrlSetData($Input7,"") ; Preis
GUICtrlSetData($Input8,"") ; Lagerplatz
GUICtrlSetData($Input9,"") ; Einband
GUICtrlSetData($Input10,"") ; ISBN
GUICtrlSetData($Input11,"") ; Seiten
GUICtrlSetData($Input12,"") ; Ausgeliehen an
GUICtrlSetData($Input13,"") ; Ausgeliehen am
GUICtrlSetData($Input14,"") ; Ausgeliehen bis
GUICtrlSetData($Input15,"") ; Bestellt: J/N
GUICtrlSetData($Edit1,"") ; Information
GUICtrlSetData($Input16,"") ; Gelesen
GUICtrlSetData($Input17,"") ; Note 1-6; und 0 0 nicht gelesen
GUICtrlSetData($Input18,"") ; Zusatz
GUICtrlSetData($Input20,"") ; Lfd.-Nr.
_SQLite_Query(-1, "SELECT ROWID,* FROM Buchverwaltung;", $hQuery)
_SQLite_QuerySingleRow(-1,"SELECT id FROM Buchverwaltung WHERE id='"&$hQuery&"'",$aworte)
If $aworte[0] <> "" Then
_SQLite_Exec(-1,"DELETE FROM Buchverwaltung WHERE id='"&$hQuery&"'")
EndIf
_ListViewFill()
EndFunc
; Datensatz von GUI2DB
Func _DsInset()
Local $aworte
$inputs1 = GUICtrlRead($Input1) ; Titel
$inputs2 = GUICtrlRead($Input2) ; Autor
$inputs3 = GUICtrlRead($Input3) ; Verlag
$inputs4 = GUICtrlRead($Input4) ; Genre
$inputs5 = GUICtrlRead($Input5) ; Erscheinungsjahr
$inputs6 = GUICtrlRead($Input6) ; Serie
$inputs7 = GUICtrlRead($Input7) ; Preis
$inputs8 = GUICtrlRead($Input8) ; Lagerplatz
$inputs9 = GUICtrlRead($Input9) ; Einband
$inputs10 = GUICtrlRead($Input10) ; ISBN
$inputs11 = GUICtrlRead($Input11) ; Seiten
$inputs12 = GUICtrlRead($Input12) ; Ausgeliehen an
$inputs13 = GUICtrlRead($Input13) ; Ausgeliehen am
$inputs14 = GUICtrlRead($Input14) ; Ausgeliehen bis
$inputs15 = GUICtrlRead($Input15) ; Bestellt: J/N
$edits1 = GUICtrlRead($Edit1) ; Information
$inputs16 = GUICtrlRead($Input16) ; Gelesen
$inputs17 = GUICtrlRead($Input17) ; Note 1-6; und 0 0 nicht gelesen
$inputs18 = GUICtrlRead($Input18) ; Zusatz
$inputs20 = GUICtrlRead($Input20) ; Lfd.-Nr.
;~ NULL (sprich nall)- ID, Tabelle Buchverwaltung
_SQLite_Exec(-1, "INSERT INTO Buchverwaltung VALUES(NULL, '" & $inputs1 & "','" & $inputs2 & "','" & $inputs3 & "','" & $inputs5 & "','" & $inputs4 & "','" & $inputs7 & "','" & $inputs9 & "','" & $inputs10 & "','" & $inputs11 & "','" & $inputs8 & "','" & $inputs6 & "','" & $inputs15 & "','" & $inputs16 & "','" & $inputs17 & "','" & $inputs18 & "','" & $edits1 & "','" & $inputs12 & "','" & $inputs13 & "','" & $inputs14 & "','" & $inputs20 & "');")
_ListViewFill()
EndFunc ;==>_DsInset
Func _ListViewFill()
_GUICtrlListView_DeleteAllItems($listview)
_SQLite_Query(-1, "SELECT ROWID,* FROM Buchverwaltung;", $hQuery)
While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row
GUICtrlCreateListViewItem(_ArrayToString($aRow, '|', 1, 21), $listview)
WEnd
_SQLite_QueryFinalize($hQuery)
_GUICtrlListView_RegisterSortCallBack($listview) ; CallBack registrieren zum sortieren
EndFunc ;==>_ListViewFill
Alles anzeigen