简体   繁体   English

限制用户每天只能注册一次java

[英]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.我将有一个带有用户名、ID 和复选框的JTable ,以表明用户在场。

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:程序通过将JTable数据存储到一个数组,然后读取以前的文件数据并将新的数组数据从JTable添加到其中来将其写入文件,例如:

the Array would be an object array, with each object consisting of UserID , UserName , Present (boolean). Array 将是一个对象数组,每个对象由UserIDUserNamePresent (布尔值)组成。 The text file is of format UserID , UserName , daysPresent , totalDays per each line.文本文件的格式为UserID , UserName , daysPresent , totalDays每行。 And so the system simply adds one to daysPresent if the array indicates the person was present.因此,如果数组表明此人在场,系统只需将daysPresent一。

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).用户可以一直按提交并将当前总天数和总天数加 1(提交按钮将总天数加 1)。 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 dateuserID形成唯一的键/关系,这意味着只能允许存在两者的一种组合

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. daysPresenttotalDays都是可计算的字段,因此它们实际上并不需要存在,只需迭代数据并在需要时对它们求和。

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.向数据源添加数据时,检查是否存在当前日期的date / userID ,如果不拒绝更新,则其他人添加新条目。

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因为您使用的是文本文件,所以您需要自己管理很多,否则数据库会为您处理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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