Sign in to follow this  
Followers 0
misterDee

Listview items

9 posts in this topic

#1 ·  Posted (edited)

Hi,

Ive a problem with reading all the items in a listview, i want to add all the items into a ms-database but only the last added item would be added in the database, is there a command for? or should i use a for-loop?...

can someone help me with this..

Thnx!

#include <date.au3>
#include <string.au3>
#include <INet.au3>
#include <File.au3>
#include <Process.au3>
#include <GuiComboBox.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListviewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>

;Globalizeren
global $db_artikelcode
global $db_artikelomschrijving
global $db_bestelnummer
global $db_inkoop
global $db_inkoopprijs
global $db_aantal

;DB connect
$FULL_MDB_FILE_NAME = @ScriptDir & "\database\db.mdb"
$dbpass=""
$CONN = ObjCreate("ADODB.Connection")
$CONN.Open('Driver={Microsoft Access Driver (*.mdb)};Dbq=' & $FULL_MDB_FILE_NAME & ";PWD=" & $dbpass& ';')
$RecordSet = ObjCreate("ADODB.Recordset")

GUICreate("Test ", 790, 700, 134, 10, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_APPWINDOW, $WS_MINIMIZEBOX, $WS_EX_RIGHT, $WS_EX_WINDOWEDGE))
GUICtrlCreatePic(@ScriptDir & "\images\main_bg_top.jpg", 0, 0, 790, 78)
GUICtrlCreatePic(@ScriptDir & "\images\main_bg_bottom.jpg", 0, 666, 790, 35)
GUISetBkColor(0xFFFFFF)
GUICtrlCreateTab(0, 76, 800, 700) 

GUICtrlCreateTabItem("Dashboard")
$zoekfld=GUICtrlCreateInput("Voer barcodenummer in", 10, 110, 140, 20)
$zoekbtn=GUICtrlCreateButton("Zoek", 160, 110, 40, 20)
$bestelbtn=Guictrlcreatebutton("Toevoegen aan bestellijst", 370, 300, 130, 20)
$listviewbtn=Guictrlcreatebutton("Verwijderen", 10, 640, 80, 20)
$bestelaanvraagbtn=Guictrlcreatebutton("Bestellingen vastleggen", 110, 640, 120, 20)
GUICtrlCreateGroup("", 10, 140, 510, 190)
GUICtrlCreateLabel("Artikelcode:", 20, 155)
$set_artikelcode=GUICtrlCreateEdit($db_artikelcode, 20, 175, 300, 20, $ES_READONLY) 
GUICtrlSetColor(-1, 0xff0000)  
GUICtrlCreateLabel("Artikelomschrijving:", 20, 205)
$set_artikelomschrijving=GUICtrlCreateEdit($db_artikelomschrijving, 20, 225, 300, 20, $ES_READONLY) 
GUICtrlSetColor(-1, 0xff0000)  
GUICtrlCreateLabel("Bestelnummer:", 20, 255)
$set_bestelnummer=GUICtrlCreateEdit($db_bestelnummer, 20, 275, 150, 20, $ES_READONLY) 
GUICtrlSetColor(-1, 0xff0000) 
$set_inkoopprijs=GUICtrlCreateEdit($db_inkoopprijs, 204, 275, 54, 20, $ES_READONLY) 
GUICtrlSetColor(-1, 0xff0000)  
GUICtrlCreateLabel("Inkoopprijs:", 205, 255)
$set_aantal=GUICtrlCreateInput($db_aantal, 286, 275, 34, 20)
GUICtrlSetColor(-1, 0xff0000)  
GUICtrlCreateLabel("Aantal:", 288, 255)
$listview=GUICtrlCreateListView("Artikelcode | Artikelomschrijving | Bestelnummer | Inkoopprijs | Aantal | Datum", 0, 350, 790, 284)

Func _Get($zoekquery)
    $artikelen=$conn.Execute("SELECT artikelcode,artikelomschrijving,bestelnummer,inkoopprijs FROM orderdirect WHERE barcode like '"& $zoekquery &"';")
        With $artikelen
        While NOT .EOF
            $db_artikelcode=.fields("artikelcode").value
            $db_artikelomschrijving=.fields("artikelomschrijving").value
            $db_bestelnummer=.fields("bestelnummer").value
            $db_inkoopprijs=.fields("inkoopprijs").value
    .Movenext
WEnd
EndWith
EndFunc

GUICtrlCreateTabItem("Bestellingenlijst")
$listview2=GUICtrlCreateListView("Artikelcode | Artikelomschrijving | Bestelnummer | Inkoopprijs | Aantal | Datum", 0, 110, 790, 284)
$bestellingen=$conn.Execute("SELECT * FROM bestellingen") 
    With $bestellingen
    While NOT .EOF
        $db_artikelcode=.fields("artikelcode").value
        Guictrlcreatelistviewitem($db_artikelcode, $listview2)
    .Movenext
WEnd
EndWith 

Func _searchquery()
    $waarde=GUICtrlRead($zoekfld)
    if $waarde <> "" then
        _Get($waarde)
        GUICtrlSetData($set_artikelcode, $db_artikelcode)
        GUICtrlSetData($set_artikelomschrijving, $db_artikelomschrijving)
        GUICtrlSetData($set_bestelnummer, $db_bestelnummer)
        GUICtrlSetData($set_inkoopprijs, $db_inkoopprijs)
        Else    
        GUIGetMsg()
    EndIf
EndFunc
        
Func _addlistview()
    $read_aantal=Guictrlread($set_aantal)
    $iWeekday = _DateToDayOfWeek (@YEAR, @MON, @MDAY)
    GUICtrlCreateListViewItem($db_artikelcode &"|"& $db_artikelomschrijving &"|"& $db_bestelnummer &"|"& $db_inkoopprijs &"|"& $read_aantal &"|"& _DateDayOfWeek($iWeekDay), $listview)
EndFunc     
        
Func _bestelaanvraag()
    $CONN.Execute("INSERT into bestellingen (Artikelcode) values('"&$db_artikelcode&"')")
EndFunc

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $zoekbtn
            _searchquery()
        Case $bestelbtn 
            _addlistview()
        Case $listviewbtn
            _GUICtrlListView_DeleteItemsSelected($listview)
        Case $bestelaanvraagbtn
            _bestelaanvraag()
    EndSwitch
WEnd
Edited by misterDee

Share this post


Link to post
Share on other sites



Post your code here.

Share this post


Link to post
Share on other sites

Post your code here.

Forgotten, here it is

Share this post


Link to post
Share on other sites

Your code doesn't match your description. I see you reading the database with a SELECT query and then creating listview items. I don't see you reading the contents of the listview for any purpose, let alone copying it to a database.

What is it you wanted that code to do that it doesn't do now?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Your code doesn't match your description. I see you reading the database with a SELECT query and then creating listview items. I don't see you reading the contents of the listview for any purpose, let alone copying it to a database.

What is it you wanted that code to do that it doesn't do now?

:)

thnx for your replay,

If im adding something in the first listview, and want to write it in the database (ms-access).. its writing only the last added item, so in 'bestellingenlijst' (the second tab), you only see 1 item

you know what i mean?

thnx,

D

Share this post


Link to post
Share on other sites

Well, to minimize confusion, put all your function declarations at the bottom. This isn't required, but it makes the script easier to read:

#include <date.au3>
#include <string.au3>
#include <INet.au3>
#include <File.au3>
#include <Process.au3>
#include <GuiComboBox.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListviewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>

;Globalizeren
Global $db_artikelcode
Global $db_artikelomschrijving
Global $db_bestelnummer
Global $db_inkoop
Global $db_inkoopprijs
Global $db_aantal

;DB connect
$FULL_MDB_FILE_NAME = @ScriptDir & "\database\db.mdb"
$dbpass = ""
$CONN = ObjCreate("ADODB.Connection")
$CONN.Open('Driver={Microsoft Access Driver (*.mdb)};Dbq=' & $FULL_MDB_FILE_NAME & ";PWD=" & $dbpass & ';')
$RecordSet = ObjCreate("ADODB.Recordset")

GUICreate("Test ", 790, 700, 134, 10, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_APPWINDOW, $WS_MINIMIZEBOX, $WS_EX_RIGHT, $WS_EX_WINDOWEDGE))
GUICtrlCreatePic(@ScriptDir & "\images\main_bg_top.jpg", 0, 0, 790, 78)
GUICtrlCreatePic(@ScriptDir & "\images\main_bg_bottom.jpg", 0, 666, 790, 35)
GUISetBkColor(0xFFFFFF)
GUICtrlCreateTab(0, 76, 800, 700)

GUICtrlCreateTabItem("Dashboard")
$zoekfld = GUICtrlCreateInput("Voer barcodenummer in", 10, 110, 140, 20)
$zoekbtn = GUICtrlCreateButton("Zoek", 160, 110, 40, 20)
$bestelbtn = GUICtrlCreateButton("Toevoegen aan bestellijst", 370, 300, 130, 20)
$listviewbtn = GUICtrlCreateButton("Verwijderen", 10, 640, 80, 20)
$bestelaanvraagbtn = GUICtrlCreateButton("Bestellingen vastleggen", 110, 640, 120, 20)
GUICtrlCreateGroup("", 10, 140, 510, 190)
GUICtrlCreateLabel("Artikelcode:", 20, 155)
$set_artikelcode = GUICtrlCreateEdit($db_artikelcode, 20, 175, 300, 20, $ES_READONLY)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("Artikelomschrijving:", 20, 205)
$set_artikelomschrijving = GUICtrlCreateEdit($db_artikelomschrijving, 20, 225, 300, 20, $ES_READONLY)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("Bestelnummer:", 20, 255)
$set_bestelnummer = GUICtrlCreateEdit($db_bestelnummer, 20, 275, 150, 20, $ES_READONLY)
GUICtrlSetColor(-1, 0xff0000)
$set_inkoopprijs = GUICtrlCreateEdit($db_inkoopprijs, 204, 275, 54, 20, $ES_READONLY)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("Inkoopprijs:", 205, 255)
$set_aantal = GUICtrlCreateInput($db_aantal, 286, 275, 34, 20)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("Aantal:", 288, 255)
$listview = GUICtrlCreateListView("Artikelcode | Artikelomschrijving | Bestelnummer | Inkoopprijs | Aantal | Datum", 0, 350, 790, 284)
GUICtrlCreateTabItem("Bestellingenlijst")
$listview2 = GUICtrlCreateListView("Artikelcode | Artikelomschrijving | Bestelnummer | Inkoopprijs | Aantal | Datum", 0, 110, 790, 284)
$bestellingen = $CONN.Execute("SELECT * FROM bestellingen")
With $bestellingen
    While Not .EOF
        $db_artikelcode = .fields("artikelcode" ).value
        GUICtrlCreateListViewItem($db_artikelcode, $listview2)
        .Movenext
    WEnd
EndWith

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $zoekbtn
            _searchquery()
        Case $bestelbtn
            _addlistview()
        Case $listviewbtn
            _GUICtrlListView_DeleteItemsSelected($listview)
        Case $bestelaanvraagbtn
            _bestelaanvraag()
    EndSwitch
WEnd


Func _Get($zoekquery)
    $artikelen = $CONN.Execute("SELECT artikelcode,artikelomschrijving,bestelnummer,inkoopprijs FROM orderdirect WHERE barcode like '" & $zoekquery & "';")
    With $artikelen
        While Not .EOF
            $db_artikelcode = .fields("artikelcode" ).value
            $db_artikelomschrijving = .fields("artikelomschrijving" ).value
            $db_bestelnummer = .fields("bestelnummer" ).value
            $db_inkoopprijs = .fields("inkoopprijs" ).value
            .Movenext
        WEnd
    EndWith
EndFunc   ;==>_Get

Func _searchquery()
    $waarde = GUICtrlRead($zoekfld)
    If $waarde <> "" Then
        _Get($waarde)
        GUICtrlSetData($set_artikelcode, $db_artikelcode)
        GUICtrlSetData($set_artikelomschrijving, $db_artikelomschrijving)
        GUICtrlSetData($set_bestelnummer, $db_bestelnummer)
        GUICtrlSetData($set_inkoopprijs, $db_inkoopprijs)
    Else
        GUIGetMsg()
    EndIf
EndFunc   ;==>_searchquery

Func _addlistview()
    $read_aantal = GUICtrlRead($set_aantal)
    $iWeekday = _DateToDayOfWeek(@YEAR, @MON, @MDAY)
    GUICtrlCreateListViewItem($db_artikelcode & "|" & $db_artikelomschrijving & "|" & $db_bestelnummer & "|" & $db_inkoopprijs & "|" & $read_aantal & "|" & _DateDayOfWeek($iWeekday), $listview)
EndFunc   ;==>_addlistview

Func _bestelaanvraag()
    $CONN.Execute("INSERT into bestellingen (Artikelcode) values('" & $db_artikelcode & "')")
EndFunc   ;==>_bestelaanvraag

When you click a button and run _Get(), a loop runs through the result set of a SELECT query, leaving the fields from the last result in the variables $db_artikelcode, $db_artikelomschrijving, $db_bestelnummer, and $db_inkoopprijs. All the previous rows in the result set were overwritten in the loop, so only the last one remains at the end of the loop.

When you click a different button, _addlistview() adds one item to the listview.

When you click yet another button _bestelaanvraag() does an INSERT of on row to a database.

What did you want it to do besides that?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Well, to minimize confusion, put all your function declarations at the bottom. This isn't required, but it makes the script easier to read:

#include <date.au3>
#include <string.au3>
#include <INet.au3>
#include <File.au3>
#include <Process.au3>
#include <GuiComboBox.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListviewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>

;Globalizeren
Global $db_artikelcode
Global $db_artikelomschrijving
Global $db_bestelnummer
Global $db_inkoop
Global $db_inkoopprijs
Global $db_aantal

;DB connect
$FULL_MDB_FILE_NAME = @ScriptDir & "\database\db.mdb"
$dbpass = ""
$CONN = ObjCreate("ADODB.Connection")
$CONN.Open('Driver={Microsoft Access Driver (*.mdb)};Dbq=' & $FULL_MDB_FILE_NAME & ";PWD=" & $dbpass & ';')
$RecordSet = ObjCreate("ADODB.Recordset")

GUICreate("Test ", 790, 700, 134, 10, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_APPWINDOW, $WS_MINIMIZEBOX, $WS_EX_RIGHT, $WS_EX_WINDOWEDGE))
GUICtrlCreatePic(@ScriptDir & "\images\main_bg_top.jpg", 0, 0, 790, 78)
GUICtrlCreatePic(@ScriptDir & "\images\main_bg_bottom.jpg", 0, 666, 790, 35)
GUISetBkColor(0xFFFFFF)
GUICtrlCreateTab(0, 76, 800, 700)

GUICtrlCreateTabItem("Dashboard")
$zoekfld = GUICtrlCreateInput("Voer barcodenummer in", 10, 110, 140, 20)
$zoekbtn = GUICtrlCreateButton("Zoek", 160, 110, 40, 20)
$bestelbtn = GUICtrlCreateButton("Toevoegen aan bestellijst", 370, 300, 130, 20)
$listviewbtn = GUICtrlCreateButton("Verwijderen", 10, 640, 80, 20)
$bestelaanvraagbtn = GUICtrlCreateButton("Bestellingen vastleggen", 110, 640, 120, 20)
GUICtrlCreateGroup("", 10, 140, 510, 190)
GUICtrlCreateLabel("Artikelcode:", 20, 155)
$set_artikelcode = GUICtrlCreateEdit($db_artikelcode, 20, 175, 300, 20, $ES_READONLY)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("Artikelomschrijving:", 20, 205)
$set_artikelomschrijving = GUICtrlCreateEdit($db_artikelomschrijving, 20, 225, 300, 20, $ES_READONLY)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("Bestelnummer:", 20, 255)
$set_bestelnummer = GUICtrlCreateEdit($db_bestelnummer, 20, 275, 150, 20, $ES_READONLY)
GUICtrlSetColor(-1, 0xff0000)
$set_inkoopprijs = GUICtrlCreateEdit($db_inkoopprijs, 204, 275, 54, 20, $ES_READONLY)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("Inkoopprijs:", 205, 255)
$set_aantal = GUICtrlCreateInput($db_aantal, 286, 275, 34, 20)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("Aantal:", 288, 255)
$listview = GUICtrlCreateListView("Artikelcode | Artikelomschrijving | Bestelnummer | Inkoopprijs | Aantal | Datum", 0, 350, 790, 284)
GUICtrlCreateTabItem("Bestellingenlijst")
$listview2 = GUICtrlCreateListView("Artikelcode | Artikelomschrijving | Bestelnummer | Inkoopprijs | Aantal | Datum", 0, 110, 790, 284)
$bestellingen = $CONN.Execute("SELECT * FROM bestellingen")
With $bestellingen
    While Not .EOF
        $db_artikelcode = .fields("artikelcode" ).value
        GUICtrlCreateListViewItem($db_artikelcode, $listview2)
        .Movenext
    WEnd
EndWith

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $zoekbtn
            _searchquery()
        Case $bestelbtn
            _addlistview()
        Case $listviewbtn
            _GUICtrlListView_DeleteItemsSelected($listview)
        Case $bestelaanvraagbtn
            _bestelaanvraag()
    EndSwitch
WEnd


Func _Get($zoekquery)
    $artikelen = $CONN.Execute("SELECT artikelcode,artikelomschrijving,bestelnummer,inkoopprijs FROM orderdirect WHERE barcode like '" & $zoekquery & "';")
    With $artikelen
        While Not .EOF
            $db_artikelcode = .fields("artikelcode" ).value
            $db_artikelomschrijving = .fields("artikelomschrijving" ).value
            $db_bestelnummer = .fields("bestelnummer" ).value
            $db_inkoopprijs = .fields("inkoopprijs" ).value
            .Movenext
        WEnd
    EndWith
EndFunc   ;==>_Get

Func _searchquery()
    $waarde = GUICtrlRead($zoekfld)
    If $waarde <> "" Then
        _Get($waarde)
        GUICtrlSetData($set_artikelcode, $db_artikelcode)
        GUICtrlSetData($set_artikelomschrijving, $db_artikelomschrijving)
        GUICtrlSetData($set_bestelnummer, $db_bestelnummer)
        GUICtrlSetData($set_inkoopprijs, $db_inkoopprijs)
    Else
        GUIGetMsg()
    EndIf
EndFunc   ;==>_searchquery

Func _addlistview()
    $read_aantal = GUICtrlRead($set_aantal)
    $iWeekday = _DateToDayOfWeek(@YEAR, @MON, @MDAY)
    GUICtrlCreateListViewItem($db_artikelcode & "|" & $db_artikelomschrijving & "|" & $db_bestelnummer & "|" & $db_inkoopprijs & "|" & $read_aantal & "|" & _DateDayOfWeek($iWeekday), $listview)
EndFunc   ;==>_addlistview

Func _bestelaanvraag()
    $CONN.Execute("INSERT into bestellingen (Artikelcode) values('" & $db_artikelcode & "')")
EndFunc   ;==>_bestelaanvraag

When you click a button and run _Get(), a loop runs through the result set of a SELECT query, leaving the fields from the last result in the variables $db_artikelcode, $db_artikelomschrijving, $db_bestelnummer, and $db_inkoopprijs. All the previous rows in the result set were overwritten in the loop, so only the last one remains at the end of the loop.

When you click a different button, _addlistview() adds one item to the listview.

When you click yet another button _bestelaanvraag() does an INSERT of on row to a database.

What did you want it to do besides that?

:)

I know it looks strange but its a order-program for my work, someone choose a product... that he want to buy, thats comes in 'bestellingenlijst'-tab

But the problem is only 1 item in the listview comes with the INSERT-command in the $listview2 (database)

Share this post


Link to post
Share on other sites

Your _bestelaanvraag() function does an INSERT of the value in $db_artikelcode. The value in $db_artikelcode is set by the _Get() function in a loop that always leaves the last value there, as I described before.

So, when you hit the button that runs the _bestelaanvraag() function, what do you want it to INSERT other than $db_artikelcode? Do you want it to read all the values from a listview and write them to the database? Then use ControlListView(), or _GUICtrlListView_GetItemText() in a loop to get the item texts and perform an INSERT with each one.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Your _bestelaanvraag() function does an INSERT of the value in $db_artikelcode. The value in $db_artikelcode is set by the _Get() function in a loop that always leaves the last value there, as I described before.

So, when you hit the button that runs the _bestelaanvraag() function, what do you want it to INSERT other than $db_artikelcode? Do you want it to read all the values from a listview and write them to the database? Then use ControlListView(), or _GUICtrlListView_GetItemText() in a loop to get the item texts and perform an INSERT with each one.

:)

Yes i want a loop thats INSERT each record in listview into the database, can you mayb give me a example? i cant get it fixed ;)

thnx for your support btw, (Y)

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0