Reputation: 5
Looking for guidelines to create application file. For example I have an application that store user input into a file (Textbox, DataGrid, ListBox etc). I'm looking for WPF-C# implementation.
I would like to have the following:
What do real applications use to create their application file? (Note: I'm not looking for database saving or SQL)
I'm just looking for hints and guidelines. Thank you.
Upvotes: 0
Views: 233
Reputation: 3224
Mark a flag to notify that changes were done to the textbox. Better, customize your textbox and put a flag as property which is set internally when textbox's text is changed.
You can do in a few ways. Some of them are -
There are other ways too. I'll edit the answer as I remember them.
Upvotes: 0
Reputation: 38394
Use the IsDirty pattern, which is where you have a boolean property for each field that you flip to true on TextChanged events. This can be used to determine when to show the asterix. After they click save you clear the IsDirty properties for each field.
Bind your form to a class object that represents the data you want to save, and serialize that object to a file on save.
Upvotes: 0
Reputation: 33118
There's many options for achieving your goal, the most common solutions would involve either serializing your classes and storing them to disk or exporting the data your classes contain into a regular text document like CSV.
If you want files that usable files like CSV types I would recommend looking at the FileHelpers. Another thing to keep in mind using a database is the same as storing a file to disk. That's how databases work (unless its an in memory db) it's just a different type of file.
Upvotes: 0
Reputation: 5252
One way I've approached this in the past is to just have a Settings/Application object.
Use a form level variable to determine if something has been changed.
If it has been, then prompt the user.
If they click yes, then serialize your Settings/Applications object. If you want it to be human readable/editable, then use an Xml serializer, if you don't care about that, use the binary serializer.
Upvotes: 1