Alexxander Posted July 2, 2015 Share Posted July 2, 2015 i have files with csv formatbuy is what the user boughtsell is what the user sold this small script must tell me what i have in stock(storage)expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> ;basic GUI Global $GUI = GUICreate("", 500, 650) Global $hListView = GUICtrlCreateListView(" product |quantity|sold|Stock", 25, 25, 450, 600) $buylist = _FileListToArray(@ScriptDir & "\Database\Buy") $selllist = _FileListToArray(@ScriptDir & "\Database\Sell") ;_ArrayDisplay($selllist) For $i = 1 To $buylist[0] $product = StringSplit(FileRead(@ScriptDir & "\Database\Buy\" & $buylist[$i]),";") $quantity = StringSplit(FileRead(@ScriptDir & "\Database\Buy\" & $buylist[$i]),";") $sold = 0 for $x = 1 to $selllist[0] if StringSplit(FileRead(@ScriptDir & "\Database\Sell\" & $selllist[$x]),";")[1] = $product[1] Then $sold = StringSplit(FileRead(@ScriptDir & "\Database\Sell\" & $selllist[$x]),";")[4] $stock = $quantity[4] - $sold ;MsgBox(0,0,$stock ) Else $sold = 0 EndIf Next $stock = $quantity[4] - $sold GUICtrlCreateListViewItem($product[1] & "|" & $quantity[4] & "|" & $sold & "|" & $stock , $hListView) Next ;Context Menu Global $hCMenu = GUICtrlCreateContextMenu($hListView) ;add a context menu to the listview. I don't think you can add a seperate one to each item unless you write your own function. GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch WEnd it is only working for the last itemcoudl any one help please ?i attached the files Database.zip Link to comment Share on other sites More sharing options...
mikell Posted July 2, 2015 Share Posted July 2, 2015 (edited) Just remove thisElse $sold = 0 Edited July 2, 2015 by mikell Alexxander 1 Link to comment Share on other sites More sharing options...
AutoBert Posted July 2, 2015 Share Posted July 2, 2015 This is my try:expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> ;basic GUI Global $GUI = GUICreate("", 500, 650) Global $hListView = GUICtrlCreateListView(" product |quantity|sold|Stock", 25, 25, 450, 600) $buylist = _FileListToArray(@ScriptDir & "\Database\Buy") ConsoleWrite(@error&@CRLF) $selllist = _FileListToArray(@ScriptDir & "\Database\Sell") ConsoleWrite(@error&@CRLF) For $i = 1 To $buylist[0] $product = StringSplit(FileRead(@ScriptDir & "\Database\Buy\" & $buylist[$i]),";") $quantity = StringSplit(FileRead(@ScriptDir & "\Database\Buy\" & $buylist[$i]),";") $sold = 0 $stock = $quantity[4] for $x = 1 to $selllist[0] if StringSplit(FileRead(@ScriptDir & "\Database\Sell\" & $selllist[$x]),";")[1] = $product[1] Then $sold = StringSplit(FileRead(@ScriptDir & "\Database\Sell\" & $selllist[$x]),";")[4] $stock -= $sold ;MsgBox(0,0,$stock ) EndIf Next GUICtrlCreateListViewItem($product[1] & "|" & $quantity[4] & "|" & $sold & "|" & $stock , $hListView) Next ;Context Menu Global $hCMenu = GUICtrlCreateContextMenu($hListView) ;add a context menu to the listview. I don't think you can add a seperate one to each item unless you write your own function. GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch WEndbut it don't works:>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\Bert\AutoIt3.My\Downloads\Stock.au3" /UserParams +>18:41:37 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0 Keyboard:00000407 OS:WIN_81/ CPU:X64 OS:X64 Environment(Language:0407) +> SciTEDir => C:\Program Files\AutoIt3\SciTE UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.12.0) from:C:\Program Files\AutoIt3 input:C:\Users\Bert\AutoIt3.My\Downloads\Stock.au3 +>18:41:37 AU3Check ended.rc:0 >Running:(3.3.12.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Users\Bert\AutoIt3.My\Downloads\Stock.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop 1 1 "C:\Users\Bert\AutoIt3.My\Downloads\Stock.au3" (14) : ==> Subscript used on non-accessible variable.: For $i = 1 To $buylist[0] For $i = 1 To $buylist^ ERROR ->18:41:37 AutoIt3.exe ended.rc:1 +>18:41:37 AutoIt3Wrapper Finished. >Exit code: 1 Time: 1.319The database.zip seems to be corrupted. Link to comment Share on other sites More sharing options...
mikell Posted July 2, 2015 Share Posted July 2, 2015 Worked well for me using the provided Database.zip, try to dowload it and extract the folder again Link to comment Share on other sites More sharing options...
Alexxander Posted July 3, 2015 Author Share Posted July 3, 2015 Just remove thisElse $sold = 0yes it worked !Would you please explain why we did that ?i mean if ye cant find the product in the sell folder we wo should not make it 0 ? Link to comment Share on other sites More sharing options...
mikell Posted July 3, 2015 Share Posted July 3, 2015 You loop through the sell folderIf the product was found in a file then a value was assigned to $soldBUT the For loop continued testing next files... the product was not found and $sold was reset to 0It's the reason why you always got $sold =0, except for the last file Alexxander 1 Link to comment Share on other sites More sharing options...
Alexxander Posted July 4, 2015 Author Share Posted July 4, 2015 (edited) You loop through the sell folderIf the product was found in a file then a value was assigned to $soldBUT the For loop continued testing next files... the product was not found and $sold was reset to 0It's the reason why you always got $sold =0, except for the last file Thank you ! here is my final codeexpandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> #include <Misc.au3> ;basic GUI Global $GUI = GUICreate("قائمة الجرد", 500, 600) Global $hListView = GUICtrlCreateListView("#|المادة |الكمية|مباع|في المستودع", 25, 25, 450, 500) $btn_refresh = GUICtrlCreateButton("تحديث",100,540,300,50) GUICtrlSetImage(-1, "shell32.dll", 21) GUISetState() list() func list() $buylist = _FileListToArray(@ScriptDir & "\Database\Buy") $selllist = _FileListToArray(@ScriptDir & "\Database\Sell") For $i = 1 To $buylist[0] $product = StringSplit(FileRead(@ScriptDir & "\Database\Buy\" & $buylist[$i]),";") $quantity = StringSplit(FileRead(@ScriptDir & "\Database\Buy\" & $buylist[$i]),";") $sold = 0 for $x = 1 to $selllist[0] if StringSplit(FileRead(@ScriptDir & "\Database\Sell\" & $selllist[$x]),";")[1] = $product[1] Then $sold = StringSplit(FileRead(@ScriptDir & "\Database\Sell\" & $selllist[$x]),";")[4] + $sold $stock = $quantity[4] - $sold ;MsgBox(0,0,$stock ) EndIf Next $stock = $quantity[4] - $sold GUICtrlCreateListViewItem($i & "|" & $product[1] & "|" & $quantity[4] & "|" & $sold & "|" & $stock , $hListView) Next EndFunc ;Context Menu Global $hCMenu = GUICtrlCreateContextMenu($hListView) ;add a context menu to the listview. I don't think you can add a seperate one to each item unless you write your own function. GUISetState() $z = 0 While 1 Switch GUIGetMsg() Case -3 Exit case $btn_refresh _GUICtrlListView_DeleteAllItems($hListView) list() EndSwitch WEnd the problem i'am facing is when there is a duplicate or more in the buy list i would like in that case to only only display one item and the quantity will be the duplicates sumany ideas ? Edited July 4, 2015 by Alexxander Link to comment Share on other sites More sharing options...
mikell Posted July 4, 2015 Share Posted July 4, 2015 Using many files to build your database is not a very convenient wayAnyway please try thisFunc list() $buylist = _FileListToArray(@ScriptDir & "\Database\Buy") Local $buy_array[$buylist[0]][2] For $i = 1 To $buylist[0] $tmp = StringSplit(FileRead(@ScriptDir & "\Database\Buy\" & $buylist[$i]),";") $buy_array[$i-1][0] = $tmp[1] $buy_array[$i-1][1] = $tmp[4] Next _ArraySort($buy_array) ;_ArrayDisplay($buy_array, "sorted") For $i = UBound($buy_array)-1 to 1 step -1 If $buy_array[$i][0] = $buy_array[$i-1][0] Then $buy_array[$i-1][1] += $buy_array[$i][1] _ArrayDelete($buy_array, $i) EndIf Next ; _ArrayDisplay($buy_array, "duplicates managed") $selllist = _FileListToArray(@ScriptDir & "\Database\Sell") For $i = 0 To UBound($buy_array)-1 $sold = 0 for $x = 1 to $selllist[0] $sold_array = StringSplit(FileRead(@ScriptDir & "\Database\Sell\" & $selllist[$x]),";") $soldprod = $sold_array[1] if $soldprod = $buy_array[$i][0] Then $sold += $sold_array[4] Next $stock = $buy_array[$i][1] - $sold GUICtrlCreateListViewItem($i & "|" & $buy_array[$i][0] & "|" & $buy_array[$i][1] & "|" & $sold & "|" & $stock , $hListView) Next EndFunc Alexxander 1 Link to comment Share on other sites More sharing options...
Alexxander Posted July 5, 2015 Author Share Posted July 5, 2015 Thank you mikell, you are awesome ! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now