翻譯|使用教程|編輯:莫成敏|2019-10-24 10:26:23.257|閱讀 240 次
概述:VARCHART XGantt是用于工業(yè)4.0項目管理、交互式的甘特圖絕佳解決方案,世界級甘特圖大師。本教程介紹如何使用日歷(.NET版本內容),文章內容較多,本文主要介紹定義日歷的后半部分內容~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
VARCHART XGantt是一個交互式的甘特圖控件,其模塊化的設計讓您可以創(chuàng)建滿足您和您的客戶所需求的應用程序。相較于其他甘特圖控件,VARCHART XGantt穩(wěn)定性高,開發(fā)時間長,各大行業(yè)的知名公司都在使用它。本文主要描述了如何使用日歷教程中的定義日歷的后面部分內容,現(xiàn)在跟著小編來了解一下吧~
區(qū)分一天中的工作時間和非工作時間需要一個日配置文件,該日配置文件可以指定精確的時鐘時間,例如從8.00 h到12.00 h am和從1.00 h到5.00 h pm。由于新創(chuàng)建的日配置文件僅包含工作時間,因此任何中斷都應定義為非工作間隔。
示例代碼C#
// Defining a day profile VcCalenderProfile calendarProfile = calendar.CalendarProfileCollection.Add("DayProfile"); calendarProfile.Type = VcCalendarProfileType.vcDayProfile; VcInterval interval = calendarProfile.IntervalCollection.Add("Interval_1"); // 00:00-8:00 interval.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:00 interval.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:00 interval.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 profile Dim calendarProfile As VcCalenderProfile = calendar.CalendarProfileCollection.Add("DayProfile") calendarProfile.Type = VcCalendarProfileType.vcDayProfile Dim interval As VcInterval = calendarProfile.IntervalCollection.Add("Interval_1") ' 00:00-8:00 interval.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:00 interval.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:00 interval.CalendarProfileName = "" interval.StartTime = New DateTime(2011, 1, 1, 17, 0, 0) interval.EndTime = New DateTime(2011, 1, 1, 0, 0, 0)
時鐘時間由對象DateTime設置。日期部分被忽略,因為在這種情況下它毫無意義。只需要在構造函數(shù)中設置日期,即可為構造函數(shù)所需的所有參數(shù)設置一個值。在Interval_3中,指定0h或24h是很重要的,因為后者在DateTime對象中不被接受。
一年中的定期日期(例如1月1日的除夕夜或12月25日和26日的圣誕節(jié)和節(jié)禮日),由涵蓋全年的日歷配置文件定義。
示例代碼C#
// Setting a profile of fixed annual holidays VcCalenderProfile calendarProfile = calendar.CalendarProfileCollection.Add("YearProfile"); calendarProfile.Type = VcCalendarProfileType.vcYearProfile; VcInterval interval = calendarProfile.IntervalCollection.Add("New Year"); 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 holidays Dim calendarProfile As VcCalenderProfile = calendar.CalendarProfileCollection.Add("YearProfile") calendarProfile.Type = VcCalendarProfileType.vcYearProfile Dim interval As VcInterval = calendarProfile.IntervalCollection.Add("New Year") interval.CalendarProfileName = "" interval.DayInStartMonth = 1 interval.StartMonth = VcMonth.vcJanuary interval.DayInEndMonth = 1 interval.EndMonth = VcMonth.vcJanuary SetAppearanceForHolidays(interval) interval = calendarProfile.IntervalCollection.Add("Christmas") interval.CalendarProfileName = "" interval.DayInStartMonth = 25 interval.StartMonth = VcMonth.vcDecember interval.DayInEndMonth = 26 interval.EndMonth = VcMonth.vcDecember SetAppearanceForHolidays(interval)
為了避免重復設置產(chǎn)生相同的假期外觀,我們使用名為SetAppearanceForHolidays的方法收集調用:
示例代碼C#
// Method to set the visual appearance of holidays void 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 holidays Private 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 = True End Sub
請注意:顏色屬性僅在其CalendarProfileName設置為<WORK>或<NONWORK>的間隔內有效。另外,間隔屬性UseGraphicalAttribute需要設置為true。對于calenderGrid屬性UseGraphicalAttributesOfIntervals同樣如此。
每年必須計算浮動假期(例如復活節(jié))和其他依賴于它們的假期,并且需要將其作為固定日期分配給日歷。下面的方法對此非常有用:
示例代碼C#
// Method to find floating holidays public enum Anniversary { AshWednesday, GoodFriday, EasterSunday, EasterMonday, FeastOfCorpusChristi, AscensionOfChrist, WhitSunday, WhitMonday, CentralEuropeanSummerTimeStart, CentralEuropeanSummerTimeEnd } private DateTime calculateAnniversaryForYear(int year, Anniversary specialDay) { 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 CentralEuropeanSummerTimeEnd End Enum Private 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 floating holidays into an interval interval = 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 floating holidays into an interval interval = calendar.IntervalCollection.Add("Weekly_Pattern") interval.CalendarProfileName = "WeekProfile" interval = calendar.IntervalCollection.Add("Yearly_Pattern") interval.CalendarProfileName = "YearProfile" Dim startYear As Integer = vcGantt1.TimeScaleStart.Year Dim endYear As Integer = vcGantt1.TimeScaleEnd.Year Dim i As Integer For 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) Next vcGantt1.CalendarCollection.Update()
這些是組裝日歷所需的摘要步驟。根據(jù)要求,可以省略單個步驟:
1、創(chuàng)建不同工作日的日配置文件
2、通過使用日配置文件組裝周配置文件
3、定義假期資料
4、將周配置文件和假日配置文件分配給日歷的間隔集合
5、為間隔集合分配其他日期(例如浮動假期)
間隔對象允許定義可解釋為工作時間或非工作時間的時間段。通過CalendarProfileName屬性將句點區(qū)分為<WORK>或<NONWORK>。通過此屬性,日歷還可以引用其他現(xiàn)有配置文件并采用其設置。設置此屬性時,請注意,根據(jù)間隔類型,只能分配某些配置文件類型。間隔類型由選定的配置文件類型隱式選擇。日歷配置文件的預設默認值vcDayProfile可以在初始時(即在定義間隔之前)通過相應的設置進行修改。
配置文件類型建議允許的間隔類型。例如,日期配置文件始終需要vcDayProfileInterval類型的間隔。
日歷配置文件可以顯示類型為日配置文件、周配置文件、年配置文件和變量配置文件。在一天配置文件中,只能通過在一天的限制范圍內的時鐘時間來定義間隔。一周配置文件包含要在某些天應用的日期配置文件。年份配置文件分配選定的一天配置文件,這些配置文件適用于單個重復日期或幾個重復日期。變量配置文件包含一系列不同的工作時間。根據(jù)間隔類型vcCalendarInterval、vcDayProfileInterval、vcWeekProfileInterval、vcYearProfileInterval和vcVariableProfileInterval,僅對象的某些屬性是相關的。下表映射了概要文件類型和相關屬性。
CalendarInterval在精確定義的間隔中描述了唯一的時間跨度。例:2010年5月5日從11:30時到2010年9月15日17:00時。
YearProfileInterval允許定義每年重復一次的天數(shù)或時間跨度。例:5月1日或12月24日至26日。
WeekProfileInterval處理一周中的一天或幾天。例:星期六或星期一至星期五。
DayProfileInterval處理一天之內的時間規(guī)格。例:8.00時至17.00時。
VariableProfile描述了時間跨度,而不引用定義的日期或時間。時間間隔的單位可以是天、小時、分鐘或秒,并且由時間間隔對象的屬性TimeUnit指定。示例:4小時。
本教程內容尚未完結哦,后續(xù)將會更新.NET版本中如何使用日歷的“如何使用日歷進行計算”,感興趣的朋友可以繼續(xù)關注我們哦~您也可以下載VARCHART XGantt免費版體驗一下~
相關內容推薦:
VARCHART XGantt用戶手冊(.NET版):如何使用日歷(上)
想要購買VARCHART XGantt正版授權,或了解更多產(chǎn)品信息請點擊
1024,慧都致敬程序員們,zend現(xiàn)金優(yōu)惠券限時放送,只剩最后一天了!!!
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn