翻譯|使用教程|編輯:莫成敏|2019-10-23 09:59:38.930|閱讀 342 次
概述:VARCHART XGantt是用于工業4.0項目管理、交互式的甘特圖絕佳解決方案,世界級甘特圖大師。本教程介紹如何使用日歷(.NET版本內容),文章內容較多,本文主要介紹定義日歷的前部分內容~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
VARCHART XGantt是一個交互式的甘特圖控件,其模塊化的設計讓您可以創建滿足您和您的客戶所需求的應用程序。相較于其他甘特圖控件,VARCHART XGantt穩定性高,開發時間長,各大行業的知名公司都在使用它。本文主要描述了如何使用日歷教程中的定義日歷的前面一部分內容,現在跟著小編來了解一下吧~
日歷表示工作時間和非工作時間的無間隔序列。在具有可變配置文件的日歷(輪班日歷)中,不同的時間段會重復成功,例如早、晚或夜班。日歷本身沒有視覺外觀,僅是工作時間和非工作時間的邏輯區別。只有將日歷分配給CalendarGrid對象,日歷才能變得可見。
在VARCHART XGantt中,日歷還可以從工期中得出節點的開始和結束日期。如果未設置其他選項,則將使用名為BaseCalendar的預定義基本日歷進行所有計算。在基本日歷中,將星期一至星期五定義為工作時間,而星期日和星期六則不工作。如果需要,可以修改基本日歷。
定義日歷
日歷可以在設計時通過屬性頁定義,也可以在運行時通過應用程序編程接口(API)定義。在本教程中,我們將從開發人員的角度解釋日歷的基本處理,并提供一些C#編程示例。
在VcGantt控件中,存在一個對象VcCalendarCollection,它負責管理所有日歷。它具有與VARCHART XGantt中的其他集合類似的管理功能。預定義的BaseCalendar和在設計時創建的任何其他日歷會自動構成集合的一部分。
可以通過CalendarCollection對象的Add方法創建一個新日歷。該方法需要唯一的名稱才能識別日歷。最初,新日歷僅由工作時間組成。
請注意:日歷必須至少包含一個時間間隔,因為不能存在包含非工作時間的日歷。
為了使我們的編程示例的結果可在甘特圖的圖片中得到驗證,為編程示例中的時間范圍定義了從2011年1月1日到2011年12月31日的恒定時間段。如果日歷在集合中被激活,則日歷只能在甘特圖的背景中可見:
示例代碼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
如果現在希望重新激活默認的基本日歷,則可以通過以下設置來執行此操作:
示例代碼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
在下面的示例中,我們將顯示如何按時間間隔定義工作時間配置文件。定義非工作日的不規則模式: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()
在視覺上,可以通過淺灰色陰影來識別非工作時間。由于默認情況下工作時間沒有顏色,因此圖表的白色背景在其中仍然可見。在下一步中,我們希望工作時間以淺黃色顯示,非工作時間以淺藍色顯示。顏色由可在間隔處定義的圖形屬性產生。
示例代碼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()
下面的示例顯示如何定義一個星期,其中星期一至星期五為工作時間,而周末為空閑時間。到目前為止引入的選項還不足以滿足此要求;必須提供VcCalendarProfile類型的對象。
請注意:在VARCHART XGantt中,可以在全局或局部級別上定義VcCalendarProfile對象。本地日歷配置文件對象只能在定義它們的日歷中使用,而全局對象可以同時在不同的日歷中使用。在我們的編程示例中,僅使用本地日歷配置文件對象。就功能而言,本地日歷與全局日歷沒有區別。如果創建了具有相同名稱的本地配置文件和全局配置文件,則在相應的日歷內僅對本地配置文件進行尋址;無法訪問全局配置文件。
vcWeekProfile類型的日歷配置文件允許描述一周中某天的工作時間和非工作時間。僅在將周配置文件添加到日歷的間隔集合后,該配置文件才生效。可以省略設置StartDateTime和EndDateTime,因為我們希望我們的設置在日歷的整個期間內都是有效的,沒有任何限制。預設名稱<WORK>和<NONWORK>的日歷配置文件具有定義的含義:它們用于分配工作時間和非工作時間。
示例代碼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"本教程內容尚未完結,想要了解更多產品文章請繼續關注我們!您也可以下載VARCHART XGantt試用版嘗試一下~
相關內容推薦:
VARCHART XGantt用戶手冊(ActiveX版):如何使用日歷(上)
VARCHART XGantt用戶手冊(ActiveX版):如何使用日歷(中)
VARCHART XGantt用戶手冊(ActiveX版):如何使用日歷(下)
想要購買VARCHART XGantt正版授權,或了解更多產品信息請點擊
1024,慧都致敬程序員們,zend現金優惠券限時放送,了解詳情請點擊下方圖片
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn