Esempio n. 1
0
        /// <summary>
        /// 鼠标拖拽触发的事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);
            this.Focus();
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                DesignerItem newItem = null;
                Object       content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));

                if (content != null)
                {
                    int maxValue = value++;
                    newItem         = new DesignerItem(TradeCode, maxValue.ToString());
                    newItem.Content = content;
                    var lbl = content as Label;
                    if (lbl != null)
                    {
                        newItem.ToolTip = lbl.ToolTip;
                    }

                    Point position = e.GetPosition(this);
                    if (dragObject.DesiredSize.HasValue)
                    {
                        Size desiredSize = dragObject.DesiredSize.Value;
                        newItem.Width  = desiredSize.Width;
                        newItem.Height = desiredSize.Height;

                        MyCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        MyCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));
                    }
                    else
                    {
                        MyCanvas.SetLeft(newItem, Math.Max(0, position.X));
                        MyCanvas.SetTop(newItem, Math.Max(0, position.Y));
                    }

                    this.Children.Add(newItem);

                    //更新选中项
                    foreach (ISelectable item in this.SelectedItems)
                    {
                        item.IsSelected = false;
                    }
                    SelectedItems.Clear();
                    newItem.IsSelected = true;
                    this.SelectedItems.Add(newItem);
                }

                e.Handled = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新设计面板中集合
        /// </summary>
        private void UpdateZIndex()
        {
            //更新所有元素
            List <UIElement> ordered = (from UIElement item in this.Children
                                        orderby Canvas.GetZIndex(item as UIElement)
                                        select item as UIElement).ToList();

            for (int i = 0; i < ordered.Count; i++)
            {
                //Canvas.SetZIndex(ordered[i], i);
            }


            //更新item序号
            List <DesignerItem> ordereditem = (from DesignerItem item in this.Children.OfType <DesignerItem>()

                                               orderby Convert.ToInt32((item as DesignerItem).CurrentSerialNumber)
                                               select item as DesignerItem).ToList();

            value = ordereditem.Count;
            for (int i = 0; i < ordereditem.Count; i++)
            {
                ordereditem[i].CurrentSerialNumber = i.ToString();
                ContentPresenter contentPresenter =
                    ordereditem[i].Template.FindName("PART_ContentPresenter", ordereditem[i]) as ContentPresenter;
                if (contentPresenter != null)
                {
                    if (VisualTreeHelper.GetChildrenCount(contentPresenter) > 0)
                    {
                        UIElement contentVisual = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement;
                        Label     txt           = DesignerItem.FindVisualChild <Label>(contentVisual as Label);
                        if (txt != null)
                        {
                            txt.Content = ordereditem[i].CurrentSerialNumber;
                        }
                    }
                }
            }

            //更新所有连线
            List <Connection> orderedconn = (from Connection item in this.Children.OfType <Connection>()
                                             select item as Connection).ToList();

            orderedconn.ForEach(x =>
            {
                if (x.Sink.ParentDesignerItem != null)
                {
                    x.Sink.ParentDesignerItem.ParentSerialNumber = x.Source.ParentDesignerItem.CurrentSerialNumber;
                }
            });
        }
Esempio n. 3
0
        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem designerItem = this.DataContext as DesignerItem;
            MyCanvas     designer     = VisualTreeHelper.GetParent(designerItem) as MyCanvas;

            if (designerItem != null && designer != null && designerItem.IsSelected)
            {
                double minLeft = double.MaxValue;
                double minTop  = double.MaxValue;

                var designerItems = from item in designer.SelectedItems
                                    where item is DesignerItem
                                    select item;

                foreach (DesignerItem item in designerItems)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
                    minTop  = double.IsNaN(top) ? 0 : Math.Min(top, minTop);
                }

                double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
                double deltaVertical   = Math.Max(-minTop, e.VerticalChange);

                foreach (DesignerItem item in designerItems)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    if (double.IsNaN(left))
                    {
                        left = 0;
                    }
                    if (double.IsNaN(top))
                    {
                        top = 0;
                    }

                    Canvas.SetLeft(item, left + deltaHorizontal);
                    Canvas.SetTop(item, top + deltaVertical);
                }

                designer.InvalidateMeasure();
                e.Handled = true;
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Load加载事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 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;
                 Label     txt           = FindVisualChild <Label>(contentVisual as Label);
                 if (txt != null)
                 {
                     txt.Content = CurrentSerialNumber;
                 }
                 ComponentCode = (contentVisual as Label).Tag.ToString().Trim();
                 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;
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 反解析交易流程
        /// </summary>
        /// <param name="itemXML">TradeFlow对象</param>
        /// <param name="key">当前流程ID</param>
        /// <param name="OffsetX">X轴偏移量</param>
        /// <param name="OffsetY">Y轴偏移量</param>
        /// <param name="lbl">DesignerItem对象</param>
        /// <returns>DesignerItem</returns>
        private static DesignerItem DeserializeDesignerItem(string tradecode, string key, float OffsetX, float OffsetY, Label lbl, Dictionary <string, string> m_Connection, List <SubRel> subRelList = null)
        {
            var lb = new Label();

            lb.IsHitTestVisible = false;
            lb.Tag        = lbl.Tag;
            lb.Foreground = Brushes.Red;
            lb.Width      = 145;
            lb.Content    = lbl.Content;
            var tmptooltip = "";

            if (m_Connection != null && m_Connection.Count > 0)
            {
                foreach (var o in m_Connection)
                {
                    tmptooltip += o.Key + "," + o.Value + "\n";
                }
                tmptooltip += "---------------------\n";
            }
            if (subRelList != null && subRelList.Count > 0)
            {
                subRelList.ForEach(x =>
                {
                    tmptooltip += x.Memo + "," + x.InData + "," + x.InType.ToString() + "," + x.OutData + "\n";
                });
            }
            lb.ToolTip = tmptooltip;
            lb.Style   = DesignerStyle as Style;
            var item = new DesignerItem(tradecode, key, subRelList, m_Connection);

            item.Width   = 145;
            item.Height  = 23;
            item.IsGroup = true;
            Canvas.SetLeft(item, Double.Parse("10", CultureInfo.InvariantCulture) + OffsetX);
            Canvas.SetTop(item, Double.Parse("5", CultureInfo.InvariantCulture) + OffsetY);
            Canvas.SetZIndex(item, 1);
            item.Content  = lb;
            item.ToolTips = lb.ToolTip.ToString();


            return(item);
        }
        /// <summary>
        /// 递归查找流程线条,线条是否已经连接。
        /// </summary>
        /// <param name="SourceDesignerItem">原元素</param>
        /// <param name="HitDesignerItem">目标元素</param>
        /// <returns>True-存在,False-不存在</returns>
        public bool TraversalParentElement(DesignerItem SourceDesignerItem, DesignerItem HitDesignerItem)
        {
            bool result = false;

            foreach (var item in this.designerCanvas.Children)
            {
                if (item is Connection)
                {
                    var sinkItem = item as Connection;
                    if (sinkItem.Source.ParentDesignerItem == hitDesignerItem && sinkItem.Sink.ParentDesignerItem == SourceDesignerItem)//判断相邻两个元素是否存在线条
                    {
                        if (sinkItem.Source.ParentDesignerItem == hitDesignerItem && sinkItem.Sink.ParentDesignerItem == SourceDesignerItem)
                        {
                            result = true;
                            break;
                        }
                    }
                    if (TempDesignerItem != null)
                    {
                        if (TempDesignerItem == hitDesignerItem)
                        {
                            result = true;
                            break;
                        }
                    }

                    if (sinkItem.Sink.ParentDesignerItem == SourceDesignerItem)//判断不相邻两个元素是否存在线条
                    {
                        if (sinkItem.Source.ParentDesignerItem != hitDesignerItem)
                        {
                            TempDesignerItem = sinkItem.Source.ParentDesignerItem;
                            result           = this.TraversalParentElement(sinkItem.Source.ParentDesignerItem, hitDesignerItem);
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// 打开流程
        /// </summary>
        /// <param name="tradeFlowListEntity">交易流程实体层</param>
        /// <param name="typeList">组件类型列表</param>
        /// <param name="subRelListEntity">映射关系实体层</param>

        public void Open(List <T_plt_tradeFlowEntity> tradeFlowListEntity, List <Label> typeList, List <T_plt_subrelEntity> subRelListEntity)
        {
            #region 初始化

            flowList = new List <TradeFlow>(); //流程实例列表
            var sublist = new List <SubRel>(); //参数关系列表
            //List<string> connectionOverList = new List<string>();//零时序号列表

            if (SerialNumber != null)
            {
                SerialNumber.Clear();       //清空序号
            }
            Children.Clear();               //清空画布
            SelectService.ClearSelection(); //清空画布引用关系
            #endregion
            #region 实体转换
            if (tradeFlowListEntity != null)
            {
                if (tradeFlowListEntity.Count() > 0)
                {
                    tradeFlowListEntity.ForEach(x5 =>
                    {
                        var flow        = new TradeFlow();
                        flow.TradeCode  = x5.TxCode.Trim();
                        flow.CompCode   = x5.CompCode.Trim();
                        flow.Trade_Flow = x5.TradeFlow.Trim();
                        flow.FlowCode   = x5.FlowCode.Trim();
                        flowList.Add(flow);
                    });
                }
            }
            if (subRelListEntity != null)
            {
                if (subRelListEntity.Count() > 0)
                {
                    subRelListEntity.ForEach(x =>
                    {
                        var rel          = new SubRel();
                        rel.TradeCode    = x.tx_code.Trim();
                        rel.CompCode     = x.comp_code.Trim();
                        rel.OutData      = x.out_data.Trim();
                        rel.InType       = x.in_data_type.Trim() == "1"?TypeOpt.常量:TypeOpt.表达式;
                        rel.InData       = x.in_data.Trim();
                        rel.Memo         = x.memo.Trim();
                        rel.SerialNumber = x.flow_no.Trim();
                        sublist.Add(rel);
                    });
                }
            }
            #endregion

            if (flowList.Count() < 1)
            {
                return;                         //如果不存在交易流程,返回
            }
            #region item和线的处理
            LayOut();//对容器的元素进行布局
            var i = 0;
            foreach (Tx_Node node in m_LstNodes)
            {
                SerialNumber.Add(Convert.ToInt32(node.Flow_code)); //组件
                var lbl = typeList.Where(z => z.Tag.ToString().Trim() == node.Component_code.Trim()).FirstOrDefault();
                if (lbl != null)
                {
                    var tmp = new List <SubRel>();
                    sublist.ForEach(x =>
                    {
                        if (x.SerialNumber == node.Flow_code)
                        {
                            tmp.Add(x);
                        }
                    });
                    var item = DeserializeDesignerItem(TradeCode, node.Flow_code, node.X, node.Y, lbl, m_Connection[node.Component_code], tmp);
                    if (!string.IsNullOrWhiteSpace(node.Sub_tx_code.Trim()))
                    {
                        item.IsDragConnectionOver = true;
                    }
                    Canvas.SetZIndex(item, 1);
                    this.Children.Add(item);
                    ControlTemplate template = DesignerItem.GetConnectorDecoratorTemplate(item) as ControlTemplate;
                    DesignerItem.SetConnectorDecoratorTemplate(item, template);
                }
                i++;
            }

            this.InvalidateVisual();//使元素的呈现无效,并强制执行完整的新布局处理过程。布局循环完成后
            if (m_LstEntrys == null)
            {
                return;
            }

            foreach (Tx_Entry entry in m_LstEntrys)
            {
                string sourceID = entry.StartNode;
                string sinkID   = entry.EndNode;
                if (!string.IsNullOrEmpty(sinkID) && !string.IsNullOrEmpty(sourceID))
                {
                    var sourceConnector = GetConnector(sourceID, 6);
                    var sinkConnector   = GetConnector(sinkID, 2);
                    var connection      = new Connection(sourceConnector, sinkConnector, entry.Condition, entry.ConditionList);
                    Canvas.SetZIndex(connection, 2);
                    this.Children.Add(connection);
                }
            }
            #endregion
            //value = SerialNumber.OrderByDescending(x2 => x2).FirstOrDefault() + 1;//出
            UpdateZIndex();
        }