原創(chuàng)|使用教程|編輯:龔雪|2014-01-09 11:13:03.000|閱讀 1611 次
概述:在使用XGantt進(jìn)行任務(wù)管理特別是生產(chǎn)任務(wù)管理時,你可能常常需要在甘特圖中顯示全局視圖模式和詳細(xì)視圖模式。本文將為你講解全局視圖模式與詳細(xì)視圖模式在XGantt中的使用。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
在使用甘特圖進(jìn)行多任務(wù)管理的時候,用戶通常都希望既能看到成千上萬個任務(wù)的全局顯示,又能實(shí)時對某個任務(wù)的詳情進(jìn)行快速查看。然而很多時候,當(dāng)需要在重重任務(wù)中查看某一任務(wù)時,它卻迷失在汪洋大海中難以發(fā)現(xiàn)。為了在圖中找這小小的幾個像素,卻要耐心等待整體畫面加載直至完成。
其實(shí),解決這一問題有很多方法,今天我們就以VARCHART XGantt為例,介紹一種方法:全局視圖模式與詳細(xì)視圖模式的使用。
在全局視圖模式中,任務(wù)條的形狀是寬度不一的矩形,每個任務(wù)條的邊界是隱藏的。多個相鄰的任務(wù)條一起構(gòu)成了一個單一的活動板塊。整體畫面是整齊而緊湊的(如下圖)。
全局視圖模式(展示了將近300個任務(wù)):

由全局視圖模式切換到詳細(xì)視圖模式,默認(rèn)的XGantt右鍵菜單需要替換為一個新的包含“Build subdiagram”(生成子圖)和“Restore full diagram”(恢復(fù)全圖)選項(xiàng)的菜單。當(dāng)轉(zhuǎn)到子圖時,用戶選擇查看的任務(wù)將顯示相關(guān)細(xì)節(jié),而其他未選的任務(wù)則由“ActiveNodeFilter”隱藏起來。另外,時標(biāo)部分被限制在盡可能小的范圍內(nèi),任務(wù)條的邊界顯示出來,并配有一個標(biāo)簽。這些任務(wù)條被調(diào)整到一定寬度,一字排列,當(dāng)鼠標(biāo)指在某個任務(wù)上時,工具提示框?qū)@示任務(wù)詳情(如下圖)。
詳細(xì)視圖模式:

選擇右鍵菜單中的“Restore full diagram”(恢復(fù)全圖)項(xiàng),則又可以回到全局視圖模式了。
所需C#代碼:
private void contextMenuItem_BuildSubDiagram_Click(object sender, EventArgs e)
{
VcLayer layer = vcGantt1.LayerCollection.LayerByName("Tasks");
layer.LineType = VcLineType.vcLineType0;
layer.Shape = VcLayerShape.vcSWRoundedRectangleLayer;
layer.Format.get_FormatField(0).TextDataFieldIndex = vcGantt1.DetectFieldIndex("Tasks", "ID");
layer.Height = 1500;
vcGantt1.ActiveNodeFilter = vcGantt1.FilterCollection.MarkedNodesFilter;
VcNodeCollection visibleNodes = vcGantt1.NodeCollection;
visibleNodes.SelectNodes(VcSelectionType.vcAllVisible);
optimizeTimescaleStartEndEx(visibleNodes, 20);
vcGantt1.FitRangeIntoView(vcGantt1.TimeScaleStart, vcGantt1.TimeScaleEnd, 0);
vcGantt1.ScrollToNodeLine(visibleNodes.FirstNode(), VcVerticalAlignment.vcVerCenterAligned);
}
private void contextMenuItem_RestoreFullDiagram_Click(object sender, EventArgs e)
{
VcLayer layer = vcGantt1.LayerCollection.LayerByName("nodes");
layer.LineType = VcLineType.vcNone;
layer.Shape = VcLayerShape.vcRectangleLayer;
layer.Format.get_FormatField(0).TextDataFieldIndex = -1;
layer.Height = 500; vcGantt1.ActiveNodeFilter = null;
vcGantt1.OptimizeTimeScaleStartEnd(720);
vcGantt1.TimeScaleCollection.Active.get_Section(0).UnitWidth = 400;
}
private void vcGantt1_VcNodeRightClicking(object sender, VcNodeClickingEventArgs e)
{
e.ReturnStatus = VcReturnStatus.vcRetStatNoPopup;
myContextMenu.Show(MousePosition);
}
private void vcGantt1_VcDiagramRightClicking(object sender, VcDiagramClickingEventArgs e)
{
e.ReturnStatus = VcReturnStatus.vcRetStatNoPopup;
myContextMenu.Show(MousePosition);
}
private void optimizeTimescaleStartEndEx(VcNodeCollection nodes, int marginsInMinutes)
{
if(nodes.Count > 0)
{
DateTime earliestDate = new DateTime(2222, 1, 1);
DateTime latestDate = new DateTime(1900,1,1);
foreach (VcNode node in nodes)
{
//Earliest Date
DateTime t = (DateTime)node.get_DataField(8);
if (t < earliestDate)
{
earliestDate = t;
}
//Latest Date
int d = Int32.Parse(node.get_DataField(7).ToString());^
t = vcGantt1.CalendarCollection.Active.AddDuration(t, d);
if (t > latestDate)
{
latestDate = t;
}
}
vcGantt1.TimeScaleStart = earliestDate.AddMinutes(-marginsInMinutes);
vcGantt1.TimeScaleEnd = latestDate.AddMinutes(marginsInMinutes);
}
}
//The VcToolTipTextSupplying property has to be activated to display tool tips.
private void vcGantt1_VcToolTipTextSupplying(object sender, VcToolTipTextSupplyingEventArgs e)
{
vcGantt1.ToolTipDuration = 25000;
if(e.HitObjectType == VcObjectType.vcObjTypeNodeInDiagram)
{
VcNode node = (VcNode)e.HitObject; e.Text = "ID: " + node.ID + "\n";
e.Text += "Machine: " + node.get_DataField(1) + "\n";
}
else if (e.HitObjectType == VcObjectType.vcObjTypeTimeScale)
{
e.Text = "Preset Timescale: " + vcGantt1.TimeScaleCollection.Active.Name;
}
}
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)