翻譯|使用教程|編輯:莫成敏|2019-10-24 10:26:23.257|閱讀 253 次
概述:VARCHART XGantt是用于工業(yè)4.0項(xiàng)目管理、交互式的甘特圖絕佳解決方案,世界級(jí)甘特圖大師。本教程介紹如何使用日歷(.NET版本內(nèi)容),文章內(nèi)容較多,本文主要介紹定義日歷的后半部分內(nèi)容~
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
VARCHART XGantt是一個(gè)交互式的甘特圖控件,其模塊化的設(shè)計(jì)讓您可以創(chuàng)建滿(mǎn)足您和您的客戶(hù)所需求的應(yīng)用程序。相較于其他甘特圖控件,VARCHART XGantt穩(wěn)定性高,開(kāi)發(fā)時(shí)間長(zhǎng),各大行業(yè)的知名公司都在使用它。本文主要描述了如何使用日歷教程中的定義日歷的后面部分內(nèi)容,現(xiàn)在跟著小編來(lái)了解一下吧~
點(diǎn)擊下載VARCHART XGantt免費(fèi)版
區(qū)分一天中的工作時(shí)間和非工作時(shí)間需要一個(gè)日配置文件,該日配置文件可以指定精確的時(shí)鐘時(shí)間,例如從8.00 h到12.00 h am和從1.00 h到5.00 h pm。由于新創(chuàng)建的日配置文件僅包含工作時(shí)間,因此任何中斷都應(yī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)
時(shí)鐘時(shí)間由對(duì)象DateTime設(shè)置。日期部分被忽略,因?yàn)樵谶@種情況下它毫無(wú)意義。只需要在構(gòu)造函數(shù)中設(shè)置日期,即可為構(gòu)造函數(shù)所需的所有參數(shù)設(shè)置一個(gè)值。在Interval_3中,指定0h或24h是很重要的,因?yàn)楹笳咴?strong>DateTime對(duì)象中不被接受。
一年中的定期日期(例如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)
為了避免重復(fù)設(shè)置產(chǎn)生相同的假期外觀,我們使用名為SetAppearanceForHolidays的方法收集調(diào)用:
示例代碼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
請(qǐng)注意:顏色屬性?xún)H在其CalendarProfileName設(shè)置為<WORK>或<NONWORK>的間隔內(nèi)有效。另外,間隔屬性UseGraphicalAttribute需要設(shè)置為true。對(duì)于calenderGrid屬性UseGraphicalAttributesOfIntervals同樣如此。
每年必須計(jì)算浮動(dòng)假期(例如復(fù)活節(jié))和其他依賴(lài)于它們的假期,并且需要將其作為固定日期分配給日歷。下面的方法對(duì)此非常有用:
示例代碼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
在下一步中,將周配置文件和假日配置文件作為間隔分配給日歷。然后以相同的方式計(jì)算浮動(dòng)假期并將其分配給日歷:
示例代碼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ù)要求,可以省略單個(gè)步驟:
1、創(chuàng)建不同工作日的日配置文件
2、通過(guò)使用日配置文件組裝周配置文件
3、定義假期資料
4、將周配置文件和假日配置文件分配給日歷的間隔集合
5、為間隔集合分配其他日期(例如浮動(dòng)假期)
間隔對(duì)象允許定義可解釋為工作時(shí)間或非工作時(shí)間的時(shí)間段。通過(guò)CalendarProfileName屬性將句點(diǎn)區(qū)分為<WORK>或<NONWORK>。通過(guò)此屬性,日歷還可以引用其他現(xiàn)有配置文件并采用其設(shè)置。設(shè)置此屬性時(shí),請(qǐng)注意,根據(jù)間隔類(lèi)型,只能分配某些配置文件類(lèi)型。間隔類(lèi)型由選定的配置文件類(lèi)型隱式選擇。日歷配置文件的預(yù)設(shè)默認(rèn)值vcDayProfile可以在初始時(shí)(即在定義間隔之前)通過(guò)相應(yīng)的設(shè)置進(jìn)行修改。
配置文件類(lèi)型建議允許的間隔類(lèi)型。例如,日期配置文件始終需要vcDayProfileInterval類(lèi)型的間隔。
日歷配置文件可以顯示類(lèi)型為日配置文件、周配置文件、年配置文件和變量配置文件。在一天配置文件中,只能通過(guò)在一天的限制范圍內(nèi)的時(shí)鐘時(shí)間來(lái)定義間隔。一周配置文件包含要在某些天應(yīng)用的日期配置文件。年份配置文件分配選定的一天配置文件,這些配置文件適用于單個(gè)重復(fù)日期或幾個(gè)重復(fù)日期。變量配置文件包含一系列不同的工作時(shí)間。根據(jù)間隔類(lèi)型vcCalendarInterval、vcDayProfileInterval、vcWeekProfileInterval、vcYearProfileInterval和vcVariableProfileInterval,僅對(duì)象的某些屬性是相關(guān)的。下表映射了概要文件類(lèi)型和相關(guān)屬性。
CalendarInterval在精確定義的間隔中描述了唯一的時(shí)間跨度。例:2010年5月5日從11:30時(shí)到2010年9月15日17:00時(shí)。
YearProfileInterval允許定義每年重復(fù)一次的天數(shù)或時(shí)間跨度。例:5月1日或12月24日至26日。
WeekProfileInterval處理一周中的一天或幾天。例:星期六或星期一至星期五。
DayProfileInterval處理一天之內(nèi)的時(shí)間規(guī)格。例:8.00時(shí)至17.00時(shí)。
VariableProfile描述了時(shí)間跨度,而不引用定義的日期或時(shí)間。時(shí)間間隔的單位可以是天、小時(shí)、分鐘或秒,并且由時(shí)間間隔對(duì)象的屬性TimeUnit指定。示例:4小時(shí)。
本教程內(nèi)容尚未完結(jié)哦,后續(xù)將會(huì)更新.NET版本中如何使用日歷的“如何使用日歷進(jìn)行計(jì)算”,感興趣的朋友可以繼續(xù)關(guān)注我們哦~您也可以下載VARCHART XGantt免費(fèi)版體驗(yàn)一下~
相關(guān)內(nèi)容推薦:
VARCHART XGantt用戶(hù)手冊(cè)(.NET版):如何使用日歷(上)
VARCHART XGantt用戶(hù)手冊(cè)>>>
想要購(gòu)買(mǎi)VARCHART XGantt正版授權(quán),或了解更多產(chǎn)品信息請(qǐng)點(diǎn)擊
1024,慧都致敬程序員們,zend現(xiàn)金優(yōu)惠券限時(shí)放送,只剩最后一天了!!!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn