VARCHART XGantt .NET的最佳實踐:通過表互動式交換任務
VARCHART XGantt是一款功能強大的甘特圖控制元件,其模組化的設計讓您可以建立滿足需要的應用程式。XGantt可用於.NET,ActiveX和ASP.NET應用程式,可以快速、簡單地整合到您的應用程式中,幫助您識別效能瓶頸、避免延遲以及高效利用資源,使複雜資料變得更加容易理解。
本文主要通過利用VARCHART XGantt來處理文章提及的可能發生的情況,向大家展示VARCHART XGantt.NET的最佳實踐,即通過表互動式交換任務。
專案情況
客戶已經開發出一個圖形規劃板,用於使用VARCHART XGantt管理他的機器。任務在機器上按順序執行,沒有緩衝時間。在計劃表的表格區域中,任務按開始日期排序,相應地按順序列出。這在甘特區顯示為“下降樓梯”。
專案需求
客戶希望能夠僅在表區域中通過拖放更改機器內的任務順序。從技術上講,這個問題必須通過製作一個已經在表格中移動的任務來實現。需要相應地改變任務的程序順序,如下所示:
移動前
移動後
解決方案
在VARCHART XGantt中以互動方式移動節點會觸發事件VcNodeModifying和VcNodeModifiedEx。
VcNodemodifying首先檢查任務是否已被移動到另一個組,因為根據規範這是違規的。需要檢查在移動任務之後其機器資料欄位的內容是否已經改變。如果內容已更改,則ReturnStatus將設定為vcRetStatFalse
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); }
重新計算日期後,任務將再次顯示為降序樓梯:
檢視轉載原文請點選這裡。