/// <summary> /// 删除项 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteItem(object sender, EventArgs e) { try { if (GlobalParams.myJobTreeView.SelectedNode == null) { return; } string nodeText = GlobalParams.myJobTreeView.SelectedNode.Text.ToString(); int level = GlobalParams.myJobTreeView.SelectedNode.Level; string fatherNodeText = string.Empty; //如果是子节点 if (level == 1) { fatherNodeText = GlobalParams.myJobTreeView.SelectedNode.Parent.Text; } foreach (TreeNode toolNode in GlobalParams.myJobTreeView.Nodes) { if (level == 1) { if (toolNode.Text == fatherNodeText) { foreach (var itemNode in toolNode.Nodes) { if (itemNode != null) { if (((TreeNode)itemNode).Text == nodeText) { //移除连线集合中的这条连线 for (int i = 0; i < D_itemAndSource.Count; i++) { if (((TreeNode)itemNode) == D_itemAndSource.Keys.ToArray()[i] || ((TreeNode)itemNode) == D_itemAndSource[D_itemAndSource.Keys.ToArray()[i]]) { D_itemAndSource.Remove(D_itemAndSource.Keys.ToArray()[i]); } } ((TreeNode)itemNode).Remove(); GlobalParams.myJobTreeView.SelectedNode = null; } } } } } else { if (((TreeNode)toolNode).Text == nodeText) { ((TreeNode)toolNode).Remove(); break; } } } //如果是父节点 if (level == 0) { for (int i = 0; i < L_toolList.Count; i++) { if (L_toolList[i].toolName == nodeText) { try { //移除连线集合中的这条连线 for (int j = D_itemAndSource.Count - 1; j >= 0; j--) { if (nodeText == D_itemAndSource.Keys.ToArray()[j].Parent.Text || nodeText == D_itemAndSource[D_itemAndSource.Keys.ToArray()[j]].Parent.Text) { D_itemAndSource.Remove(D_itemAndSource.Keys.ToArray()[j]); } } } catch { } L_toolList.RemoveAt(i); } } } else { for (int i = 0; i < L_toolList.Count; i++) { if (L_toolList[i].toolName == fatherNodeText) { for (int j = 0; j < L_toolList[i].toolInput.Count; j++) { if (L_toolList[i].toolInput[j].value.ToString() == Regex.Split(nodeText, "《")[0]) { L_toolList[i].RemoveInputIO(Regex.Split(nodeText, "《")[0]); } } for (int j = 0; j < L_toolList[i].toolOutput.Count; j++) { if (L_toolList[i].toolOutput[j].IOName == nodeText.Substring(3)) { L_toolList[i].RemoveOutputIO(nodeText.Substring(3)); } } } } } } catch (Exception ex) { //LogHelper.SaveErrorInfo(ex); } }
/// <summary> /// 删除连线及值传递 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteLine(object sender, EventArgs e) { try { if (GlobalParams.myJobTreeView.SelectedNode == null) { return; } string nodeText = GlobalParams.myJobTreeView.SelectedNode.Text.ToString(); int level = GlobalParams.myJobTreeView.SelectedNode.Level; string fatherNodeText = string.Empty; foreach (TreeNode toolNode in GlobalParams.myJobTreeView.Nodes) { if (level == 1) { fatherNodeText = GlobalParams.myJobTreeView.SelectedNode.Parent.Text; if (toolNode.Text == fatherNodeText) { foreach (var itemNode in toolNode.Nodes) { if (itemNode != null) { if (((TreeNode)itemNode).Text == nodeText) { // 移除连线集合中的这条连线 for (int i = 0; i < D_itemAndSource.Count; i++) { if (((TreeNode)itemNode) == D_itemAndSource.Keys.ToArray()[i] || ((TreeNode)itemNode) == D_itemAndSource[D_itemAndSource.Keys.ToArray()[i]]) { D_itemAndSource.Remove(D_itemAndSource.Keys.ToArray()[i]); } } // 修改节点的显示 for (int i = 0; i < L_toolList.Count; i++) { if (L_toolList[i].toolName == fatherNodeText) { for (int j = 0; j < L_toolList[i].toolInput.Count; j++) { string last = Regex.Split(nodeText, "《")[1]; // "《"后边的部分 string ConnectString = "《" + last; // 拼接后字符 if (L_toolList[i].toolInput[j].value.ToString() == ConnectString) { string source = Regex.Split(nodeText, "《")[0]; // "《"之前的部分,即未连线初始部分 L_toolList[i].toolInput[j].value = null; //重新置null ((TreeNode)itemNode).Text = source; } } for (int j = 0; j < L_toolList[i].toolOutput.Count; j++) { if (L_toolList[i].toolOutput[j].IOName == nodeText.Substring(3)) { L_toolList[i].RemoveOutputIO(nodeText.Substring(3)); } } } } } } } } } } } catch (Exception ex) { //LogHelper.SaveErrorInfo(ex); } }