簡體   English   中英

如何獲取不在列表中直接的值?

[英]How to get values that are not directly in the list?

我想從基於所選日期的列表中獲取值。 我知道這很模糊,但請繼續閱讀以了解。 我有兩個列表,房間和fullList。

房間僅包含房間號/名稱:

7-04
7-05
7-06
7-07 (Small Conference Room)
7-08
Large Conference Room

fullList由幾個字符串組成(“#”用作定界符,並且空間與上面的列表相同):

event_id + "#" + text + "#" + eventStart + "#" + eventEnd + "#" + repeat+ "#" + Days + "#" + room + "#" + startDate);

fullList中的一個簡單輸入顯示為:

"3#CISC3345#10:45#13:00#0#Monday:Wednesday#7-08#10/03/2014"

我想要的是一個新列表,在該列表中,我想為每個房間獲取eventStart之前和evnetEnd之后的時間,其邊界為“ 9:00”和“ 22:00”。

這樣的例子:

示例數據如下所示(每行都是fullList中的一個值):

Event_ID    Event       EventStart  EventEnd    Days               Repeat Rooms   DayStarts
  2         CISC 3660   09:00:00    12:30:00    Monday               1    7-07     9/19/2014    
  4         MATH 2501   15:00:00    17:00:00    Monday:Wednesday     0    7-04     10/13/2014   
  5         CISC 1110   14:00:00    16:00:00    Monday               1    7-07     9/19/2014    
  7         CISC 1340   15:00:00    22:00:00    Monday               1    7-08     9/19/2014    

我想獲取不在eventStart和eventEnd之間的時間。

例如 對於SelectedDate(9/19/2014),列表應返回:

Room  FreeTimeStart  FreeTimeEnd
7-07   12:30:00       14:00:00
7-07   16:00:00       22:00:00
7-08   09:00:00       15:00:00

例2。 選定日期(10/13/2014):

Room  FreeTimeStart  FreeTimeEnd
7-04    9:00:00       15:00:00
7-04   17:00:00       22:00:00  
public class FullList {
    public int ID              { get; set; }
    public string Event        { get; set; }
    public string Text         { get; set; }
    public DateTime EventStart { get; set; }
    public DateTime EventEnd   { get; set; }
    public string  Days        { get; set; }
    public int Repeat          { get; set; }
    public string Room         { get; set; }
    public DateTime StartDate  { get; set; }

    public override string ToString() {
        return ID + "#" + Text + "#" + EventStart + "#" + EventEnd + "#" + Repeat+ "#" + Days + "#" + Room + "#" + StartDate);
    }
}

public class FullListCollection : List<FullList> {

    public List<FullList> FindByStartEnd (DateTime start, DateTime end) {
        return this.FindAll(x => x.EventStart >= start && x.EventEnd <= end);
    }
}

// in the client class, assume we have a populated FullListCollection
myEventList // our list of events
FullListCollection EventsInDateRange = myEventList.FindByStartEnd ( <somestartdate>, <someenddate>);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM