2014-11-04 31 views
0

我想根据选定日期从列表中获取值。我知道这是模糊的,但请继续阅读以便理解。 我有两个列表,房间和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之间的时间。

ex。对于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 

ex2。 SelectedDate(2014年10月13日):

Room FreeTimeStart FreeTimeEnd 
7-04 9:00:00  15:00:00 
7-04 17:00:00  22:00:00 
+2

你应该从一个字符串改变'fullList'到具有诸如'eventId','text','eventStart'等一类..这将使过滤更容易。 – 2014-11-04 17:23:17

+0

好的,那么我将如何得到其他(结果)列表? – User765876 2014-11-04 17:35:32

+0

你首先必须做@David建议的事情。另外,告诉我们你从哪里得到像'event_id'这样的值。 – 2014-11-04 18:11:31

回答

0
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>);