禁用周末和节假日在阿贾克斯日历扩展控制 [英] Disabling weekend and national Holidays in ajax calender extender control

查看:228
本文介绍了禁用周末和节假日在阿贾克斯日历扩展控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图用一个Ajax CalenderExtender我的应用程序。

I have been trying to use an ajax CalenderExtender for my application.

我有许多小的操作在我的应用程序,如添加持续时间启动任务的日期找到的完成日期,如果(这取决于它的起始日期)的结束日期更改更改任务持续时间等。

I have many small operations in my app like adding duration to start date of a task to find the finish date, change duration of a task if its end date is changed (depending on its start date),etc.

不过,虽然我做的所有这些操作我想跳过所有的节假日和周六,周日从计算的如。开始于2014年1月23日有5天的持续时间的任务要完成对2014年1月29日(加入2天SAT n的时间太阳),而不是2014年1月27日。同样要在其他业务进行为好。

But while I do all these operations I want to skip all the holidays and saturday , sundays from the calculations for eg. a task starting on 01/23/2014 with a duration of 5 days should finish on 01/29/2014 (adding 2 days for sat n sun in duration) instead of 01/27/2014. Same should be performed on other operations as well.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

有关周六,周日,这很容易。只是检查 DateTime.DayOfWeek 日期的属性。

For Sundays and Saturdays, it's easy. Just check the DateTime.DayOfWeek property of your dates.

如果您有将开始日期的操作启动,将结束日期结束,你可以看到什么日期是星期六或星期日是这样的:

If you have an operation that will start on date start and will end on date end, you can see what dates are Saturdays or Sundays like this:

List<DateTime> satsAndSundays;
for (DateTime temp = start; temp <= end; temp.AddDays(1))
{
    if (temp.DayOfWeek == DayOfWeek.Sunday ||
        temp.DayOfWeek == DayOfWeek.Saturday)
    {
        satsAndSundays.add(temp);
    }
}

和,因为你可以知道有多少天之间存在启动结束做类似:

And since you can know how many days there are between start and end by doing something like:

TimeSpan span = end - start;
int totalDays = (int)span.TotalDays;
// TotalDays is actually a double, I'm just discarding the non integer part.

您可以FID出你有多少个工作日内必须有做 totalDays - saysAndSundays.Count

You may fid out how many work days you have there by doing totalDays - saysAndSundays.Count.

编辑:我刚刚看了一遍这个问题。如果你想有一个任务开始在给定日期,并采取 X 工作日内,你可以做这样的:

I just read the question again. If you want a task to start on a given date, and take x work days, you can do it like this:

DateTime end = start;
for (int i = x; i >= 0;) // the third parameter of the for is empty on purpose
{
    end = end.AddDays(1);
    if (end.DayOfWeek != DayOfWeek.Saturday &&
        end.DayOfWeek != DayOfWeek.Sunday)
    {
        i--;
    }
}

Afther循环,结束 X 个工作日之后启动(只要没有假期之间)。

Afther the loop, end will be x workdays after start (provided there are no holidays in between).

有关假日,虽然,没有alghoritm为,在框架。你需要从某些源(文件,数据库,Web服务等)获取它们。或者你可以编写自己的程序,以数字出来 - 这不是一个固定的日期也遵循公式,当谈到在发生的时候最假期。别考虑到,然而,节假日可以通过培养和地区而异。如果应用程序是在整个国家被使用,例如,它可以是相当实现城市范围假期的努力。根据您的需求,它甚至可能会更好,要么让用户输入这些日子是节假日,或使自己的数据库,你的应用程序可以访问和使用。

For holidays, though, there is no alghoritm for that in the framework. You need to fetch them from some source (a file, a database, a web service etc.). Or you could write your own program to figure them out - most holidays that are not on a fixed date do follow formulas when it comes to when they happen. Do take into account, however, that holidays may vary by culture and region. If your application is to be used throughout a country, for example, it may be quite the effort to implement city-wide holidays. Depending on your needs, it might even be better to either let the users input which days are holidays, or making your own database your app can access and use.

这篇关于禁用周末和节假日在阿贾克斯日历扩展控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆