FlowMap.cs
资源名称:gdiFlow.rar [点击查看]
上传用户:yhzmled
上传日期:2014-08-04
资源大小:35k
文件大小:37k
源码类别:
xml/soap/webservice
开发平台:
C#
- /*
- *author: l_dragon email:l_dragon2000@163.com
- *last update:2003/04/03
- * */
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Windows.Forms;
- using System.Xml;
- namespace gdiFlow
- {
- /// <summary>
- /// FlowMap 的摘要说明。
- /// </summary>
- public class FlowMap : System.Windows.Forms.UserControl
- {
- private System.ComponentModel.IContainer components;
- //7种状态对应菜单
- private System.Windows.Forms.ContextMenu menuStatus;
- private System.Windows.Forms.MenuItem menuAdd;
- private System.Windows.Forms.MenuItem menuBegin;
- private System.Windows.Forms.MenuItem menuCommon;
- private System.Windows.Forms.MenuItem menuChild;
- private System.Windows.Forms.MenuItem menuAuto;
- private System.Windows.Forms.MenuItem menuBranch;
- private System.Windows.Forms.MenuItem menuTogether;
- private System.Windows.Forms.MenuItem menuGoto;
- private System.Windows.Forms.MenuItem menuEnd;
- //状态处理对应的操作菜单
- private System.Windows.Forms.ContextMenu menuDelSet;
- private System.Windows.Forms.MenuItem menuDelStatus;
- private System.Windows.Forms.MenuItem menuSetStatus;
- private System.Collections.ArrayList aryStatus=new ArrayList();//存放所有status对象,
- private System.Collections.ArrayList aryDisposal=new ArrayList();//存放所有Disposal对象
- public FlowStatus gStatus;//在Form中被选中的唯一状态;
- private FlowStatus gFrom=null,gTo=null;//画线时的from 和 to
- private int intMouseX;//鼠标按下时坐标x值
- private int intMouseY;//鼠标按下时坐标Y值
- private bool blCtrlDown=false;//ctrl键是否按下
- private int intStatusW=90;//状态对象矩形的宽度;
- private int intStautsH=45;//状态对象矩形的高度;
- /*
- * 状态类型ID,STATUS_TYPE_ID
- * 0 开始
- 1 结束
- 2 普通
- 3 子流
- 4 自动
- 5 分流
- 6 合流
- 7 转流程
- */
- private int intStatusType;//状态类型
- public FlowMap()
- {
- // 该调用是 Windows.Forms 窗体设计器所必需的。
- InitializeComponent();
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Component Designer generated code
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器
- /// 修改此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- //
- // FlowMap
- //
- this.Name = "FlowMap";
- this.Size = new System.Drawing.Size(512, 344);
- this.Load += new System.EventHandler(this.FlowMap_Load);
- this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.myMouseUp);
- this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.myKeyUp);
- this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.myKeyDown);
- this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.myMouseMove);
- this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.myMouseDown);
- }
- #endregion
- private void menuBegin_Click(object sender, System.EventArgs e)
- {
- this.intStatusType=0;
- addStatus();
- }
- private void menuCommon_Click(object sender, System.EventArgs e)
- {
- this.intStatusType=2;
- addStatus();
- }
- private void menuChild_Click(object sender, System.EventArgs e)
- {
- this.intStatusType=3;
- addStatus();
- }
- private void menuAuto_Click(object sender, System.EventArgs e)
- {
- this.intStatusType=4;
- addStatus();
- }
- private void menuBranch_Click(object sender, System.EventArgs e)
- {
- this.intStatusType=5;
- addStatus();
- }
- private void menuTogether_Click(object sender, System.EventArgs e)
- {
- this.intStatusType=6;
- addStatus();
- }
- private void menuGoto_Click(object sender, System.EventArgs e)
- {
- this.intStatusType=7;
- addStatus();
- }
- private void menuEnd_Click(object sender, System.EventArgs e)
- {
- this.intStatusType=1;
- addStatus();
- }
- public void addStatus()
- {
- //增加状态按钮按下,新建一个状态,在状态列表中增加一个状态对象.
- //如果状态对象列表中有已经被删除的状态对象,
- //将其在新位置重新显示
- for(int i=0;i<aryStatus.Count;i++)
- {
- FlowStatus objTempS=(FlowStatus)aryStatus[i];
- if(objTempS.blDisplay==false)
- {
- objTempS._x=this.intMouseX;
- objTempS._y=this.intMouseY;
- objTempS.intStatusTypeId=this.intStatusType;
- objTempS.blDisplay=true;
- int j=i+1;
- objTempS.dblStatusId=Convert.ToDouble(j);
- objTempS.strStatusName="状态"+Convert.ToString(j);
- repaint();
- return;
- }
- }
- FlowStatus objStatus=new FlowStatus(intMouseX,intMouseY,this.intStatusW,this.intStautsH);
- objStatus.intStatusTypeId=this.intStatusType;
- int intI=aryStatus.Count+1;
- objStatus.dblStatusId=Convert.ToDouble(intI);
- objStatus.strStatusName="状态"+Convert.ToString(intI);
- this.aryStatus.Add(objStatus);
- repaint();
- }
- //删除一个状态(status)对象
- private void menuDelStatus_Click(object sender, System.EventArgs e)
- {
- if(this.gStatus!=null)
- {
- if(gStatus.intStatusTypeId==0)
- {
- MessageBox.Show("开始状态不能删除!");
- return;
- }
- if(gStatus.intStatusTypeId==1)
- {
- MessageBox.Show("结束状态不能删除!");
- return;
- }
- double tempStatusId=gStatus.dblStatusId;
- int j=aryDisposal.Count;
- for(int i=0;i<j;i++)
- {
- FlowDisposal objDisp=(FlowDisposal)aryDisposal[i];
- if(objDisp.dblCurStatusId==tempStatusId || objDisp.dblPreStatusId==tempStatusId)
- {
- objDisp.clearProperty();
- }
- }
- this.gStatus.clearProperty();
- this.gStatus=null;
- }
- }
- private void menuSetStatus_Click(object sender, System.EventArgs e)
- {
- frmStatusSet frmSet=new frmStatusSet();
- frmSet.setThisStatus(this.gStatus);
- frmSet.setAryStatus(this.aryStatus);
- frmSet.setAryDisposal(this.aryDisposal);
- frmSet.MaximizeBox=false;
- frmSet.MinimizeBox=false;
- frmSet.ShowDialog();
- repaint();
- }
- //显示增加时的右键菜单
- public void showMenu(MouseEventArgs ex)
- {
- this.intMouseX=ex.X;
- this.intMouseY=ex.Y;
- this.menuStatus = new System.Windows.Forms.ContextMenu();
- this.menuAdd = new System.Windows.Forms.MenuItem();
- this.menuBegin = new System.Windows.Forms.MenuItem();
- this.menuCommon = new System.Windows.Forms.MenuItem();
- this.menuChild = new System.Windows.Forms.MenuItem();
- this.menuAuto = new System.Windows.Forms.MenuItem();
- this.menuBranch = new System.Windows.Forms.MenuItem();
- this.menuTogether = new System.Windows.Forms.MenuItem();
- this.menuGoto = new System.Windows.Forms.MenuItem();
- this.menuEnd = new System.Windows.Forms.MenuItem();
- //
- // menuStatus
- //
- this.menuStatus.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuAdd});
- //
- // menuAdd
- //
- this.menuAdd.Index = 0;
- this.menuAdd.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuBegin,
- this.menuCommon,
- this.menuChild,
- this.menuAuto,
- this.menuBranch,
- this.menuTogether,
- this.menuGoto,
- this.menuEnd});
- this.menuAdd.Text = "添加状态";
- //
- // menuBegin
- //
- this.menuBegin.Index = 0;
- this.menuBegin.Text = "开始";
- this.menuBegin.Click += new System.EventHandler(this.menuBegin_Click);
- //
- // menuCommon
- //
- this.menuCommon.Index = 1;
- this.menuCommon.Text = "普通";
- this.menuCommon.Click += new System.EventHandler(this.menuCommon_Click);
- //
- // menuChild
- //
- this.menuChild.Index = 2;
- this.menuChild.Text = "子流";
- this.menuChild.Click += new System.EventHandler(this.menuChild_Click);
- //
- // menuAuto
- //
- this.menuAuto.Index = 3;
- this.menuAuto.Text = "自动";
- this.menuAuto.Click += new System.EventHandler(this.menuAuto_Click);
- //
- // menuBranch
- //
- this.menuBranch.Index = 4;
- this.menuBranch.Text = "分流";
- this.menuBranch.Click += new System.EventHandler(this.menuBranch_Click);
- //
- // menuTogether
- //
- this.menuTogether.Index = 5;
- this.menuTogether.Text = "合流";
- this.menuTogether.Click += new System.EventHandler(this.menuTogether_Click);
- //
- // menuGoto
- //
- this.menuGoto.Index = 6;
- this.menuGoto.Text = "转流程";
- this.menuGoto.Click += new System.EventHandler(this.menuGoto_Click);
- //
- // menuEnd
- //
- this.menuEnd.Index = 7;
- this.menuEnd.Text = "结束";
- this.menuEnd.Click += new System.EventHandler(this.menuEnd_Click);
- this.ContextMenu= this.menuStatus;
- }
- //设置处理的右键菜单
- public void showStatusMenu()
- {
- this.menuDelSet=new System.Windows.Forms.ContextMenu();
- this.menuDelStatus =new System.Windows.Forms.MenuItem() ;
- this.menuSetStatus =new System.Windows.Forms.MenuItem();
- this.menuDelStatus.Text="删除";
- this.menuDelStatus.Click += new System.EventHandler(this.menuDelStatus_Click);
- this.menuSetStatus.Text="属性";
- this.menuSetStatus.Click += new System.EventHandler(this.menuSetStatus_Click);
- this.menuDelSet.MenuItems.Add(menuDelStatus);
- this.menuDelSet.MenuItems.Add("-");
- this.menuDelSet.MenuItems.Add(menuSetStatus); this.ContextMenu=this.menuDelSet;
- }
- public void myMouseDown(object sender, MouseEventArgs ex)
- {
- int intClickCount=ex.Clicks;
- if(ex.Button == MouseButtons.Left)
- {
- if(intClickCount==1)
- {
- this.drawMouseObjs(ex,1);
- }
- if(intClickCount==2 )//鼠标左键双击
- {
- this.gStatus=this.SelectStatus(ex.X,ex.Y);//选中了某状态对象
- if(gStatus!=null)
- {
- frmStatusSet frmSet=new frmStatusSet();
- frmSet.setThisStatus(this.gStatus);
- frmSet.setAryStatus(this.aryStatus);
- frmSet.setAryDisposal(this.aryDisposal);
- frmSet.MaximizeBox=false;
- frmSet.MinimizeBox=false;
- frmSet.ShowDialog();
- repaint();
- }
- }
- }
- if(ex.Button == MouseButtons.Right)//鼠标右键
- {
- this.gStatus=this.SelectStatus(ex.X,ex.Y);//选中了某状态对象
- if(gStatus!=null)
- {
- this.showStatusMenu(); //显示设置当前状态对象的菜单
- }
- else
- {
- showMenu(ex);//显示增加对象的菜单
- }
- }
- }
- public void myMouseMove(object sender, MouseEventArgs ex)
- {
- if(ex.Button == MouseButtons.Left )
- {
- this.drawMouseObjs(ex,2);
- }
- }
- public void myMouseUp(object sender, MouseEventArgs ex)
- {
- if(ex.Button == MouseButtons.Left )
- {
- this.drawMouseObjs(ex,3);
- }
- }
- public void myKeyDown(object sender, KeyEventArgs ex)
- {
- if(ex.Control==true)//键盘中ctrl键被按下
- {
- int intCount=this.aryStatus.Count;
- if(intCount==0)
- {
- return;
- }
- else
- {
- foreach (Object item in aryStatus)
- {
- FlowStatus objTemp=(FlowStatus)item;
- objTemp.isMove=0;
- }
- }
- this.blCtrlDown=true;
- }
- }
- // public void myKeyPressed(Object o, KeyPressEventArgs e)
- //{
- //if(e.KeyChar == (char)13)
- //e.Handled=true;
- //}
- public void myKeyUp(object sender, KeyEventArgs ex)//键盘中ctrl键被松开
- {
- if(ex.Control==true)
- {
- int intCount=this.aryStatus.Count;
- if(intCount==0)
- {
- return;
- }
- else
- {
- foreach (Object item in aryStatus)
- {
- FlowStatus objTemp=(FlowStatus)item;
- objTemp.isMove=1;
- }
- }
- }
- this.blCtrlDown=false;
- }
- /**
- * 鼠标事件触发时画图的处理
- * @param MouseEventArgs ex鼠标事件
- * @param int intEvent 鼠标事件类型
- * <br>intEvent等于1.代表鼠标按下.intEvent等于2.代表鼠标移动.intEvent等于3.代表鼠标松开.
- *<br>处理步骤如下:
- *<br>intEvent等于1,鼠标按下时如果鼠标的坐标在某状态内,更新状态的last_x,last_y坐标(用来在以移动后更新状态坐标位置)
- * 该状态可以移动
- *<br>intEvent等于2,如果状态可以移动,更新状态位置
- *<br>intEvent等于3,如果状态可以移动,更新状态位置,设置该状态为不能移动。
- * **/
- public void drawMouseObjs(MouseEventArgs ex,int intEvent)
- {
- int statusSize=aryStatus.Count;
- if(statusSize==0) return ;
- if(this.blCtrlDown==false)//ctrl键没有按下
- {
- foreach (Object item in aryStatus)
- {
- FlowStatus objStatus=(FlowStatus)item;
- switch(intEvent)
- {
- case 1://mouseDown()
- if(objStatus.contains(ex.X,ex.Y))
- {
- Graphics g = this.CreateGraphics();
- objStatus.last_x= objStatus._x - ex.X;
- objStatus.last_y = objStatus._y-ex.Y;
- objStatus.isMove=1;
- int x1=objStatus._x;
- int y1=objStatus._y;
- int w1=objStatus._w;
- int h1=objStatus._h;
- Pen penWhite=new Pen(Color.White,2);
- g.DrawRectangle(penWhite,x1,y1,w1,h1);
- g.FillRectangle(new SolidBrush(Color.White),x1,y1,w1,h1);
- g.FillRectangle(new SolidBrush(Color.White),x1+6,y1+6,w1,h1);
- g.DrawRectangle(new Pen(Color.Black),x1,y1,w1,h1);
- g.Dispose();
- return;
- }
- break;
- case 2://mouseMove()
- if(objStatus.isMove==1)
- {
- Graphics g = this.CreateGraphics();
- int x1=objStatus._x;
- int y1=objStatus._y;
- int w1=objStatus._w;
- int h1=objStatus._h;
- g.DrawRectangle(new Pen(Color.White),x1,y1,w1,h1);
- objStatus.setLocation(ex.X,ex.Y);
- this.checkStatus(objStatus);
- int x2=objStatus._x;
- int y2=objStatus._y;
- Pen penBlack=new Pen(Color.Black);
- g.DrawRectangle(penBlack,x2,y2,w1,h1);
- g.Dispose();
- return;
- }
- break;
- case 3://mouseUp()
- if(objStatus.isMove==1)
- {
- updateLocation(ex,objStatus);
- objStatus.isMove=0;
- repaint();
- return;
- }
- break;
- }//end switch
- }//end for
- }//end if
- else if(this.blCtrlDown==true)//ctrl键按下
- {
- foreach (Object item in aryStatus)
- {
- FlowStatus objStatus=(FlowStatus)item;
- switch(intEvent)
- {
- case 1://mouseDown()
- if(objStatus.contains(ex.X,ex.Y))
- {
- this.gFrom=objStatus;
- return;
- }
- break;
- case 2://mouseMove()
- break;
- case 3://mouseUp()
- this.blCtrlDown=false;
- if(this.gFrom!=null)
- {
- if(objStatus.contains(ex.X,ex.Y)&&objStatus.dblStatusId!=gFrom.dblStatusId)
- {
- this.gTo=objStatus;
- if(gFrom.intStatusTypeId==1)
- {
- MessageBox.Show("结束状态只有流入的处理!");
- gFrom=null;
- gTo=null;
- return;
- }
- if(gTo.intStatusTypeId==0)
- {
- MessageBox.Show("起始状态只有流出的处理!");
- gFrom=null;
- gTo=null;
- return;
- }
- int intDispCount=this.aryDisposal.Count;
- if(intDispCount!=0)
- {
- foreach (Object item2 in aryDisposal)
- {
- FlowDisposal objTemp=(FlowDisposal)item2;
- if(objTemp.dblPreStatusId ==gFrom.dblStatusId && objTemp.dblCurStatusId==gTo.dblStatusId)
- {
- MessageBox.Show("该处理已经存在!");
- return;
- }
- }
- }
- //如果处理对象列表中有已经被删除的处理对象,
- //将其在新位置重新显示
- for(int i=0;i<this.aryDisposal.Count;i++)
- {
- FlowDisposal tempDisp=(FlowDisposal)aryDisposal[i];
- if(tempDisp.blDisplay==false)
- {
- int x1=gFrom._x+Convert.ToInt32(gFrom._w/2);
- int y1=gFrom._y+Convert.ToInt32(gFrom._h/2);
- int x2=gTo._x+Convert.ToInt32(gTo._w/2);
- int y2=gTo._y+Convert.ToInt32(gTo._h/2); tempDisp.x1=x1; tempDisp.y1=y1; tempDisp.x2=x2; tempDisp.y2=y2; tempDisp.intCurX=Convert.ToInt32((x1+x2)/2); tempDisp.intCurY=Convert.ToInt32((y1+y2)/2); tempDisp.dblPreStatusId=gFrom.dblStatusId; tempDisp.dblCurStatusId=gTo.dblStatusId;
- tempDisp.blDisplay=true;
- int j=i+1;
- tempDisp.dblDisposalId=Convert.ToDouble(j);
- tempDisp.strDisposalName="处理"+Convert.ToString(j);
- tempDisp.lbDispName.Text="处理"+Convert.ToString(j);
- tempDisp.lbDispName.Location = new System.Drawing.Point(tempDisp.intCurX-Convert.ToInt32(tempDisp.intlblw/2) , tempDisp.intCurY-Convert.ToInt32(tempDisp.intlblh/2) );
- tempDisp.lbDispName.Visible=true;
- tempDisp.aryStatusObjs=this.aryStatus;
- repaint();
- return;
- }
- }
- FlowDisposal objTempDisp=new FlowDisposal(gFrom,gTo);
- objTempDisp.getFormwh(this.Width,this.Height);//让Disposal中的lable得到Form的大小,防止label在移动时移出Form;
- int intTemp=this.aryDisposal.Count+1;
- objTempDisp.dblDisposalId=Convert.ToDouble(intTemp);
- objTempDisp.strDisposalName="处理"+Convert.ToString(intTemp);
- objTempDisp.lbDispName.Text="处理"+Convert.ToString(intTemp);
- this.aryDisposal.Add(objTempDisp);
- objTempDisp.aryDisp=this.aryDisposal; //将aryDisposal传入Disposal对象.用来在删除时,remove掉Disposal列表里面对应的对象
- objTempDisp.aryStatusObjs=this.aryStatus;//将aryStatus传入到disposal对象,用来设置经办状态;
- repaint();
- return;
- }
- }
- break;
- }//end switch
- }//end for
- }
- }
- public void drawAllDisposal()//画所有的线
- {
- foreach (Object item in aryDisposal)
- {
- FlowDisposal objDisp=(FlowDisposal)item;
- if(objDisp.blDisplay)
- {
- Graphics g = this.CreateGraphics();
- Pen penBlack=new Pen(Color.Black);
- g.DrawLine(penBlack,objDisp.x1,objDisp.y1,objDisp.intCurX,objDisp.intCurY);
- drawArrowLine(objDisp.intCurX,objDisp.intCurY,objDisp.x2,objDisp.y2);
- g.Dispose();
- this.Controls.Add(objDisp.lbDispName);
- }
- }
- }
- public void drawArrowLine(int xFrom,int yFrom,int xTo,int yTo)//画第2点带箭头的线
- {
- Graphics g = this.CreateGraphics();
- Pen penBlack=new Pen(Color.Black);
- g.DrawLine( penBlack,xFrom,yFrom,xTo,yTo);
- int cxArrow = 12 ;
- double angSlope = 0;
- double angOffset = Math.PI/8;
- int xDiv = 0, yDiv = 0;
- int xTD = 0, yTD = 0;
- int xTF = xFrom - xTo;
- int yTF = yFrom - yTo;
- if (xTF == 0)
- {//如果是垂直线没有atan2
- if (yTF>0)
- {
- angSlope = Math.PI/2;//90度
- }
- else
- {
- angSlope = -(Math.PI/2);//负90度
- }
- }
- else
- {
- angSlope = Math.Atan2(yTF,xTF);//正切弧度
- }
- xTD = (int)( cxArrow * Math.Cos( angSlope - angOffset) );
- yTD = (int)( cxArrow * Math.Sin( angSlope - angOffset) );
- xDiv = xTo + xTD;
- yDiv = yTo + yTD;
- g.DrawLine(penBlack,xTo,yTo,xDiv,yDiv);
- xTD = (int)( cxArrow * Math.Cos( angSlope + angOffset) );
- yTD = (int)( cxArrow * Math.Sin( angSlope + angOffset) );
- xDiv = xTo + xTD;
- yDiv = yTo + yTD;
- g.DrawLine(penBlack,xTo,yTo,xDiv,yDiv);
- g.Dispose();
- }
- /**
- * 拖拽后更新状态和处理的位置。
- * @param MouseEventArgs e 鼠标事件
- * @param FlowStatus objStatus 状态对象
- *<br>处理步骤如下:
- *<br>确定托拽后的新坐标
- *<br>判定新状态是否在面板坐标内,如果不在,将其改变在面板内。
- *<br>更新状态的新位置
- *<br>更新与状态关联的处理的新位置。
- *<br>重画
- * **/
- public void updateLocation(MouseEventArgs e,FlowStatus objStatus)
- {
- objStatus.setLocation(e.X,e.Y);
- this.checkStatus(objStatus);//节点是否在画板内。
- int PosX=objStatus._x+Convert.ToInt32(objStatus._w/2);
- int PosY=objStatus._y+Convert.ToInt32(objStatus._h/2);
- double dblStatusId=objStatus.dblStatusId;
- foreach (Object item in aryDisposal)
- {
- FlowDisposal objDispTemp=(FlowDisposal)item;
- double dblFromId=objDispTemp.dblPreStatusId;
- double dblToId=objDispTemp.dblCurStatusId;
- if(dblStatusId==dblFromId)
- {
- objDispTemp.x1=PosX;
- objDispTemp.y1=PosY;
- }
- if(dblStatusId==dblToId)
- {
- objDispTemp.x2=PosX;
- objDispTemp.y2=PosY;
- }
- }
- }
- /**
- * 让状态图形始终处在画板内
- *@param FlowStatus objStatus
- **/
- public void checkStatus(FlowStatus objStatus)
- {
- int w = this.Width;
- int h = this.Height;
- int new_x = objStatus._x;
- int new_y = objStatus._y;
- int statusW=objStatus._w;
- int statusH=objStatus._h;
- if((objStatus._x+statusW)>w)
- {
- new_x = (int)w-statusW-6;
- }
- if(objStatus._x< 0)
- {
- new_x = 0;
- }
- if((objStatus._y+statusH)>h)
- {
- new_y = (int)h-statusH-6;
- }
- if(objStatus._y < 0)
- {
- new_y = 0;
- }
- objStatus._x=new_x;
- objStatus._y=new_y;
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- repaint();
- base.OnPaint(e);
- }
- public void repaint()//画图
- {
- String strType="";
- Graphics g = this.CreateGraphics();
- //先将图形所有区域用白色填充
- Pen WhitePen=new Pen(Color.White);
- g.DrawRectangle(WhitePen,0,0,this.Width,this.Height);
- g.FillRectangle(new SolidBrush(Color.White),0,0,this.Width,this.Height);
- //填充完毕
- foreach (Object item in aryStatus)//画代表状态的矩形
- {
- FlowStatus objStatus=(FlowStatus)item;
- if(objStatus.blDisplay)//是否已经被删除,如果没有blDisplay==true则画图显示
- {
- int intType=objStatus.intStatusTypeId;
- int x1=objStatus._x;
- int y1=objStatus._y;
- int w1=objStatus._w;
- int h1=objStatus._h;
- string strName=objStatus.strStatusName;
- Pen penBlack=new Pen(Color.Black,2);
- g.DrawRectangle(penBlack,x1,y1,w1,h1);
- g.FillRectangle(new SolidBrush(Color.FromArgb(30,30,30)),x1+6,y1+6,w1,h1);
- g.FillRectangle(new SolidBrush(Color.Orange),x1,y1,w1,Convert.ToInt32(h1*0.6));
- g.FillRectangle(new SolidBrush(Color.Blue),x1,y1+Convert.ToInt32((h1*0.6)),w1,Convert.ToInt32(h1*0.4));
- switch(intType)
- {
- case 0:
- strType="开始";
- break;
- case 1:
- strType="结束";
- break;
- case 2:
- strType="普通";
- break;
- case 3:
- strType="子流";
- break;
- case 4:
- strType="自动";
- break;
- case 5:
- strType="分流";
- break;
- case 6:
- strType="合流";
- break;
- case 7:
- strType="转流程";
- break;
- }
- Font drawFont = new Font("宋体", 9);
- StringFormat drawFormat = new StringFormat();
- drawFormat.Alignment = StringAlignment.Center;
- SolidBrush drawBrush = new SolidBrush(Color.Black);
- RectangleF drawRect = new RectangleF( x1, y1, w1, Convert.ToInt32(h1*0.6));
- RectangleF drawRect2 = new RectangleF( x1, y1+Convert.ToInt32(h1*0.6), w1, Convert.ToInt32(h1*0.4));
- g.DrawString(strType,drawFont, drawBrush, drawRect, drawFormat);
- g.DrawString(strName,drawFont, new SolidBrush(Color.White), drawRect2, drawFormat);
- }//end if
- }//end for
- g.Dispose();//画代表状态的矩形
- this.drawAllDisposal();//画线
- }
- public FlowStatus SelectStatus(int mouseX,int mouseY)//通过鼠标点的位置找到包含该点的状态对象
- {
- FlowStatus objStatus=null;
- int statusSize=aryStatus.Count;
- if(statusSize==0) return null;
- foreach (Object item in aryStatus)
- {
- FlowStatus objTemp=(FlowStatus)item;
- if(objTemp.contains(mouseX,mouseY))
- {
- objStatus=objTemp;
- return objStatus;
- }
- }
- return objStatus;
- }
- private void FlowMap_Load(object sender, System.EventArgs e)
- {
- }
- public string objToXml()//将拓扑图生成xml字符串
- {
- try
- {
- XmlDocument doc= new XmlDocument();
- doc.LoadXml("<root></root>");//根节点
- XmlNode root = doc.DocumentElement;
- XmlElement elemMap = doc.CreateElement("FlowMap");//拓扑图节点
- XmlAttribute mapAttr = doc.CreateAttribute("ID");//拓扑图编号
- mapAttr.Value = "1";
- elemMap.Attributes.Append(mapAttr);
- XmlElement elemStatusList=doc.CreateElement("StatusList");//状态对象列表节点
- elemMap.AppendChild(elemStatusList);
- foreach(FlowStatus itemStatus in this.aryStatus)
- {
- if(itemStatus.blDisplay)//状态对象没有被删除
- {
- XmlElement elemStatus = doc.CreateElement("Status");//状态对象节点
- XmlAttribute StatusAttr = doc.CreateAttribute("statusId");//状态对象编号
- StatusAttr.Value =Convert.ToString(itemStatus.dblStatusId);
- elemStatus.Attributes.Append(StatusAttr);
- //状态对象的其余属性用xml节点来表示
- XmlElement elemstatusTypeId = doc.CreateElement("statusTypeId");
- elemstatusTypeId.InnerText=Convert.ToString(itemStatus.intStatusTypeId);
- elemStatus.AppendChild(elemstatusTypeId);
- XmlElement elemstatusName = doc.CreateElement("statusName");
- elemstatusName.InnerText=itemStatus.strStatusName;
- elemStatus.AppendChild(elemstatusName);
- XmlElement elemstatusX = doc.CreateElement("statusX");
- elemstatusX.InnerText=Convert.ToString(itemStatus._x);
- elemStatus.AppendChild(elemstatusX);
- XmlElement elemstatusY = doc.CreateElement("statusY");
- elemstatusY.InnerText=Convert.ToString(itemStatus._y);
- elemStatus.AppendChild(elemstatusY);
- XmlElement elemstatusJoinRule = doc.CreateElement("statusJoinRule");
- elemstatusJoinRule.InnerText=Convert.ToString(itemStatus.strJoinRule);
- elemStatus.AppendChild(elemstatusJoinRule);
- XmlElement elemstatusInterfixField = doc.CreateElement("statusInterfixField");
- elemstatusInterfixField.InnerText=Convert.ToString(itemStatus.strInterfixField);
- elemStatus.AppendChild(elemstatusInterfixField);
- XmlElement elemsstatusComExtend = doc.CreateElement("statusComExtend");
- elemsstatusComExtend.InnerText=itemStatus.strComExtend;
- elemStatus.AppendChild(elemsstatusComExtend);
- XmlElement elemstatusChildFlowType = doc.CreateElement("statusChildFlowType");
- elemstatusChildFlowType.InnerText=itemStatus.strChildFlowType;
- elemStatus.AppendChild(elemstatusChildFlowType);
- XmlElement elemstatusChildFlowHint = doc.CreateElement("statusChildFlowHint");
- elemstatusChildFlowHint.InnerText=itemStatus.strChildFlowHint;
- elemStatus.AppendChild(elemstatusChildFlowHint);
- XmlElement elemstatusChildFlow = doc.CreateElement("statusChildFlow");
- elemstatusChildFlow.InnerText=itemStatus.strChildFlow;
- elemStatus.AppendChild(elemstatusChildFlow);
- XmlElement elemstatusChangeFlowName = doc.CreateElement("statusChangeFlowName");
- elemstatusChangeFlowName.InnerText=itemStatus.strChangeFlowName;
- elemStatus.AppendChild(elemstatusChangeFlowName);
- XmlElement elemstatusChangeStatusName = doc.CreateElement("statusChangeStatusName");
- elemstatusChangeStatusName.InnerText=itemStatus.strChangeStatusName;
- elemStatus.AppendChild(elemstatusChangeStatusName);
- XmlElement elemstatusAutoFieldList = doc.CreateElement("statusAutoFieldList");
- elemstatusAutoFieldList.InnerText=itemStatus.strAutoFieldList;
- elemStatus.AppendChild(elemstatusAutoFieldList);
- XmlElement elemstatusAutoRule = doc.CreateElement("statusAutoRule");
- elemstatusAutoRule.InnerText=itemStatus.strAutoRule;
- elemStatus.AppendChild(elemstatusAutoRule);
- XmlElement elemstatusAutoFieldName = doc.CreateElement("statusAutoFieldName");
- elemstatusAutoFieldName.InnerText=itemStatus.strAutoFieldName;
- elemStatus.AppendChild(elemstatusAutoFieldName);
- XmlElement elemstatusJoinRule2= doc.CreateElement("statusJoinRule2");
- elemstatusJoinRule2.InnerText=itemStatus.strJoinRule2;
- elemStatus.AppendChild(elemstatusJoinRule2);
- elemStatusList.AppendChild(elemStatus);//将状态对象加入到状态对象列表中
- }
- }
- XmlElement elemDisposalList=doc.CreateElement("DisposalList");//处理对象列表节点
- elemMap.AppendChild(elemDisposalList);
- foreach(FlowDisposal itemDisp in this.aryDisposal)
- {
- if(itemDisp.blDisplay)//没有被删除
- {
- XmlElement elemDisp= doc.CreateElement("Disposal");//处理对象节点
- XmlAttribute DispAttr = doc.CreateAttribute("disposalId");//处理对象编号
- DispAttr.Value =Convert.ToString(itemDisp.dblDisposalId);
- elemDisp.Attributes.Append(DispAttr);
- //处理对象的其余属性用xml节点来表示
- XmlElement elemdisposalName = doc.CreateElement("disposalName");
- elemdisposalName.InnerText=itemDisp.strDisposalName;
- elemDisp.AppendChild(elemdisposalName);
- XmlElement elemdisposalHint = doc.CreateElement("disposalHint");
- elemdisposalHint.InnerText=itemDisp.strDisposalHint;
- elemDisp.AppendChild(elemdisposalHint);
- XmlElement elemdisposalTransactStatusId = doc.CreateElement("disposalTransactStatusId");
- elemdisposalTransactStatusId.InnerText=Convert.ToString(itemDisp.dblTransactStatusId);
- elemDisp.AppendChild(elemdisposalTransactStatusId);
- XmlElement elemdisposalGroupLimit = doc.CreateElement("disposalGroupLimit");
- elemdisposalGroupLimit.InnerText=Convert.ToString(itemDisp.intGroupLimit);
- elemDisp.AppendChild(elemdisposalGroupLimit);
- XmlElement elemdisposalCurStatusId = doc.CreateElement("disposalCurStatusId");
- elemdisposalCurStatusId.InnerText=Convert.ToString(itemDisp.dblCurStatusId);
- elemDisp.AppendChild(elemdisposalCurStatusId);
- XmlElement elemdisposalPreStatusId = doc.CreateElement("disposalPreStatusId");
- elemdisposalPreStatusId.InnerText=Convert.ToString(itemDisp.dblPreStatusId);
- elemDisp.AppendChild(elemdisposalPreStatusId);
- XmlElement elemdisposalX = doc.CreateElement("disposalX");
- elemdisposalX.InnerText=Convert.ToString(itemDisp.intCurX);
- elemDisp.AppendChild(elemdisposalX);
- XmlElement elemdisposalY = doc.CreateElement("disposalY");
- elemdisposalY.InnerText=Convert.ToString(itemDisp.intCurY);
- elemDisp.AppendChild(elemdisposalY);
- XmlElement elemX1 = doc.CreateElement("X1");
- elemX1.InnerText=Convert.ToString(itemDisp.x1);
- elemDisp.AppendChild(elemX1);
- XmlElement elemY1 = doc.CreateElement("Y1");
- elemY1.InnerText=Convert.ToString(itemDisp.y1);
- elemDisp.AppendChild(elemY1);
- XmlElement elemX2 = doc.CreateElement("X2");
- elemX2.InnerText=Convert.ToString(itemDisp.x2);
- elemDisp.AppendChild(elemX2);
- XmlElement elemY2 = doc.CreateElement("Y2");
- elemY2.InnerText=Convert.ToString(itemDisp.y2);
- elemDisp.AppendChild(elemY2);
- elemDisposalList.AppendChild(elemDisp);
- }
- }
- root.AppendChild(elemMap);
- return doc.OuterXml;
- }
- catch(Exception e)
- {
- string strError="格式错误,转换出错!";
- MessageBox.Show(strError);
- return strError;
- }
- }
- public void xmlToObj(string strXml)//将xml字符转换成拓扑图
- {
- this.aryStatus.Clear();
- this.aryDisposal.Clear();
- this.Controls.Clear();
- try
- {
- XmlDocument doc= new XmlDocument();
- doc.LoadXml(strXml);//根节点
- XmlNodeList eMapList=doc.GetElementsByTagName("FlowMap");
- XmlNode eMapNode=eMapList[0];//拓扑图对象
- double tmpFlowId=Convert.ToDouble(eMapNode.Attributes["ID"].Value);//拓扑图编号
- XmlNodeList eStatusList=doc.GetElementsByTagName("Status");
- for(int i=0;i<eStatusList.Count;i++)
- {
- FlowStatus objTemp=new FlowStatus(0,0,this.intStatusW,this.intStautsH);
- XmlNode eStatus=eStatusList[i];//状态对象
- objTemp.dblStatusId= Convert.ToDouble(eStatus.Attributes["statusId"].Value);//状态编号
- if (eStatus.HasChildNodes)
- {
- for (int j=0; j<eStatus.ChildNodes.Count; j++)
- {
- if(eStatus.ChildNodes[j].Name.Equals("statusTypeId"))
- {
- objTemp.intStatusTypeId=Convert.ToInt32(eStatus.ChildNodes[j].InnerText);
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusName"))
- {
- objTemp.strStatusName=eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusX"))
- {
- objTemp._x =Convert.ToInt32(eStatus.ChildNodes[j].InnerText);
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusY"))
- {
- objTemp._y =Convert.ToInt32(eStatus.ChildNodes[j].InnerText);
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusJoinRule"))
- {
- objTemp.strJoinRule =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusInterfixField"))
- {
- objTemp.strInterfixField =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusComExtend"))
- {
- objTemp.strComExtend =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusChildFlowType"))
- {
- objTemp.strChildFlowType =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusChildFlowHint"))
- {
- objTemp.strChildFlowHint =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusChildFlow"))
- {
- objTemp.strChildFlow =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusChangeFlowName"))
- {
- objTemp.strChangeFlowName =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusChangeStatusName"))
- {
- objTemp.strChangeStatusName =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusAutoFieldList"))
- {
- objTemp.strAutoFieldList =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusAutoRule"))
- {
- objTemp.strAutoRule =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusAutoFieldName"))
- {
- objTemp.strAutoFieldName =eStatus.ChildNodes[j].InnerText;
- }
- if(eStatus.ChildNodes[j].Name.Equals("statusJoinRule2"))
- {
- objTemp.strJoinRule2 =eStatus.ChildNodes[j].InnerText;
- }
- }//end for
- }//end if
- this.aryStatus.Add(objTemp);
- }//end for
- XmlNodeList eDispList=doc.GetElementsByTagName("Disposal");
- for(int i=0;i<eDispList.Count;i++)
- {
- FlowDisposal tmpDisp=new FlowDisposal();
- XmlNode eDisposal=eDispList[i];//状态对象
- tmpDisp.dblDisposalId= Convert.ToDouble(eDisposal.Attributes["disposalId"].Value);//状态编号
- if (eDisposal.HasChildNodes)
- {
- for (int j=0; j<eDisposal.ChildNodes.Count; j++)
- {
- if(eDisposal.ChildNodes[j].Name.Equals("disposalName"))
- {
- tmpDisp.strDisposalName =eDisposal.ChildNodes[j].InnerText;
- }
- if(eDisposal.ChildNodes[j].Name.Equals("disposalHint"))
- {
- tmpDisp.strDisposalHint =eDisposal.ChildNodes[j].InnerText;
- }
- if(eDisposal.ChildNodes[j].Name.Equals("disposalTransactStatusId"))
- {
- tmpDisp.dblTransactStatusId=Convert.ToDouble(eDisposal.ChildNodes[j].InnerText);
- }
- if(eDisposal.ChildNodes[j].Name.Equals("disposalGroupLimit"))
- {
- tmpDisp.intGroupLimit=Convert.ToInt32(eDisposal.ChildNodes[j].InnerText);
- }
- if(eDisposal.ChildNodes[j].Name.Equals("disposalCurStatusId"))
- {
- tmpDisp.dblCurStatusId=Convert.ToDouble(eDisposal.ChildNodes[j].InnerText);
- }
- if(eDisposal.ChildNodes[j].Name.Equals("disposalPreStatusId"))
- {
- tmpDisp.dblPreStatusId=Convert.ToDouble(eDisposal.ChildNodes[j].InnerText);
- }
- if(eDisposal.ChildNodes[j].Name.Equals("disposalX"))
- {
- tmpDisp.intCurX=Convert.ToInt32(eDisposal.ChildNodes[j].InnerText);
- }
- if(eDisposal.ChildNodes[j].Name.Equals("disposalY"))
- {
- tmpDisp.intCurY=Convert.ToInt32(eDisposal.ChildNodes[j].InnerText);
- }
- if(eDisposal.ChildNodes[j].Name.Equals("X1"))
- {
- tmpDisp.x1=Convert.ToInt32(eDisposal.ChildNodes[j].InnerText);
- }
- if(eDisposal.ChildNodes[j].Name.Equals("Y1"))
- {
- tmpDisp.y1=Convert.ToInt32(eDisposal.ChildNodes[j].InnerText);
- }
- if(eDisposal.ChildNodes[j].Name.Equals("X2"))
- {
- tmpDisp.x2=Convert.ToInt32(eDisposal.ChildNodes[j].InnerText);
- }
- if(eDisposal.ChildNodes[j].Name.Equals("Y2"))
- {
- tmpDisp.y2=Convert.ToInt32(eDisposal.ChildNodes[j].InnerText);
- }
- }//end for
- }//end if
- tmpDisp.getFormwh(this.Width,this.Height);
- tmpDisp.setLabelProp();
- this.aryDisposal.Add(tmpDisp);
- }//end for
- this.repaint();
- }//end try
- catch(Exception e)
- {
- string strError="格式错误,转换出错!";
- MessageBox.Show(strError);
- }
- }
- }
- }