简体   繁体   中英

Restrict user to registering only once a day java

I don't have any code so far, but my initial idea is quite simple. I will have a JTable with user's names, IDs, and a checkbox to indicate the user was present.

The program writes this to file by storing the JTable data to an array and then reading the previous file data and adding the new array data from JTable to it, for example:

the Array would be an object array, with each object consisting of UserID , UserName , Present (boolean). The text file is of format UserID , UserName , daysPresent , totalDays per each line. And so the system simply adds one to daysPresent if the array indicates the person was present.

My only problem is; the user can do this as many times a day as they want. The user can keep pressing submit and adding 1 to the total days present as well as the total days (submit button adds one to total days). Can anyone think of some way to restrict the user to only be able to submit a register once a day, although I am thinking of adding a checkbox for late so maybe some way in which somehow, the data for one day is only added to the array at the end of the day or something? I don't really know about that, I can't think of how I could possibly implement it. Also, how the total days is only increased if a register is completed for a certain day?

I appreciate I haven't submitted any code and there's a lot of questions but I am unable to currently start it. Apologies.

Any help is appreciated and ask any questions if you don't understand. Thanks.

The basic answer is, you need to associate a date value with each entry

date | userID | userName | present

The date and userID form a unique key/relationship, meaning that only one combination of both can be allowed to exist

daysPresent and totalDays are both calculable fields, so they don't really need to be present, simply iterate of the data and sum them if you need them.

When adding data to the data source, check to see if a date / userID for the current date exists, if it doesn't reject the update, others add the new entry.

Because you're using a text file, you're going to need to manage a lot of this yourself, a database would otherwise take care of it for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM