表不会变色,不知道为什么,我做的一切都好,但仍然没有。当我把(现在> expirationDate)没有任何事情发生时,但当我把"<"它的颜色。我认为问题出在截止日期功能上。
这是我的代码:
private void button2_Click_2(object sender, EventArgs e)
{
DateTime datum = DateTime.Now;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
var now = DateTime.Now;
var expirationDate = DateTime.Parse(row.Cells[4].Value.ToString());
var vremesada = DateTime.Parse(row.Cells[3].Value.ToString());
var sevenDayBefore = expirationDate.AddDays(-7);
if (now > sevenDayBefore && now < expirationDate)
{
row.DefaultCellStyle.BackColor = Color.Yellow;
}
else if (now > expirationDate)
{
row.DefaultCellStyle.BackColor = Color.Red;
}
/*
if (expirationDate > DateTime.Now)
{
row.DefaultCellStyle.BackColor = Color.Yellow;
}
else if (sevenDayBefore < DateTime.Now()
{
row.DefaultCellStyle.BackColor = Color.Red;
}*/
}
}
图片:http://prntscr.com/6pzgiv