WorkFlowImage.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:17k
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Drawing;
- using System.Drawing.Imaging;
- using ClassDrawableObjects.com.etong;
- using com.etong.DAL.FC;
- public struct TaskPoint
- {
- public int TaskID;
- public Point Center;
- //public TaskPoint(int iTaskID, Point pCenter)
- //{
- // TaskID = iTaskID;
- // Center = pCenter;
- //}
- }
- public partial class Workflow_WorkFlowImage : System.Web.UI.Page
- {
- private TaskPoint[] mept;
- private DShapeList drawingList;
- private const int initX =250; //初始圆心X坐标
- private const int initY =50; //初始圆心Y坐标
- private const int ellipseW =109; //椭圆宽
- private const int ellipseH =69; //椭圆高
- private const int distanceX = 50; //X方向间距
- private const int distanceY = 50; //Y方向间距
- private const int canvasW = 500; //画布宽
- private const int canvasH =440; //画布高
- private int RealWidth = canvasW; //实际宽
- private int RealHeight = canvasH ; //实际高
- protected void Page_Load(object sender, EventArgs e)
- {
- //在此处放置初始化页的用户代码
- int iWFID;
-
- drawingList = new DShapeList();
- try
- {
- iWFID = Convert.ToInt32( Request.QueryString["PID"]);
- }
- catch
- {
- iWFID = -1;
- }
- EtongFlyChouWFTask tsk = EtongFlyChouWFTask.GetInitTask(iWFID);
- if (tsk !=null)
- {
- //绘制初始任务
- DFilledEllipse ellipse = new DFilledEllipse(new Point(initX, initY), new Size(ellipseW, ellipseH), Color.Black, Color.FromArgb(204, 255, 204));
- ellipse.Desc = tsk.TaskName;
- drawingList.Add(ellipse);
- mept = new TaskPoint[1];
- mept[0].TaskID = tsk.TaskID;
- mept[0].Center = new Point(initX, initY);
- DrawProcess(tsk);
- }
-
- Response.ContentType = "image/gif";
- Bitmap bitMap = new Bitmap(RealWidth, RealHeight);
- Graphics g = System.Drawing.Graphics.FromImage(bitMap);
- try
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- g.Clear(Color.White);
- drawingList.DrawList(g);
- bitMap.Save(Response.OutputStream,ImageFormat.Gif);
- }
- finally
- {
- g.Dispose();
- bitMap.Dispose();
- }
- }
-
- protected Point GetPreTaskCenter(int TaskID)
- {
- int i;
- if (mept != null)
- {
- for (i=0;i<mept.Length;i++)
- {
- if (mept[i].TaskID == TaskID)
- {
- return mept[i].Center;
- }
- }
- }
- return mept[0].Center;
- }
- protected void DrawProcess(EtongFlyChouWFTask tsk)
- {
- DFilledEllipse ellipse;
- DLine line;
- ArrayList al,al1;
- int i;
- if (tsk != null)
- {
- //得到下一步任务
- al = tsk.GetNextTask();
- if (al != null)
- {
- if (al.Count==0) return;
- //获得上级任务的圆心位置
- Point prePt = this.GetPreTaskCenter(tsk.TaskID);
- int preX = prePt.X;
- int preY = prePt.Y;
- if (al.Count==1)
- {
- //只有一个下级任务
- tsk = al[0] as EtongFlyChouWFTask;
- //如果绘制过则无须继续
- if (this.TaskHasDraw(tsk.TaskID) == true) return;
- //得到上级任务
- al1 = tsk.GetPrevioueTasks();
-
- if (al1.Count == 1)
- {
- //只有一个上级任务
- mept = new TaskPoint[al.Count];
- line = new DLine(new Point(preX, preY + ellipseH / 2), new Point(preX, preY + ellipseH / 2 + distanceY), Color.Black);
- line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
- drawingList.Add(line);
- ellipse = new DFilledEllipse(new Point(preX, preY + ellipseH + distanceY), new Size(ellipseW, ellipseH), Color.Black, Color.FromArgb(204, 255, 204));
- ellipse.Desc = tsk.TaskName;
- drawingList.Add(ellipse);
- //mept(mept.Length);
- //mept[mept.Length - 1].TaskID = tsk.TaskID;
- //mept[mept.Length - 1].Center = new Point(preX, preY + ellipseH + distanceY);
- mept[0].TaskID = tsk.TaskID;
- mept[0].Center = new Point(preX, preY + ellipseH + distanceY);
- //判断有无超过预定大小
- //if (mept[mept.Length - 1].Center.X + ellipseW / 2 + 10 > RealWidth)
- //{
- // RealWidth = mept[mept.Length - 1].Center.X + ellipseW / 2 + 10;
- //}
- //if (mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10 > RealHeight)
- //{
- // RealHeight = mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10;
- //}
- if (mept[0].Center.X + ellipseW / 2 + 10 > RealWidth)
- {
- RealWidth = mept[0].Center.X + ellipseW / 2 + 10;
- }
- if (mept[0].Center.Y + ellipseH / 2 + 10 > RealHeight)
- {
- RealHeight = mept[0].Center.Y + ellipseH / 2 + 10;
- }
- }
- else
- {
- //有若干个上级
- //如果有一个上级未绘制则无须继续
- for (i = 0; i < al1.Count; i++)
- {
- if (this.TaskHasDraw((al1[i] as EtongFlyChouWFTask).TaskID) == true) return;
- }
- int maxY = 0;
- Point left = new Point(0, 0);
- Point right = new Point(0, 0);
- //找最深的椭圆圆心位置
- for (i = 0; i < al1.Count; i++)
- {
- prePt = this.GetPreTaskCenter((al1[i] as EtongFlyChouWFTask).TaskID);
- preY = prePt.Y;
- if (preY > maxY) maxY = preY;
- }
- mept = new TaskPoint[al.Count];
- for (i = 0; i < al1.Count; i++)
- {
- prePt = this.GetPreTaskCenter((al1[i] as EtongFlyChouWFTask).TaskID);
- preX = prePt.X;
- preY = prePt.Y;
- line = new DLine(new Point(preX, preY + ellipseH / 2), new Point(preX, maxY + ellipseH / 2 + distanceY / 2), Color.Black);
- line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
- drawingList.Add(line);
- if (i == 0)
- {
- left = new Point(preX, maxY + ellipseH / 2 + distanceY / 2);
- }
- else if (i == al1.Count - 1)
- {
- right = new Point(preX, maxY + ellipseH / 2 + distanceY / 2);
- }
- } //exit for
- line = new DLine(left, right, Color.Black);
- drawingList.Add(line);
- line = new DLine(new Point((right.X + left.X) / 2, left.Y), new Point((right.X + left.X) / 2, left.Y + distanceY / 2), Color.Black);
- line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
- drawingList.Add(line);
- ellipse = new DFilledEllipse(new Point((right.X + left.X) / 2, left.Y + (distanceY + ellipseH) / 2), new Size(ellipseW, ellipseH), Color.Black, Color.FromArgb(204, 255, 204));
- ellipse.Desc = tsk.TaskName;
- drawingList.Add(ellipse);
- //mept = new mept(mept.Length);
- //mept[mept.Length - 1].TaskID = tsk.TaskID;
- //mept[mept.Length - 1].Center = new Point((right.X + left.X) / 2, left.Y + distanceY);
- mept[0].TaskID = tsk.TaskID;
- mept[0].Center = new Point((right.X + left.X) / 2, left.Y + distanceY);
- //判断有无超过预定大小
- //if (mept[mept.Length - 1].Center.X + ellipseW / 2 + 10 > RealWidth)
- //{
- // RealWidth = mept[mept.Length - 1].Center.X + ellipseW / 2 + 10;
- //}
- //if (mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10 > RealHeight)
- //{
- // RealHeight = mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10;
- //}
- if (mept[0].Center.X + ellipseW / 2 + 10 > RealWidth)
- {
- RealWidth = mept[0].Center.X + ellipseW / 2 + 10;
- }
- if (mept[0].Center.Y + ellipseH / 2 + 10 > RealHeight)
- {
- RealHeight = mept[0].Center.Y + ellipseH / 2 + 10;
- }
- }// end if
- }
- else if (al.Count % 2 ==0)
- {
- mept = new TaskPoint[al.Count];
- //有偶数个下级任务
- double c = al.Count/2; //两侧各有几个椭圆
- line = new DLine(new Point(preX,preY + ellipseH / 2), new Point(preX, preY + ellipseH / 2 + distanceY / 2), Color.Black);
- line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
- drawingList.Add(line);
- line = new DLine(new Point(Convert.ToInt32(preX - (ellipseW + distanceX) * (c-0.5)),preY + ellipseH / 2 + distanceY / 2), new Point(Convert.ToInt32( preX + (ellipseW + distanceX) * (c-0.5)), preY + ellipseH / 2 + distanceY / 2), Color.Black);
- drawingList.Add(line);
- for (i=0;i<al.Count;i++)
- {
- tsk = al[i] as EtongFlyChouWFTask;
- line = new DLine(new Point(Convert.ToInt32(preX - (ellipseW + distanceX) * (c - i-0.5)), preY + ellipseH / 2 + distanceY / 2), new Point(Convert.ToInt32(preX - (ellipseW + distanceX) * (c - i-0.5)), preY + ellipseH / 2 + distanceY), Color.Black);
- line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
- drawingList.Add(line);
- ellipse = new DFilledEllipse(new Point(Convert.ToInt32(preX - (ellipseW + distanceX) * (c - i-0.5)), preY + ellipseH + distanceY), new Size(ellipseW, ellipseH), Color.Black, Color.FromArgb(204, 255, 204));
- ellipse.Desc = tsk.TaskName;
- drawingList.Add(ellipse);
- //mept[mept.Length - 1].TaskID = tsk.TaskID;
- //mept[mept.Length - 1].Center = new Point(Convert.ToInt32(preX - (ellipseW + distanceX) * (c - i - 0.5)), preY + ellipseH + distanceY);
- mept[i].TaskID = tsk.TaskID;
- mept[i].Center = new Point(Convert.ToInt32(preX - (ellipseW + distanceX) * (c - i - 0.5)), preY + ellipseH + distanceY);
- //判断有无超过预定大小
- //if (mept[mept.Length - 1].Center.X + ellipseW/2 + 10 > RealWidth)
- //{
- // RealWidth = mept[mept.Length - 1].Center.X + ellipseW/2 +10;
- //}
- //if (mept[mept.Length - 1].Center.Y + ellipseH/2 +10 >RealHeight)
- //{
- // RealHeight = mept[mept.Length - 1].Center.Y + ellipseH/2 + 10;
- //}
- if (mept[i].Center.X + ellipseW / 2 + 10 > RealWidth)
- {
- RealWidth = mept[i].Center.X + ellipseW / 2 + 10;
- }
- if (mept[i].Center.Y + ellipseH / 2 + 10 > RealHeight)
- {
- RealHeight = mept[i].Center.Y + ellipseH / 2 + 10;
- }
- } // exit for
- }
- else
- {
- mept = new TaskPoint[al.Count];
- //有奇数个下级任务
- int c = (al.Count - 1) / 2; //两侧各有几个椭圆
- line = new DLine(new Point(preX, preY + ellipseH / 2), new Point(preX, preY + ellipseH / 2 + distanceY / 2), Color.Black);
- line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
- drawingList.Add(line);
- line = new DLine(new Point(preX - (ellipseW + distanceX) * c, preY + ellipseH / 2 + distanceY / 2), new Point(preX + (ellipseW + distanceX) * c, preY + ellipseH / 2 + distanceY / 2), Color.Black);
- drawingList.Add(line);
- for (i =0 ;i < al.Count;i++)
- {
- tsk = al[i] as EtongFlyChouWFTask;
- line = new DLine(new Point(preX - (ellipseW + distanceX) * (c - i), preY + ellipseH / 2 + distanceY / 2), new Point(preX - (ellipseW + distanceX) * (c - i), preY + ellipseH / 2 + distanceY), Color.Black);
- line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
- drawingList.Add(line);
- ellipse = new DFilledEllipse(new Point(preX - (ellipseW + distanceX) * (c - i), preY + ellipseH + distanceY), new Size(ellipseW, ellipseH), Color.Black, Color.FromArgb(204, 255, 204));
- ellipse.Desc = tsk.TaskName;
- drawingList.Add(ellipse);
- //mept[mept.Length - 1].TaskID = tsk.TaskID;
- //mept[mept.Length - 1].Center = new Point(preX - (ellipseW + distanceX) * (c - i), preY + ellipseH + distanceY);
- mept[i].TaskID = tsk.TaskID;
- mept[i].Center = new Point(preX - (ellipseW + distanceX) * (c - i), preY + ellipseH + distanceY);
- //判断有无超过预定大小
- //if (mept[mept.Length - 1].Center.X + ellipseW / 2 + 10 > RealWidth)
- //{
- // RealWidth = mept[mept.Length - 1].Center.X + ellipseW / 2 + 10;
- //}
- //if (mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10 > RealHeight)
- //{
- // RealHeight = mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10;
- //}
- if (mept[i].Center.X + ellipseW/2 + 10 > RealWidth)
- {
- RealWidth = mept[i].Center.X + ellipseW/2 +10;
- }
- if (mept[i].Center.Y + ellipseH/2 +10 > RealHeight)
- {
- RealHeight = mept[i].Center.Y + ellipseH/2 + 10;
- }
- } // exit for
- }//end al if
- //继续往下绘制
- //alold = al;
- //if (alold.Count > 0 && alold.Count != i) ;
- //else alold = al;
- for (i=0;i<al.Count;i++)
- {
- tsk = al[i] as EtongFlyChouWFTask;
- DrawProcess(tsk);
- }
- } // end if
- } // end if
- }
-
- private bool TaskHasDraw(int TaskID)
- {
- int i;
- if (mept == null) return false;
- else
- {
- for (i=0;i< mept.Length;i++)
- {
- if (mept[i].TaskID == TaskID) return true;
- }
- return false;
- }
- }
- }