Welcome!

PowerBuilder Authors: Dan Joe Barry, Ian Thain, Yakov Werde, Paul Slater, Bruce Armstrong

Related Topics: PowerBuilder

PowerBuilder: Article

A Real-Time Physical Inventory Solution Using PocketBuilder, ASA, and a Wi-Fi Connection

A case study: A physical inventory count is necessary to reconcile the quantity on hand stored in a database

Step 5: Connect to your database
In the open event of the application object, connect to your database and open your main window:

SQLCA.DBMS='odb'
SQLCA.DBPARM="ConnectString='DSN=blwmed;UID=dba;PWD=sql'"
CONNECT USING SQLCA;
If SQLCA.SQLCODE <> 0 then
    Messagebox("Connect Error", SQLCA.SQLErrText)
    Halt Close
End If

Open(w_main)

Step 6: Write code to initialize the bar code scanner
PocketBuilder has native hardware support for the PPT8800 called SymbolBarCodeScanner. Drop one in on your main window and call it bar_code.

Add your initialization code to a ue_postopen event:

bar_code.Open()
bar_code.ScanNoWait()

Step 7: Create a GUI
Note: The information that is retrieved when you scan a bar code is typically the SKU. The title, author, and quantity are retrieved from the database using the SKU as a key. Though not technically necessary (we really only need SKU and quantity to perform the update), it's a nice touch for the user. It is populated in the cb_ok clicked event as part of processing the SKU (See Figure 4).

Step 8: Code for the ScanTriggered event


int iRet
string stmp
iRet = This.RetrieveData()
If iRet = 1 Then
stmp = This.ScannedData
sle_sku.Text = stmp
cb_ok.TriggerEvent('clicked')
End If
iRet = This.ScanNoWait()
Notice, we must specifically state what field we want to put the scanned data into. This is not the case with the Y cable scanners you might have seen at POS stations. These typically emulate the keyboard so it is possible to scan into any text field without further coding. This is not the case with the Symbol.

Step 9: Process the scanned data in the clicked event of CB_OK


String ls_text
Integer li_scanned
Datastore lds_Item
Long ll_rowcount

ls_Text = Upper(Trim(sle_sku.text))
li_scanned = Integer(sle_scanned.Text)

lds_Item = CREATE datastore
lds_Item.dataobject = 'd_inventory'
lds_Item.SetTransObject(SQLCA)

ll_RowCount = lds_Item.Retrieve(ls_Text)
If ll_RowCount <= 0 Then
MessageBox(is_ModuleName, 'Item Not Found')
sle_sku.text = ''
Return 1
End If
st_title.text = lds_Item.GetItemString(1, 'in_title')
st_author.text = lds_Item.GetItemString(1, 'in_author')
st_qty.text = String(lds_Item.GetItemNumber
(1, 'in_qty_onhand')+ li_scanned)

UPDATE "group1"."inventory_tb"
SET "in_qty_onhand" = "in_qty_onhand" + :li_scanned
WHERE "group1"."inventory_tb"."in_isbn" = :ls_text;
If SQLCA.SQLCode <> 0 Then
MessageBox(is_ModuleName, SQLCA.SQLErrText)
Return -1
Else
COMMIT;
End If

DESTROY lds_item

Return 1
Step 10: Cleanup
In the close event of the main window, release the bar code scanner object:

bar_code.Close()

In the close event of the application object, disconnect from your database:

DISCONNECT USING SQLCA;

Simple. We're done.

Wondering how to learn more? Check out the following links. One of particular interest to the SymbolBarcodeObject is the mobility kit. Here you can find just about anything you want to do with bar codes. These would be implemented as external function calls in PocketBuilder. If you are looking for examples, see Reed Shilt's original implementation of the SymbolBarcodeObject on CodeExchange. Note: Most of these require a handle to the bar code object. This can be obtained by using the DeviceHandle() method.

Resources

More Stories By Deanne M. Chance

Ms. Chance graduated in 1996 with a degree in computer science from the University of Illinois. She has been a frequent contributor to the PowerBuilder Developer's Journal and gave a key presentation at Sybase TechWave 2005 entitled "A Real-Time Physical Inventory Solution Using PocketBuilder ASA and a WiFi Connection." She has held several engineering positions, starting a career at Motorola where she focused on mobile I.P. by doing real-time embedded programming for the base radio controller group as part of the iDEN/Nextel project.

Comments (4) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
SYS-CON Australia News Desk 12/26/05 02:44:00 PM EST

Why do a physical inventory? A physical inventory count is necessary to reconcile the quantity on hand stored in a database versus what is really on the shelf. In a retail environment, this process is typically done once a year. In a perfect world, these values would always be in sync.

Chance 11/28/05 11:46:24 AM EST

Pardon me I meant to say PocketBuilder, not Powerbuilder!

Chance 11/28/05 11:44:47 AM EST

One other note, I make a reference to using the DeviceHandle() method to get an instance handle to the barcode object. Although this is valid for version 1.5x in later versions of Powerbuilder it has been changed to the read only property DeviceHandle

Chance 11/28/05 09:00:02 AM EST

Hi this is Chance. I noticed the author of this article is Ch Chance. This is somewhat amusing as I use to suffer from a serious stuttering problem. However, no more. So, I was wondering could you change that to Written by: Chance
Thanks!!!!!