Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With VFP DryCleaning POS Pickup Form

Status
Not open for further replies.

foxprox558

Programmer
Oct 19, 2013
53
0
0
US
Ok, So if you will take a look at the picture attached to the thread, you will see the basic layout of the pickup form

the order database is arranged to store the customer number of the customer, when you choose the customer from the top of the form, search through the orders database and find all the orders so you can select the ones you need to pick up.
I need help with putting them in this grid and having it to where you can select multiple orders and have it auto-total in the bottom text box, then save them all as paid when you push pay. This Should Be The Final Problem I'm having. Sorry for the numerous posts, but as said before, I'm kind of new to FoxPro!
 
LOCAL lcCustno
lcCustno = thisform.combo1.Value && You may need to get the custno from the combo.list array instaed.

Code:
Select Orders.*, .F. as IsSelected From Orders where custno = m.lcCustno INTO CURSOR curOrders

That'll get you the orders of a choosen customer. You may also need to add a further condition about the order being an open, yet unpaid order, etc.

You can bind the grid to that cursor, in the simple case Grid.recordsource = "curOrders"
You can do that for seeing how it comes out, just now.

But wait: This will only work once, the moment you repeat the SQL query in the find button click, the grid will go blank. Especially when you add columns and controls in the form designer, this will hurt you as you lose the grid controls, code put in there etc. So it's best to have two separate cursors curOrders for querying and curOrdersGRD for the grid.

In the form Load() do
Code:
Select Orders.*, .F. as IsSelected From Orders where .F. INTO CURSOR curOrdersGRD READWRITE

In the Find button click do the query with the custno and then

Code:
Select * From Orders where custno = m.lcCustno INTO CURSOR curOrders NOFILTER

Select curOrdersGRD 
ZAP IN curOrdersGRD 
Append FROM DBF("curOrders")

You can set the grid recordsource as curOrdersGRD in the form designer, as that cursor will exist from Load event on until the form is close. This is saving you trouble with grid reconstruction. Now you can visually design the grid and add columns and headers as needed, including a column for the "IsSelected" field, in which you put a checkbox for selection of the record. If you don't know how come back and ask. And let the builder help you with assigning fields to columns, right click on the grid and choose "Builder...".

Now you could init text2.value with 0 and recompute the total in the grid.columnN.check1.interactivechange event. (where N is whatever column number you put the checkbox, perhaps column1)

The total is computed by SELECT SUM(price) AS total FROM curOrdersGRD WHERE IsSelected INTO ARRAY anTotal and you can display it with thisform.text2.value = anTotal, make that field readonly, perhaps. Also just make the grids selection column with check1 editable.

Bye, Olaf.
 
There are two possible ways of selecting multiple items in a grid.

The first one involves adding a logical field to the underlying table; let's call it Selected. Then add a column to the grid, containing a checkbox. Set the ControlSource of the checkbox column to the Selected field in the table. Then have the user tick the checkbox to select an item, at which point the Selected field in the table will become .T.

To get the total of the selected fields, you can do it like this:

Code:
SELECT SUM(OrderValue) FROM TheTable WHERE Selected INTO ARRAY TotalValue
THISFORM.txtTotal.Value = TotalValue(1)

or, you can use this alternative syntax:

Code:
SELECT TheTable
SUM OrderValue TO THISFORM.txtTotal.Value FOR Selected

When the user clicks the Pay button, you can do the following, which updates the Paid field in the selected items:

Code:
UPDATE TheTable SET Paid = .T. WHERE Selected

An alternative approach would be to create a second cursor, which just contains the selected items, and a second grid, to show just the selected items. You would add a button to the form. When the user clicks the button, the currently selected row in the main grid (the row that is highlighted) will move to the second grid, and the corresponding record will be inserted into the second cursor.

This is probably easier from the user's point of view, but will involve more programming, so I suggest you try the checkbox approach first, and see how you get on with it.

This Should Be The Final Problem I'm having. Sorry for the numerous posts,

No need to be sorry. We were all beginners once. The forum is here to help you.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
curOrders is a cursor generated by the given Code: Select * From Orders where custno = m.lcCustno INTO CURSOR curOrders NOFILTER

I gave you the full Find Button Click code. To see the cursor you need to prepare the grid to show the second cursor cur OrdersGRD you generate in Load and then empty and refill in the Find Button Click.

Bye, Olaf.

 
having it to where you can select multiple orders
and notice that Olaf's SQL Query code includes:
.F. as IsSelected

Within the Form's grid showing the orders, you will want to have one of the columns represented with a Checkbox instead of the default Textbox so that the user can select multiple orders to pay.

Good Luck,
JRB-Bldr



 
Yes.

myself said:
Now you can visually design the grid and add columns and headers as needed, including a column for the "IsSelected" field, in which you put a checkbox for selection of the record. If you don't know how come back and ask.

Bye, Olaf.
 
Another suggestion to use in conjunction with the Grid Column Checkbox would be to use the DynamicBackColor property for all of the Grid's Columns to change the row (record) background color to something easily noticeable (maybe: YELLOW or GREEN) when IsSelected = TRUE so that the user can easily identify that they have chosen the correct Orders.

And, as Olaf has said: If you don't know how come back and ask.

Good Luck,
JRB-Bldr

 
I'm getting an operand error on this line of code, and I think it's because of the .F., Could somebody tell me what the * in
Select Orders.*, .F. as IsSelected From Orders where .F. INTO CURSOR curOrdersGRD READWRITE
and the .F. ^ ^ ^^^^^ ^ ^^^^ ^^^^^^ ^^^^^^^^^^^^
What's This ----------What's This??----------
 
You're barking up the wrong tree. The query is fine. (I just ran it on the orders table in the sample data that ships with VFP.)

Select * means you want all fields from the source table in the result set.
 
Just as an FYI: Could somebody tell me what the *
The asterix ( * ) is a 'wild card' meaning get EVERYTHING (all fields) from the specified data table

But as to your problem....
Select Orders.*, .F. as IsSelected From Orders where .F. INTO CURSOR curOrdersGRD READWRITE

You can't just tell the SQL Query to get records where FALSE.
For a WHERE clause like that you have to tell the query what field is FALSE.

Good Luck,
JRB-Bldr

 
No JRB-Bldr,

Where <clause>

expects <caluse> to be a logical expression resulting in a logical value, and therefore WHERE .F. is just fine. I use this all the time as a simple way to get an empty cursor with the structure as needed, in this case all orders fields plus the IsSelected field for the checkbox or the DynamicBackColor, which also would be a nice idea.

Bye, Olaf.


 
Ok, Well the problem is that I'm not using an SQL Table, its a regular FoxPro Table. Can Somebody Please Tell Me How To Query The Table To Get The Customer Number along with all the orders?
 
And another thing is whenever I close/release the form, I have also coded the 'Close' Command button to do the "Use" command to release the used database, but if I try to go back to another form that uses the 'account' database, it says "Error File Is In Use", even being that the database has been released.
 
I think you still have some overall problems, but let's concentrate on one problem at a time.
The SQL Query is for a DBF, it works for a DBF, .F. is Foxpro Syntax for false, it's not SQL Server. But which Foxpro Version are you using? READWRITE is only available since VFP7, for example.

Bye, Olaf.
 
As you have VFP8, this query will work, as Dan confirmed.

The only prerequisite is your table is named orders and found in the current dir or along SET("PATH"). If the table name would be a problem, you would get an open file prompt, not an operand error. Tht error must come from somewhere else. How about adding a little error handling?

Code:
ON ERROR DEBUGOUT Error(), Message(), Program(), Line()

Put that in your main program or in the form load right before the query. Have the debugger open, at least the Debut Output window, then start. If errors happen, their number, message and the program and line having the error are output there. That should get you started finding out what really errors.

For more advanced error handling watch this tutorial: Besides that article series is a nice introduction. Also
Bye, Olaf.
 
So, how do I fix my dilemma of not being able to append current (Pending) orders into the grid on screen and make them selectable?
 
Well, error handling should point you to the real problems.

You're not asking for a simple single query or function but a whole form. As you are a VFP beginner this will not work instantly. Perhaps lay this aside first and learn foundations with the learning videos. Then you'll get your own ideas for solving that. What I and Mike layed out is surely not the only way to do it.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top