2011-07-03 45 views
0

我正在處理的情況下,我需要根據日期列組我的DevExpress網格。問題是,我需要我的團隊被稱爲:過去,現在和未來。這裏是LINQ:需要有一個網格根據日期分組到邏輯組

GridJobSummary.DataSource = from luke in DbContext.JobBookings 
      where luke.LocumID == LocumID 
      orderby luke.Job.JobDate descending 
      select new { 
       luke.JobID, 
       luke.Job.JobDate, 
       ClientID = luke.Job.Branch.ClientID, 
       ClientName = String.Format("{0} ({1})", luke.Job.Branch.Client.Name, luke.Job.Branch.Client.Number), 
       BranchID = luke.Job.BranchID, 
       BranchName = String.Format("{0} ({1})", luke.Job.Branch.Number, luke.Job.Branch.Number), 
       JobBookingStatusName = luke.JobBookingStatus.Name 
      }; 

GridJobSummaryView.Columns["JobID"].Visible = false; 
GridJobSummaryView.Columns["ClientID"].Visible = false; 
GridJobSummaryView.Columns["BranchID"].Visible = false; 

GridJobSummaryView.Columns["JobDate"].DisplayFormat.FormatType = FormatType.DateTime; 
GridJobSummaryView.Columns["JobDate"].DisplayFormat.FormatString = "ddd, dd-MMM-yyyy"; 
GridJobSummaryView.Columns["JobDate"].SortOrder = ColumnSortOrder.Ascending; 

現在,

如果[工作日期<今天],它進入過去組。

如果[作業日期> =今天 < =(今天+ 1個月)],它的電流

如果[工作日期>(今日+ 1個月)],這是未來。如何將我的網格分組到這個虛擬組中?問候。

回答

1

添加屬性 「組名」 到所選對象:

select new { 
       luke.JobID, 
       luke.Job.JobDate, 
       ClientID = luke.Job.Branch.ClientID, 
       ClientName = String.Format("{0} ({1})", luke.Job.Branch.Client.Name, luke.Job.Branch.Client.Number), 
       BranchID = luke.Job.BranchID, 
       BranchName = String.Format("{0} ({1})", luke.Job.Branch.Number, luke.Job.Branch.Number), 
       JobBookingStatusName = luke.JobBookingStatus.Name, 
       GroupName = GetGroupNameByDate(luke.Job.JobDate) 
      }; 

// ..... 
string GetGroupNameByDate(DateTime date) { 
    var today = DateTime.Today; 
    if (date < today) { return "Past"; } 
    else if (date >= today && date <= today.AddMonths(1)) { return "Current"; } 
    else { return "Future"; } 
} 
+0

完美的作品 – DoomerDGR8