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

VARCHART XGantt免费版

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

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

示例代码

'Setting a profile of fixed annual holidaysDim calendarProfile As VcCalendarProfileDim interval As VcIntervalSet calendarProfile =calendar.CalendarProfileCollection.Add("YearProfile")calendarProfile.Type = vcYearProfileSet interval = calendarProfile.IntervalCollection.Add("New Year")interval.CalendarProfileName = ""interval.DayInStartMonth = 1interval.StartMonth = vcJanuaryinterval.DayInEndMonth = 1interval.EndMonth = vcJanuaryCall SetAppearanceForHolidays(interval)Set interval = calendarProfile.IntervalCollection.Add("Christmas")interval.CalendarProfileName = ""interval.DayInStartMonth = 25interval.StartMonth = vcDecemberinterval.DayInEndMonth = 26interval.EndMonth = vcDecemberCall SetAppearanceForHolidays(interval)

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

示例代码

'Method to set the visual appearance of holidaysPrivate Sub SetAppearanceForHolidays(ByVal interval As VcInterval) interval.BackColorAsARGB = &HFFFFA4A4 interval.Pattern = vcWeavePattern interval.PatternColorAsARGB = &HFF404040 interval.LineColor = &HFF808080 interval.LineThickness = 1 interval.LineType = vcSolid interval.UseGraphicalAttributes = TrueEnd Sub

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

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

示例代码

'Method to find floating holidaysConst AshWednesday = 0Const GoodFriday = 1Const EasterSunday = 2Const EasterMonday = 3Const FeastOfCorpusChristi = 4Const AscensionOfChrist = 5Const WhitSunday = 6Const WhitMonday = 7Const CentralEuropeanSummerTimeStart = 8Const CentralEuropeanSummerTimeEnd = 9Private Function calculateAnniversaryForYear(ByVal year As Integer,ByVal specialDay As Integer) As Date Dim g As Integer Dim c As Integer Dim h As Integer Dim i As Integer Dim j As Integer Dim month As Integer Dim day As Integer Dim dayOffset As Integer g = year Mod 19 c = year Mod 100 h = (c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) Mod 30 i = h - (h / 28) * (1 - (29 / (h + 1)) * ((21 - g) / 11)) j = (year + year / 4 + i + 2 - c + c / 4) Mod 7 month = 3 + (i - j + 40) / 44 day = i - j + 28 - 31 * (month / 4) dayOffset = 0 Select Case specialDay Case AshWednesday dayOffset = -40 Case GoodFriday dayOffset = -2 Case EasterSunday dayOffset = 0 Case EasterMonday dayOffset = 1 Case AscensionOfChrist dayOffset = 39 Case WhitSunday dayOffset = 49 Case WhitMonday dayOffset = 50 Case FeastOfCorpusChristi dayOffset = 60 Case CentralEuropeanSummerTimeStart  month = 3 day = 31 - Weekday("31.3" + yearConvert + 1) Case CentralEuropeanSummerTimeEnd month = 10 day = 31 - Weekday("31.10" + yearConvert + 1) End Select Dim tmpDate As Date tmpDate = day & "." & month & "." & year calculateAnniversaryForYear = tmpDate + dayOffsetEnd Function

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

示例代码

'Assembling the week profile, the holiday profile and the floatingholidays into an intervalSet interval = calendar.IntervalCollection.Add("Weekly_Pattern")interval.CalendarProfileName = "WeekProfile"Set interval = calendar.IntervalCollection.Add("Yearly_Pattern")interval.CalendarProfileName = "YearProfile"Dim startYear As IntegerDim endYear As IntegerstartYear = year(VcGantt1.TimeScaleStart)endYear = year(VcGantt1.TimeScaleEnd)Dim i As IntegerFor i = startYear To endYear Step i + 1 Set interval = calendar.IntervalCollection.Add("GoodFriday_" & i) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i, GoodFriday) interval.EndDateTime = calculateAnniversaryForYear(i, EasterMonday) 'interval.StartDateTime Call SetAppearanceForHolidays(interval) Set interval = calendar.IntervalCollection.Add("EasterMonday_" & i) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i, EasterMonday) interval.EndDateTime = interval.StartDateTime Call SetAppearanceForHolidays(interval) Set interval =calendar.IntervalCollection.Add("FeastOfCorpusChristi_" & i) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i,FeastOfCorpusChristi) interval.EndDateTime = interval.StartDateTime Call SetAppearanceForHolidays(interval) Set interval = calendar.IntervalCollection.Add("AscensionOfChrist_" &i) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i,AscensionOfChrist) interval.EndDateTime = interval.StartDateTime  Call SetAppearanceForHolidays(interval) Set interval = calendar.IntervalCollection.Add("WhitMonday_" & i) interval.CalendarProfileName = "" interval.StartDateTime = calculateAnniversaryForYear(i, WhitMonday) interval.EndDateTime = interval.StartDateTime Call SetAppearanceForHolidays(interval)NextVcGantt1.CalendarCollection.Update

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

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

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

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

  3. 定义假期资料

  4. 将星期概要和假日概要分配给日历的间隔集合

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

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

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

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

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

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

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

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小时。

本教程内容尚未完结,敬请期待该教程最后一部分内容“如何使用日历进行计算”~感兴趣的朋友可以下载VARCHART XGantt免费版评估一下~

相关内容推荐:

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

VARCHART XGantt用户手册>>>


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

1024,致敬程序员们,zend现金优惠券限时放送,了解详情请点击下方图片

735×380-2.png

标签:

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

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

相关推荐

发表回复

登录后才能评论