Jump to content

Help with a library tool


Recommended Posts

Hi guys

I'm new to autoit and my sister wanted me to make her a library database tool so I tried to do it in autoit.

I ran into some dead ends and would be glad if someone more experienced could give me a few hints. :)

What I'm missing is :

- "Ändern" should open a childgui and load the listview item selected in the listview into the inputboxes (the childgui is the same as "Neu")

- "Neu" should add new entries into the listview, couldn't figure out the code for that

- When the chilgui is getting closed it will automatically exit, how can I limit it to the main gui only?

- "Suchen" should search for the strings in the categories (specified in the drowdown box) in the listview and display them

- A way to load/save the contents of the listview into a file

Here's my code.

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiList.au3>
#include <File.au3>

$Gui = GUICreate("Datenbank",788,514, 100,200)
GUICtrlCreateGroup ("Suche", 4, 0, 475, 45)
GUICtrlCreateGroup ("Aktionen", 485, 0, 300, 45)
$Combo = GuiCtrlCreateCombo("", 290, 18, 90, 120, $CBS_DROPDOWNLIST)
$String = GuiCtrlCreateInput("", 10, 18, 250, 20)
GUICtrlCreateLabel ( "in", 270, 21 )
GUICtrlSetData($Combo,"Buchtitel|Author|ausgeliehen am|ausgeliehen bis|Name|Adresse|Telefon|e-Mail|Kommentar", "Buchtitel")

$Button_1 = GuiCtrlCreateButton("Suchen", 390, 18, 80, 20)
$Button_2 = GuiCtrlCreateButton("Löschen", 695, 18, 80, 20)
$Button_3 = GuiCtrlCreateButton("Ändern", 595, 18, 80, 20)
$Button_4 = GuiCtrlCreateButton("Neu", 495, 18, 80, 20)
$List = GuiCtrlCreateListView ("Buchtitel|Author|ausgeliehen am|ausgeliehen bis|Name|Adresse|Telefon|e-Mail|Kommentar",4,50,780,460)
GUICtrlSetState($String,$GUI_FOCUS)
GuiSetState()

$Gui3 = GUICreate("Eintrag Ändern",790,115, 100,200)
$aInput_1 = GuiCtrlCreateInput("Buchtitel", 5, 5, 260, 20)
$aInput_2 = GuiCtrlCreateInput("Author", 525, 5, 260, 20)
$aInput_3 = GuiCtrlCreateInput("ausgeliehen am", 5, 30, 260, 20)
$aInput_4 = GuiCtrlCreateInput("ausgeliehen bis", 5, 55, 260, 20)
$aInput_5 = GuiCtrlCreateInput("Name", 270, 5, 250, 20)
$aInput_6 = GuiCtrlCreateInput("Adresse", 270, 30, 250, 20)
$aInput_7 = GuiCtrlCreateInput("Telefon", 525, 30, 260, 20)
$aInput_8 = GuiCtrlCreateInput("e-Mail", 270, 55, 250, 20)
$aInput_9 = GuiCtrlCreateInput("Kommentar", 525, 55, 260, 20)
$aButton_1 = GuiCtrlCreateButton("Speichern", 5, 80, 780, 30)

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($List) ]

If FileExists ("data.ini") = False Then
    FileWrite ("data.ini","")
EndIf

;~ Load the previously saved data



While 1
    $msg = GuiGetMsg($Gui)
    Select
    Case $msg = $GUI_EVENT_CLOSE
;~      Save listview data into the ini file before closing
        Exit
    Case $msg = $Button_1
;~      A search function
    Case $msg = $Button_2
        $confirm = MsgBox (4, "Löschen bestätigen", "Wirklich löschen?")
        If $confirm = 6 Then
        _GUICtrlListViewDeleteItemsSelected($List)
    Else 
        Sleep ( 1 )
        EndIf
    Case $msg = $Button_3
        $result = ChildGui()
    Case $msg = $Button_4
        GUISetState (1, $Gui3)
    Case $msg = $aButton_1
;~      Save as a new item in the listview
    Case $msg = $List
        _GUICtrlListViewSort($List, $B_DESCENDING, GUICtrlGetState($List))
    Case Else
        ;;;
EndSelect
WEnd
Edited by Griffith
Link to comment
Share on other sites

Here is code with some of your questions (not all) solved:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiList.au3>
#include <File.au3>

$Gui = GUICreate("Datenbank",788,514, 100,200)
GUICtrlCreateGroup ("Suche", 4, 0, 475, 45)
GUICtrlCreateGroup ("Aktionen", 485, 0, 300, 45)
$Combo = GuiCtrlCreateCombo("", 290, 18, 90, 120, $CBS_DROPDOWNLIST)
$String = GuiCtrlCreateInput("", 10, 18, 250, 20)
GUICtrlCreateLabel ( "in", 270, 21 )
GUICtrlSetData($Combo,"Buchtitel|Author|ausgeliehen am|ausgeliehen bis|Name|Adresse|Telefon|e-Mail|Kommentar", "Buchtitel")

$Button_1 = GuiCtrlCreateButton("Suchen", 390, 18, 80, 20)
$Button_2 = GuiCtrlCreateButton("Löschen", 695, 18, 80, 20)
$Button_3 = GuiCtrlCreateButton("Ändern", 595, 18, 80, 20)
$Button_4 = GuiCtrlCreateButton("Neu", 495, 18, 80, 20)
$List = GuiCtrlCreateListView ("Buchtitel|Author|ausgeliehen am|ausgeliehen bis|Name|Adresse|Telefon|e-Mail|Kommentar",4,50,780,460)
GUICtrlSetState($String,$GUI_FOCUS)
GuiSetState()

$Gui3 = GUICreate("Eintrag Ändern",790,115, 100,200, -1, -1, $Gui)
$aInput_1 = GuiCtrlCreateInput("Buchtitel", 5, 5, 260, 20)
$aInput_2 = GuiCtrlCreateInput("Author", 525, 5, 260, 20)
$aInput_3 = GuiCtrlCreateInput("ausgeliehen am", 5, 30, 260, 20)
$aInput_4 = GuiCtrlCreateInput("ausgeliehen bis", 5, 55, 260, 20)
$aInput_5 = GuiCtrlCreateInput("Name", 270, 5, 250, 20)
$aInput_6 = GuiCtrlCreateInput("Adresse", 270, 30, 250, 20)
$aInput_7 = GuiCtrlCreateInput("Telefon", 525, 30, 260, 20)
$aInput_8 = GuiCtrlCreateInput("e-Mail", 270, 55, 250, 20)
$aInput_9 = GuiCtrlCreateInput("Kommentar", 525, 55, 260, 20)
$aButton_1 = GuiCtrlCreateButton("Speichern", 5, 80, 780, 30)

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($List) ]

If Not FileExists ("data.txt") Then FileWrite ("data.txt","")

;~ Load the previously saved data
LoadListView($list, 'data.txt')

While 1
    $msg = GuiGetMsg(1)
    Select
    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $Gui
        ;~   Save listview data into the ini file before closing
        SaveListView($list, 'data.txt')
        Exit
    Case $msg[0] = $Button_1
;~   A search function
    Case $msg[0] = $Button_2
        $confirm = MsgBox (4, "Löschen bestätigen", "Wirklich löschen?")
        If $confirm = 6 Then
            _GUICtrlListViewDeleteItemsSelected($List)
        EndIf
    Case $msg[0] = $Button_3
;~         $result = ChildGui()
    Case $msg[0] = $Button_4
        GUISetState (@SW_SHOW , $Gui3)
    Case $msg[0] = $aButton_1
;~   Save as a new item in the listview
        GUISetState (@SW_HIDE , $Gui3)
    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $Gui3
        GUISetState (@SW_HIDE , $Gui3)
    Case $msg[0] = $List
        _GUICtrlListViewSort($List, $B_DESCENDING, GUICtrlGetState($List))
    EndSelect
WEnd

Func SaveListView($list, $file)
    $data = ''
    For $i = 0 To _GUICtrlListViewGetItemCount($list) - 1
        $data &= _GUICtrlListViewGetItemText($list, $i) & @CRLF
    Next
    $data = StringTrimRight($data,2)
    FileDelete($file)
    FileWrite($file, $data)
EndFunc

Func LoadListView($list, $file)
    $data = FileRead($file)
    $data = StringSplit($data, @CRLF, 1)
    For $i = 1 To $data[0] - 1
        GuiCtrlCreateListViewItem($data[$i],$List)
    Next
EndFunc
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...