private void tlGroup_DragDrop(object sender, DragEventArgs e) { try { if (cbeGroup.Text == string.Empty || cbeGroup.Properties.Items.Count == 0) { if (MsgBox.Confirm(Resource.GetString(Resource.Strings.PlayListTimeSliceGroupControlGroupItemCountEmpty), MessageBoxButtons.YesNo) == DialogResult.Yes) { EditGroup(string.Empty); } return; } if (e.Data.GetDataPresent(typeof(LibraryNode))) { _node = (LibraryNode)e.Data.GetData(typeof(LibraryNode)); //Is not message if (_node.Tag == null || ((LibraryItem)(_node.Tag)) == null) { return; } if (((LibraryItem)(_node.Tag)).Type == LibraryType.Message) { _adpater = ((MessageInfo)(_node.Tag)).ToProxy() as MessageAdapterInfo; //Message length is not equal the group length if (_adpater.Target.Length == 0) { MsgBox.Error(Resource.GetString(Resource.Strings.PlayListMessageLengthIsZero)); return; } _adpater.TargetId = _adpater.Target.Id; //LibraryGroup.Current.Messages.GetByName(((MessageInfo)(_node.Tag)).Name).IsLock = true; TreeListNode node = tlGroup.AppendNode(_adpater.ToArrayTimeSliceGroupItem(_currentGroup.Length), -1, _adpater); _nodesList.Add(node); if (_nodesList.Count == 1) { tlGroup.FocusedNode = node; SetDefaultNailImage(); } Save(); } } else { if (e.Data.GetDataPresent("DevExpress.XtraTreeList.Nodes.TreeListNode", false)) { _node = (TreeListNode)e.Data.GetData(typeof(TreeListNode)); TreeListHitInfo hInfo = tlGroup.CalcHitInfo(tlGroup.PointToClient(new Point(e.X, e.Y))); _sourceNode = _node; _destinationNode = hInfo.Node; //Save(); } } } catch (Exception ex) { DataGate.Log.Error(Resource.GetString(Resource.Strings.PlayListTimeSliceGroupControlDragDropException), ex); } }
/// <summary> /// Function:ReLoad Nodes /// Author :Jerry Xu /// Date :2008-7-15 /// </summary> /// <param name="sourceNode">Source Node:TreeListNode</param> /// <param name="destinationNode">Destination Node:TreeListNode</param> private void ReLoadNodes(TreeListNode sourceNode, TreeListNode destinationNode) { //Drag source node is null or destionation node is null, exit if (sourceNode == null || destinationNode == null) { return; } int sourceIndex = 0; //source node index; int destinationIndex = 0; //destination node index; _nodes = new TreeListNode[_nodesList.Count]; _nodesList.CopyTo(_nodes, 0); for (int i = 0; i < _nodes.Length; i++) { if (_nodes[i] == sourceNode) { sourceIndex = i; } if (_nodes[i] == destinationNode) { destinationIndex = i; } } _tempNodes = new TreeListNode[_nodes.Length]; //drag forward if (sourceIndex > destinationIndex) { for (int i = 0; i < _nodes.Length; i++) { if (i < destinationIndex || i > sourceIndex) { _tempNodes[i] = _nodes[i]; } if (i == sourceIndex) { _tempNodes[destinationIndex] = _nodes[i]; } if (i >= destinationIndex && i < sourceIndex) { _tempNodes[i + 1] = _nodes[i]; } } } else//Drag backward { for (int i = 0; i < _nodes.Length; i++) { if (i < sourceIndex || i >= destinationIndex) { _tempNodes[i] = _nodes[i]; } if (i == sourceIndex) { _tempNodes[destinationIndex - 1] = _nodes[i]; } if (i > sourceIndex && i < destinationIndex) { _tempNodes[i - 1] = _nodes[i]; } } } //Clear nodes tlGroup.Nodes.Clear(); _nodesList.Clear(); //Reload nodes for (int i = 0; i < _tempNodes.Length; i++) { _adpater = (MessageAdapterInfo)(_tempNodes[i].Tag); //_message = LibraryGroup.Current.Messages.GetByName(_adpater.MessageName); _nodesList.Add(tlGroup.AppendNode(_adpater.ToArrayTimeSliceGroupItem(_currentGroup.Length), -1, _adpater)); //_nodes[i] = tlGroup.AppendNode(DataGate.ToArrayTimeSliceGroupItem(_currentGroup.Length ,_adpater), -1, _adpater); } //Clear source node and destination node _sourceNode = null; _destinationNode = null; }