예제 #1
0
 void DesignerItem_Loaded(object sender, RoutedEventArgs e)
 {
     if (base.Template != null)
     {
         ContentPresenter contentPresenter =
             this.Template.FindName("PART_ContentPresenter", this) as ContentPresenter;
         if (contentPresenter != null)
         {
             if (VisualTreeHelper.GetChildrenCount(contentPresenter) > 0)
             {
                 UIElement contentVisual = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement;
                 if (contentVisual != null)
                 {
                     DragThumb thumb = this.Template.FindName("PART_DragThumb", this) as DragThumb;
                     Control   connectorDecorator = this.Template.FindName("PART_ConnectorDecorator", this) as Control;
                     if (thumb != null)
                     {
                         ControlTemplate template =
                             DesignerItem.GetDragThumbTemplate(contentVisual) as ControlTemplate;
                         if (template != null)
                         {
                             thumb.Template = template;
                         }
                     }
                     if (connectorDecorator != null)
                     {
                         ControlTemplate template =
                             DesignerItem.GetConnectorDecoratorTemplate(contentVisual) as ControlTemplate;
                         if (template != null)
                         {
                             connectorDecorator.Template = template;
                         }
                     }
                 }
             }
         }
     }
 }
예제 #2
0
        /// <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
        }