Jump to content

For an Inventory system(ON HOLD)


Recommended Posts

I plan on coding an inventory system for a friend to keep track of all of their action figures. It will not be interfacing with anything crazy and will have a very small interface.

My main question is, what is the best way to keep track of this data? Would it be using a .txt or would something else be better? I would think an array would take up too much memory, especially if the log will have several hundred items in it.

Here is what I have come up with so far as for the gui. This is only to show what I am looking to do, it can be very spartan.

Posted Image

This is only the add an entry page. I would also have an index page as well as a query page.

as far as code goes, if I did text it would just be something really simple like

FileWrite ("inventory.txt",@CRLF&$itemname&"//"&$itemdescription$&"//"&$quantity)

Where I would be using the // as dividers for when it loads an item into the query page so that information can be updated.

Any input will be greatly appreciated and I will make sure to post the finished code, this will hopefully be useful to many people.

thanks

Edited by Altometer
Link to comment
Share on other sites

A text file is as good as any to store this kind of data; if you keep the various info properly separated (// should be good as separator) then it will be easy to retrive and process it further.

There might be several approaches with pro's and con's

*.txt:

- small file

- easy to maintain and to work with

- read the whole file in the memory (_FileReadToArray preferred), modify the array in memory and write the array to file (overwrite) at the end = the fastest way to work with text files

- con: it involves full file write when changing anything inside

*.ini

- small file (basically a text file itself)

- data inside can be changed very easy without rewriting the file content

- con: there is a size limit = not very good when using it for a very large number of items; but this size limit can be avoided using an udf from "Example Scripts"

*.xls

- very versatile, complex data manipulation

- con: need Excel installed

You can see that any approach is good. As about your concern that the array to hold this data for hundreds of items would require a big amount of memory - NO WAY. You would need thousands or hundred of thousands items to start experiencing some memory usage.

Keep this in mind: the fastest data manipulation is done for the data present "in the memory" so use arrays as often as you can.

At this point I can't give you much more "specific" help. Decide which way you're going, start putting your code together and you'll get more help.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Okay, this is what I have so far.

I could use help figuring out the array portion of it. I was able to create a dummy log file with the variables seperated, however I can't figure out how to get autoit to split the lines in the array.

I use

_filereadtoarray("bin\iinventory.txt,$ainventory)

and

iinventory looks sorta like this

Captain planet//1950's captain planet action fig//2000
megatron//transformers trans metal mint megatron//2

It only seperates each line into a different array address($ainventory[0] = the first line.)

What I need to figure out is how to seperate each item seperated by // because these things will be subject to change and I don't want the user to have to remove an entry to update the quantity.

I have heavily commented this for any pointers. I think I am headed in the right direction at least.

#include <file.au3>
;#NoTrayIcon //will be added soon, for testing purposes left in.
#cs
Proposed functions,
1. Read log.txt file to an array*completed I think
2. Remove seperating values and place each item of the array into a droplist
3. Give the user the ability to create new entries with the following 3 variables
    Name
    Description
    Quantity
        Set the option for quantity 0 to remove the entry or not.
4.Search function, where user can look for the name or description of an object using a searchbox.
5.Backup function.*complete
#CE

;variables
dim $ainventory
dim $logbackdir
dim $setting="bin\isettings.ini"
dim $logloc=FileReadLine($setting,1)
dim $msgnolog
dim $msglooklog

;check if the settings file exists and creates one if nonexistant
If Not FileExists($setting) Then
    DirCreate("bin")
    _FileCreate($setting)
    FileWrite($setting,"bin\iinventory.txt"&@CRLF&"1")
EndIf

;checks if the inventory log exists and lets you make or find one.
If Not FileExists($logloc) Then
    $msgnolog=MsgBox(4,"","There was no inventory file found, Would you like to create a new one?")
    If $msgnolog=6 Then
        _FileCreate($logloc)
    Else
        $msglooklog=MsgBox(36,"","Would you like to look for an existing inventory file?")
        If $msglooklog=6 Then changelogdir()
    EndIf
EndIf


;reads to the array
If Not _FileReadToArray($logloc,$ainventory) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf


;simple and clean backup script, easily imported to a button in the yet to be coded Gui
Func backuplog()
$logbackdir=FileSaveDialog("Chose where you want to save the file",@MyDocumentsDir,"Text files (*.txt)",16)
if FileExists($logloc) Then
    FileCopy($logloc,$logbackdir)
Else
    MsgBox(48,"ERROR","Ooops, looks like you moved or havn't created a log yet!")
EndIf
EndFunc

;self explanatory
Func changelogdir()
    $logloc=FileOpenDialog("Please chose the log file","bin\","Text files (*.txt)",1)
    _FileWritetoLine($setting,1,$logloc,1)
EndFunc

I also realize that this program could be used for more than action figures, I hope it will prove useful to someone else when it is complete.

Currently working on the gui, will be checking this topic.

Link to comment
Share on other sites

Basic gui I have

Posted Image

This presents several problems that I have no clue how to solve,

How would I cause the formatting to stay the same for each item in the listbox? (if one item has a longer name it causes the rest of the data to shift more to the left)

How can I make the scrollbox able to scroll to the right if the user enters a particularly long description?

and a much more embarrassing question, How on earth would I sort it?

You guys are awesome! I wouldn't have even gotten this far if it weren't for these forums!

Link to comment
Share on other sites

I can only second advices toward using a real database; SQLite would be a perfect fit and enjoys good AutoIt support.

From experience, those "tiny programs" slowly grow by adding new functionalities not anticipated. Your friend will at some point add origin, buy price, year production, street price, special notes, you name it. Then (s)he will be wanting buy, sell, exchange on eBay and elsewhere and that will require adding more fields.

Given that what can do 1000 can do 100 as well, best select the right tool at once rather than build a sand castle.

That will also have the benefit to teach you how a simple DB engine can be put to work and that will be a nice experience.

IMVHO

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

As other people said here, I would recommend using SQLite but the choice is yours finally.

Split the lines from your text file: StringSplit

Do not use an Edit control - use instead a ListView control

To add a horizontal scroll bar (if needed) - use $WS_HSCROLL

To sort - you need to sort the array and refresh the data in your control.

Already, your desire to sort the info has added a new dimension to your project and it slowly becomes more complex.

Here is some code; modify the GUI to suit your needs and make it work with your text file - once you figure that out, we'll see how to do the sorting.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 498, 329, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$ListView1 = GUICtrlCreateListView("Name|Description|Quantity", 8, 40, 369, 281, BitOR($GUI_SS_DEFAULT_LISTVIEW,$WS_HSCROLL,$WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES))
GUICtrlSetOnEvent(-1, "ListView1Click")
_GUICtrlListView_SetColumnWidth($ListView1, 0, 85)
_GUICtrlListView_SetColumnWidth($ListView1, 1, 200)
_GUICtrlListView_SetColumnWidth($ListView1, 2, 85)
$ItName = GUICtrlCreateInput("Item Name", 8, 8, 113, 21)
GUICtrlSetOnEvent(-1, "ItNameChange")
$ItDescr = GUICtrlCreateInput("Item Description", 128, 8, 177, 21)
GUICtrlSetOnEvent(-1, "ItDescrChange")
$ItQty = GUICtrlCreateInput("Qty", 312, 8, 65, 21)
GUICtrlSetOnEvent(-1, "ItQtyChange")
$AddNew = GUICtrlCreateButton("Add New", 384, 8, 107, 25)
GUICtrlSetOnEvent(-1, "AddNewClick")
$SortName = GUICtrlCreateButton("Sort by NAME", 385, 38, 107, 25)
GUICtrlSetOnEvent(-1, "SortNameClick")
$SortQty = GUICtrlCreateButton("Sort by QTY", 385, 66, 107, 25)
GUICtrlSetOnEvent(-1, "SortQtyClick")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;$LineArray is the array you get from _FileReadToArray
Dim $LineArray[3] = [2,"Captain planet//1950's captain planet action fig//2000","megatron//transformers trans metal mint megatron//2"]
;set listView text
For $i=1 To UBound($LineArray)-1
    $split = StringSplit($LineArray[$i], "//", 1)
    _GUICtrlListView_AddItem($ListView1, $split[1])
    _GUICtrlListView_AddSubItem($ListView1, $i-1, $split[2], 1)
    _GUICtrlListView_AddSubItem($ListView1, $i-1, $split[3], 2)
Next



While 1
    Sleep(100)
WEnd

Func AddNewClick()
    Local $items = _GUICtrlListView_GetItemCount($ListView1)
    _GUICtrlListView_AddItem($ListView1, GUICtrlRead($ItName))
    _GUICtrlListView_AddSubItem($ListView1, $items, GUICtrlRead($ItDescr), 1)
    _GUICtrlListView_AddSubItem($ListView1, $items, GUICtrlRead($ItQty), 2)
EndFunc
Func Form1Close()
    Exit
EndFunc
Func ItDescrChange()

EndFunc
Func ItNameChange()

EndFunc
Func ItQtyChange()

EndFunc
Func ListView1Click()

EndFunc
Func SortNameClick()

EndFunc
Func SortQtyClick()

EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Personally, when having to deal with GUIs and databases, I'd much rather resort to C# (from the small pool of languages I'm familiar with) over AutoIt, but that's just me...

DataGridViews already support column sorting. It's easier to manipulate and populate GUI items too.

Edited by omikron48
Link to comment
Share on other sites

Sorry for the seemingly unresponsiveness, getting caught up in a much more urgent coding project involving auto-changing user's mydocuments directories and moving their email files. Autoit has to be one of the greatest network admin assisting tools ever!

Link to comment
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
 Share

  • Recently Browsing   0 members

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