Hallo Leute,
ich habe ein Problem beim Einfügen von neuen Datensätzen in die Sqlite Datenbank. Ich habe ein vorläufiges Gui - Fenster zum Neueinfügen gemacht. Kann mir vielleicht einer zeigen, wie ich es am Besten umsetzen kann?
Ich bräuchte noch eine Idee, wie man durch das Anklicken der Einträge im Listview, rechts die jeweiligen passenden Felder ausgefüllt werden.
Wäre das eine Möglichkeit zum Anklicken _GUICtrlListView_ClickItem
Gruß
Neight
C
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SQLite.au3>
#include <GuiListView.au3>
#include <ComboConstants.au3>
#include <SQLite.dll.au3>
Global Const $sDbMineral = @ScriptDir & "\mineraldb.sqlite"
Global $hDB, $iRval, $aResult, $iRows, $iColumns, $DB, $QLite,$pic
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Mineraliendatenbank", 1181, 736, 214, 142)
$MenuItem3 = GUICtrlCreateMenu("&File")
$MenuItem4 = GUICtrlCreateMenuItem("New"&@TAB&"Ctrl+Down", $MenuItem3)
$MenuItem5 = GUICtrlCreateMenuItem("Open"&@TAB&"", $MenuItem3)
$MenuItem6 = GUICtrlCreateMenuItem("Save"&@TAB&"Shift+Ctrl+0", $MenuItem3)
$MenuItem7 = GUICtrlCreateMenuItem("Exit"&@TAB&"", $MenuItem3)
$MenuItem2 = GUICtrlCreateMenu("&Edit")
$MenuItem9 = GUICtrlCreateMenuItem("Delete"&@TAB&"", $MenuItem2)
$MenuItem1 = GUICtrlCreateMenu("&Help")
$MenuItem8 = GUICtrlCreateMenuItem("About"&@TAB&"", $MenuItem1)
GUISetBkColor(0xB9D1EA)
$Group1 = GUICtrlCreateGroup("", 176, 80, 945, 553)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Nummer", 224, 128, 55, 20)
$Nummer = GUICtrlCreateInput("", 296, 128, 41, 24)
$Label2 = GUICtrlCreateLabel("Name", 384, 128, 41, 20)
$Name = GUICtrlCreateInput("", 440, 128, 177, 24)
$Group2 = GUICtrlCreateGroup("allg. Eigenschaften", 208, 192, 401, 177)
$Label3 = GUICtrlCreateLabel("Formel", 224, 224, 46, 20)
$Formel = GUICtrlCreateInput("", 280, 224, 105, 24)
$Label4 = GUICtrlCreateLabel("Gewicht", 224, 264, 51, 20)
$Gewicht = GUICtrlCreateInput("", 280, 264, 105, 24)
$Farbe = GUICtrlCreateLabel("Farbe", 224, 304, 40, 20)
$Farb = GUICtrlCreateInput("", 280, 304, 105, 24)
$Label5 = GUICtrlCreateLabel("Radioaktiv", 400, 224, 69, 20)
$Checkbox1 = GUICtrlCreateCheckbox("Ja", 480, 224, 41, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Nein", 544, 224, 41, 17)
$Label6 = GUICtrlCreateLabel("Magnetisch", 400, 256, 73, 20)
$Ja = GUICtrlCreateCheckbox("Ja", 480, 256, 49, 17)
$Nein = GUICtrlCreateCheckbox("Nein", 544, 256, 49, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$pic = GUICtrlCreatePic("", 640, 112, 441, 305, BitOR($GUI_SS_DEFAULT_PIC,$SS_RIGHTJUST,$WS_BORDER))
$Group3 = GUICtrlCreateGroup("Funddaten", 208, 416, 409, 153)
$Fundor = GUICtrlCreateLabel("Fundort", 224, 456, 49, 20)
$Fundort = GUICtrlCreateInput("", 304, 456, 241, 24)
$Fundlan = GUICtrlCreateInput("", 304, 504, 241, 24)
$Fundland = GUICtrlCreateLabel("Fundland", 224, 504, 60, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Bild öffnen", 744, 424, 97, 33)
$Button2 = GUICtrlCreateButton("Bild löschen", 880, 424, 97, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateInput("", 312, 24, 465, 21)
$Suche = GUICtrlCreateLabel("Suche", 256, 24, 55, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Zurueck = GUICtrlCreateButton("Zurück", 440, 648, 65, 33)
$Vor = GUICtrlCreateButton("Vor", 696, 648, 65, 33)
$ListView1 = GUICtrlCreateListView("", 8, 88, 150, 545)
_GUICtrlListView_AddColumn($ListView1, "Name", 70)
_GUICtrlListView_AddColumn($ListView1, "Nummer", 150)
;Global $aHeader = StringSplit($ListView1, '|')
Global $hListView = GUICtrlGetHandle($ListView1)
$cContextMenue = GUICtrlCreateContextMenu($ListView1)
GUICtrlCreateListViewItem("",$ListView1)
;Dim $Form1_1_AccelTable[2][2] = [["^{DOWN}", $MenuItem4],["^+0", $MenuItem6]]
;GUISetAccelerators($Form1_1_AccelTable)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_SQLite_Startup()
If @error Then Exit MsgBox(16, "SQLite Fehler", "SQLite.dll konnte nicht geladen werden!")
ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF)
Global $hDB = _SQLite_Open($sDbMineral)
If @error Then Exit MsgBox(16, "SQLite Fehler", "Die Datenbank kann nicht geöffnet werden!")
If FileExists("mineraldb.sqlite") Then
$DB = _SQLite_Open("mineraldb.sqlite")
If @error Then Exit MsgBox(16, "SQLite Fehler", "Die Datenbank kann nicht geöffnet werden!")
_SQLite_Exec(-1, "CREATE TABLE IF NOT EXISTS Mineralien (Nummer INTEGER PRIMARY KEY,Name TEXT,Formel TEXT,Gewicht TEXT,Farbe TEXT,Fundort TEXT,Fundland TEXT);")
_SQLite_Exec(-1, "INSERT INTO Mineralien(Nummer,Name,Formel,Gewicht,Farbe,Fundort,Fundland) VALUES ('1', 'xxx', 'Dhgdgd', '500', 'XXX', 'Hier', 'hier');")
_SQLite_Exec(-1, "INSERT INTO Mineralien(Nummer,Name,Formel,Gewicht,Farbe,Fundort,Fundland) VALUES ('2', 'xxxx', 'Dhgdgd', '500', 'XXX', 'Hier', 'hier');")
Endif
While True
Switch GUIGetMsg()
Case -3
_SQLite_Close($DB)
_SQLite_Shutdown()
Exit
Case $MenuItem5
$iRva = _SQLite_GetTable2d(-1, "SELECT Nummer, * FROM Mineralien;", $aResult, $iRows, $iColumns)
_SQLite_GetTable2d(-1, "SELECT Name, * FROM Mineralien;", $aResult, $iRows, $iColumns)
_ArrayDelete($aResult,0)
_GUICtrlListView_AddArray($ListView1, $aResult)
Case $MenuItem4
_NeuerDatensatz()
Case $Button1
$open = FileOpenDialog("Wählen Sie eine Datei aus.", @TempDir, "Bilder (*.jpg;*.bmp;*.png)")
If @error Then
MsgBox(4096, "", "Keine Datei ausgewählt")
Endif
GUICtrlSetImage($pic,$open)
Case $MenuItem7
Exit
EndSwitch
WEnd
Func _NeuerDatensatz()
#Region ### START Koda GUI section ### Form=
$XXX = GUICreate("Neuer Datensatz", 530, 241, 192, 131)
$Nummer = GUICtrlCreateInput("Nummer", 24, 56, 121, 21)
$Input2 = GUICtrlCreateInput("Formel", 24, 104, 121, 21)
$Input3 = GUICtrlCreateInput("Farbe", 24, 152, 121, 21)
$Input4 = GUICtrlCreateInput("Name", 200, 56, 121, 21)
$Input5 = GUICtrlCreateInput("Gewicht", 200, 104, 121, 21)
$Input6 = GUICtrlCreateInput("Fundort", 200, 152, 121, 21)
$Input1 = GUICtrlCreateInput("Fundland", 376, 56, 121, 21)
$Bitte = GUICtrlCreateLabel("Bitte alle Felder ausfüllen!", 40, 16, 129, 17)
$OK = GUICtrlCreateButton("OK", 168, 192, 169, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $OK
_SQLite_Exec(-1, "INSERT INTO Mineralien (Nummer,Name,Formel,Gewicht,Farbe,Fundort,Fundland) VALUES ('"_
& GUICtrlRead($Nummer[1]) & "','" & GUICtrlRead($Input4[2]) & "','" & GUICtrlRead($Input2[3]) & "','" & GUICtrlRead($Input5[4]) & "','" & GUICtrlRead($Input3[5])& "','" & GUICtrlRead($Input6[6])& "','" & GUICtrlRead($Input1[7]) & "');")
EndSwitch
WEnd
Endfunc
Alles anzeigen