0

在我的应用程序中,我正在对员工进行查询,以了解每个人有多少订单。我想添加一个日期过滤器。所以我创建了两个日期时间选择器并为它们构建了一个函数。我应该在哪里以及如何在它们之间进行整合,或者我可以在查询中输入一些如何?

代码:

   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)
4

1 回答 1

1

可以对DataGridViewColumnDataGridViewCell类进行子类化以托管您选择的任何控件。

MSDN 上的这篇文章更详细地解释了该过程,甚至包括一些示例代码:
How to: Host Controls in Windows Forms DataGridView Cells

您还可以在代码项目中找到完整示例:Generic DataGridView V2.0

于 2013-02-17T09:57:23.000 回答