Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

c# - 如何在C#中根据日期范围动态生成事件(How to generate events dynamically according to date range in c#)

I have an application written in c# to allow users to manage events, when adding I allow the users to add a repeat type of Daily,Monthly,Weekly and another option to select how many times it should be repeated or till what day it should be repeated.

(我有一个用c#编写的应用程序,允许用户管理事件,添加时,我允许用户添加重复类型“每日”,“每月”,“每周”,并提供另一个选项来选择应重复多少次或直到哪一天。重复。)

Now when displaying the events I need to show all the events that are available for a week.

(现在,在显示事件时,我需要显示一周内可用的所有事件。)

EX: The user adds an event today and that event repeats daily for 30 days

(例如:用户今天添加了一个活动,该活动每天重复30天)

When displaying the events I query for events using

(显示事件时,我使用查询事件)

var events = db.Evnt.Where(l => l.repeatTill >= weekEnd).ToList()

Once I get the results I need to generate the repeating events and display them to the user, How can I achieve this

(获得结果后,我需要生成重复事件并将其显示给用户,我该如何实现)

Final output should be something like this

(最终输出应该是这样的)

E1
11/24/2019 10:00 - 11/24/2019 11:00
E1
11/25/2019 10:00 - 11/25/2019 11:00
E1
11/26/2019 10:00 - 11/26/2019 11:00
E1
11/27/2019 10:00 - 11/27/2019 11:00
E1
11/28/2019 10:00 - 11/28/2019 11:00
E1
11/29/2019 10:00 - 11/29/2019 11:00
E1
11/30/2019 10:00 - 11/30/2019 11:00
E1
12/01/2019 10:00 - 12/01/2019 11:00

If the user filters from 11/24/2019 - 12/08/2019 the output should be

(如果用户从11/24/2019-12/08/2019进行过滤,则输出应为)

E1
11/24/2019 10:00 - 11/24/2019 11:00
E1
11/25/2019 10:00 - 11/25/2019 11:00
E1
11/26/2019 10:00 - 11/26/2019 11:00
E1
11/27/2019 10:00 - 11/27/2019 11:00
E1
11/28/2019 10:00 - 11/28/2019 11:00
E1
11/29/2019 10:00 - 11/29/2019 11:00
E1
11/30/2019 10:00 - 11/30/2019 11:00
E1
12/01/2019 10:00 - 12/01/2019 11:00
E1
12/02/2019 10:00 - 12/02/2019 11:00
E1
12/03/2019 10:00 - 12/03/2019 11:00
E1
12/04/2019 10:00 - 12/04/2019 11:00
E1
12/05/2019 10:00 - 12/05/2019 11:00
E1
12/06/2019 10:00 - 12/06/2019 11:00
E1
12/07/2019 10:00 - 12/07/2019 11:00
E1
12/08/2019 10:00 - 12/08/2019 11:00

How can I achieve this?

(我该如何实现?)

  ask by mike oconner translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could calculate the difference between the date range from the available data and then run a loop to generate the events for that date range.

(您可以根据可用数据计算日期范围之间的差异,然后运行循环以生成该日期范围的事件。)

Make sure to change the start date of the event to the start date of the date ranges start date that was used when calculating the time difference.

(确保将事件的开始日期更改为计算时差时使用的日期范围的开始日期。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...