public ConnectionAdorner(DesignerCanvas designer, Connection connection)
            : base(designer)
        {
            this.designerCanvas = designer;
            adornerCanvas = new Canvas();
            this.visualChildren = new VisualCollection(this);
            this.visualChildren.Add(adornerCanvas);

            this.connection = connection;
            this.connection.PropertyChanged += new PropertyChangedEventHandler(AnchorPositionChanged);

            InitializeDragThumbs();

            drawingPen = new Pen(Brushes.LightSlateGray, 1);
            drawingPen.LineJoin = PenLineJoin.Round;
        }
        /// <summary>
        /// 初始化流程图
        /// </summary>
        /// <param name="flowList"></param>
        public void LoadFlowChart(List<Tx_Node> flowList)
        {
            _countedNodes = new List<Tx_Node>();
            _nodes = new List<Tx_Node>();
            _allEntrys = new List<Tx_Entry>();
            if (flowList == null || flowList.Count() < 1) return;
            //int m_MaxFlowCode = flowList.Count() + 1;
            startNode =(Convert.ToInt32(flowList.Select(x => x.Code).Min())-1).ToString();
            endNode = (Convert.ToInt32(flowList.Select(x => x.Code).Max()) + 1).ToString();
            _nodes.Add(new Tx_Node(startNode, "", "开始"));
            _nodes.Add(new Tx_Node(endNode, "", "结束"));
            LayOut(flowList);//确定布局,初始化数据
            if (_countedNodes == null) return;
            #region 构造流程节点
            foreach (var node in _countedNodes)
            {
                Label lbl = new Label { Width = 150, Height = 45, Content = node.Name, Tag = node.Code };
                lbl.Style = nodeStyle as Style;
                DesignerItem item = new DesignerItem(node.Code);
                item.Remark = node.Content;//备注
                item.ErrorInfo = node.ErrInfo;//错误信息
                switch (node.Stat.ToUpper())
                {
                    case "Z":
                        item.SourceTipSymbol = DesignerItemTip.Error; //失败
                        item.ToolTip = "结账失败";
                        break;
                    case "Y":
                        item.SourceTipSymbol = DesignerItemTip.Success;//成功
                        item.ToolTip = "结账成功";
                        break;
                    case "N":
                        item.SourceTipSymbol=DesignerItemTip.UnHandled;//未处理
                        item.ToolTip = "未处理";
                        break;
                    case "S":
                        item.SourceTipSymbol = DesignerItemTip.Execute;//正在执行
                         //if (_focusAdornerLayer == null)
                         //            {
                         //               _focusAdornerLayer = AdornerLayer.GetAdornerLayer(item);
                         //           }
                         //           _preAdorder = new FocusAdorner(item);
                         //           _preAdorder.IsClipEnabled = true;
                         //           _focusAdornerLayer.Add(_preAdorder);
                        item.ToolTip = "正在执行";
                        break;
                    default:
                        item.SourceTipSymbol = DesignerItemTip.None;
                        break;
                }
                Canvas.SetLeft(item, Double.Parse("10", CultureInfo.InvariantCulture) + node.X);
                Canvas.SetTop(item, Double.Parse("5", CultureInfo.InvariantCulture) + node.Y);
                Canvas.SetZIndex(item, Int32.Parse("0"));
                item.Content = lbl;
                item.ToolTip = node.Content;
                if (!string.IsNullOrEmpty(node.Sub_Code.Trim()))
                    item.IsDragConnectionOver = true;
                this.Children.Add(item);
                ControlTemplate template = DesignerItem.GetConnectorDecoratorTemplate(item) as ControlTemplate;
                DesignerItem.SetConnectorDecoratorTemplate(item, template);
            }
            #endregion

            #region  构造流程线条
            this.InvalidateVisual();//使元素的呈现无效,并强制执行完整的新布局处理过程。布局循环完成后
            if (_allEntrys == null) return;
            foreach (Tx_Entry entry in _allEntrys)
            {
                string sourceID = entry.StartNode;
                string sinkID = entry.EndNode;
                string sourceConnectorName = "ConnectorBottomName";
                string sinkConnectorName = "ConnectorTopName";
                if (!string.IsNullOrEmpty(sinkID) && !string.IsNullOrEmpty(sourceID))
                {
                    String strContent = entry.Condition;
                    Connector sourceConnector = GetConnector(sourceID, sourceConnectorName);
                    Connector sinkConnector = GetConnector(sinkID, sinkConnectorName);
                    Connection connection = new Connection(sourceConnector, sinkConnector, strContent);
                    Canvas.SetZIndex(connection, 5);
                    this.Children.Add(connection);
                }
            }
            #endregion
        }
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (HitConnector != null)
            {
                Connector sourceConnector = this.sourceConnector;
                Connector sinkConnector = this.HitConnector;
                Connection newConnection = new Connection(sourceConnector, sinkConnector);

                // connections are added with z-index of zero
                this.designerCanvas.Children.Insert(0, newConnection);
            }
            if (HitDesignerItem != null)
            {
                this.HitDesignerItem.IsDragConnectionOver = false;
            }

            if (this.IsMouseCaptured) this.ReleaseMouseCapture();

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.designerCanvas);
            if (adornerLayer != null)
            {
                adornerLayer.Remove(this);
            }
        }