public static List<CustomTreeNode> GetCustomCapturePointListFromTable(DataTable capturePointsTable) { List<CustomTreeNode> capturePointList = new List<CustomTreeNode>(); for (int i = 0; i < capturePointsTable.Rows.Count; i++) { object obj = new object(); XmlAttributeCollection attrCol = null; CustomTreeNode treeNode = new CustomTreeNode(capturePointsTable.Rows[i].ItemArray[0].ToString(), attrCol); treeNode.nodeLevel = Convert.ToInt32(capturePointsTable.Rows[i].ItemArray[4]); treeNode.nodeIndex = Convert.ToInt32(capturePointsTable.Rows[i].ItemArray[5]); treeNode.parentLevel = Convert.ToInt32(capturePointsTable.Rows[i].ItemArray[6]); treeNode.parentIndex = Convert.ToInt32(capturePointsTable.Rows[i].ItemArray[7]); treeNode.isNodeUsed = true; string[] usedAttributeNames = capturePointsTable.Rows[i].ItemArray[1].ToString().Split(','); string parentNode = capturePointsTable.Rows[i].ItemArray[2].ToString(); string[] usedAttributeValues = capturePointsTable.Rows[i].ItemArray[3].ToString().Split(','); treeNode.parentNodeText = parentNode; treeNode.customizedAttributeCollection = new List<CustomizedAttribute>(); for (int j = 0; j < usedAttributeNames.Length; j++) { treeNode.customizedAttributeCollection.Add(new CustomizedAttribute(usedAttributeNames[j], usedAttributeValues[j], true)); } capturePointList.Add(treeNode); } return capturePointList; }
//This function is called recursively until all nodes are loaded private void addTreeNodeForSingleEvent(XmlNode xmlNode, TreeNode treeNode) { XmlNode xNode; TreeNode tNode; XmlNodeList xNodeList; if (xmlNode.HasChildNodes) { //The current node has children xNodeList = xmlNode.ChildNodes; for (int x = 0, j = 0; x <= xNodeList.Count - 1; x++, j++) //Loop through the child nodes { xNode = xmlNode.ChildNodes[x]; if (xNode.NodeType != XmlNodeType.Text) { CustomTreeNode customTreeNode = new CustomTreeNode(xNode.Name, xNode.Attributes); treeNode.Nodes.Add(customTreeNode); //nodeIncludedText tNode = treeNode.Nodes[j]; addTreeNodeForSingleEvent(xNode, tNode); } else { j = x - 1; } } } else //No children, so add the outer xml (trimming off whitespace) // treeNode.Text = xmlNode.Name; // treeNode.Text = xmlNode.Attributes["name"].Value; treeNode.Text = xmlNode.Attributes["name"] == null ? xmlNode.Name : xmlNode.Attributes["name"].Value; }
private void OperateOnTreeNode(CustomTreeNode customTreeNode, CustomTreeNode[] treeNodeNodes) { if (!customTreeNode.isNodeUsed) { customTreeNode.Checked = false; } else { customTreeNode.Checked = true; } for (int j = 0; (j < treeNodeNodes.Length) && (treeNodeNodes[j].isNodeUsed); j++) { if (string.Equals(treeNodeNodes[j].Text, customTreeNode.Text) && !treeNodeNodes[j].nodeVisited) { //if (treeNodeNodes[j].isNodeUsed) { // customTreeNode.Checked = true; //} treeNodeNodes[j].nodeVisited = true; for (int k = 0; k < treeNodeNodes[j].customizedAttributeCollection.Count; k++) { CustomizedAttribute customAttrFromDB = treeNodeNodes[j].customizedAttributeCollection[k]; for (int l = 0; l < customTreeNode.customizedAttributeCollection.Count; l++) { CustomizedAttribute customAttrFromTree = customTreeNode.customizedAttributeCollection[l]; if (customAttrFromDB.attribute == null && customAttrFromTree.attribute != null) { if (string.Equals(customAttrFromTree.attribute.Name, customAttrFromDB.attrName)) { customAttrFromTree.attrName = customAttrFromDB.attrName; customAttrFromTree.attrValue = customAttrFromDB.attrValue; } } } } } } if (customTreeNode.Nodes.Count > 0) { RestoreSelectedCapturePoints(treeNodeNodes, customTreeNode.Nodes); } }
private void InterpretCaptureEvent(AdvancedRecomendation captureEvent) { ParseEventFromDatabase(captureEvent); CustomTreeNode[] customArray = new CustomTreeNode[captureEvent.CaptureEventCapturePointsList.Count]; captureEvent.CaptureEventCapturePointsList.CopyTo(customArray); RestoreSelectedCapturePoints(customArray, tvOutput.Nodes); }
private CustomTreeNode GetRespectiveCapturePoint(CustomTreeNode customTreeNode, AdvancedRecomendation captureEvent, XmlNode xNode, int index, int level, int parentIndex, int parentLevel) { for (int i = 1; i < captureEvent.CaptureEventCapturePointsList.Count; i++) { if (captureEvent.CaptureEventCapturePointsList[i].nodeIndex == index && captureEvent.CaptureEventCapturePointsList[i].nodeLevel == level && captureEvent.CaptureEventCapturePointsList[i].parentIndex == parentIndex && captureEvent.CaptureEventCapturePointsList[i].parentLevel == parentLevel) { if (string.Equals(captureEvent.CaptureEventCapturePointsList[i].Text, xNode.Name)) { if ((captureNodesSelectedNames.Count < captureEvent.CaptureEventCapturePointsList.Count - 1) || (!captureNodesSelectedNames.Contains(xNode.Name))) { customTreeNode.customizedAttributeCollection = captureEvent.CaptureEventCapturePointsList[i].customizedAttributeCollection; customTreeNode.isNodeUsed = captureEvent.CaptureEventCapturePointsList[i].isNodeUsed; if ((level == 2) && (!string.Equals(captureNodesSelectedNames[captureNodesSelectedNames.Count - 1], xNode.Name))) { captureNodesSelectedNames.Add(xNode.Name); } else if (level < 2) { captureNodesSelectedNames.Add(xNode.Name); } } } } } return customTreeNode; }
private bool ValidatdByCheckingParentIndexAndUsage(List<CustomTreeNode> captureEventCapturePointsList, CustomTreeNode customTreeNodeCapturePoint, int parentIndex) { for (int i = 0; i < captureEventCapturePointsList.Count; i++) { if (!string.IsNullOrEmpty(customTreeNodeCapturePoint.parentNodeText)) { if (string.Equals(customTreeNodeCapturePoint.parentNodeText, captureEventCapturePointsList[i].Text)) { if (!captureEventCapturePointsList[i].isNodeUsed) { return false; } else if (captureEventCapturePointsList[i].Index != parentIndex) { return false; } } } } return true; }
private void RestoreSelectedSiblingCapturePoints(CustomTreeNode[] Array, TreeNodeCollection collection) { if (collection != null) { for (int i = 0; i < collection.Count; i++) { collection[i].Checked = false; for (int j = 0; (j < Array.Length) && (Array[j].isNodeUsed); j++) { if (string.Equals(Array[j].Text, collection[i].Text) && !Array[j].nodeVisited) { collection[i].Checked = true; Array[j].nodeVisited = true; for (int k = 0; k < Array[j].customizedAttributeCollection.Count; k++) { CustomizedAttribute customAttrFromDB = Array[j].customizedAttributeCollection[k]; for (int l = 0; l < (collection[i] as CustomTreeNode).customizedAttributeCollection.Count; l++) { CustomizedAttribute customAttrFromTree = (collection[i] as CustomTreeNode).customizedAttributeCollection[l]; if (customAttrFromDB.attribute == null && customAttrFromTree.attribute != null) { if (string.Equals(customAttrFromTree.attribute.Name, customAttrFromDB.attrName)) { customAttrFromTree.attrName = customAttrFromDB.attrName; customAttrFromTree.attrValue = customAttrFromDB.attrValue; } } //customAttrFromTree.isUsed = false; //if (string.Equals(customAttrFromTree.attribute.Name, customAttrFromDB.attrName)) { // customAttrFromTree.isUsed = customAttrFromDB.isUsed; // customAttrFromTree.attrValue = customAttrFromDB.attrValue; // customAttrFromTree.attrName = customAttrFromDB.attrName; //} } } } } RestoreSelectedSiblingCapturePoints(Array, collection[i].Nodes); } } }
private void RestoreSelectedCapturePoints(CustomTreeNode[] treeNodeNodes, TreeNodeCollection collection) { if (collection != null) { for (int i = 0; i < collection.Count; i++) { //(collection[i] as CustomTreeNode).che //RestoreSelectedCapturePoints(Array, collection[i].Nodes); OperateOnTreeNode(collection[i] as CustomTreeNode, treeNodeNodes); } } }
private void addTreeNodeForSingleEventFromDatabase(XmlNode xmlNode, TreeNode treeNode, AdvancedRecomendation captureEvent, int level, int index, int parentLevel, int parentIndex) { int newParentLevel = 0; XmlNode xNode; TreeNode tNode; XmlNodeList xNodeList; if (xmlNode.HasChildNodes) { //The current node has children xNodeList = xmlNode.ChildNodes; for (int x = 0, j = 0; x <= xNodeList.Count - 1; x++, j++) //Loop through the child nodes { xNode = xmlNode.ChildNodes[x]; if (xNode.NodeType != XmlNodeType.Text) { CustomTreeNode customTreeNode = new CustomTreeNode(xNode.Name, xNode.Attributes); int currentIndex = j; customTreeNode = GetRespectiveCapturePoint(customTreeNode, captureEvent, xNode, currentIndex, level, parentIndex, parentLevel); treeNode.Nodes.Add(customTreeNode); //nodeIncludedText tNode = treeNode.Nodes[j]; newParentLevel = level; int newParentIndex = currentIndex; if (xNode.HasChildNodes) { //addTreeNodeForSingleEventFromDatabase(xNode, tNode, captureEvent, level + 1, 0, newParentIndex, newParentLevel); int indextElementTypeOnly = 0; for (int i = 0; i < xNode.ChildNodes.Count; i++) { XmlNode childNode = xNode.ChildNodes[i]; if (childNode.NodeType != XmlNodeType.Text) { customTreeNode = new CustomTreeNode(childNode.Name, childNode.Attributes); currentIndex = i; customTreeNode = GetRespectiveCapturePoint(customTreeNode, captureEvent, childNode, indextElementTypeOnly, level + 1, j, level); tNode.Nodes.Add(customTreeNode); indextElementTypeOnly++; } } } } else { j = x - 1; } } } else { //No children, so add the outer xml (trimming off whitespace) // treeNode.Text = xmlNode.Name; // treeNode.Text = xmlNode.Attributes["name"].Value; treeNode.Text = xmlNode.Attributes["name"] == null ? xmlNode.Name : xmlNode.Attributes["name"].Value; } }
private void populateTreeviewSingleEventFromDatabase(string document, AdvancedRecomendation captureEvent) { try { //Just a good practice -- change the cursor to a //wait cursor while the nodes populate XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(document); this.Cursor = Cursors.WaitCursor; //First, we'll load the Xml document //Now, clear out the treeview, //and add the first (root) node tvOutput.Nodes.Clear();//captureEvent.CaptureEventCapturePointsList[i] CustomTreeNode customRootNode = new CustomTreeNode(xDoc.DocumentElement.Name, xDoc.DocumentElement.Attributes); customRootNode.isNodeUsed = true; customRootNode.customizedAttributeCollection = captureEvent.CaptureEventCapturePointsList[0].customizedAttributeCollection; tvOutput.Nodes.Add(customRootNode); TreeNode tNode = new TreeNode(); tNode = (TreeNode)tvOutput.Nodes[0]; //We make a call to addTreeNode, //where we'll add all of our nodes addTreeNodeForSingleEventFromDatabase(xDoc.DocumentElement, tNode, captureEvent, 1, 0, 0, 0); //Expand the treeview to show all nodes tvOutput.ExpandAll(); } catch (XmlException xExc) //Exception is thrown is there is an error in the Xml { CommonUtils.ShowError(xExc.Message, xExc); } catch (Exception ex) { //General exception CommonUtils.ShowError(ex.Message, ex); } finally { this.Cursor = Cursors.Default; //Change the cursor back } }