gpt4 book ai didi

c# - 如何显示营业时间?

转载 作者:行者123 更新时间:2023-11-30 18:10:44 25 4
gpt4 key购买 nike

我正在尝试显示工作时间/天数的间隔,它应该如下所示:

Opening Times
(来源:clip2net.com)

我有一张表,用于存储天数、开门时间和关门时间每一天

table
(来源:clip2net.com)

然后我创建了查询=>

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

这个查询提供了所有分组的时间间隔和包含在这个时间范围内的天数但我遇到了问题 - 我创建了代表该组的下半部分,但它无法正常工作。也许有人可以向我解释所需的视角或显示开放时间的基本逻辑。

多谢指教...

最佳答案

下一个方法对我有用:

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

关于c# - 如何显示营业时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1111556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com