How to display opening time?

I am trying to show the working hours / days intervals, it should look like this:

Opening times
(source: clip2net.com )

I have a table where I store the day number, opening time and closing time for each day

table
(source: clip2net.com )

Then I created a request =>

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()
};

This query provides all the grouped time intervals and days that are included in this time range. But I ran into a problem - I created the second half representing these groups, but it does not work properly. Maybe someone could explain to me the necessary point of view or this basic logic of showing the opening time.

Thanks for the advice...

+3
source share
1

:

  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]";
         }
      }
+1

Source: https://habr.com/ru/post/1712327/


All Articles