3

I have generated a Bill Generator application without using a database. This application generates bills and saves them with a file name in a folder as an HTML file. Right now I am using a timestamp to generate a unique ID for each bill. Now I want to reduce the length of my ID; I want to use serial number.

Problem: I am using an integer variable and on click I increment the value by one, but when I restart my application, the counter is reset...

How can I save last generated value and pick up where I left off when the application restarts?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Sahil Ali
  • 113
  • 2
  • 11

3 Answers3

3

Here are some options, depending on your application and needs:

  • Use a text file.
  • Store the value in a user-scoped Setting.
  • Save the value somewhere in the registry.
  • Parse the value from the last generated bill and resume where you left off.
  • Save the value on your web server and retrieve it when necessary.
  • Have your web server or something else persistent always generate the values instead of creating them locally.
  • Ask the user to remember the number and enter it the next time.
lc.
  • 113,939
  • 20
  • 158
  • 187
  • Thanks, now do you want to explain your downvote? I'd like the opportunity to improve my answer, which you are implicitly denying me of by not commenting. :) – lc. Oct 04 '12 at 06:35
  • I wanted to give you a downvote too, but if someone had did this already, I will give you the answer. If this is a we application hosted on IIS, no same admin would let you save something in registry. – radu florescu Oct 04 '12 at 16:51
  • @Floradu88 And we have *absolutely no idea* if this is a web app or not. In fact I'm inclined to believe it's NOT a web app because the OP uses language like "restart my application". Regardless, this is why I offer many different suggestions *"depending on your application and needs"*. – lc. Oct 05 '12 at 04:45
  • As I suspected, which makes the registry a viable solution. Thank you for clarifying. – lc. Oct 05 '12 at 06:17
0

If you're insisting to use a date/time driven value, use the following?

DateTime.Now.Ticks
Hadi Eskandari
  • 25,575
  • 8
  • 51
  • 65
0

Using the Settings feature of .NET you can create and access values that are persist between application execution sessions. Settings can represent user preferences, or valuable information the application needs to use.
See this MSDN Link for more information on Settings.

Saurabh R S
  • 3,037
  • 1
  • 34
  • 44
  • WiLL these settings remains same when I'LL start using my application on new Computer/new windows...? – Sahil Ali Oct 04 '12 at 12:22
  • Have a look at this : http://stackoverflow.com/questions/453161/best-practice-to-save-application-settings-in-a-windows-forms-application – Saurabh R S Oct 04 '12 at 15:15