Page 1 of 1

Multiple Frame Update Issue

Posted: Wed Jul 10, 2019 8:06 pm
by Joshua
I have a multiple frame application I'm working on. When a button is pressed there is interaction with another frame. However in this frame the data can change after it is checked and before the transaction is resolved. How can I make sure that this frame doesn't change it's data until the first transaction is completed? :?:


Thank you,
Joshua

Re: Multiple Frame Update Issue

Posted: Wed Jul 10, 2019 8:37 pm
by ONEEYEMAN
Hi,
Are you using an MDI interface?

Thank you.

Re: Multiple Frame Update Issue

Posted: Wed Jul 10, 2019 9:45 pm
by doublemax
Your problem description is a little vague. Are you using multiple threads? If not, everything happens in a strict sequential order.

Re: Multiple Frame Update Issue

Posted: Wed Jul 10, 2019 10:01 pm
by Joshua
I am not using any wxmdi classes so I don't think so. Sorry for the vagueness, how could I do it better? I am not using multiple threads. I am adding and removing items to list boxes in the different frames. It certainly sounds like strict sequential order means this will work right, is this true? Sounds like it should work fine, I just borrowed a book, "Stress Management for Dummies."


Thanks so much, great forum!

Joshua

Re: Multiple Frame Update Issue

Posted: Wed Jul 10, 2019 10:04 pm
by doublemax
Sorry for the vagueness, how could I do it better?
The description is too abstract. What exactly is happening in the frames? What "transactions" are you talking about? Give an example about what's happening. Maybe even some (pseudo) code.

Re: Multiple Frame Update Issue

Posted: Thu Jul 11, 2019 6:07 pm
by Joshua
The project is a restaurant cash register system with multiple frames for the different virtual screens. One frame is in the kitchen for example. A typical transaction would delete an order from two windows and rename the items that have been ordered from:

10000 10001 fries 1/2
10000 10002 soda 2/2


to:


10000 10002 soda 1/1


The first number is the order nunber and the second number is the item number for in the order. I too advantage of the fact that list boxes can automatically sort alph numerically so that the orders will stay in a time-based manner because of the items being in order as they are added (with the order and item numbers.) The reason the item number is 10002 is because the user would have deleted the first item.


The order is transferred from frame to frame as it is processed through the system and the last transaction is removal from the final screen. This is done with selecting in the list box and buttons. The program will also keep a record of the transactions (ordering, deleting, refunding) with SQL.


The order can be deleted from the main register and that would delete from the kitchen too. This is where there was a potential problem. What if the order was transferred from the kitchen to the serving screen at the same time! If I tried to delete the order and it wasn't there than the code would be faulty, however even worse the item would now need to be deleted from the other serving window and it wasn't yet. Of course, the main register frame also sends the order back to the kitchen.

The one thing I am uncertain of implemmenting yet are undo frames for delete. Oh, the kitchen screen will refund too and the kitchen register keeps track of money spent in a different text box. Finally, the serving frame can send order items back to the kitchen if there was a mistake.

Re: Multiple Frame Update Issue

Posted: Thu Jul 11, 2019 6:29 pm
by doublemax
Ok, thanks for the explanation, it's much clearer now.

In an application like this it's important to never duplicate any data. All frames must act on the same data.
The program will also keep a record of the transactions (ordering, deleting, refunding) with SQL.
It's good that you're already using a SQL database, but it sounds like you're using it only for recording a history. Instead i would suggest to make the database the "single source of truth", meaning that all frames are just views and controllers for this data. And if one frame changes the data, you'll need to send an event (or signal, or whatever) to all views, so that they can update themselves.

You may have to redesign and restructure your application for this, but it sounds like you're still in the early stages. It will definitely pay off in the long run.

Re: Multiple Frame Update Issue

Posted: Thu Jul 11, 2019 6:31 pm
by Joshua
Sorry, if the post isn't exactly right the whole thing is still a little abstract to me too!

Re: Multiple Frame Update Issue

Posted: Thu Jul 11, 2019 6:47 pm
by Joshua
I think they did a great job on this wxWidgets. Firstly, the parent/child scheme cleans up nicely. Second, (which I'm assuming is true?) the strict sequential order means I don't have to worry about something like mutexes (said liberally.) Thirdly the forum is quick and mostly effective. Lastly, the help documentation is really good. Oh, I like the great code samples too.


Thanks doublemax,
Joshua

Re: Multiple Frame Update Issue

Posted: Thu Jul 11, 2019 7:09 pm
by Joshua
Could you elaborate? What's an example of using SQL with the views, delete for example? Are you suggesting reading from the database and doing what?

Re: Multiple Frame Update Issue

Posted: Thu Jul 11, 2019 7:29 pm
by doublemax
Let's suppose you have a SQL table with all orders. And you have a frame with a listctrl that displays all open orders. Then you'd have a method like UpdateOrders() which would do a SQL SELECT to get all orders and populate the listctrl with them.

If you delete an order, you update the db with DELETE and call UpdateOrders() again, so that the listctrl gets updated.

If you have several listctrl in the application, you must make sure that they are all notified when something in the DB changes. E.g. you could send and event for this.

You should also *not* have SQL commands all over the place in your application. Have one central class that handles all DB related stuff. This has the advantage that you can replace the underlying database easily if you ever have to and you also have a central place from where you can send notifications that the database was updated.