/// <summary> /// 排列记录 /// </summary> /// <param name="tableName">数据表名</param> private void SortRecord(string tableName) { Node currentNode = guideTree.SelectedNode; if (currentNode != null) { List <string> recordList = new List <string>(); Dictionary <string, string> idDictionary = new Dictionary <string, string>(); foreach (Node childNode in currentNode.Nodes) { string nodeName = childNode.Text; string nodeID = childNode.Tag as string; idDictionary[nodeName] = nodeID; recordList.Add(nodeName); } SortForm sortForm = new SortForm(recordList); if (sortForm.ShowDialog() == DialogResult.OK) { // 数据记录排序 List <string> idList = new List <string>(); foreach (string recordName in sortForm.RecordList) { idList.Add(idDictionary[recordName]); } SetRecordOrder(tableName, idList); // 树结点排序 Node[] nodeArray = new Node[idList.Count]; foreach (Node childNode in currentNode.Nodes) { string nodeID = childNode.Tag as string; int index = idList.IndexOf(nodeID); nodeArray[index] = childNode; } currentNode.Nodes.Clear(); foreach (Node node in nodeArray) { currentNode.Nodes.Add(node); } } } }
/// <summary> /// 排列记录 /// </summary> /// <param name="tableName">数据表名</param> private void SortRecord(string tableName) { Node currentNode = guideTree.SelectedNode; if (currentNode != null) { List<string> recordList = new List<string>(); Dictionary<string, string> idDictionary = new Dictionary<string, string>(); foreach (Node childNode in currentNode.Nodes) { string nodeName = childNode.Text; string nodeID = childNode.Tag as string; idDictionary[nodeName] = nodeID; recordList.Add(nodeName); } SortForm sortForm = new SortForm(recordList); if (sortForm.ShowDialog() == DialogResult.OK) { // 数据记录排序 List<string> idList = new List<string>(); foreach (string recordName in sortForm.RecordList) { idList.Add(idDictionary[recordName]); } SetRecordOrder(tableName, idList); // 树结点排序 Node[] nodeArray = new Node[idList.Count]; foreach (Node childNode in currentNode.Nodes) { string nodeID = childNode.Tag as string; int index = idList.IndexOf(nodeID); nodeArray[index] = childNode; } currentNode.Nodes.Clear(); foreach (Node node in nodeArray) { currentNode.Nodes.Add(node); } } } }