VARCHART XGantt用戶手冊(cè)(.NET版):如何使用日歷(上)
VARCHART XGantt是一個(gè)交互式的甘特圖控件,其模塊化的設(shè)計(jì)讓您可以創(chuàng)建滿足您和您的客戶所需求的應(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)版
日歷表示工作時(shí)間和非工作時(shí)間的無(wú)間隔序列。在具有可變配置文件的日歷(輪班日歷)中,不同的時(shí)間段會(huì)重復(fù)成功,例如早、晚或夜班。日歷本身沒(méi)有視覺(jué)外觀,僅是工作時(shí)間和非工作時(shí)間的邏輯區(qū)別。只有將日歷分配給CalendarGrid對(duì)象,日歷才能變得可見(jiàn)。
在VARCHART XGantt中,日歷還可以從工期中得出節(jié)點(diǎn)的開(kāi)始和結(jié)束日期。如果未設(shè)置其他選項(xiàng),則將使用名為BaseCalendar的預(yù)定義基本日歷進(jìn)行所有計(jì)算。在基本日歷中,將星期一至星期五定義為工作時(shí)間,而星期日和星期六則不工作。如果需要,可以修改基本日歷。
定義日歷
日歷可以在設(shè)計(jì)時(shí)通過(guò)屬性頁(yè)定義,也可以在運(yùn)行時(shí)通過(guò)應(yīng)用程序編程接口(API)定義。在本教程中,我們將從開(kāi)發(fā)人員的角度解釋日歷的基本處理,并提供一些C#編程示例。
在VcGantt控件中,存在一個(gè)對(duì)象VcCalendarCollection,它負(fù)責(zé)管理所有日歷。它具有與VARCHART XGantt中的其他集合類似的管理功能。預(yù)定義的BaseCalendar和在設(shè)計(jì)時(shí)創(chuàng)建的任何其他日歷會(huì)自動(dòng)構(gòu)成集合的一部分。
可以通過(guò)CalendarCollection對(duì)象的Add方法創(chuàng)建一個(gè)新日歷。該方法需要唯一的名稱才能識(shí)別日歷。最初,新日歷僅由工作時(shí)間組成。
請(qǐng)注意:日歷必須至少包含一個(gè)時(shí)間間隔,因?yàn)椴荒艽嬖诎枪ぷ鲿r(shí)間的日歷。
為了使我們的編程示例的結(jié)果可在甘特圖的圖片中得到驗(yàn)證,為編程示例中的時(shí)間范圍定義了從2011年1月1日到2011年12月31日的恒定時(shí)間段。如果日歷在集合中被激活,則日歷只能在甘特圖的背景中可見(jiàn):
示例代碼C#
// Creating and activating a new calendar vcGantt1.TimeScaleEnd = new DateTime(2012, 1, 1); vcGantt1.TimeScaleStart = new DateTime(2011, 1, 1); VcCalendar calendar = vcGantt1.CalendarCollection.Add("CompanyCalendar1"); vcGantt1.CalendarCollection.Active = calendar;
示例代碼VB.NET
'Creating and activating a new calendar vcGantt1.TimeScaleEnd = New DateTime(2012, 1, 1) vcGantt1.TimeScaleStart = New DateTime(2011, 1, 1) Dim calendar As VcCalendar = vcGantt1.CalendarCollection.Add("CompanyCalendar1") vcGantt1.CalendarCollection.Active = calendar
如果現(xiàn)在希望重新激活默認(rèn)的基本日歷,則可以通過(guò)以下設(shè)置來(lái)執(zhí)行此操作:
示例代碼C#
// Re-activating the default calendar VcCalendar calendar = vcGantt1.CalendarCollection.CalendarByName("BaseCalendar"); vcGantt1.CalendarCollection.Active = calendar;
示例代碼VB.NET
' Re-activating the default calendar Dim calendar As VcCalendar = vcGantt1.CalendarCollection.CalendarByName("BaseCalendar") vcGantt1.CalendarCollection.Active = calendar
在下面的示例中,我們將顯示如何按時(shí)間間隔定義工作時(shí)間配置文件。定義非工作日的不規(guī)則模式:2011年1月1日以及2011年1月6日至1月20日,除了10日和11日的兩天:
示例代碼C#
// Defining non-working times vcGantt1.TimeScaleEnd = new DateTime(2012, 1, 1); vcGantt1.TimeScaleStart = new DateTime(2011, 1, 1); VcCalendar calendar = vcGantt1.CalendarCollection.Add("CompanyCalendar1"); vcGantt1.CalendarCollection.Active = calendar; VcInterval interval = calendar.IntervalCollection.Add("NewYear"); interval.CalendarProfileName = ""; interval.StartDateTime = new DateTime(2011, 1, 1); interval.EndDateTime = new DateTime(2011, 1, 2); interval = calendar.IntervalCollection.Add("NonworkPeriod"); interval.CalendarProfileName = ""; interval.StartDateTime = new DateTime(2011, 1, 6); interval.EndDateTime = new DateTime(2011, 1, 21); interval = calendar.IntervalCollection.Add("WorkPeriod"); interval.CalendarProfileName = ""; interval.StartDateTime = new DateTime(2011, 1, 11); interval.EndDateTime = new DateTime(2011, 1, 13); vcGantt1.CalendarCollection.Update();
示例代碼VB.NET
' Defining non-working times vcGantt1.TimeScaleEnd = New DateTime(2012, 1, 1) vcGantt1.TimeScaleStart = New DateTime(2011, 1, 1) Dim calendar As VcCalendar = vcGantt1.CalendarCollection.Add("CompanyCalendar1") vcGantt1.CalendarCollection.Active = calendar Dim interval As VcInterval = calendar.IntervalCollection.Add("NewYear") interval.CalendarProfileName = "" interval.StartDateTime = New DateTime(2011, 1, 1) interval.EndDateTime = New DateTime(2011, 1, 2) interval = calendar.IntervalCollection.Add("NonworkPeriod") interval.CalendarProfileName = "" interval.StartDateTime = New DateTime(2011, 1, 6) interval.EndDateTime = New DateTime(2011, 1, 21) interval = calendar.IntervalCollection.Add("WorkPeriod") interval.CalendarProfileName = "" interval.StartDateTime = New DateTime(2011, 1, 11) interval.EndDateTime = New DateTime(2011, 1, 13) vcGantt1.CalendarCollection.Update()
在視覺(jué)上,可以通過(guò)淺灰色陰影來(lái)識(shí)別非工作時(shí)間。由于默認(rèn)情況下工作時(shí)間沒(méi)有顏色,因此圖表的白色背景在其中仍然可見(jiàn)。在下一步中,我們希望工作時(shí)間以淺黃色顯示,非工作時(shí)間以淺藍(lán)色顯示。顏色由可在間隔處定義的圖形屬性產(chǎn)生。
示例代碼C#
// Assigning colors to intervals vcGantt1.TimeScaleEnd = new DateTime(2012, 1, 1); vcGantt1.TimeScaleStart = new DateTime(2011, 1, 1); VcCalendar calendar = vcGantt1.CalendarCollection.Add("CompanyCalendar1"); vcGantt1.CalendarCollection.Active = calendar; vcGantt1.TimeScaleCollection.FirstTimeScale().get_Section(0). get_CalendarGrid(0).UseGraphicalAttributesOfIntervals = true; VcInterval interval = calendar.IntervalCollection.Add("Work"); interval.CalendarProfileName = ""; interval.BackgroundColor = Color.LightYellow; interval.UseGraphicalAttributes = true; VcInterval interval = calendar.IntervalCollection.Add("NewYear"); interval.CalendarProfileName = ""; interval.StartDateTime = new DateTime(2011, 1, 1); interval.EndDateTime = new DateTime(2011, 1, 2); interval.BackgroundColor = Color.FromArgb(212,227,245); interval.UseGraphicalAttributes = true; interval = calendar.IntervalCollection.Add("NonworkPeriod"); interval.CalendarProfileName = ""; interval.StartDateTime = new DateTime(2011, 1, 6); interval.EndDateTime = new DateTime(2011, 1, 21); interval.BackgroundColor = Color.FromArgb(212,227,245); interval.UseGraphicalAttributes = true; interval = calendar.IntervalCollection.Add("WorkPeriod"); interval.CalendarProfileName = ""; interval.StartDateTime = new DateTime(2011, 1, 11); interval.EndDateTime = new DateTime(2011, 1, 13); interval.BackgroundColor = Color.LightYellow; interval.UseGraphicalAttributes = true; vcGantt1.CalendarCollection.Update();
示例代碼VB.NET
' Assigning colors to intervals vcGantt1.TimeScaleEnd = New DateTime(2012, 1, 1) vcGantt1.TimeScaleStart = New DateTime(2011, 1, 1) Dim calendar As VcCalendar = vcGantt1.CalendarCollection.Add("CompanyCalendar1") vcGantt1.CalendarCollection.Active = calendar Dim get_CalendarGrid(0).UseGraphicalAttributesOfIntervals As vcGantt1.TimeScaleCollection.FirstTimeScale().get_Section(0). = True Dim interval As VcInterval = calendar.IntervalCollection.Add("Work") interval.CalendarProfileName = "" interval.BackgroundColor = Color.LightYellow interval.UseGraphicalAttributes = True interval = calendar.IntervalCollection.Add("NewYear") interval.CalendarProfileName = "" interval.StartDateTime = New DateTime(2011, 1, 1) interval.EndDateTime = New DateTime(2011, 1, 2) interval.BackgroundColor = Color.FromArgb(212,227,245) interval.UseGraphicalAttributes = True interval = calendar.IntervalCollection.Add("NonworkPeriod") interval.CalendarProfileName = "" interval.StartDateTime = New DateTime(2011, 1, 6) interval.EndDateTime = New DateTime(2011, 1, 21) interval.BackgroundColor = Color.FromArgb(212,227,245) interval.UseGraphicalAttributes = True interval = calendar.IntervalCollection.Add("WorkPeriod") interval.CalendarProfileName = "" interval.StartDateTime = New DateTime(2011, 1, 11) interval.EndDateTime = New DateTime(2011, 1, 13) interval.BackgroundColor = Color.LightYellow interval.UseGraphicalAttributes = True vcGantt1.CalendarCollection.Update()
下面的示例顯示如何定義一個(gè)星期,其中星期一至星期五為工作時(shí)間,而周末為空閑時(shí)間。到目前為止引入的選項(xiàng)還不足以滿足此要求;必須提供VcCalendarProfile類型的對(duì)象。
請(qǐng)注意:在VARCHART XGantt中,可以在全局或局部級(jí)別上定義VcCalendarProfile對(duì)象。本地日歷配置文件對(duì)象只能在定義它們的日歷中使用,而全局對(duì)象可以同時(shí)在不同的日歷中使用。在我們的編程示例中,僅使用本地日歷配置文件對(duì)象。就功能而言,本地日歷與全局日歷沒(méi)有區(qū)別。如果創(chuàng)建了具有相同名稱的本地配置文件和全局配置文件,則在相應(yīng)的日歷內(nèi)僅對(duì)本地配置文件進(jìn)行尋址;無(wú)法訪問(wèn)全局配置文件。
vcWeekProfile類型的日歷配置文件允許描述一周中某天的工作時(shí)間和非工作時(shí)間。僅在將周配置文件添加到日歷的間隔集合后,該配置文件才生效??梢允÷栽O(shè)置StartDateTime和EndDateTime,因?yàn)槲覀兿M覀兊脑O(shè)置在日歷的整個(gè)期間內(nèi)都是有效的,沒(méi)有任何限制。預(yù)設(shè)名稱<WORK>和<NONWORK>的日歷配置文件具有定義的含義:它們用于分配工作時(shí)間和非工作時(shí)間。
示例代碼C#
// Defining a week profile VcCalendarProfile calendarProfile = calendar.CalendarProfileCollection.Add("WeekProfile"); calendarProfile.Type = VcCalendarProfileType.vcWeekProfile; VcInterval interval = calendarProfile.IntervalCollection.Add("Mo-Fr"); interval.CalendarProfileName = ""; interval.StartWeekday = VcWeekday.vcMonday; interval.EndWeekday = VcWeekday.vcFriday; interval = calendarProfile.IntervalCollection.Add("Sa"); interval.CalendarProfileName = ""; interval.BackgroundColor = Color.FromArgb(255, 246, 159); interval.StartWeekday = VcWeekday.vcSaturday; interval.EndWeekday = VcWeekday.vcSaturday; interval = calendarProfile.IntervalCollection.Add("So"); interval.CalendarProfileName = ""; interval.BackgroundColor = Color.FromArgb(251, 211, 170); interval.StartWeekday = VcWeekday.vcSunday; interval.EndWeekday = VcWeekday.vcSunday; interval = calendar.IntervalCollection.Add("StandardWeek"); interval.CalendarProfileName = "WeekProfile";
示例代碼VB.NET
' Defining a week profile dim calendarProfile as VcCalendarProfile Set calendar.Profile = VcGantt1.CalendarProfileCollection.Add("WeekProfile") calendarProfile.Type = VcCalendarProfileType.vcWeekProfile VcInterval interval = calendarProfile.IntervalCollection.Add("Mo-Fr") interval.CalendarProfileName = "" interval.StartWeekday = VcWeekday.vcMonday interval.EndWeekday = VcWeekday.vcFriday interval = calendarProfile.IntervalCollection.Add("Sa") interval.CalendarProfileName = "" interval.BackgroundColor = Color.FromArgb(255, 246, 159) interval.StartWeekday = VcWeekday.vcSaturday interval.EndWeekday = VcWeekday.vcSaturday interval = calendarProfile.IntervalCollection.Add("Su") interval.CalendarProfileName = "" interval.BackgroundColor = Color.FromArgb(251, 211, 170) interval.StartWeekday = VcWeekday.vcSunday interval.EndWeekday = VcWeekday.vcSunday interval = calendar.IntervalCollection.Add("StandardWeek") interval.CalendarProfileName = "WeekProfile"
本教程內(nèi)容尚未完結(jié),想要了解更多產(chǎn)品文章請(qǐng)繼續(xù)關(guān)注我們!您也可以下載VARCHART XGantt試用版嘗試一下~
相關(guān)內(nèi)容推薦:
VARCHART XGantt用戶手冊(cè)(ActiveX版):如何使用日歷(上)
VARCHART XGantt用戶手冊(cè)(ActiveX版):如何使用日歷(中)
VARCHART XGantt用戶手冊(cè)(ActiveX版):如何使用日歷(下)
想要購(gòu)買VARCHART XGantt正版授權(quán),或了解更多產(chǎn)品信息請(qǐng)點(diǎn)擊“咨詢?cè)诰€客服”
1024,慧都致敬程序員們,zend現(xiàn)金優(yōu)惠券限時(shí)放送,了解詳情請(qǐng)點(diǎn)擊下方圖片