c#中的提醒与当前日期进行比较 [英] reminder in c# compare with current date

查看:134
本文介绍了c#中的提醒与当前日期进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我必须在我的项目中创建一个REMINDER,



场景是:我的项目与化学品库存有关,我必须为即将到期的化学品创建一个提醒。



任何人都可以建议我,怎么可以我创建了一个提醒化学品到期前5天与当前日期/到期日期相比......



问候,

Hi guys,

I have to create one REMINDER in my project,

the scenario is: my project is related to chemical inventory, where i have to create a reminder for the chemicals which are about to expire.

Can anyone plz suggest me, how can i create a reminder for '5days before the expiry of chemical' comparing with current date/expiry date...

Regards,

推荐答案

尝试:

Try:
DateTime expiryDate = new DateTime(2014, 1, 17);
if (DateTime.Now.AddDays(5) >= expiryDate)
    {
    Console.WriteLine("Expired");
    }


你可以这样做(伪代码):

You may do something like this (pseudo code):
class Chemical
{
  ...
}
...
void ReportExpiredChemicals(int leadTimeInDays, Action<Chemical> report)
{
    var cutoff = Today + leadTimeInDays; // some magic Today property
    DataContext dc = ...                 // some data context that provices that data table for chemicals
    var query = from c in dc.GetTable<Chemical>
                where c.ExpireDate < cutoff
                select c;
    foreach(var c in query) report(c);
}
...
void SendEmailForExpiredChemical(Chemical chemical) { ... }
...
const int twoWeeks = 14; // days;
ReportExpiredChemicals(twoWeeks, SendEmailForExpiredChemical);





干杯

Andi



Cheers
Andi


这篇关于c#中的提醒与当前日期进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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