我想在确切的交货日期前30天通知,但我不知道如何。我正在使用datagridview
来显示数据库中的数据。
我想创建一个倒计时,每天都会通知我,直到确切的交付日期。
DateTime answer = today.AddDays(30);`enter code here`
string convert1 = today.ToString("MM/dd/yy"); //Today's date
string convert = answer.ToString("MM/dd/yy"); //Today + 30days
sqlcon.Open();
command.Connection = sqlcon;
command.CommandText = "SELECT [ID], [Delivery Date], [Delivery Time], [Delivery Description] From Delivery WHERE [Delivery Date] < '" + convert + "' ORDER BY [Delivery Date] ASC";
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
if (today.Date < answer.Date)
{
MessageBox.Show("Upcoming Delivery in less than 30 days!" + "\n\n*Delivery Date:\n" + " " + reader["Delivery Date"].ToString() + "\n\n*Delivery Description:\n" + " " + reader["Delivery Description"].ToString());
}
}
}
sqlcon.Close();
答案 0 :(得分:2)
您可以创建Windows服务,定期检查要通知的实体。 Topshelf(https://github.com/Topshelf/Topshelf)是使用Windows服务的正确方法。