有谁知道我会如何编码:
每天在特定时间向管理员/经理发送电子邮件,包括数据库中的表格(库存表 - 只有四个库存),以便他们了解库存水平以及是否需要重新订购
否则
如果这四个库存水平中的一个低,通知他们证书材料/库存已达到最低水平并重新订购,将向管理员/管理员发送电子邮件。
我有发送电子邮件的代码:
protected void Button1_Click1(object sender, EventArgs e)
{
MailMessage mail = new MailMessage(from.Text, to.Text, subject.Text, body.Text);
SmtpClient Client = new SmtpClient(smtp.Text);
Client.Port = 587;
Client.Credentials = new System.Net.NetworkCredential(username.Text, password.Text);
Client.EnableSsl = true;
Client.Send(mail);
Response.Write("<script LANGUAGE='JavaScript' >alert('Mail Sent')</script>");
}
欢迎任何帮助!!!
谢谢!
答案 0 :(得分:0)
您需要一个调度程序,以便安排每日任务以检查库存水平并在需要时发送电子邮件。如果你想保留asp.net应用程序中的所有内容,你可以使用hangfire实现这一点。 Hangfire是一个调度程序。查看https://www.hangfire.io/
代码看起来像这样
RecurringJob.AddOrUpdate(
() => {
//TODO: Check your Stock Table DB
var from = "noreply@<yourcompany>.com"
var to = "admin@<yourcompny>.com"
var subject = "Low stock"
var body = "The following items are low in stock : "
// TODO: append items to body variable
MailMessage mail = new MailMessage(from, to, subject, body);
SmtpClient Client = new SmtpClient(smtp.Text);
Client.Port = 587;
Client.Credentials = new System.Net.NetworkCredential(username.Text, password.Text);
Client.EnableSsl = true;
Client.Send(mail);},
Cron.Daily);
});
答案 1 :(得分:0)
使用Windows服务监控数据,小时和数据库。
private void mainTimer_Tick(object sender, EventArgs e)
{
try
{
if (ConfigsHTM["exechour"] != null)
{
if (DateTime.Now.ToString("HH:mm:ss") == ConfigsHTM["exechour"].ToString())
{
ClassProcessing clsProc = new ClassProcessing();
clsProc.StartDate = DateTime.Now.AddDays(-1);
clsProc.EndDate = DateTime.Now.AddDays(-1);
clsProc.ProcessAll();
if (StatusHTM.Count > 0)
StatusHTM.Clear();
StatusHTM.Add("locationstatus","Todas as Unidades");
StatusHTM.Add("typestatus","Agendado");
StatusHTM.Add("exechourstatus", DateTime.Now.ToString("F"));
if (clsProc.ReprocessingDone)
StatusHTM.Add("statusstatus","OK");
else
StatusHTM.Add("statusstatus", "Falhou");
ClassStatus clsStt = new ClassStatus();
clsStt.StatusHT = StatusHTM;
clsStt.SaveStatus();
GetStatus();
}
}
}
catch (Exception ex)
{
ClassLog clsLog = new ClassLog();
clsLog.EventData = "Falha ao Iniciar a Execução do Aplicativo";
clsLog.ErrorLog();
clsLog.EventData = ex.ToString();
clsLog.ErrorLog();
}
}