我如何只能在任何项目中一次执行任何操作员 [英] how can I perfom any operaton single time only in any project

查看:56
本文介绍了我如何只能在任何项目中一次执行任何操作员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在线请假应用程序,当用户登录并且条件为以下条件时,我想在其中运行更新查询:

I am developing a on-line leave application in which I want to run a update query when user logs and the condition is:

If(datetime today.month==6)
{
//execute some statement
}


但这将在六月期间每天运行
我只想运行一次此代码


but this will run every day for June
I want to run this code only once

推荐答案

尝试一下:

Try this:

if(DateTime.Today.Month == 6 && DateTime.Today.Day == 1)
{
    //do the update 

}


您必须记住用户已登录的某个地方...实际上,整个想法都是有缺陷的...如果用户未整体登录,该怎么办?六月,该动作可能应该在他下次登录时进行...

您必须执行以下操作:
-获取运行更新查询的最后日期(提示:还将更新日期保存在表的列中).
-计算下一次应执行的更新.
-检查当前日期是否大于下一次更新的日期.
-如果是这样,请运行查询(在更新修改日期列之后)

额外提示:所有时间都应使用UTC.

最终建议:尝试自己编写用于检查日期的代码.如果需要,使用调试器.如果您在日期方面遇到困难,请搜索代码项目.关于该主题有很多疑问.
You have to remember somewhere that the user has logged... In fact, the whole idea is flawed... What if the user does not log for the whole month of June, the action should probably be done next time he log...

You have to do something like :
- Get the last date the update query was run (hint: save also update date in a column of the table).
- Compute next time an update should be done.
- Check if the current date is greater that the date of the next update.
- If so, run the query (after updating modification date column)

Extra hint: All times should be in UTC.

Final advice: Try to do the code for checking date yourself. Uses a debugger if you need. Search Code Project if you have difficulties with dates. There is a lot of questions about that subject.


该代码甚至无法编译,但思路很明确.为什么不使用布尔运算符"and"-&&"合并多个数据比较呢?

—SA
This code won''t even compile, but the idea is clear. Why not combining several data comparison using Boolean operator "and" — "&&"?

—SA


这篇关于我如何只能在任何项目中一次执行任何操作员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆