简体   繁体   English

C#Winforms:当数据库中指定的日期到来时,每个用户的后台通知

[英]C# Winforms: Background Notification for every users when the date specified in the Database has come

I am new with C#, so and currently working with a windows app that has a timer working in background that comes from the SQLServer database. 我是C#的新手,因此当前正在使用Windows应用程序,该应用程序的计时器在后台运行,该计时器来自SQLServer数据库。

For example: 例如:

A user entered the system, then checks the payment terms and then one client appeared to pay the monthly bill. 一位用户进入系统,然后检查付款条件,然后一位客户出现了要支付每月账单。 The paid for the bill for December 1, 2016 up-to December 31, 2016. And then the user will process it and scheduled the next payment for January 1, 2017. And when January 1, 2017 comes there will be a notification bubble or forms to notify the user that the client has to pay this day. 2016年12月1日至2016年12月31日之间的已付账单。然后用户将对其进行处理,并将下一次付款安排在2017年1月1日。当2017年1月1日到来时,将出现通知气泡或表格以通知用户客户必须在这一天付款。

So far, I have no codes yet because I am just in the part of brainstorming and gathering information about the project. 到目前为止,我还没有代码,因为我只是在集思广益和收集有关该项目的信息。

The question is, How can I notify a user in an specific date that is based on the specified date from the Database? 问题是,如何在基于数据库中指定日期的特定日期通知用户?

Thank you! 谢谢!

If the user only should be informed, when your application is active, this easily could be done via polling for example. 如果仅应通知用户,则当您的应用程序处于活动状态时,例如,可以通过轮询轻松地完成此操作。 You use a timer which ticks every second or sth. 您使用一个计时器,它每秒钟或每秒钟滴答一声。 you want. 你要。 In the Timer.Elapsed event you can poll the date from your Database and check it's value. Timer.Elapsed事件中,您可以从数据库中查询日期并检查其值。

So make a class: 因此,上一堂课:

public class CheckDbDate
{
   private Timer _timer;
   public event EventHandler DateReached;

   public CheckDbDate()
   {
      _timer = new Timer();
      _timer.Intervall = 500; //ms
      _timer.Elapsed += (sender, e) => CheckDate();
      _timer.Start();
   }

   public void CheckDate()
   {
      //Check your Database Date value
      if (DateTime.Now.CompareTo(dbDate) >= 0)
      {
         DateReached?.Invoke(this, new EventArgs());
      }
   }
}

So in your MainApplication Code you have to instatiate a CheckDbDate object and subscribe for the DateReached Event. 因此,在您的MainApplication Code中,您必须将CheckDbDate对象实例化并订阅DateReached事件。 You maybe need to make this stuff async, because it will block your UI every 500ms. 您可能需要使这些内容异步,因为它将每500毫秒阻塞一次UI。

This is the easiest approach i think. 我认为这是最简单的方法。

If they should be informed without having your application running. 是否在不运行您的应用程序的情况下通知他们。 You should think about a WindowsService (WCF). 您应该考虑WindowsService(WCF)。

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

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