我正在尝试使用2个日期列过滤数据网格视图中的数据 - startDate和endDate。
我想检查一下arow的结束日期是否已过期但网格视图中的acheck框的值=“已过期”,否则将其设为=“有效”
但我不知道怎么做才能帮我做这个?!
这是我尝试过的代码:
SqlConnection CN = new SqlConnection(mysql.CON.ConnectionString);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand.CommandText = "select TASDEED.ID ,ESALNO,DATTSADEED,NAME,EGARMONY,DATBEGIN,DATEND,AKARTYPE from TASDEED ";
try
{
foreach (DataGridView row in dataGridView1.Rows)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (myStatic.CalcExpire(dt.Rows[i]["DATEND"].ToString()))//
{
dataGridView1.Rows[i].Cells[8].Value = "Expired";
}
else
{
dataGridView1.Rows[i].Cells[8].Value = "Valid";
}
}
}
BindingSource bsource = new BindingSource();
bsource.DataSource = dt;
dataGridView1.DataSource = bsource;
sda.Update(dt);
sda.Fill(dt);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
这是我的CalaExpire功能:
public static bool CalcExpire(string datee)
{
try
{
string[] Arr = datee.Split('/');
long Day1 = Convert.ToInt64(Arr[2]);
long Month1 = Convert.ToInt64(Arr[1]);
long Year1 = Convert.ToInt64(Arr[0]);
System.Globalization.UmAlQuraCalendar UmDate = new System.Globalization.UmAlQuraCalendar();
long Day = Convert.ToInt64(UmDate.GetDayOfMonth(DateTime.Now));
long Month = Convert.ToInt64(UmDate.GetMonth(DateTime.Now));
long Year = Convert.ToInt64(UmDate.GetYear(DateTime.Now));
if (Year > Year1)
return true;
else if (Year == Year1 && Month > Month1)
return true;
else if (Year == Year1 && Month == Month1 && Day >= Day1)
return true;
else
return false;
}
catch { return false; }
}