Multiple Frame Update Issue

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Joshua
Earned a small fee
Earned a small fee
Posts: 18
Joined: Fri Jun 22, 2018 9:23 pm

Multiple Frame Update Issue

Post by Joshua » Wed Jul 10, 2019 8:06 pm

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

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3320
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Multiple Frame Update Issue

Post by ONEEYEMAN » Wed Jul 10, 2019 8:37 pm

Hi,
Are you using an MDI interface?

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 13736
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multiple Frame Update Issue

Post by doublemax » Wed Jul 10, 2019 9:45 pm

Your problem description is a little vague. Are you using multiple threads? If not, everything happens in a strict sequential order.
Use the source, Luke!

Joshua
Earned a small fee
Earned a small fee
Posts: 18
Joined: Fri Jun 22, 2018 9:23 pm

Re: Multiple Frame Update Issue

Post by Joshua » Wed Jul 10, 2019 10:01 pm

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

User avatar
doublemax
Moderator
Moderator
Posts: 13736
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multiple Frame Update Issue

Post by doublemax » Wed Jul 10, 2019 10:04 pm

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.
Use the source, Luke!

Joshua
Earned a small fee
Earned a small fee
Posts: 18
Joined: Fri Jun 22, 2018 9:23 pm

Re: Multiple Frame Update Issue

Post by Joshua » Thu Jul 11, 2019 6:07 pm

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.

User avatar
doublemax
Moderator
Moderator
Posts: 13736
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multiple Frame Update Issue

Post by doublemax » Thu Jul 11, 2019 6:29 pm

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.
Use the source, Luke!

Joshua
Earned a small fee
Earned a small fee
Posts: 18
Joined: Fri Jun 22, 2018 9:23 pm

Re: Multiple Frame Update Issue

Post by Joshua » Thu Jul 11, 2019 6:31 pm

Sorry, if the post isn't exactly right the whole thing is still a little abstract to me too!

Joshua
Earned a small fee
Earned a small fee
Posts: 18
Joined: Fri Jun 22, 2018 9:23 pm

Re: Multiple Frame Update Issue

Post by Joshua » Thu Jul 11, 2019 6:47 pm

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

Joshua
Earned a small fee
Earned a small fee
Posts: 18
Joined: Fri Jun 22, 2018 9:23 pm

Re: Multiple Frame Update Issue

Post by Joshua » Thu Jul 11, 2019 7:09 pm

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?

User avatar
doublemax
Moderator
Moderator
Posts: 13736
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multiple Frame Update Issue

Post by doublemax » Thu Jul 11, 2019 7:29 pm

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.
Use the source, Luke!

Post Reply