Hi!
Someone to help me for this ; I have the following code in my project:
- public void LoadRecords()
- {
- int i = 0;
- dataGridView1.Rows.Clear();
- cn.Open();
- cm = new OleDbCommand("select * from Produit", cn);
- dr = cm.ExecuteReader();
- while (dr.Read())
- {
- i += 1;
- dataGridView1.Rows.Add(i, dr["ProdID"].ToString(), dr["nom"].ToString(), dr["Quantite"].ToString(), dr["peremption"].ToString());
-
- foreach (DataGridViewRow row in dataGridView1.Rows)
- {
-
-
- var now = DateTime.npw;
-
- var expireDate = DateTime.Parse(row.Cells[3].Value.ToString());
- var sixtyDayBefore = expireDate.AddDays(-1);
- if(now > sixtyDayBefore && now > expireDate)
- {
- row.DefaultCellStyle.BackColor = Color.Yellow;
-
- }
- else if(now > expireDate)
- {
- row.DefaultCellStyle.BackColor = Color.Red;
- }
- }
-
- }
-
- cn.Close();
- dr.Close();
- }