using System.Linq; using System.Windows; using SHJX.Service.WorkFlowEdit; using SHJX.Service.Common.Utils; namespace Flowchart { class DragDropTool : IDragDropTool { DiagramView _view; FlowchartModel _model; int _row, _column; public DragDropTool(DiagramView view, FlowchartModel model) { _view = view; _model = model; } #region 继承 public void OnDragEnter(DragEventArgs e) { } public void OnDragLeave(DragEventArgs e) { } #endregion public void OnDragOver(DragEventArgs e) { e.Effects = DragDropEffects.None; if (e.Data.GetDataPresent(typeof(NodeKinds))) { var position = e.GetPosition(_view); _column = (int)(position.X / _view.GridCellSize.Width); _row = (int)(position.Y / _view.GridCellSize.Height); if (_column >= 0 && _row >= 0) if (!_model.Nodes.Where(p => p.Column.Equals(_column) && p.Row.Equals(_row)).Any()) e.Effects = e.AllowedEffects; } e.Handled = true; } public void OnDrop(DragEventArgs e) { var node = new FlowNode((NodeKinds)e.Data.GetData(typeof(NodeKinds))) { Row = _row, Column = _column }; if (node.Kind.BeIn(NodeKinds.Start, NodeKinds.End)) { if (_model.Nodes.Any(item => item.Kind.Equals(node.Kind))) { e.Handled = false; return; } } _model.Nodes.Add(node); e.Handled = true; } } }