簡體   English   中英

我正在嘗試使用asp.net C#每月自動填充報告

[英]I am trying to auto populate the report monthly using asp.net c#

我的任務是,每個月葯品表中的數量列將更新為報告表中當前月的列。 我想不使用任務計划程序來執行此操作。 我在線研究了線程和計時器。 但是,我不確定它是否會正常工作,因為線程只會每月自動更新同一列。 如您所見,我每個月需要更新不同的列。

這是我的代碼:

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";
    }
}

當前月份的列完全沒有更新。 提前致謝!

不確定計時器是否適合您的情況。 它很可能沒有被調用,因為具有計時器的當前池已停止,並且沒有其他請求“喚醒”池並重新啟動計時器。 了解有關回收應用程序池和默認設置的信息

為確保您的代碼正常運行,請與其他測試分開檢查

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM