Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written an app that tracks customer orders, it stores the whole order(customer info and order) by using serialization into one file. When creating a new order I add the customer info again along with the order into this file, this creates the same customer info with a second order and so on...making it very difficult to perform any kind of order lookup by name, unless you know the order number.

What would the logic be to keep the customer info separate from the order? Could I keep this single serialized file? If not, how do I serialize two files in one document? OR should I make this an MDI? What's the meaning of life? ... ? :-\
Posted
Comments
pasztorpisti 27-Aug-12 17:50pm    
MDI is an old and avoidable gui design. Normally you should never use it. Most users use a single window and they use it in maximized to cover the whole screen most of the time. Even MDI children are used as maximized in 99% of the time in MDI applications so its better to use tabs instead of them and allow the user to introduce splitters dynamically to be able to create two or more tabbed panels. Noone wants to waste screen space by using partially overlapping MDI children and noone wants to see the holes/wasted space between restored MDI children. Take a look at Visual Studio, it has tabs for separate documents and allows you to grab in a splitter in no time... Its a good example to follow. In general you should never choose a particular gui structure because of the underlying data structure.
Mohibur Rashid 27-Aug-12 18:48pm    
really????????????????????????????????????????????????????
pasztorpisti 27-Aug-12 18:55pm    
Absolutely.
Mohibur Rashid 27-Aug-12 19:02pm    
There is good example of tab instead of mdi, such as notepad++, almost all browsers, but this goes well when all the window show the same thing. but they don't make mdi backdated. mdi is old but not backdated
pasztorpisti 27-Aug-12 19:11pm    
Not backdated, outdated. When you split the workarea of the window you dont necessary have to show tabs on both sides of the split. A good example to a dynamic split is for example when you dock in the property editor tool window to the left or right side of visual studio. That tool panel isn't necessarily tabbed, but it can be if you dock there more than one tools.

In my opinion you don't need multiple documents or multiple files. You might just have two (almost) independent types of objects (cutomers and orders) stored in a single file.
 
Share this answer
 
Comments
Mohibur Rashid 27-Aug-12 19:07pm    
as example: op can use or follow compound document format.
DrBones69 27-Aug-12 19:36pm    
CPallini, would you elaborate on your solution?
CPallini 28-Aug-12 3:08am    
My idea is simple: a serialization file is not like a table, is more like a database, that is a collection of tables. You have to exploit that.
The next logical step in your process is to implement a customers and orders in a database.

With even a short term change, you could implement a SQLite database file for each customer and make it much easier to serialize your data for a customer and all of their transactions in one file.

A huge advantage to this is that your file format is managed by SQLite, and you can keep adding data/tables without breaking existing code or worrying about changes to the file layout.

Another benefit is that you get built in indexing / searching capabilities.
Further, there are quite a few free tools that will be able to access your data for reports and the like.
 
Share this answer
 
v2
Comments
DrBones69 27-Aug-12 19:39pm    
I like this approach, where would you put the interface mechanism to the SQL database? I've been experimenting with SQL and MFC, but I haven't tried it with the MFC Serialization. Any books or websites that I can take a peek at?
JackDingler 28-Aug-12 11:02am    
Most of the MFC overloading, I figured out as I went, many years ago.

It's pretty easy over all, unless you get into reworking the doc template functionality.

The first step is to decide if you're going to use one DB for all customers or a separate DB for each one.

If you're using only one DB, you'll likely want to make a class to handle the SQLite queries and data, and place that object in your app object. Documents then might be customer based and refer to your DB(SQLite) class. You'll probably want to create different view types for customers and orders and bind them to the same doc class.

If you're going to make a file for each customer, then the same solution applies, except you'll put your DB class in the document.

For both, you'll want to overload the MFC methods that open, close and serialize files.

To find these methods, put breakpoints in the OnNewDocument and OnSerialize and look at the call stack. Somewhere up above them, you'll see the calls where the CWinApp class is first working with file names or file handles. These are the methods you'll want to overload, so that you can support the SQLite interfaces rather than direct file I/O.

If you go with the single DB approach, you may want to remove some of the File operations from the menu altogether and replace them with options that pertain to customers and orders instead.

JackDingler 28-Aug-12 11:11am    
As to serialization, you might just manage your transactions there.

Perform a BEGIN TRANSACTION when you open the DB, then for every write, perform a Commit, and BEGIN TRANSACTION.

If the user decides not to save, then you can ROLLBACK.
JackDingler 28-Aug-12 11:07am    
One note on this. It's worth your time to get the symbols working properly in your debugger, if they don't now. you can learn an awful lot about what MFC does behind the scenes by stepping into the source code.

Furthermore, you can pull a lot of functionality forward and change the behavior, once you understand how the components work. Microsoft has been nice enough to provide source code for this purpose.
A possible layout:
- All customers are serialized in a file and will be hold in RAM as a map CustID <-> CustData
- An order has its ID as well and will be serialized, for example, as ID.odr file
- A viewed order document could be build by reading of its odr-file and the visualisation of the CustID using the customer map (read firstly)
- The list of the orders (IDs) could be scanned from the file system or hold in their own file
- ...

Why MDI or not ? :)
You could hold your lists and maps in the panes,
since only the single order viewing is important
and the other data can be modified in its own forms...
 
Share this answer
 
Comments
DrBones69 27-Aug-12 22:26pm    
"You could hold your lists and maps in the panes,
since only the single order viewing is important
and the other data can be modified in its own forms..."

Will you explain in a little more detail please.
Eugen Podsypalnikov 28-Aug-12 7:19am    
Please look for example at the Windows File Explorer :) , there are:
- Directories pane (customers)
- File pane (customers orders)
- File preview pane (order details)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900