Imports GrapeCity.Web.Input.IMCalendar
Dim nationalHoliday As HolidayStyle = New HolidayStyle()
Private Sub SetNationalHoliday()
' 2015年2月現在の国民の祝日を設定します。
' 固定の祝日を設定します。
nationalHoliday.Name = "国民の祝日"
nationalHoliday.SubStyle = New SubStyle(Color.Pink, Color.White)
nationalHoliday.Holidays.Add(New Holiday("元日", 1, 1))
nationalHoliday.Holidays.Add(New Holiday("建国記念の日", 2, 11))
nationalHoliday.Holidays.Add(New Holiday("昭和の日", 4, 29))
nationalHoliday.Holidays.Add(New Holiday("憲法記念日", 5, 3))
nationalHoliday.Holidays.Add(New Holiday("みどりの日", 5, 4))
nationalHoliday.Holidays.Add(New Holiday("こどもの日", 5, 5))
nationalHoliday.Holidays.Add(New Holiday("文化の日", 11, 3))
nationalHoliday.Holidays.Add(New Holiday("勤労感謝の日", 11, 23))
nationalHoliday.Holidays.Add(New Holiday("天皇誕生日", 12, 23))
' ハッピーマンデーを設定します。
nationalHoliday.Holidays.Add(New DayOfWeekHoliday("成人の日", MonthFlags.January, DayOfWeekInMonthFlags.Second, DayOfWeekFlags.Monday))
nationalHoliday.Holidays.Add(New DayOfWeekHoliday("海の日", MonthFlags.July, DayOfWeekInMonthFlags.Third, DayOfWeekFlags.Monday))
nationalHoliday.Holidays.Add(new DayOfWeekHoliday("敬老の日", MonthFlags.September, DayOfWeekInMonthFlags.Third, DayOfWeekFlags.Monday))
nationalHoliday.Holidays.Add(new DayOfWeekHoliday("体育の日", MonthFlags.October, DayOfWeekInMonthFlags.Second, DayOfWeekFlags.Monday))
' 年によって変化する祝日を2015年〜2025年の分を設定します。
For I As Integer = 2015 To 2025
' 春分の日、秋分の日を設定します。
SetYearHoliday(I)
Next I
' 2016年から2099年まで、山の日を設定します。
For i As Integer = 2016 To 2099
nationalHoliday.Holidays.Add(New ForceHoliday("山の日", DateTime.Parse(i.ToString() + "/8/11")))
Next
' 振替休日の扱いを設定します。
nationalHoliday.Holidays.Weekdays.Sunday = New DayOfWeekHolidayPolicy(WeekFlags.All, HolidayOverride.NextWorkday)
GcCalendar1.OverrideTipText = "振替休日"
' 休日スタイルをコレクションに追加してカレンダーに反映させます。
GcCalendar1.HolidayStyles.Add("国民の祝日", nationalHoliday)
GcCalendar1.ActiveHolidayStyles = New String() {"国民の祝日"}
End Sub
Private Sub SetYearHoliday(ByVal Year As Integer)
' 年によって変化する国民の祝日を設定します。
Dim currentYear As Integer = Year
' 1900年から2099年までを対象としています。
' この範囲を超えた年については、便宜的に2015年の設定をそのまま使用します。
If currentYear > 1899 AndAlso currentYear < 2100 Then
Select Case currentYear Mod 4
Case 0
' 春分の日を設定します。
If currentYear < 1960 Then
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")))
ElseIf currentYear >= 1960 AndAlso currentYear < 2092 Then
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/20")))
Else
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/19")))
End If
' 秋分の日を設定します。
If currentYear < 2012 Then
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")))
Else
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/22")))
End If
Case 1
' 春分の日を設定します。
If currentYear < 1993 Then
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")))
Else
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/20")))
End If
' 秋分の日を設定します。
If currentYear < 1921 Then
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/24")))
ElseIf currentYear >= 1921 AndAlso currentYear < 2045 Then
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")))
Else
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/22")))
End If
Case 2
' 春分の日を設定します。
If currentYear < 2026 Then
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")))
Else
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/20")))
End If
' 秋分の日を設定します。
If currentYear < 1950 Then
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/24")))
ElseIf currentYear >= 1950 AndAlso currentYear < 2078 Then
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")))
Else
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/22")))
End If
Case 3
' 春分の日を設定します。
If currentYear < 1927 Then
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/22")))
ElseIf currentYear >= 1927 AndAlso currentYear < 2059 Then
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")))
Else
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/20")))
End If
' 秋分の日を設定します。
If currentYear < 1983 Then
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/24")))
Else
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")))
End If
End Select
Else
' 2015年の春分の日を設定します。
nationalHoliday.Holidays.Add(New ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")))
' 2015年の秋分の日を設定します。
nationalHoliday.Holidays.Add(New ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")))
End If
' 2つの祝日に挟まれた営業日を休日に設定します。
If currentYear > 2003 Then
Dim Syubun As DateTime = CType(nationalHoliday.Holidays(nationalHoliday.Holidays.Count - 1), ForceHoliday).Start
If Syubun.DayOfWeek = System.DayOfWeek.Wednesday Then
nationalHoliday.Holidays.Add(New ForceHoliday("休日", Syubun.AddDays(-1)))
End If
End If
End Sub
using GrapeCity.Web.Input.IMCalendar;
HolidayStyle nationalHoliday = new HolidayStyle();
private void SetNationalHoliday()
{
// 2015年1月現在の国民の祝日を設定します。
// 固定の祝日を設定します。
nationalHoliday.Name = "国民の祝日";
nationalHoliday.SubStyle = new SubStyle(Color.WhiteSmoke, Color.Red);
nationalHoliday.Holidays.Add(new Holiday("元旦", 1, 1));
nationalHoliday.Holidays.Add(new Holiday("建国記念の日", 2, 11));
nationalHoliday.Holidays.Add(new Holiday("昭和の日", 4, 29));
nationalHoliday.Holidays.Add(new Holiday("憲法記念日", 5, 3));
nationalHoliday.Holidays.Add(new Holiday("みどりの日", 5, 4));
nationalHoliday.Holidays.Add(new Holiday("こどもの日", 5, 5));
nationalHoliday.Holidays.Add(new Holiday("文化の日", 11, 3));
nationalHoliday.Holidays.Add(new Holiday("勤労感謝の日", 11, 23));
nationalHoliday.Holidays.Add(new Holiday("天皇誕生日", 12, 23));
// ハッピーマンデーを設定します。
nationalHoliday.Holidays.Add(new DayOfWeekHoliday("成人の日", MonthFlags.January, DayOfWeekInMonthFlags.Second, DayOfWeekFlags.Monday));
nationalHoliday.Holidays.Add(new DayOfWeekHoliday("海の日", MonthFlags.July, DayOfWeekInMonthFlags.Third, DayOfWeekFlags.Monday));
nationalHoliday.Holidays.Add(new DayOfWeekHoliday("敬老の日", MonthFlags.September, DayOfWeekInMonthFlags.Third, DayOfWeekFlags.Monday));
nationalHoliday.Holidays.Add(new DayOfWeekHoliday("体育の日", MonthFlags.October, DayOfWeekInMonthFlags.Second, DayOfWeekFlags.Monday));
// 年によって変化する祝日を2015年〜2025年の分を設定します。
for( int i = 2015; i < 2025; i++ )
{
SetYearHoliday(i);
}
// 2016年から2099年まで、山の日を設定します。
for( int i = 2016; i < 2099; i++)
{
nationalHoliday.Holidays.Add(new ForceHoliday("山の日", DateTime.Parse(i.ToString() + "/8/11")));
}
// 振替休日の扱いを設定します。
nationalHoliday.Holidays.Weekdays.Sunday = new DayOfWeekHolidayPolicy(WeekFlags.All, HolidayOverride.NextWorkday);
GcCalendar1.OverrideTipText = "振替休日";
// 休日スタイルをコレクションに追加してカレンダーに反映させます。
GcCalendar1.HolidayStyles.Add("国民の祝日", nationalHoliday);
GcCalendar1.ActiveHolidayStyles = new string[] {"国民の祝日"};
}
private void SetYearHoliday(int Year)
{
// 年によって変化する国民の祝日を設定します。
int currentYear = Year;
// 1900年から2099年までを対象としています。
// この範囲を超えた年については、便宜的に2013年の設定をそのまま使用します。
if (currentYear > 1899 && currentYear < 2100)
{
switch (currentYear % 4)
{
case 0:
// 春分の日を設定します。
if (currentYear < 1960)
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")));
}
else if (currentYear >= 1960 && currentYear < 2092)
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/20")));
}
else
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/19")));
}
// 秋分の日を設定します。
if (currentYear < 2012)
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")));
}
else
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/22")));
}
break;
case 1:
// 春分の日を設定します。
if (currentYear < 1993)
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")));
}
else
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/20")));
}
// 秋分の日を設定します。
if (currentYear < 1921)
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/24")));
}
else if (currentYear >= 1921 && currentYear < 2045)
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")));
}
else
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/22")));
}
break;
case 2:
// 春分の日を設定します。
if (currentYear < 2026)
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")));
}
else
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/20")));
}
// 秋分の日を設定します。
if (currentYear < 1950)
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/24")));
}
else if (currentYear >= 1950 && currentYear < 2078)
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")));
}
else
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/22")));
}
break;
case 3:
// 春分の日を設定します。
if (currentYear < 1927)
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/22")));
}
else if (currentYear >= 1927 && currentYear < 2059)
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")));
}
else
{
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/20")));
}
// 秋分の日を設定します。
if (currentYear < 1983)
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/24")));
}
else
{
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")));
}
break;
}
}
else
{
// 2015年の春分の日を設定します。
nationalHoliday.Holidays.Add(new ForceHoliday("春分の日", DateTime.Parse(currentYear.ToString() + "/3/21")));
// 2015年の秋分の日を設定します。
nationalHoliday.Holidays.Add(new ForceHoliday("秋分の日", DateTime.Parse(currentYear.ToString() + "/9/23")));
}
// 2つの祝日に挟まれた営業日を休日に設定します。
if (currentYear > 2003)
{
DateTime Syubun = ((ForceHoliday)nationalHoliday.Holidays[nationalHoliday.Holidays.Count - 1]).Start;
if (Syubun.DayOfWeek == System.DayOfWeek.Wednesday)
{
nationalHoliday.Holidays.Add(new ForceHoliday("休日", Syubun.AddDays(-1)));
}
}
}