2009-07-10 64 views
3

我試圖表現出的工作小時數/天間隔它應該是這樣的:如何顯示開放時間?

Opening Times http://clip2net.com/clip/m12007/1247254068-clip-64kb.png

我有表,其中我存儲天數時,開啓時間和關閉時間每個

table http://clip2net.com/clip/m12007/1247253580-clip-4kb.png

然後我創建的查詢=>

var groups = from s in this.OpenTimes 
orderby s.Day 
group s by new { s.Till, s.Start } into gr 
select new 
{ 
    Time = gr.Key.Start + "-" + gr.Key.Till, 
    Days = this.OpenTimes 
     .Where(o => o.Start == gr.Key.Start && o.Till == gr.Key.Till) 
     .OrderBy(d => d.Day).Select(d => d.Day).ToArray() 
}; 

此查詢提供所有分組的時間間隔和包含在此時間範圍內的天數 但是我面臨的問題是 - 我創建了代表這些組的後半部分,但它無法正常工作。 也許有人可以向我解釋需要的視角或顯示開放時間的基本邏輯。

感謝意見...

+0

我不知道什麼是 「我創造了下半年,代表thsi羣體」 的意思。你是說你沒有顯示的代碼沒有按照你期望的那樣工作嗎?這是一個UI問題嗎? – NotMe 2009-07-10 19:42:21

回答

1

下一頁方法也適用於我:

result screen

public string OpeningTimesString 
     { 
     get 
     { 
      if (!this.OpeningTimes.IsLoaded) 
       this.OpeningTimes.Load(); 
      var groups = (from s in this.OpeningTimes 
         orderby s.Day, s.Start, s.Stop 
         group s by new { Stop = formatTime(s.Stop), Start = formatTime(s.Start), s.Day } into gr 
         select new 
         { 
          Time = gr.Key.Start + "-" + gr.Key.Stop, 
          Day = gr.Key.Day 
         }).ToList(); 
      string result = ""; 
      int tmp = 1; 
      for (int i = 0; i < groups.Count(); i++) 
      { 


       //One one = new One(); 
       bool exit = false; 
       tmp = i; 
       while (exit == false) 
       { 
        if (i + 1 < groups.Count && groups[i].Time.Equals(groups[i + 1].Time)) 
        { 
        i++; 
        } 
        else 
        { 
        if (tmp != i) 
         result += (NormalDayOfWeek)(groups[tmp].Day - 1) + "-" + (NormalDayOfWeek)(groups[i].Day - 1) + " : " + groups[i].Time + "<br />"; 
        else 
         result += (NormalDayOfWeek)(groups[i].Day - 1) + " : " + groups[i].Time + "<br />"; 
        exit = true; 
        } 
       } 
      } 

      if (result.IsNotNull()) 
       return result; 
      else 
       return "[%Not yet defined]"; 
     } 
     }