如何在C#/SQL Server中跟踪重复日历事件?[英] How do I track a repeating calendar event in C# / SQL Server?

本文是小编为大家收集整理的关于如何在C#/SQL Server中跟踪重复日历事件?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我想在应用程序中的日期/时间显示上显示重复事件.此日期显示可以采用日历的形式,但也可能只是即将发生的事件的列表.

处理跟踪此事件的最佳方法是什么?

例如:是否应该将事件存储一次在数据库中存储并在显示代码中投射/重复几次?该事件是否应该存储几次,然后才渲染?

推荐答案

我以前做过这样的事情,我的架构从sql服务器sysschedules表中.

/MS178644.aspx

上面链接的模式将允许您存储工作的时间表(事件).然后,您可以根据时间表的基于时间表计算事件发生的日期.这可能是一个冗长的计算,因此我会尝试缓存结果.

其他推荐答案

我认为这取决于事件的类型.像圣诞节那样,它曾经发生并且发生了,直到下一次发生之前,您真的对此不感兴趣?还是一项任务,例如"确保我每月打电话给我的妈妈",如果发生并且错过了它,您不希望它消失?

我最近实施后者的一种方法是拥有Next_occurrence(日期),reccurence_period(每周,每月,每年等)列的记录.因此,随着下一个事件的批准,它将显示在列表中.一旦通过列表项目,将具有一个回收图标,一旦按下,将将记录更新为下一个将来的事件.

再次,我不确定这是否适用于您的情况,但对我来说效果很好.

本文地址:https://www.itbaoku.cn/post/597499.html

问题描述

I'd like to display a repeating event on a date/time display in an app. This date time display can take the form of a calendar, but it could also just be a list of upcoming events.

What is the best way to handle tracking this event that can repeat?

For example: Should the event be stored once in the database and projected out / repeated several times in the display code? Should the event be stored several times and then just rendered?

推荐答案

I did something like this before and I based my schema off of SQL Servers sysschedules table.

http://technet.microsoft.com/en-us/library/ms178644.aspx

The schema linked above will allow you to store the schedule for a job (event). Then you can calculate what dates the event occurs on based off of the schedule. This may be a lengthy calculation, so I would try to cache that result somewhere.

其他推荐答案

I think it depends on type of event it is. Is it like Christmas where once it comes along and happens you really aren't interested in it until the next occurrence? Or is it a task like, "Make sure I call my mom every month", where if it happens and you missed it you wouldn't want it to go away?

One way I recently implemented the latter was to have a record that had next_occurrence (date), reoccurence_period (weekly, monthly, yearly, etc) columns. So that as the next occurence approched it would show up in the list. Once it passed the list item would have a recycle icon that once pressed would update the record to the next future occurence.

Again, i'm not sure if this applies to your situation, but it worked well for mine.