VARCHART XGantt用户手册(.NET版):如何使用日历(下)

VARCHART XGantt是用于工业4.0项目管理、交互式的甘特图绝佳解决方案,世界级甘特图大师。本教程介绍如何使用日历(.NET版本内容),文章内容较多,本文描述了使用日历的最后一部分内容——如何使用日历计算。

VARCHART XGantt是一个交互式的甘特图控件,其模块化的设计让您可以创建满足您和您的客户所需求的应用程序。相较于其他甘特图控件,VARCHART XGantt稳定性高,开发时间长,各大行业的知名公司都在使用它。本文主要描述了如何使用日历教程中的如何使用日历进行计算的内容,现在就跟着小编来了解一下吧~

VARCHART XGantt免费版

如何使用日历进行计算

日历中的计算不一定在时间范围内可见。对象CalendarAddDuration方法从开始日期和指定的工作时间单位数计算最终日期,同时考虑到非工作时间。传递负号的时间单位将导致从给定的结束日期开始计算开始日期。 CalcDuration方法是AddDuration方法的补充,它从给定的开始日期和结束日期计算工作时间单位(持续时间)数。

计算方法如何工作

请注意:指定为天、小时、分钟或秒的工作时间单位必须与VcGantt对象的属性TimeUnit定义的时间单位相对应。

AddDuration方法可确保所计算的日期始终位于工作时间间隔内。同时,如果源值位于非工作时间内,则后向计算不一定提供与前向计算的源值相等的结果。

计算的有限可逆性

以交互方式创建或修改活动时,VARCHART XGantt会自动注意活动无法在非工作时间内开始或结束。如果希望通过API创建或修改节点时行为保持一致,则需要通过手动更正开始日期或结束日期来确保这一点。为此,位于非工作时间中的开始日期需要移动到下一个工作时间间隔的开始,并且结束日期对应于上一个工作时间间隔的结束。有一些方法可以确定间隔的极限。

示例代码C#

if (calendar.IsWorkTime(startDate) == false) startDate = calendar.GetNextIntervalBorder(startDate);if (calendar.IsWorkTime(endDate) == false) endDate = calendar.GetStartOfInterval(endDate);

示例代码VB.NET

If calendar.IsWorkTime(startDate) = False Then startDate = calendar.GetNextIntervalBorder(startDate)End IfIf calendar.IsWorkTime(endDate) = False Then endDate = calendar.GetStartOfInterval(endDate)End If

夏令时

VARCHART XGantt自动支持夏令时。在中欧,DST从3月的最后一个星期日开始,到10月的最后一个星期日结束。在夏令时开始时,时钟从2:00 h延迟到3:00 h,在时钟结束时从3:00 h延迟到2:00 h。

开始夏令时:

VARCHART XGantt用户手册(.NET版):如何使用日历(下)

夏令时结束:

VARCHART XGantt用户手册(.NET版):如何使用日历(下)

如果将TimeUnit设置为小时,则在夏时制的开始日期,方法calcDuration检索23小时的时间跨度,而在最后一天,则返回25小时。如果设置为天,则两种情况下的时间跨度均为1天。

检索时间间隔的限制

Calendar对象用于检索时间间隔GetStartOfIntervalGetNextIntervalBorderGetPreviousIntervalBorder的限制的方法允许迭代工作时间间隔和非工作时间间隔。返回的结果是相对的,并以方法作为参数传递的参考日期为参考。

可以通过Calendar对象的IsWorkTime方法检查日期是否在工作时间或非工作时间。尽管新间隔的开始日期等于上一个间隔的结束日期,但是开始日期始终属于新间隔(向右打开)。

方法GetEndOfPreviousWorkTimeGetStartOfNextWorkTime不提供新的选项,而只是简化了工作时间间隔的处理。

在下面的编程示例中,将检索日历的时间间隔并将其写入文件。此外,计算给定期间内可用的工作时间:

示例代码C#

void writeCalendarIntervalsToFile (string filename, VcCalendar calendar,DateTime startDate, DateTime endDate,bool listWorkIntervals, bool listNonWorkIntervals){ TextWriter tw = newStreamWriter(Path.GetDirectoryName(Application.ExecutablePath) +filename); tw.WriteLine("Time Intervals of {0} between rn{1} - {2}rn",calendar.Name, startDate, endDate); DateTime tmpStartDate = startDate; while (tmpStartDate < endDate) { DateTime nextStartDate =calendar.GetNextIntervalBorder(tmpStartDate); if (tmpStartDate == nextStartDate) nextStartDate = endDate; if (nextStartDate > endDate) nextStartDate = endDate; if (calendar.IsWorktime(tmpStartDate)) if (listWorkIntervals) tw.WriteLine("{0} - {1} WorkInterval", tmpStartDate,nextStartDate); else if (listNonWorkIntervals) tw.WriteLine("{0} - {1} NonWorkInterval", tmpStartDate,nextStartDate); tmpStartDate = nextStartDate; } int totalWorkTime = calendar.CalcDuration(startDate, endDate); tw.WriteLine("Total work time: {0} Units", totalWorkTime); tw.Close();}

示例代码VB.NET

Private Sub writeCalendarIntervalsToFile(ByVal filename As String,ByVal calendar As VcCalendar, ByVal startDate As DateTime, ByVal endDateAs DateTime, ByVal listWorkIntervals As Boolean, ByVallistNonWorkIntervals As Boolean) Dim tw As TextWriter = NewStreamWriter(Path.GetDirectoryName(Application.ExecutablePath) +filename) tw.WriteLine("Time Intervals of {0} between rn{1} - {2}rn",calendar.Name, startDate, endDate) Dim tmpStartDate As DateTime = startDate While tmpStartDate < endDate Dim nextStartDate As DateTime =calendar.GetNextIntervalBorder(tmpStartDate) if (tmpStartDate = nextStartDate) nextStartDate = endDate if (nextStartDate > endDate) nextStartDate = endDate if (calendar.IsWorktime(tmpStartDate))  if (listWorkIntervals) tw.WriteLine("{0} - {1} WorkInterval", tmpStartDate,nextStartDate) else if (listNonWorkIntervals) tw.WriteLine("{0} - {1} NonWorkInterval", tmpStartDate,nextStartDate) tmpStartDate = nextStartDate End While Dim totalWorkTime As Integer =calendar.CalcDuration(startDate,endDate) tw.WriteLine("Total work time: {0} Units", totalWorkTime) tw.Close()End Sub

请注意:日历中的时间间隔可以精确地指定为秒,并且最多可以包含137年(以秒为单位)的间隔。

将时间间隔写入文件的代码

示例代码C#

writeCalendarIntervalsToFile("CalenderIntervals.txt", calendar,vcGantt1.TimeScaleStart, vcGantt1.TimeScaleEnd, true, true);Time Intervals of CompanyCalendar_1 between01.01.2011 00:00:00 - 01.01.2012 00:00:0001.01.2011 00:00:00 - 02.01.2011 00:00:00 non-work time02.01.2011 00:00:00 - 03.01.2011 00:00:00 non-work time03.01.2011 00:00:00 - 03.01.2011 08:00:00 non-work time03.01.2011 08:00:00 - 03.01.2011 12:00:00 work time03.01.2011 12:00:00 - 03.01.2011 13:00:00 non-work time03.01.2011 13:00:00 - 03.01.2011 17:00:00 work time03.01.2011 17:00:00 - 04.01.2011 00:00:00 non-work time04.01.2011 00:00:00 - 04.01.2011 08:00:00 non-work time04.01.2011 08:00:00 - 04.01.2011 12:00:00 work time04.01.2011 12:00:00 - 04.01.2011 13:00:00 non-work time04.01.2011 13:00:00 - 04.01.2011 17:00:00 work time04.01.2011 17:00:00 - 05.01.2011 00:00:00 non-work time...30.12.2011 00:00:00 - 30.12.2011 08:00:00 non-work time30.12.2011 08:00:00 - 30.12.2011 12:00:00 work time30.12.2011 12:00:00 - 30.12.2011 13:00:00 non-work time30.12.2011 13:00:00 - 30.12.2011 17:00:00 work time30.12.2011 17:00:00 - 31.12.2011 00:00:00 non-work time31.12.2011 00:00:00 - 01.01.2012 00:00:00 non-work timeTotal work time: 2064 Units

将时间间隔写入文件的代码

示例代码VB.NET

writeCalendarIntervalsToFile("CalenderIntervals.txt", calendar,vcGantt1.TimeScaleStart, vcGantt1.TimeScaleEnd, True, True) Time Intervals of CompanyCalendar_1 between01.01.2011 00:00:00 - 01.01.2012 00:00:0001.01.2011 00:00:00 - 02.01.2011 00:00:00 non-work time02.01.2011 00:00:00 - 03.01.2011 00:00:00 non-work time03.01.2011 00:00:00 - 03.01.2011 08:00:00 non-work time03.01.2011 08:00:00 - 03.01.2011 12:00:00 work time03.01.2011 12:00:00 - 03.01.2011 13:00:00 non-work time03.01.2011 13:00:00 - 03.01.2011 17:00:00 work time03.01.2011 17:00:00 - 04.01.2011 00:00:00 non-work time04.01.2011 00:00:00 - 04.01.2011 08:00:00 non-work time04.01.2011 08:00:00 - 04.01.2011 12:00:00 work time04.01.2011 12:00:00 - 04.01.2011 13:00:00 non-work time04.01.2011 13:00:00 - 04.01.2011 17:00:00 work time04.01.2011 17:00:00 - 05.01.2011 00:00:00 non-work time...30.12.2011 00:00:00 - 30.12.2011 08:00:00 non-work time30.12.2011 08:00:00 - 30.12.2011 12:00:00 work time30.12.2011 12:00:00 - 30.12.2011 13:00:00 non-work time30.12.2011 13:00:00 - 30.12.2011 17:00:00 work time30.12.2011 17:00:00 - 31.12.2011 00:00:00 non-work time31.12.2011 00:00:00 - 01.01.2012 00:00:00 non-work timeTotal work time: 2064 Units

本教程内容就是这样了,希望对您有所帮助!您可以继续关注我们了解更多甘特图相关文章资讯,您也可以下载VARCHART XGantt试用版体验一下~

相关内容推荐:

VARCHART XGantt用户手册(.NET版):如何使用日历(上)

VARCHART XGantt用户手册(.NET版):如何使用日历(中)

VARCHART XGantt用户手册>>>


想要购买VARCHART XGantt正版授权,或了解更多产品信息请点击“咨询在线客服”

1571968159.png

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年9月22日
下一篇 2019年9月22日

相关推荐

发表回复

登录后才能评论