Hallo Leute,
ich habe ein Problem beim Einfügen/Löschen von Bildern in der DB. Ich wollte den Namen des Bildes in die DB speichern und somit anzeigen lassen, abhängig von der jeweiligen ID. Ich hatte bisschen rum probiert , kam aber leider nicht ans Ziel. Vielleicht kann mir einer weiterhelfen bei meinem Problem?
Gruß Neight
C
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
Global $i , $g_hGUI, $g_hListView, $g_idGroupDropBox, $g_hGroupDropBox,$g_iLVOlColor, $aCtrlInput[$i] , $g_iLVTextColor, $g_iLVBkColor
Global $g_iGuiBkColor = 0x425357
Global $dbn, $num = 1, $aStr[8]
Global $aCtrlLabel[8], $aCtrlInput[8]
Global Const $DB_Bilder = DirCreate(@ScriptDir & "\Bilder")
_SQLite_Startup(@ScriptDir & "\sqlite3.dll", False, 1)
_SQLite_Startup()
If Not FileExists("MinealDB.sqlite") Then
$dbn = _SQLite_Open("MineralDB.sqlite")
_SQLite_Exec(-1, "CREATE TABLE MineralDB (ID INTEGER PRIMARY KEY AUTOINCREMENT, Name varchar(40) NOT NULL, Synonyme varchar(40) NOT NULL, Formel varchar(20), Farbe varchar(50), Dichte varchar(10), Härte varchar(10), Fundort varchar(40), Fundland varchar(40));")
Else
$dbn = _SQLite_Open("MineralDB.sqlite")
EndIf
#Region ### GUI section ###
$g_hGUI = GUICreate("Mineraliendatenbank", 1144, 611, 249, 111, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetBkColor($g_iGuiBkColor)
$g_idGroupDropBox = GUICtrlCreateGroup("", 66, 18, 1014, 510)
GUICtrlCreateGroup("Name", 76, 28, 400, 40)
$aCtrlInput[0] = GUICtrlCreateInput("", 79, 43, 386, 21)
GUICtrlCreateGroup("Synonym", 76, 84, 400, 40)
$aCtrlInput[1] = GUICtrlCreateInput("", 79, 99, 386, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Allg. Eigenschaften", 76, 145, 396, 214)
GUICtrlCreateGroup("Formel", 86, 165, 376, 40)
$aCtrlInput[2] = GUICtrlCreateInput("", 89, 180, 370, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Härte", 86, 309, 376, 40)
$aCtrlInput[5] = GUICtrlCreateInput("", 89, 324, 370, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Dichte", 86, 261, 376, 40)
$aCtrlInput[4] = GUICtrlCreateInput("", 89, 276, 370, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Farbe", 86, 213, 376, 40)
$aCtrlInput[3] = GUICtrlCreateInput("", 89, 228, 370, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GUICtrlCreateGroup("Funddaten", 76, 380, 400, 110)
GUICtrlCreateGroup("Fundort", 86, 400, 380, 40)
$aCtrlInput[6] = GUICtrlCreateInput("", 89, 415, 374, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Fundland", 86, 440, 380, 40)
$aCtrlInput[7] = GUICtrlCreateInput("", 89, 455, 374, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$g_idPic = GUICtrlCreatePic("", 614, 44, 448, 318, BitOR($GUI_SS_DEFAULT_PIC,$SS_CENTERIMAGE,$SS_RIGHTJUST,$WS_BORDER))
$g_idButton_LoadPic = GUICtrlCreateButton("Bild laden", 614, 385, 215, 33)
$g_idButton_DeletePic = GUICtrlCreateButton("Bild löschen", 847, 385, 215, 33)
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$Anzahl = GUICtrlCreateLabel("", 392, 592, 348, 17, BitOR($SS_SIMPLE, $SS_SUNKEN))
$Label2 = GUICtrlCreateLabel("", 0, 592, 380, 17, BitOR($SS_SIMPLE, $SS_SUNKEN))
$Label3 = GUICtrlCreateLabel("", 752, 592, 389, 17, BitOR($SS_SIMPLE, $SS_SUNKEN))
$btnAdd = GUICtrlCreateButton("+", 16, 48, 33, 33)
$btnDel = GUICtrlCreateButton("-", 16, 88, 33, 33)
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$g_idButton_Zurueck = GUICtrlCreateButton("Zurück", 90, 554, 430, 33)
$g_idButton_Weiter = GUICtrlCreateButton("Weiter", 618, 554, 430, 33)
$iptCount = GUICtrlCreateInput($num, 536, 560, 65, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY,$ES_CENTER))
GUISetState(@SW_SHOW)
#EndRegion ### START GUI section ###
_query($num)
_SQLite_CountRows('MineralDB')
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_quit()
Case $g_idButton_Weiter
$num += 1
GUICtrlSetData($iptCount, $num)
_query($num)
Case $g_idButton_Zurueck
If $num == 1 Then
$num = 1
GUICtrlSetData($iptCount, $num)
Else
$num -= 1
GUICtrlSetData($iptCount, $num)
_query($num)
EndIf
Case $btnAdd
If GUICtrlRead($aCtrlInput[0]) == "" Then
MsgBox(0, "ERORR", "Empty name!")
Else
_add($num)
EndIf
Case $btnDel
_del($num)
Case $g_idButton_LoadPic
$pic = FileOpenDialog("Wähle ein Bild aus!", @ScriptDir & "\Bilder" , "Bilder (*.jpg;*.bmp;*.png)", 1 + 2)
If @error Then
MsgBox(4096, "", "Keine Datei(en) ausgewählt")
Else
Endif
EndSwitch
WEnd
Func _quit()
_SQLite_Close()
_SQLite_Shutdown()
Exit
EndFunc
Func _query($id)
_clear()
Local $retarr
If _SQLite_QuerySingleRow($dbn, "SELECT * FROM MineralDB WHERE id='" & $id & "'", $retarr) == $SQLITE_OK Then
If $retarr[0] == "" Then
MsgBox(0, "ERROR", "Query error!")
Else
For $l = 0 To 7
GUICtrlSetData($aCtrlInput[$l], $retarr[$l + 1])
Next
EndIf
EndIf
EndFunc
Func _add($id)
_readipt()
Local $retarr
_SQLite_QuerySingleRow($dbn, "SELECT id FROM MineralDB WHERE id='" & $id & "'", $retarr)
If $retarr[0] <> "" Then
_SQLite_Exec($dbn, "UPDATE MineralDB SET Name='" _
& $aStr[0] & "', Synonyme='" & $aStr[1] & "',Formel='" & $aStr[2] & "',Farbe='" & $aStr[3] & "',Dichte='" & $aStr[4] _
& "',Härte='" & $aStr[5] & "',Fundort='" & $aStr[6] & "',Fundland='" & $aStr[7] & "' WHERE id='" & $id & "'")
Else
_SQLite_Exec($dbn, "INSERT INTO MineralDB (ID,Name,Synonyme,Formel,Farbe,Dichte,Härte,Fundort,Fundland) VALUES ('" _
& $num & "','" & $aStr[0] & "','" & $aStr[1] & "','" & $aStr[2] _
& "','" & $aStr[3] & "','" & $aStr[4] & "','" & $aStr[5] & "','" _
& $aStr[6] & "','" & $aStr[7] & "');")
EndIf
_SQLite_CountRows('MineralDB')
EndFunc
Func _del($id)
_clear()
Local $retarr
_SQLite_QuerySingleRow($dbn, "SELECT id FROM MineralDB WHERE id='" & $id & "'", $retarr)
If $retarr[0] <> "" Then
_SQLite_Exec($dbn, "DELETE FROM MineralDB WHERE id='" & $id & "'")
EndIf
_SQLite_CountRows('MineralDB')
EndFunc
Func _clear()
For $j = 0 To 7
GUICtrlSetData($aCtrlInput[$j], "")
Next
EndFunc
Func _readipt()
For $k = 0 To 7
$aStr[$k] = GUICtrlRead($aCtrlInput[$k])
Next
EndFunc
Func _SQLite_CountRows($_sTable)
Local $hQuery, $aQuery, $iRet = 0, $iErr
If $SQLITE_OK <> _SQLite_Query(-1, "SELECT count(*) FROM " & $_sTable & ";", $hQuery) Then
$iErr = _SQLite_ErrCode()
_SQLite_QueryFinalize($hQuery)
Return SetError(1, $iErr, -1)
EndIf
While _SQLite_FetchData($hQuery, $aQuery) = $SQLITE_OK
$iRet = $aQuery[0]
WEnd
_SQLite_QueryFinalize($hQuery)
GUICtrlSetData($Anzahl, " Anzahl der Datensätze: " & $iRet)
EndFunc
Alles anzeigen