VARCHART XGantt用户手册(ActiveX版):如何使用日历(中)
VARCHART XGantt是一个交互式的甘特图控件,其模块化的设计让您可以创建满足您和您的客户所需求的应用程序。相较于其他甘特图控件,VARCHART XGantt稳定性高,开发时间长,各大行业的知名公司都在使用它。本文主要描述了如何使用日历教程中的第二部分内容,内容紧接前文,现在就来了解一下吧~
时钟时间由对象DateTime设置。日期部分被忽略,因为在这种情况下它毫无意义。只需要在构造函数中设置日期,即可为构造函数所需的所有参数设置一个值。在Interval_3中,指定0h或24h是很重要的,因为后者在DateTime对象中不被接受。
一年中的定期日期(例如1月1日的除夕夜或12月25日至26日的圣诞节和节礼日),由涵盖全年的日历配置文件定义。
示例代码
'Setting a profile of fixed annual holidays
Dim calendarProfile As VcCalendarProfile
Dim interval As VcInterval
Set calendarProfile =
calendar.CalendarProfileCollection.Add("YearProfile")
calendarProfile.Type = vcYearProfile
Set interval = calendarProfile.IntervalCollection.Add("New Year")
interval.CalendarProfileName = ""
interval.DayInStartMonth = 1
interval.StartMonth = vcJanuary
interval.DayInEndMonth = 1
interval.EndMonth = vcJanuary
Call SetAppearanceForHolidays(interval)
Set interval = calendarProfile.IntervalCollection.Add("Christmas")
interval.CalendarProfileName = ""
interval.DayInStartMonth = 25
interval.StartMonth = vcDecember
interval.DayInEndMonth = 26
interval.EndMonth = vcDecember
Call SetAppearanceForHolidays(interval)为了避免重复设置产生相同的外观,我们使用名为SetAppearanceForHolidays的方法收集调用:
示例代码
'Method to set the visual appearance of holidays Private 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 = True End Sub
请注意:颜色属性仅在其CalendarProfileName设置为或的间隔内有效。另外,间隔属性UseGraphicalAttribute需要设置为true。对于calenderGrid属性UseGraphicalAttributesOfIntervals同样如此。
每年必须计算浮动假期(例如复活节)和其他与之相关的假期,并且需要将其作为固定日期分配给日历。下面的方法对此非常有用:
示例代码
'Method to find floating holidays
Const AshWednesday = 0
Const GoodFriday = 1
Const EasterSunday = 2
Const EasterMonday = 3
Const FeastOfCorpusChristi = 4
Const AscensionOfChrist = 5
Const WhitSunday = 6
Const WhitMonday = 7
Const CentralEuropeanSummerTimeStart = 8
Const CentralEuropeanSummerTimeEnd = 9
Private 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 + dayOffset
End Function在下一步中,将周配置文件和假日配置文件作为间隔分配给日历。然后以相同的方式计算浮动假期并将其分配给日历:
示例代码
'Assembling the week profile, the holiday profile and the floating
holidays into an interval
Set interval = calendar.IntervalCollection.Add("Weekly_Pattern")
interval.CalendarProfileName = "WeekProfile"
Set interval = calendar.IntervalCollection.Add("Yearly_Pattern")
interval.CalendarProfileName = "YearProfile"
Dim startYear As Integer
Dim endYear As Integer
startYear = year(VcGantt1.TimeScaleStart)
endYear = year(VcGantt1.TimeScaleEnd)
Dim i As Integer
For 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)
Next
VcGantt1.CalendarCollection.Update
这些是组装日历所需的摘要步骤。根据要求,可以省略单个步骤:
创建不同工作日的日配置文件
通过使用日配置文件组装周配置文件
定义假期资料
将星期概要和假日概要分配给日历的间隔集合
为间隔集合分配其他日期(例如,浮动假期)
间隔对象允许定义可解释为工作时间或非工作时间的时间段。通过CalendarProfileName属性将句点区分为或。通过此属性,日历还可以引用其他现有配置文件并采用其设置。设置此属性时,请注意,根据间隔类型,只能分配某些配置文件类型。间隔类型由选定的配置文件类型隐式选择。日历配置文件的预设默认值vcDayProfile可以在初始时(即在定义间隔之前)通过相应的设置进行修改。

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

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

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正版授权,或了解更多产品信息请点击
1024,慧都致敬程序员们,zend现金优惠券限时放送,了解详情请点击下方图片


QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线