VARCHART XGantt .NET的最佳实践:通过表交互式交换任务

VARCHART XGantt是一款功能强大的甘特图控件,其模块化的设计让您可以创建满足需要的应用程序。XGantt可用于.NET,ActiveX和ASP.NET应用程序,可以快速、简单地集成到您的应用程序中,帮助您识别性能瓶颈、避免延迟以及高效利用资源,使复杂数据变得更加容易理解。

XGantt展示图

本文主要通过利用VARCHART XGantt来处理文章提及的可能发生的情况,向大家展示VARCHART XGantt.NET的最佳实践,即通过表交互式交换任务。


项目情况

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


项目需求

客户希望能够仅在表区域中通过拖放更改机器内的任务顺序。从技术上讲,这个问题必须通过制作一个已经在表格中移动的任务来实现。需要相应地改变任务的进程顺序,如下所示:

移动前

移动后


解决方案

VARCHART XGantt中以交互方式移动节点会触发事件VcNodeModifyingVcNodeModifiedEx

VcNodemodifying首先检查任务是否已被移动到另一个组,因为根据规范这是违规的。需要检查在移动任务之后其机器数据字段的内容是否已经改变。如果内容已更改,则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);

}

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


查看转载原文请点击这里

猜你喜欢

转载自blog.csdn.net/ymy_666666/article/details/85265294