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 calendarvcGantt1.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 calendarvcGantt1.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 calendarVcCalendar calendar =vcGantt1.CalendarCollection.CalendarByName("BaseCalendar");vcGantt1.CalendarCollection.Active = calendar;
示例代码VB.NET
' Re-activating the default calendarDim 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 timesvcGantt1.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 timesvcGantt1.TimeScaleEnd = New DateTime(2012, 1, 1)vcGantt1.TimeScaleStart = New DateTime(2011, 1, 1)Dim calendar As VcCalendar =vcGantt1.CalendarCollection.Add("CompanyCalendar1")vcGantt1.CalendarCollection.Active = calendarDim 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 intervalsvcGantt1.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 intervalsvcGantt1.TimeScaleEnd = New DateTime(2012, 1, 1)vcGantt1.TimeScaleStart = New DateTime(2011, 1, 1)Dim calendar As VcCalendar =vcGantt1.CalendarCollection.Add("CompanyCalendar1")vcGantt1.CalendarCollection.Active = calendarDim get_CalendarGrid(0).UseGraphicalAttributesOfIntervals AsvcGantt1.TimeScaleCollection.FirstTimeScale().get_Section(0). = TrueDim interval As VcInterval = calendar.IntervalCollection.Add("Work")interval.CalendarProfileName = "" interval.BackgroundColor = Color.LightYellowinterval.UseGraphicalAttributes = Trueinterval = 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 = Trueinterval = 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 = Trueinterval = calendar.IntervalCollection.Add("WorkPeriod")interval.CalendarProfileName = ""interval.StartDateTime = New DateTime(2011, 1, 11)interval.EndDateTime = New DateTime(2011, 1, 13)interval.BackgroundColor = Color.LightYellowinterval.UseGraphicalAttributes = TruevcGantt1.CalendarCollection.Update()

下面的示例显示如何定义一个星期,其中星期一至星期五为工作时间,而周末为空闲时间。到目前为止引入的选项还不足以满足此要求;必须提供VcCalendarProfile类型的对象。
请注意:在VARCHART XGantt中,可以在全局或局部级别上定义VcCalendarProfile对象。本地日历配置文件对象只能在定义它们的日历中使用,而全局对象可以同时在不同的日历中使用。在我们的编程示例中,仅使用本地日历配置文件对象。就功能而言,本地日历与全局日历没有区别。如果创建了具有相同名称的本地配置文件和全局配置文件,则在相应的日历内仅对本地配置文件进行寻址;无法访问全局配置文件。
vcWeekProfile类型的日历配置文件允许描述一周中某天的工作时间和非工作时间。仅在将周配置文件添加到日历的间隔集合后,该配置文件才生效。可以省略设置StartDateTime和EndDateTime,因为我们希望我们的设置在日历的整个期间内都是有效的,没有任何限制。预设名称<WORK>和<NONWORK>的日历配置文件具有定义的含义:它们用于分配工作时间和非工作时间。
示例代码C#
// Defining a week profileVcCalendarProfile 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 profiledim calendarProfile as VcCalendarProfileSet calendar.Profile =VcGantt1.CalendarProfileCollection.Add("WeekProfile")calendarProfile.Type = VcCalendarProfileType.vcWeekProfileVcInterval interval = calendarProfile.IntervalCollection.Add("Mo-Fr")interval.CalendarProfileName = ""interval.StartWeekday = VcWeekday.vcMondayinterval.EndWeekday = VcWeekday.vcFridayinterval = calendarProfile.IntervalCollection.Add("Sa")interval.CalendarProfileName = ""interval.BackgroundColor = Color.FromArgb(255, 246, 159)interval.StartWeekday = VcWeekday.vcSaturdayinterval.EndWeekday = VcWeekday.vcSaturdayinterval = calendarProfile.IntervalCollection.Add("Su")interval.CalendarProfileName = ""interval.BackgroundColor = Color.FromArgb(251, 211, 170)interval.StartWeekday = VcWeekday.vcSundayinterval.EndWeekday = VcWeekday.vcSundayinterval = calendar.IntervalCollection.Add("StandardWeek") interval.CalendarProfileName = "WeekProfile"
本教程内容尚未完结,想要了解更多产品文章请继续关注我们!您也可以下载VARCHART XGantt试用版尝试一下~
相关内容推荐:
VARCHART XGantt用户手册(ActiveX版):如何使用日历(上)
VARCHART XGantt用户手册(ActiveX版):如何使用日历(中)
VARCHART XGantt用户手册(ActiveX版):如何使用日历(下)
VARCHART XGantt用户手册>>>
想要购买VARCHART XGantt正版授权,或了解更多产品信息请点击“咨询在线客服”
1024,致敬程序员们,zend现金优惠券限时放送,了解详情请点击下方图片

标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!