在if条件下如何写有效期问题

时间:2018-11-08 21:20:29

标签: c# sql-server

此代码在数量减少时会更改行颜色,但是现在我需要用它来解决这样的到期问题

private void DgvStock_CellFormatting_1(object sender, DataGridViewCellFormattingEventArgs e)
{
    foreach (DataGridViewRow row in DgvStock.Rows)
    {
        int Qty = Convert.ToInt32(row.Cells[4].Value);
        if (Qty <= 10)
        {
            row.DefaultCellStyle.ForeColor = Color.White;
            row.DefaultCellStyle.BackColor = Color.Red;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您的问题尚不清楚,但是据我了解,请检查下面的代码是否对您有帮助。

private void DgvStock_CellFormatting_1(object sender, DataGridViewCellFormattingEventArgs e)
{
    foreach (DataGridViewRow row in DgvStock.Rows)
    {
        int Qty = Convert.ToInt32(row.Cells[4].Value);
        if (Qty <= 10)
        {
            row.DefaultCellStyle.ForeColor = Color.White;
            row.DefaultCellStyle.BackColor = Color.Red;
        }

DateTime exp = Convert.ToDateTime(row.Cells["yourExpiryDateColumn"].Value);
        if (exp <= System.DateTime.Now.AddDays(-90))//Updated -90 days
        {
            row.DefaultCellStyle.ForeColor = Color.White;
            row.DefaultCellStyle.BackColor = Color.Red;
        }
    }
}