我正在使用三个按钮处理winforms应用程序:
然而,我所看到的是,在将过期过滤器应用于租用/租用表后,如果我再次点击出租/租用(有效地摆脱过滤器),过滤器仍然存在。所以我的意思是,如果我点击Rent,Overdue然后Rent,过期的过滤器应该消失,但它仍然存在。我该如何解决这个问题?
到目前为止,这是我的代码:
public void viewOverdue_Click(object sender, EventArgs e)
{
viewOverdue.ForeColor = Color.Red;
DateTime overdueDate = default(DateTime);
DateTime today = DateTime.Now;
string odDate = null;
if (today.DayOfWeek == DayOfWeek.Monday)
{
overdueDate = today.AddDays(-12);
odDate = overdueDate.Date.ToString("dd/MM/yyyy HH:mm:ss");
}
else if (today.DayOfWeek == DayOfWeek.Tuesday)
{
overdueDate = today.AddDays(-13);
odDate = overdueDate.Date.ToString("dd/MM/yyyy HH:mm:ss");
}
else if (today.DayOfWeek == DayOfWeek.Wednesday)
{
overdueDate = today.AddDays(-7);
odDate = overdueDate.Date.ToString("dd/MM/yyyy HH:mm:ss");
}
else if (today.DayOfWeek == DayOfWeek.Thursday)
{
overdueDate = today.AddDays(-8);
odDate = overdueDate.Date.ToString("dd/MM/yyyy HH:mm:ss");
}
else if (today.DayOfWeek == DayOfWeek.Friday)
{
overdueDate = today.AddDays(-9);
odDate = overdueDate.Date.ToString("dd/MM/yyyy HH:mm:ss");
}
else if (today.DayOfWeek == DayOfWeek.Saturday)
{
overdueDate = today.AddDays(-10);
odDate = overdueDate.Date.ToString("dd/MM/yyyy HH:mm:ss");
}
else if (today.DayOfWeek == DayOfWeek.Sunday)
{
overdueDate = today.AddDays(-11);
odDate = overdueDate.Date.ToString("dd/MM/yyy HH:mm:ss");
}
CurrencyManager manager = (CurrencyManager)BindingContext[dataGridView1.DataSource];
manager.SuspendBinding();
DateTime dateBase = DateTime.Parse(odDate);
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if(row.Cells[0].Value != null)
{
DateTime dateRow = DateTime.Parse(row.Cells[0].Value.ToString());
row.Visible = (dateRow <= dateBase);
}
}
manager.ResumeBinding();
}
}
public void visible()
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Visible = true;
}
}
private void viewHire_Click(object sender, EventArgs e)
{
viewOverdue.ForeColor = Color.Black;
viewHire.ForeColor = Color.Red;
viewRent.ForeColor = Color.Black;
dataGridView1.DataSource = hireBindingSource;
Globals.notesTbl = "hireNotes";
visible();
}
private void viewRent_Click(object sender, EventArgs e)
{
viewOverdue.ForeColor = Color.Black;
viewHire.ForeColor = Color.Black;
viewRent.ForeColor = Color.Red;
dataGridView1.DataSource = rentBindingSource;
Globals.notesTbl = "rentNotes";
visible();
}