• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

on a new year reset property number

Hi,

I'm kind of in a brainless state right now :D

But I have kind of an issue which first off I thought to be easy but now that I think about it, I'm not sure how to start.

So I have a client class which has a property amountOfRents. Now This number should be resetted each 31dec 23:59:59.

I mean, how can this be solved? And when do you need to check for this?
0
Mutsop
Asked:
Mutsop
  • 2
1 Solution
 
käµfm³d 👽Commented:
What kind of application is this? How often is it executed?
0
 
MutsopAuthor Commented:
Well I found a project list to get some ideas for a project from dreamincode: A limosine rental service.
Now my idea was each time a client rents a Limosine, "amountOfRents" increase with one. After for example 2 rents he gets 5% discount, after 10 rents he gets 10%, and so on....

I would like to reset that number each end of the year.
0
 
Jacques Bourgeois (James Burger)Commented:
I have the following in one of my applications that needs to trigger a reset when the year change:
If CurrentStatus.YearlyReset < Date.Today.Year Then
    If MessageBox.Show("Ready for the annual reset?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
    Reset()
    CurrentStatus.YearlyReset = Date.Today.Year
    CurrentStatus.Save()
End If

Open in new window

This code runs at the start of the application. CurrentStatus is a class whose values are stored in a file (that is what Save does) and is loaded just before i run this code. Its YearlyReset property is changed to the current year whenever the reset has been triggered, so it won't be triggered again during that year.

If your application is running full time, a similar procedure could be called at a regular interval from a timer.

The year can be recorded in different places: Windows registry, user configuration setting, database, etc. If you call the method only when the application starts, it does not matter much. If you call it every minute or so however, a user configuration setting or a class that stays in memory (as I do) will increase performance, because the value is readily available when the application makes the check.

Depending on where amountOfRents is located and how it is accessed by your application, you might also have a Scheduled Task recorded in Windows that would call a small application yearly at the given time to update the value.
0
 
käµfm³d 👽Commented:
For application type, I was referring to Forms, Console, or web application  : )
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now