VARCHART XGantt用户手册(.NET版):如何使用日历(中)

VARCHART XGantt免费版

区分一天中的工作时间和非工作时间需要一个日配置文件,该日配置文件可以指定精确的时钟时间,例如从8.00 h到12.00 h am和从1.00 h到5.00 h pm。由于新创建的日配置文件仅包含工作时间,因此任何中断都应定义为非工作间隔。

示例代码C#

// Defining a day profileVcCalenderProfile calendarProfile =calendar.CalendarProfileCollection.Add("DayProfile");calendarProfile.Type = VcCalendarProfileType.vcDayProfile;VcInterval interval =calendarProfile.IntervalCollection.Add("Interval_1");// 00:00-8:00interval.CalendarProfileName = "";interval.StartTime = new DateTime(2011, 1, 1, 0, 0, 0);interval.EndTime = new DateTime(2011, 1, 1, 8, 0, 0);interval = calendarProfile.IntervalCollection.Add("Interval_2");// 12:00-13:00interval.CalendarProfileName = "";interval.StartTime = new DateTime(2011, 1, 1, 12, 0, 0);interval.EndTime = new DateTime(2011, 1, 1, 13, 0, 0);interval = calendarProfile.IntervalCollection.Add("Interval_3");// 17:00-24:00interval.CalendarProfileName = "";interval.StartTime = new DateTime(2011, 1, 1, 17, 0, 0);interval.EndTime = new DateTime(2011, 1, 1, 0, 0, 0);

示例代码VB.NET

' Defining a day profileDim calendarProfile As VcCalenderProfile =calendar.CalendarProfileCollection.Add("DayProfile")calendarProfile.Type = VcCalendarProfileType.vcDayProfileDim interval As VcInterval =calendarProfile.IntervalCollection.Add("Interval_1")' 00:00-8:00interval.CalendarProfileName = ""interval.StartTime = New DateTime(2011, 1, 1, 0, 0, 0)interval.EndTime = New DateTime(2011, 1, 1, 8, 0, 0)interval = calendarProfile.IntervalCollection.Add("Interval_2")' 12:00-13:00interval.CalendarProfileName = ""interval.StartTime = New DateTime(2011, 1, 1, 12, 0, 0)interval.EndTime = New DateTime(2011, 1, 1, 13, 0, 0)interval = calendarProfile.IntervalCollection.Add("Interval_3")' 17:00-24:00interval.CalendarProfileName = ""interval.StartTime = New DateTime(2011, 1, 1, 17, 0, 0) interval.EndTime = New DateTime(2011, 1, 1, 0, 0, 0)

时钟时间由对象DateTime设置。日期部分被忽略,因为在这种情况下它毫无意义。只需要在构造函数中设置日期,即可为构造函数所需的所有参数设置一个值。在Interval_3中,指定0h或24h是很重要的,因为后者在DateTime对象中不被接受。

一年中的定期日期(例如1月1日的除夕夜或12月25日和26日的圣诞节节礼日),由涵盖全年的日历配置文件定义。

示例代码C#

// Setting a profile of fixed annual holidaysVcCalenderProfile calendarProfile =calendar.CalendarProfileCollection.Add("YearProfile");calendarProfile.Type = VcCalendarProfileType.vcYearProfile;VcInterval interval = calendarProfile.IntervalCollection.Add("NewYear");interval.CalendarProfileName = "";interval.DayInStartMonth = 1 ;interval.StartMonth = VcMonth.vcJanuary;interval.DayInEndMonth = 1;interval.EndMonth = VcMonth.vcJanuary;SetAppearanceForHolidays(interval);interval = calendarProfile.IntervalCollection.Add("Chrismas");interval.CalendarProfileName = "";interval.DayInStartMonth = 25 ;interval.StartMonth = VcMonth.vcDecember;interval.DayInEndMonth = 26;interval.EndMonth = VcMonth.vcDecember;SetAppearanceForHolidays(interval);

示例代码VB.NET

' Setting a profile of fixed annual holidaysDim calendarProfile As VcCalenderProfile =calendar.CalendarProfileCollection.Add("YearProfile")calendarProfile.Type = VcCalendarProfileType.vcYearProfileDim interval As VcInterval = calendarProfile.IntervalCollection.Add("NewYear")interval.CalendarProfileName = ""interval.DayInStartMonth = 1interval.StartMonth = VcMonth.vcJanuaryinterval.DayInEndMonth = 1interval.EndMonth = VcMonth.vcJanuarySetAppearanceForHolidays(interval)interval = calendarProfile.IntervalCollection.Add("Christmas")interval.CalendarProfileName = ""interval.DayInStartMonth = 25interval.StartMonth = VcMonth.vcDecemberinterval.DayInEndMonth = 26 interval.EndMonth = VcMonth.vcDecemberSetAppearanceForHolidays(interval)

为了避免重复设置产生相同的假期外观,我们使用名为SetAppearanceForHolidays的方法收集调用:

示例代码C#

// Method to set the visual appearance of holidaysvoid SetAppearanceForHolidays(VcInterval interval){ interval.BackgroundColor = Color.FromArgb(255, 255, 164, 164); interval.Pattern = VcFillPattern.vcWeavePattern; interval.PatternColor = Color.FromArgb(255, 64, 64, 64); interval.LineColor = Color.FromArgb(255, 128, 128, 128); interval.LineThickness = 1; interval.LineType = VcLineType.vcSolid; interval.UseGraphicalAttributes = true;}

示例代码VB.NET

' Method to set the visual appearance of holidaysPrivate Sub SetAppearanceForHolidays(ByVal interval As VcInterval) interval.BackgroundColor = Color.FromArgb(255, 255, 164, 164) interval.Pattern = VcFillPattern.vcWeavePattern interval.PatternColor = Color.FromArgb(255, 64, 64, 64) interval.LineColor = Color.FromArgb(255, 128, 128, 128) interval.LineThickness = 1 interval.LineType = VcLineType.vcSolid interval.UseGraphicalAttributes = TrueEnd Sub

请注意:颜色属性仅在其CalendarProfileName设置为<WORK><NONWORK>的间隔内有效。另外,间隔属性UseGraphicalAttribute需要设置为true。对于calenderGrid属性UseGraphicalAttributesOfIntervals同样如此。

每年必须计算浮动假期(例如复活节)和其他依赖于它们的假期,并且需要将其作为固定日期分配给日历。下面的方法对此非常有用:

示例代码C#

// Method to find floating holidays public enum Anniversary { AshWednesday, GoodFriday, EasterSunday, EasterMonday, FeastOfCorpusChristi, AscensionOfChrist, WhitSunday, WhitMonday,  CentralEuropeanSummerTimeStart, CentralEuropeanSummerTimeEnd }private DateTime calculateAnniversaryForYear(int year, AnniversaryspecialDay){ int g = year % 19; int c = year / 100; int h = (c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) % 30; int i = h - (h / 28) * (1 - (29 / (h + 1)) * ((21 - g) / 11)); int j = (year + year / 4 + i + 2 - c + c / 4) % 7; int month = 3 + (i - j + 40) / 44; int day = i - j + 28 - 31 * (month / 4); int dayOffset = 0; switch (specialDay) { case Anniversary.AshWednesday: dayOffset = -40; break; case Anniversary.GoodFriday: dayOffset = -2; break; case Anniversary.EasterSunday: break; case Anniversary.EasterMonday: dayOffset = 1; break; case Anniversary.AscensionOfChrist: dayOffset = 39; break; case Anniversary.WhitSunday: dayOffset = 49; break; case Anniversary.WhitMonday: dayOffset = 50; break; case Anniversary.FeastOfCorpusChristi: dayOffset = 60; break; case Anniversary.CentralEuropeanSummerTimeStart: month = 3; day = 31 - Convert.ToInt32(new DateTime(year, 3,31).DayOfWeek); break; case Anniversary.CentralEuropeanSummerTimeEnd: month = 10; day = 31 - Convert.ToInt32(new DateTime(year, 10,31).DayOfWeek); break; } return new DateTime(year, month, day).AddDays(dayOffset); }

示例代码VB.NET

' Method to find floating holidays Public Enum Anniversary AshWednesday  GoodFriday EasterSunday EasterMonday FeastOfCorpusChristi AscensionOfChrist WhitSunday WhitMonday CentralEuropeanSummerTimeStart CentralEuropeanSummerTimeEndEnd EnumPrivate Function calculateAnniversaryForYear(ByVal year As Integer,ByVal specialDay As Anniversary) As DateTime Dim g As Integer = Decimal.Remainder( year , 19 ) Dim c As Integer = year / 100 Dim h As Integer = (c - c / 4 -(8 * c + 13) / 25 + 19 * g + 15) % 30 Dim i As Integer = h -(h / 28) *(1 -(29 /(h + 1)) *((21 - g) / 11)) Dim j As Integer = (year + year / 4 + i + 2 - c + c / 4) % 7 Dim month As Integer = 3 +(i - j + 40) / 44 Dim day As Integer = i - j + 28 - 31 *(month / 4) Dim dayOffset As Integer = 0 Select Case specialDay Case Anniversary.AshWednesday dayOffset = -40 Case Anniversary.GoodFriday dayOffset = -2 Case Anniversary.EasterSunday Exit Function Case Anniversary.EasterMonday dayOffset = 1 Case Anniversary.AscensionOfChrist dayOffset = 39 Case Anniversary.WhitSunday dayOffset = 49 Case Anniversary.WhitMonday dayOffset = 50 Case Anniversary.FeastOfCorpusChristi dayOffset = 60 Case Anniversary.CentralEuropeanSummerTimeStart month = 3 day = 31 - Convert.ToInt32(New DateTime(year, 3, 31).DayOfWeek) Case Anniversary.CentralEuropeanSummerTimeEnd month = 10 day = 31 - Convert.ToInt32(New DateTime(year, 10,31).DayOfWeek) End Select Return New DateTime(year, month, day).AddDays(dayOffset)End Function

在下一步中,将周配置文件和假日配置文件作为间隔分配给日历。然后以相同的方式计算浮动假期并将其分配给日历:

示例代码C#

// Assembling the week profile, the holiday profile and the floatingholidays into an intervalinterval = calendar.IntervalCollection.Add("Weekly_Pattern"); interval.CalendarProfileName = "WeekProfile";interval = calendar.IntervalCollection.Add("Yearly_Pattern");interval.CalendarProfileName = "YearProfile";int startYear = vcGantt1.TimeScaleStart.Year;int endYear = vcGantt1.TimeScaleEnd.Year;for (int i=startYear; i<=endYear; i++){ interval = calendar.IntervalCollection.Add("GoodFriday_" +i.ToString()); interval.CalendarProfileName = ""; interval.StartDateTime = calculateAnniversaryForYear(i,Anniversary.GoodFriday); interval.EndDateTime = interval.StartDateTime; SetAppearanceForHolidays(interval); interval = calendar.IntervalCollection.Add("EasterMonday_" +i.ToString()); interval.CalendarProfileName = ""; interval.StartDateTime = calculateAnniversaryForYear(i,Anniversary.EasterMonday); interval.EndDateTime = interval.StartDateTime; SetAppearanceForHolidays(interval); interval = calendar.IntervalCollection.Add("FeastOfCorpusChristi_" +i.ToString()); interval.CalendarProfileName = ""; interval.StartDateTime = calculateAnniversaryForYear(i, Anniversary.FeastOfCorpusChristi); interval.EndDateTime = interval.StartDateTime; SetAppearanceForHolidays(interval); interval = calendar.IntervalCollection.Add("AscensionOfChrist_" +i.ToString()); interval.CalendarProfileName = ""; interval.StartDateTime = calculateAnniversaryForYear(i,Anniversary.AscensionOfChrist); interval.EndDateTime = interval.StartDateTime; SetAppearanceForHolidays(interval); interval = calendar.IntervalCollection.Add("WhitMonday_" +i.ToString()); interval.CalendarProfileName = ""; interval.StartDateTime = calculateAnniversaryForYear(i,Anniversary.WhitMonday); interval.EndDateTime = interval.StartDateTime; SetAppearanceForHolidays(interval);}vcGantt1.CalendarCollection.Update();

示例代码VB.NET

' Assembling the week profile, the holiday profile and the floatingholidays into an intervalinterval = calendar.IntervalCollection.Add("Weekly_Pattern")interval.CalendarProfileName = "WeekProfile" interval = calendar.IntervalCollection.Add("Yearly_Pattern")interval.CalendarProfileName = "YearProfile"Dim startYear As Integer = vcGantt1.TimeScaleStart.YearDim endYear As Integer = vcGantt1.TimeScaleEnd.YearDim i As IntegerFor i = startYear To endYear Step i + 1 interval = calendar.IntervalCollection.Add("GoodFriday_" +i.ToString()) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i,Anniversary.GoodFriday) interval.EndDateTime = interval.StartDateTime SetAppearanceForHolidays(interval) interval = calendar.IntervalCollection.Add("EasterMonday_" +i.ToString()) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i,Anniversary.EasterMonday) interval.EndDateTime = interval.StartDateTime SetAppearanceForHolidays(interval) interval = calendar.IntervalCollection.Add("FeastOfCorpusChristi_" +i.ToString()) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i, Anniversary.FeastOfCorpusChristi) interval.EndDateTime = interval.StartDateTime SetAppearanceForHolidays(interval) interval = calendar.IntervalCollection.Add("AscensionOfChrist_" +i.ToString()) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i,Anniversary.AscensionOfChrist) interval.EndDateTime = interval.StartDateTime SetAppearanceForHolidays(interval) interval = calendar.IntervalCollection.Add("WhitMonday_" +i.ToString()) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i,Anniversary.WhitMonday) interval.EndDateTime = interval.StartDateTime SetAppearanceForHolidays(interval)NextvcGantt1.CalendarCollection.Update()

VARCHART XGantt用户手册(.NET版):如何使用日历(中)

这些是组装日历所需的摘要步骤。根据要求,可以省略单个步骤:

1、创建不同工作日的日配置文件

2、通过使用日配置文件组装周配置文件

3、定义假期资料

4、将周配置文件和假日配置文件分配给日历的间隔集合

5、为间隔集合分配其他日期(例如浮动假期)

间隔对象允许定义可解释为工作时间或非工作时间的时间段。通过CalendarProfileName属性将句点区分为<WORK><NONWORK>。通过此属性,日历还可以引用其他现有配置文件并采用其设置。设置此属性时,请注意,根据间隔类型,只能分配某些配置文件类型。间隔类型由选定的配置文件类型隐式选择。日历配置文件的预设默认值vcDayProfile可以在初始时(即在定义间隔之前)通过相应的设置进行修改。

VARCHART XGantt用户手册(.NET版):如何使用日历(中)

配置文件类型建议允许的间隔类型。例如,日期配置文件始终需要vcDayProfileInterval类型的间隔。

VARCHART XGantt用户手册(.NET版):如何使用日历(中)

日历配置文件可以显示类型为日配置文件周配置文件年配置文件变量配置文件。在一天配置文件中,只能通过在一天的限制范围内的时钟时间来定义间隔。一周配置文件包含要在某些天应用的日期配置文件。年份配置文件分配选定的一天配置文件,这些配置文件适用于单个重复日期或几个重复日期。变量配置文件包含一系列不同的工作时间。根据间隔类型vcCalendarIntervalvcDayProfileIntervalvcWeekProfileIntervalvcYearProfileIntervalvcVariableProfileInterval,仅对象的某些属性是相关的。下表映射了概要文件类型和相关属性。

VARCHART XGantt用户手册(.NET版):如何使用日历(中)

CalendarInterval在精确定义的间隔中描述了唯一的时间跨度。例:2010年5月5日从11:30时到2010年9月15日17:00时。

YearProfileInterval允许定义每年重复一次的天数或时间跨度。例:5月1日或12月24日至26日。

WeekProfileInterval处理一周中的一天或几天。例:星期六或星期一至星期五。

DayProfileInterval处理一天之内的时间规格。例:8.00时至17.00时。

VariableProfile描述了时间跨度,而不引用定义的日期或时间。时间间隔的单位可以是天、小时、分钟或秒,并且由时间间隔对象的属性TimeUnit指定。示例:4小时。

本教程内容尚未完结哦,后续将会更新.NET版本中如何使用日历的“如何使用日历进行计算”,感兴趣的朋友可以继续关注我们哦~您也可以下载VARCHART XGantt免费版体验一下~

相关内容推荐:

VARCHART XGantt用户手册(.NET版):如何使用日历(上)

VARCHART XGantt用户手册>>>


想要购买VARCHART XGantt正版授权,或了解更多产品信息请点击“咨询在线客服”

1024,致敬程序员们,zend现金优惠券限时放送,只剩最后一天了!!!

795×380-2.png

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年9月20日
下一篇 2019年9月20日

相关推荐

发表回复

登录后才能评论