/// <summary>
/// 递归选中子节点
/// </summary>
/// <param name="treeNode">节点</param>
/// <param name="nodeChecked">bool值</param>
private void CheckAllChildNodes(TreeNode treeNode, bool nodeChecked)
{
foreach(TreeNode node in treeNode.Nodes)
{
node.Checked = nodeChecked;
if(node.Nodes.Count > 0)
{
//如果当前结点有子节点,调用递归函数
this.CheckAllChildNodes(node, nodeChecked);
}
}
}
/// <summary>
/// 调出某一操作员的相关权限
/// </summary>
/// <param name="treeView">权限树</param>
/// <param name="PopeArray">模块ID</param>
private void CallRecursive(TreeView treeView,string [] PopeArray)
{
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode n in nodes)
{
//n.Checked =true;
PrintRecursive(n,PopeArray);
}
}
/// <summary>
/// 递归调用
/// </summary>
/// <param name="treeNode">节点</param>
/// <param name="PopeArray">模块ID</param>
private void PrintRecursive(TreeNode treeNode,string [] PopeArray)
{
foreach (TreeNode tn in treeNode.Nodes)
{
foreach (string str in PopeArray)
{
if (str.Trim().ToString()==((COM.JS.Park.DMT.DMTModule)tn.Tag).MOD_ID.Trim().ToString())
{
tn.Checked =true;
tn.Parent.Checked =true;
}
}
PrintRecursive(tn,PopeArray);
}
}
/// <summary>
/// 设置树节点背景色
/// </summary>
/// <param name="treeNode"></param>
/// <param name="_flag"></param>
private void SetTreeBackRecursive(TreeNode treeNode,bool _flag)
{
foreach (TreeNode tn in treeNode.Nodes)
{
if (_flag==true)
tn.BackColor=System.Drawing.Color.White;
else
tn.BackColor=System.Drawing.Color.FromArgb(((System.Byte)(231)), ((System.Byte)(240)), ((System.Byte)(250)));
SetTreeBackRecursive(tn,_flag);
}
}
#region 树节点拖动
private void trv_ParkTree_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
//取源节点信息 获得进行"Drag"操作中拖动的字符串
TreeNode sourceNode=this.trv_ParkTree.SelectedNode;
string dummy = "temp" ;
string source_Text = ( string ) e.Data.GetData ( dummy.GetType ( ) ) ;
string target_Text="";
int source_id=0;
source_Text = source_Text.Substring ( source_Text.IndexOf ( ":" ) + 1 ).Trim ( ) ;
string soruceNodeType=this.checkNode(sourceNode);
TreeNode DragNode = new TreeNode ( source_Text ) ; //新建一个节点
DragNode.Tag=sourceNode.Tag;
switch (soruceNodeType) //根据源节点类型取相关ID
{
case "ParkNode":
source_id=((OMTPark)this.trv_ParkTree.SelectedNode.Tag).PRK_ID;
DragNode.ImageIndex =0;
break;
case "RootParkNode":
source_id=((OMTPark)this.trv_ParkTree.SelectedNode.Tag).PRK_ID;
soruceNodeType="ParkNode";
DragNode.ImageIndex =1;
break;
case "ComputerNode":
source_id=((OMTComputer)this.trv_ParkTree.SelectedNode.Tag).COM_ID;
DragNode.ImageIndex =2;
break;
case "MachineNode":
source_id=((OMTMachine)this.trv_ParkTree.SelectedNode.Tag).MAC_NO;
DragNode.ImageIndex =3;
break;
default:
break;
}
//MessageBox.Show (source_Text+" "+soruceNodeType);
//取目标节点信息
m_Position.X = e.X ;
m_Position.Y = e.Y ;
m_Position = trv_ParkTree.PointToClient ( m_Position ) ;
TreeNode DropNode = this.trv_ParkTree.GetNodeAt ( m_Position ) ;
string targetNodeType=this.checkNode(DropNode);
target_Text=DropNode.Text.Trim();
//MessageBox.Show (DropNode.Text);
//在目标组件中加入以此字符串为标题的项目
if ( DropNode != null && source_id.ToString()!="" )
{
if ( (soruceNodeType=="ComputerNode" && targetNodeType=="RootParkNode") || (soruceNodeType=="ParkNode" && targetNodeType=="ParkNode") || (soruceNodeType=="ComputerNode" && targetNodeType=="ParkNode") || (soruceNodeType=="MachineNode" && targetNodeType=="ComputerNode") )
{
if (source_Text==target_Text)
{
MessageBox.Show (this,"拖放位置不对","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
return;
}
if (targetNodeType=="RootParkNode" && soruceNodeType=="ParkNode")
{
((OMTPark)sourceNode.Tag).PPARK_ID=((OMTPark)DropNode.Tag).PRK_ID;
((OMTPark)sourceNode.Tag).store();
}
else if (targetNodeType=="ParkNode" && soruceNodeType=="ComputerNode" || targetNodeType=="RootParkNode" && soruceNodeType=="ComputerNode")
{
((OMTComputer)sourceNode.Tag).PRK_ID =((OMTPark)DropNode.Tag).PRK_ID;
((OMTComputer)sourceNode.Tag).store();
}
else if (targetNodeType=="ComputerNode" && soruceNodeType=="MachineNode")
{
((OMTMachine)sourceNode.Tag).COM_ID=((OMTComputer)DropNode.Tag).COM_ID;
((OMTMachine)sourceNode.Tag).store();
}
initLoadTree();
//DropNode.Nodes.Insert(DropNode.Index+1 , DragNode ); //插入到目标节点
//this.trv_ParkTree.SelectedNode.Remove();
}
else
{
MessageBox.Show ("拖放位置不正确","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
}
private void trv_ParkTree_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
//判断是否目前拖动的数据是字符串,如果是,则拖动字符串对目的组件进行拷贝
if ( e.Data.GetDataPresent ( DataFormats.Text ) )
{
e.Effect = DragDropEffects.Move ;
}
else
{
e.Effect = DragDropEffects.None ;
}
}
private void trv_ParkTree_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
//判断是否是鼠标右键按动
if(this.trv_ParkTree.SelectedNode==null)
{
return;
}
else if( this.trv_ParkTree.SelectedNode.Parent==null)
{
return;
}
else if( e.Button == MouseButtons.Right )
{
return;
}
string strItem = e.Item.ToString ( ) ; //开始进行"Drag"操作
//DoDragDrop ( strItem , DragDropEffects.Copy | DragDropEffects.Move ) ;
DoDragDrop(strItem, DragDropEffects.Move);
}
private void trv_ParkTree_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
}
#endregion