[英]I am trying to auto populate the report monthly using asp.net c#
My task is that every month, the quantity column in the medicine table will be updated to the current month's column in the report table. 我的任务是,每个月药品表中的数量列将更新为报告表中当前月的列。 I would like to do this without using task scheduler. 我想不使用任务计划程序来执行此操作。 I researched online about threading and timer. 我在线研究了线程和计时器。 However, I am unsure if it will work as threading will only auto update the same column every month. 但是,我不确定它是否会正常工作,因为线程只会每月自动更新同一列。 As you can see, I need to update different columns every month. 如您所见,我每个月需要更新不同的列。
Here are my codes: 这是我的代码:
DateTime today = DateTime.Today;
DateTime firstDay = new DateTime(today.Year, today.Month, 1);
if (today == firstDay)
{
while (true)
{
string sql1 = "SELECT quantity FROM medicine";
DataSet ds = DBMgr.GetDataSet(sql1);
int quantity = int.Parse(ds.Tables[0].Rows[0]["quantity"].ToString());
string month = DateTime.Now.ToString("MMMM");
if (month.Equals("January"))
{
string sql = "UPDATE report SET Jan = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("February"))
{
string sql = "UPDATE report SET Feb = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("March"))
{
string sql = "UPDATE report SET Mar = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("April"))
{
string sql = "UPDATE report SET Apr = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("May"))
{
string sql = "UPDATE report SET May = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("June"))
{
string sql = "UPDATE report SET June = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("July"))
{
string sql = "UPDATE report SET July = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("August"))
{
string sql = "UPDATE report SET Aug = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("September"))
{
string sql = "UPDATE report SET Sep = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("October"))
{
string sql = "UPDATE report SET Oct = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("November"))
{
string sql = "UPDATE report SET Nov = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("December"))
{
string sql = "UPDATE report SET Dec = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
else
{
LblMsg.Text = "An Error Occurred";
}
}
the current month's column was not updated at all. 当前月份的列完全没有更新。 Thanks in advance! 提前致谢!
Not sure that timer will work for your case. 不确定计时器是否适合您的情况。 Most probably it is not called, because the current pool, that has a timer was stoped and there are no other requests to 'wake up' the pool and restart timer. 它很可能没有被调用,因为具有计时器的当前池已停止,并且没有其他请求“唤醒”池并重新启动计时器。 Read about recycling app pools and default settings 了解有关回收应用程序池和默认设置的信息
To be sure that your code is working, check it separatelly with another test 为确保您的代码正常运行,请与其他测试分开检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.