VARCHART XGantt系列教程:.NET最佳实践 – 通过表交互式交换任务

VARCHART XGantt是一款功能强大的Gantt控件(.NET和ActiveX版),可让您轻松创建智能甘特图。最近,我们的一位客户联系了我们,他遇到了一个非常复杂的问题,希望我们可以帮助他解决。我确信其他使用VARCHART XGantt的开发人员也会对我们提出的方法感兴趣,因此我决定简要介绍一下问题及其解决方案。

该方法涉及通过表交互式交换任务,因此,调整它们必须处理的顺序。

VARCHART XGantt最新版免费下载试用

初步情况

客户已经开发出一个图形规划板,用于使用VARCHART XGantt .NET版管理他的机器。在机器上,任务按顺序运行,没有缓冲时间。在计划表的表格区域中,相应地列出了任务,这些任务按开始日期排序。这在甘特区显示为“下降楼梯”。

VARCHART XGantt系列教程:.NET最佳实践 - 通过表交互式交换任务

需求

客户希望能够通过拖放和仅在表区域中更改机器内的任务顺序。从技术上讲,这个问题必须通过制作一个已经在表格中移动的任务来实现,例如,已经放置它的任务的前身(及时)。为此,需要相应地改变任务的进程顺序。例如,如果任务2和任务3必须交换,则应如下所示:

移动前:

VARCHART XGantt系列教程:.NET最佳实践 - 通过表交互式交换任务

移动后:

VARCHART XGantt系列教程:.NET最佳实践 - 通过表交互式交换任务

解决方案

在VARCHART XGantt中以交互方式移动节点会触发事件VcNodeModifying和VcNodeModifiedEx。

VcNodemodifying首先检查任务是否已被移动到另一个组,因为根据规范,这不应该被允许。为了实现这一点,需要检查,无论是在移动任务之后,其Machine数据字段(分组字段)的内容是否已经改变。如果内容已更改,则ReturnStatus将设置为vcRetStatFalse,从而撤消移动。在这种情况下,事件VcNodeModifiedEx将不会出现。

private void vcGantt1_VcNodeModifying(object sender, VcNodeModifyingEventArgs e){   //Make sure that a task cannot be moved to another machine   string oldGroupName = e.OldNode.get_DataField(eMainData.Machine).ToString();   string newGroupName = e.Node.get_DataField(eMainData.Machine).ToString();   e.ReturnStatus = oldGroupName == newGroupName      VcReturnStatus.vcRetStatDefault : VcReturnStatus.vcRetStatFalse;}

如果允许移动任务(任务在其组内移动),则必须重新安排任务。这是通过搜索组中所有任务的最早开始日期在 VcNodeModifiedEx 事件中完成的。然后,您再次运行该组的所有任务,并重新计算其开始和结束日期,从最早的开始日期开始,并考虑相应的机器日历。在VcNodeCollection nodesInGroup中(请参阅代码!),节点按表中显示的顺序列出。

private void vcGantt1_VcNodeModifiedEx(object sender, VcNodeModifiedExEventArgs e){   DateTime minStartDate = DateTime.MaxValue;   DateTime startDate;   DateTime endDate;   VcCalendar cal =       vcGantt1.CalendarCollection.CalendarByName(e.Node.get_DataField(eMainData.Machine).ToString());   VcNodeCollection nodesInGroup = e.Node.SuperGroup.NodeCollection;   //Mark the moved node as "moved"   e.Node.set_DataField(eMainData._Moved, "1");   e.Node.Update();   //Search for the earliest start date of the nodes in the group   foreach (VcNode node in nodesInGroup)   {      startDate = Convert.ToDateTime(node.get_DataField(eMainData.Start));      minStartDate = (startDate < minStartDate startDate : minStartDate);   }   startDate = minStartDate;   //Reposition the tasks on the machine so that they follow each other    //without gaps or overlaps.   vcGantt1.SuspendUpdate(true);   foreach (VcNode node in nodesInGroup)   {      endDate = cal.AddDuration(startDate, Convert.ToInt32(node.get_DataField(eMainData.Duration)));      node.set_DataField(eMainData.Start, startDate);      node.set_DataField(eMainData.End, endDate);      node.Update();      startDate = (cal.IsWorktime(endDate) endDate : cal.GetStartOfNextWorktime(endDate));   }   vcGantt1.SuspendUpdate(false);}

重新计算日期后,任务将再次显示为降序楼梯。

VARCHART XGantt系列教程:.NET最佳实践 - 通过表交互式交换任务
想要购买 VARCHART XGantt 正版授权,或者获取更多该产品有趣的可视化技巧的朋友可以点击”咨询在线客服”哦~

标签:甘特图甘特图开发资源优化资源管理

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

上一篇 2018年9月20日
下一篇 2018年9月21日

相关推荐

发表回复

登录后才能评论