在我的应用程序中,我正在对员工进行查询,以了解每个人有多少订单。我想添加一个日期过滤器。所以我创建了两个日期时间选择器并为它们构建了一个函数。我应该在哪里以及如何在它们之间进行整合,或者我可以在查询中输入一些如何?
代码:
private void Form3_Load(object sender, EventArgs e)
{
this.employeesTableAdapter.Fill(this.nORTHWNDDataSet.Employees);
using (NorthWindDataContext db = new NorthWindDataContext())
{
var query =
from d in db.Employees
select new EmployeeData
{
FirstName = d.FirstName,
EmployeeID = d.EmployeeID
};
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = query;
}
}
public bool CheckDate(DateTime date)
{
DateTime floorDate = FromDate.Value;
DateTime roofDate = ToDate.Value;
if (date > floorDate && date < roofDate)
{
return true;
}
else
{
return false;
}
}
private void displayOrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
using (NorthWindDataContext db = new NorthWindDataContext())
{
if (db.Employees == null)
{
}
EmployeeData currentEmployee = (EmployeeData)dataGridView1.SelectedRows[0].DataBoundItem;
var query =
from o in db.Employees
where o.EmployeeID == currentEmployee.EmployeeID
select new
{
orderNumber = o.Orders.Count()
};
dataGridView2.AutoGenerateColumns = false;
dataGridView2.DataSource = query;
}
就像是
where o.EmployeeID == currentEmployee.EmployeeID && o.Orders.Where(x=>x.OrderDate.Value.Date>FromDate.Value.Date&&<ToDate.Value.Date)