第五章 工作流定义工具的设计与实现(六)

5.7 开发工作流图形定义工具

5.7.6 图形工具主界面程序

    ......(接前页)

    private void Panel_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {

          ......(续前面代码)

                  //如果是迁移
                  if(nodetype == nodetypedefine.transition)
                  {
                      Pen pen=new Pen(Color.Red);
                      AdjustableArrowCap arrow=new AdjustableArrowCap(5,10,false);
                      pen.CustomEndCap=arrow;
                      //记录鼠标点击节点在节点数组中的位置的临时变量
                      int tempint=-1;
                      //判断鼠标是否点在node节点上
                      NodeClass tempnode=null;
                      bool innode=false;
                      for(int i=0;i<nodearray.Count & innode==false;i++)
                      {
                          tempnode=nodearray.GetNode(i);
                          if(tempnode.IsPointInNode(e.X,e.Y))
                          {
                              innode=true;
                              tempint=i;
                          }
                      }

                      //如果点击位置在节点内
                      if(innode == true)
                      {

                          //如果是第一次点击(选择迁移的起始节点)
                          if(clickcount == 0)
                          {

                              //让node1指向选择的节点
                              node1=tempnode;
                          }

                          //如果是第二次点击(选择迁移指向的节点)
                          if(clickcount == 1)
                          {
                              //如果两个节点不是同一节点
                              if(! tempnode.IsSameNode(node1))
                                    
                                  node2=tempnode;
                                  //开始节点和过程逻辑节点只能指向任务节点(除或分支可以是旁

                                  //路,即从或分支直接到或连接)
                                  if((node1.NodeType == nodetypedefine.start ||

                                      node1.NodeType == nodetypedefine.andsplit ||

                                       node1.NodeType == nodetypedefine.andjoin ||

                                        node1.NodeType == nodetypedefine.orjoin) &

                                        (node2.NodeType != nodetypedefine.tasknode))
                                  {

                                       //冲值node1,让它指向空地址
                                       node1=null;
                                       node2=null;
                                       clickcount = 0;
                                       nodetype = nodetypedefine.notask;
                                       return;
                                  }
                                  //如果迁移末端是过程逻辑节点,则首端只能是任务节点(除或连接

                                  //之外,因为或分支的旁路是分支节点和连接节点直接相连)
                                  if((node2.NodeType ==  nodetypedefine.andsplit ||

                                       node2.NodeType == nodetypedefine.andjoin ||

                                       node2.NodeType == nodetypedefine.orsplit) &

                                       (node1.NodeType != nodetypedefine.tasknode))
                                  {
                                       node1=null;
                                       node2=null;
                                       clickcount = 0;
                                       nodetype = nodetypedefine.notask;
                                       return;
                                  }

                                  //如果起始节点不是分支节点,则只能有一个后继节点
                                  if(node1.NodeType != nodetypedefine.andsplit &

                                        node1.NodeType != nodetypedefine.orsplit)
                                  {

                                      //如果迁移数组中已经有从node1引出的迁移
                                      if(transitionarray.GetFromNodeTransition(node1.NodeName)

                                              != null)
                                      {
                                          node1=null;
                                          node2=null;
                                          clickcount = 0;
                                          nodetype = nodetypedefine.notask;
                                          return;
                                      }
                                  }

                                  //如果末端节点不是连接节点,则只能有一个前驱节点
                                  if(node2.NodeType != nodetypedefine.andjoin &

                                           node2.NodeType != nodetypedefine.orjoin)
                                  {

                                      //如果迁移数组中已经有指向node2的迁移
                                      if(transitionarray.GetToNodeTransition(node2.NodeName)

                                              != null)
                                      {
                                          node1=null;
                                          node2=null;
                                          clickcount = 0;
                                          nodetype = nodetypedefine.notask;
                                          return;
                                      }
                                          
                                  //迁移的首端节点不能是结束节点,迁移的末端节点不能是开始节点
                                  if(node1.NodeType != nodetypedefine.end & node2.NodeType

                                          != nodetypedefine.start)
                                  {
                                      //绘制和添加迁移
                                      //如果两个节点间还没有迁移(两个节点间只能有一个迁移)
                                      if(! transitionarray.HasTransitionBetweenTwoNodes

                                             (node1.NodeName,node2.NodeName))
                                      {
                                          g.DrawLine(pen,node1.LeftTopX+node1.Width/2,

                                                    node1.LeftTopY+node1.Height,

                                                    node2.LeftTopX+node2.Width/2,

                                                           node2.LeftTopY);
                                          g.Dispose();
                                          TransitionClass transition=new TransitionClass();
                                          transition.FromNode=node1.NodeName;
                                          transition.ToNode=node2.NodeName;
                                          transitionarray.AddTransition(transition);
                                          //设置节点的processlogic属性
                                          if(node1.NodeType == nodetypedefine.andjoin)
                                          {
                                              //连接节点隔一个任务节点紧跟一个分支节点的情况。

                                              //中间的任务节点将具有双重逻辑。
                                              if(node2.ProcessLogic.Trim() != "")

                                                   //设置node2指向的节点的过程逻辑属性
                                                   node2.ProcessLogic="AndJoin&"

                                                                     +node2.ProcessLogic;
                                              else
                                                   node2.ProcessLogic="AndJoin";
                                          }
                                          if(node1.NodeType == nodetypedefine.orjoin)
                                          {
                                             if(node2.ProcessLogic.Trim() != "")
                                                  node2.ProcessLogic="OrJoin&"

                                                            +node2.ProcessLogic;
                                             else
                                                  node2.ProcessLogic="OrJoin";
                                          }
                                          if(node2.NodeType == nodetypedefine.andsplit)
                                          {
                                             if(node1.ProcessLogic.Trim() != "")

                                                  //设置node1指向的节点的过程逻辑属性
                                                  node1.ProcessLogic=node1.ProcessLogic

                                                           +"&AndSplit";
                                             else
                                                  node1.ProcessLogic="AndSplit";
                                          }
                                          if(node2.NodeType == nodetypedefine.orsplit)
                                          {
                                             if(node1.ProcessLogic.Trim() != "")
                                                  node1.ProcessLogic=node1.ProcessLogic

                                                           +"&OrSplit";
                                             else
                                                  node1.ProcessLogic="OrSplit";
                                          }
                                       }//如果两个节点间没有迁移
                                    }//如果迁移的首端节点不是结束节点,末端节点不是开始节点

                                    //重置node1,让它指向空地址
                                    node1=null;
                                    node2=null;
                                    clickcount = 0;
                                    nodetype = nodetypedefine.notask;
                                    return;
                                 }//如果两次点击不是同一节点
                              }//如果是第二次点击
                              if(clickcount == 0)
                                  clickcount++;
                          }//如果点击位置在节点内
                     }//如果绘制的是迁移
                     //选中节点(用于移动节点)
                     if(nodetype == nodetypedefine.notask)
                     {
                         NodeClass tempnode=null;
                         for(int i=0;i<nodearray.nodeList.Count;i++)
                         {
                             tempnode=(NodeClass)nodearray.nodeList[i];

                             //如果点击位置在节点框内
                             if(e.X >= tempnode.LeftTopX & e.Y>=tempnode.LeftTopY &

                                   e.X<=tempnode.LeftTopX+tempnode.Width &

                                       e.Y<=tempnode.LeftTopY+tempnode.Height)
                             {

                                  //设置鼠标选中节点为点击节点
                                  pickednode=tempnode;
                             }
                         }
                     }//选中节点   
                 }//鼠标左键
                 //如果是鼠标右键点击
                 if(e.Button ==  MouseButtons.Right)    
                 {
                     //选中节点
                     if(nodetype == nodetypedefine.notask)//这个判断似乎不需要
                     {
                         NodeClass tempnode=null;
                         for(int i=0;i<nodearray.nodeList.Count;i++)
                         {
                             tempnode=(NodeClass)nodearray.nodeList[i];
                             if(e.X >= tempnode.LeftTopX & e.Y>=tempnode.LeftTopY &

                                    e.X<=tempnode.LeftTopX+tempnode.Width &

                                     e.Y<=tempnode.LeftTopY+tempnode.Height)
                             {
                                  R_pickednode=tempnode;
                                  break;
                              }
                         }
                     }
                }//鼠标右键
           }//Panel_MouseDown

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值