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: Set current node state /// Author : Jerry Xu /// Date : 2008-7-13 /// </summary> /// <param name="node">TreeListNode:message info</param> /// <param name="check">bool</param> private void SetCheckedNode(TreeListNode node, bool check) { MessageAdapterInfo item = (MessageAdapterInfo)(node.Tag); tlGroup.FocusedNode = node; tlGroup.BeginUpdate(); node["IsActive"] = check; item.IsActive = check; tlGroup.EndUpdate(); }
private void tlGroup_MouseDown(object sender, MouseEventArgs e) { try { tlGroup.SetFocusedNode(tlGroup.CalcHitInfo(new Point(e.X, e.Y)).Node); if (tlGroup.FocusedNode != null && tlGroup.FocusedNode.Tag != null && (tlGroup.FocusedNode.Tag as MessageAdapterInfo).Target != null) { ControlService.NailImageBox.Image = (tlGroup.FocusedNode.Tag as MessageAdapterInfo).Target.Image; ControlService.RefreshPropertyGrid(tlGroup.FocusedNode.Tag); } _pMouse = new Point(e.X, e.Y); //Get node info by mouse point TreeListHitInfo hInfo = tlGroup.CalcHitInfo(new Point(e.X, e.Y)); if (e.Button == MouseButtons.Left) { //When click the active column£¬change active state if (hInfo.HitInfoType == HitInfoType.Cell && hInfo.Column.Caption == Resource.GetString(Resource.Strings.PlayListTimeSliceGroupControlGroupItemActiveTitle)) { TreeListNode node = hInfo.Node; MessageAdapterInfo item = (MessageAdapterInfo)(hInfo.Node.Tag); SetCheckedNode(node, !item.IsActive); Save(); } else { return; } } } catch (Exception ex) { DataGate.Log.Error(Resource.GetString(Resource.Strings.PlayListTimeSliceGroupControlConfigMessageActiveException), ex); } }
/// <summary> /// Function: Remove item from messages /// Author ; Jerry Xu /// Date : 2008-7-23 /// </summary> private void RemoveMessage() { //δ¿¼ÂÇɾ³ýʱ£¬´úÀíÊÇ·ñÓÐЧ£¬É¾³ýºó£¬Currentδ½øÐÐÌæ»»²Ù×÷ if (MsgBox.Confirm(Resource.GetString(Resources.Resource.Strings.ConfirmDeleteItem)) == DialogResult.Yes) { if (tlGroup.FocusedNode != null && tlGroup.FocusedNode.Tag != null) { _nodes = new TreeListNode[_nodesList.Count]; _nodesList.CopyTo(_nodes, 0); if (_nodes.Length > 1) { _tempNodes = new TreeListNode[_nodes.Length - 1]; } int t = 0; for (int i = 0; i < _nodes.Length; i++) { if (_nodes[i] != tlGroup.FocusedNode) { _tempNodes[t++] = _nodes[i]; } } _nodes = _tempNodes; _nodesList.Clear(); if (_nodes != null && _nodes.Length > 0) { _nodesList.AddRange(_nodes); } //LibraryGroup.Current.Messages.GetByName((tlGroup.FocusedNode.Tag as MessageAdapterInfo).Target.Name).IsLock = false; MessageAdapterInfo adapter = tlGroup.FocusedNode.Tag as MessageAdapterInfo; if (adapter.Id == _currentGroup.CurrentMessageAdapterID) { tlGroup.Nodes.Remove(tlGroup.FocusedNode); if (tlGroup.Nodes.Count > 0) { tlGroup.FocusedNode = tlGroup.Nodes[0]; } else { tlGroup.FocusedNode = null; } SetDefaultNailImage(); } else if (adapter.Target.Id == _currentGroup.NailImageID) { tlGroup.Nodes.Remove(tlGroup.FocusedNode); if (tlGroup.Nodes.Count > 0) { tlGroup.FocusedNode = tlGroup.Nodes[0]; } else { tlGroup.FocusedNode = null; } SetDefaultNailImage(true); } else { tlGroup.Nodes.Remove(tlGroup.FocusedNode); } } } }
/// <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; }