WorkFlowImage.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:17k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Drawing;
  12. using System.Drawing.Imaging;
  13. using ClassDrawableObjects.com.etong;
  14. using com.etong.DAL.FC;
  15. public struct TaskPoint
  16. {
  17.     public int TaskID;
  18.     public Point Center;
  19.     //public TaskPoint(int iTaskID, Point pCenter)
  20.     //{
  21.     //    TaskID = iTaskID;
  22.     //    Center = pCenter;
  23.     //}
  24. }
  25. public partial class Workflow_WorkFlowImage : System.Web.UI.Page
  26. {
  27.     private TaskPoint[] mept;
  28.     private DShapeList drawingList;
  29.     private const int initX =250;               //初始圆心X坐标
  30.     private const int initY =50;                //初始圆心Y坐标
  31.     private const int ellipseW =109;            //椭圆宽
  32.     private const int ellipseH =69;             //椭圆高
  33.     private const int distanceX = 50;           //X方向间距
  34.     private const int distanceY = 50;           //Y方向间距
  35.     private const int canvasW = 500;            //画布宽
  36.     private const int canvasH =440;             //画布高
  37.     private int RealWidth = canvasW;      //实际宽
  38.     private int RealHeight = canvasH ;    //实际高
  39.     protected void Page_Load(object sender, EventArgs e)
  40.     {
  41.         //在此处放置初始化页的用户代码
  42.         int iWFID;
  43.         
  44.         drawingList = new DShapeList();
  45.         try
  46.         {
  47.             iWFID = Convert.ToInt32( Request.QueryString["PID"]);
  48.         }
  49.         catch
  50.         {
  51.             iWFID = -1;
  52.         }
  53.         EtongFlyChouWFTask tsk = EtongFlyChouWFTask.GetInitTask(iWFID);
  54.         if (tsk !=null) 
  55.         {
  56.             //绘制初始任务
  57.             DFilledEllipse ellipse = new DFilledEllipse(new Point(initX, initY), new Size(ellipseW, ellipseH), Color.Black, Color.FromArgb(204, 255, 204));
  58.             ellipse.Desc = tsk.TaskName;
  59.             drawingList.Add(ellipse);
  60.             mept = new TaskPoint[1];
  61.             mept[0].TaskID = tsk.TaskID;
  62.             mept[0].Center = new Point(initX, initY);
  63.             DrawProcess(tsk);
  64.         }
  65.         
  66.         Response.ContentType = "image/gif";
  67.         Bitmap bitMap = new Bitmap(RealWidth, RealHeight);
  68.         Graphics g = System.Drawing.Graphics.FromImage(bitMap);
  69.         try 
  70.         {
  71.             g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  72.             g.Clear(Color.White);
  73.             drawingList.DrawList(g);
  74.             bitMap.Save(Response.OutputStream,ImageFormat.Gif);
  75.         }
  76.         finally 
  77.         {
  78.             g.Dispose();
  79.             bitMap.Dispose();
  80.         }
  81.     }
  82.     
  83.     protected Point GetPreTaskCenter(int TaskID)
  84.     {
  85.         int i;
  86.         if (mept != null)
  87.         {
  88.             for (i=0;i<mept.Length;i++)
  89.             {
  90.                 if (mept[i].TaskID == TaskID)
  91.                 {
  92.                     return mept[i].Center;
  93.                 }
  94.             }
  95.         }
  96.         return mept[0].Center;
  97.     }
  98.     protected void DrawProcess(EtongFlyChouWFTask tsk)
  99.     {
  100.         DFilledEllipse ellipse;
  101.         DLine line;
  102.         ArrayList al,al1;
  103.         int i;
  104.         if (tsk != null)
  105.         {
  106.             //得到下一步任务
  107.             al = tsk.GetNextTask();
  108.             if (al != null)
  109.             {
  110.                 if (al.Count==0) return;
  111.                 //获得上级任务的圆心位置
  112.                 Point prePt = this.GetPreTaskCenter(tsk.TaskID);
  113.                 int preX = prePt.X;
  114.                 int preY = prePt.Y;
  115.                 if (al.Count==1) 
  116.                 {
  117.                     //只有一个下级任务
  118.                     tsk = al[0] as EtongFlyChouWFTask;
  119.                     //如果绘制过则无须继续
  120.                     if (this.TaskHasDraw(tsk.TaskID) == true) return;
  121.                     //得到上级任务
  122.                     al1 = tsk.GetPrevioueTasks();
  123.                     
  124.                     if (al1.Count == 1)
  125.                     {
  126.                         //只有一个上级任务
  127.                         mept = new TaskPoint[al.Count];
  128.                         line = new DLine(new Point(preX, preY + ellipseH / 2), new Point(preX, preY + ellipseH / 2 + distanceY), Color.Black);
  129.                         line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
  130.                         drawingList.Add(line);
  131.                         ellipse = new DFilledEllipse(new Point(preX, preY + ellipseH + distanceY), new Size(ellipseW, ellipseH), Color.Black, Color.FromArgb(204, 255, 204));
  132.                         ellipse.Desc = tsk.TaskName;
  133.                         drawingList.Add(ellipse);
  134.                         //mept(mept.Length);
  135.                         //mept[mept.Length - 1].TaskID = tsk.TaskID;
  136.                         //mept[mept.Length - 1].Center = new Point(preX, preY + ellipseH + distanceY);
  137.                         mept[0].TaskID = tsk.TaskID;
  138.                         mept[0].Center = new Point(preX, preY + ellipseH + distanceY);
  139.                         //判断有无超过预定大小
  140.                         //if (mept[mept.Length - 1].Center.X + ellipseW / 2 + 10 > RealWidth)
  141.                         //{
  142.                         //    RealWidth = mept[mept.Length - 1].Center.X + ellipseW / 2 + 10;
  143.                         //}
  144.                         //if (mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10 > RealHeight)
  145.                         //{
  146.                         //    RealHeight = mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10;
  147.                         //}
  148.                         if (mept[0].Center.X + ellipseW / 2 + 10 > RealWidth)
  149.                         {
  150.                             RealWidth = mept[0].Center.X + ellipseW / 2 + 10;
  151.                         }
  152.                         if (mept[0].Center.Y + ellipseH / 2 + 10 > RealHeight)
  153.                         {
  154.                             RealHeight = mept[0].Center.Y + ellipseH / 2 + 10;
  155.                         }
  156.                     }
  157.                     else
  158.                     {
  159.                         //有若干个上级
  160.                         //如果有一个上级未绘制则无须继续
  161.                         for (i = 0; i < al1.Count; i++)
  162.                         {
  163.                             if (this.TaskHasDraw((al1[i] as EtongFlyChouWFTask).TaskID) == true) return;
  164.                         }
  165.                         int maxY = 0;
  166.                         Point left = new Point(0, 0);
  167.                         Point right = new Point(0, 0);
  168.                         //找最深的椭圆圆心位置
  169.                         for (i = 0; i < al1.Count; i++)
  170.                         {
  171.                             prePt = this.GetPreTaskCenter((al1[i] as EtongFlyChouWFTask).TaskID);
  172.                             preY = prePt.Y;
  173.                             if (preY > maxY) maxY = preY;
  174.                         }
  175.                         mept = new TaskPoint[al.Count];
  176.                         for (i = 0; i < al1.Count; i++)
  177.                         {
  178.                             prePt = this.GetPreTaskCenter((al1[i] as EtongFlyChouWFTask).TaskID);
  179.                             preX = prePt.X;
  180.                             preY = prePt.Y;
  181.                             line = new DLine(new Point(preX, preY + ellipseH / 2), new Point(preX, maxY + ellipseH / 2 + distanceY / 2), Color.Black);
  182.                             line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
  183.                             drawingList.Add(line);
  184.                             if (i == 0)
  185.                             {
  186.                                 left = new Point(preX, maxY + ellipseH / 2 + distanceY / 2);
  187.                             }
  188.                             else if (i == al1.Count - 1)
  189.                             {
  190.                                 right = new Point(preX, maxY + ellipseH / 2 + distanceY / 2);
  191.                             }
  192.                         }  //exit for
  193.                         line = new DLine(left, right, Color.Black);
  194.                         drawingList.Add(line);
  195.                         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);
  196.                         line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
  197.                         drawingList.Add(line);
  198.                         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));
  199.                         ellipse.Desc = tsk.TaskName;
  200.                         drawingList.Add(ellipse);
  201.                         //mept = new mept(mept.Length);
  202.                         //mept[mept.Length - 1].TaskID = tsk.TaskID;
  203.                         //mept[mept.Length - 1].Center = new Point((right.X + left.X) / 2, left.Y + distanceY);
  204.                         mept[0].TaskID = tsk.TaskID;
  205.                         mept[0].Center = new Point((right.X + left.X) / 2, left.Y + distanceY);
  206.                         //判断有无超过预定大小
  207.                         //if (mept[mept.Length - 1].Center.X + ellipseW / 2 + 10 > RealWidth)
  208.                         //{
  209.                         //    RealWidth = mept[mept.Length - 1].Center.X + ellipseW / 2 + 10;
  210.                         //}
  211.                         //if (mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10 > RealHeight)
  212.                         //{
  213.                         //    RealHeight = mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10;
  214.                         //}
  215.                         if (mept[0].Center.X + ellipseW / 2 + 10 > RealWidth)
  216.                         {
  217.                             RealWidth = mept[0].Center.X + ellipseW / 2 + 10;
  218.                         }
  219.                         if (mept[0].Center.Y + ellipseH / 2 + 10 > RealHeight)
  220.                         {
  221.                             RealHeight = mept[0].Center.Y + ellipseH / 2 + 10;
  222.                         }
  223.                     }// end if
  224.                 }
  225.                 else if (al.Count % 2 ==0) 
  226.                 {
  227.                     mept = new TaskPoint[al.Count];
  228.                     //有偶数个下级任务
  229.                     double c = al.Count/2; //两侧各有几个椭圆
  230.                     line = new DLine(new Point(preX,preY + ellipseH / 2), new Point(preX, preY + ellipseH / 2 + distanceY / 2), Color.Black);
  231.                     line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
  232.                     drawingList.Add(line);
  233.                     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);
  234.                     drawingList.Add(line);
  235.                     for (i=0;i<al.Count;i++) 
  236.                     {
  237.                         tsk = al[i] as EtongFlyChouWFTask;
  238.                         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);
  239.                         line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
  240.                         drawingList.Add(line);
  241.                         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));
  242.                         ellipse.Desc = tsk.TaskName;
  243.                         drawingList.Add(ellipse);
  244.                         //mept[mept.Length - 1].TaskID = tsk.TaskID;
  245.                         //mept[mept.Length - 1].Center = new Point(Convert.ToInt32(preX - (ellipseW + distanceX) * (c - i - 0.5)), preY + ellipseH + distanceY);
  246.                         mept[i].TaskID = tsk.TaskID;
  247.                         mept[i].Center = new Point(Convert.ToInt32(preX - (ellipseW + distanceX) * (c - i - 0.5)), preY + ellipseH + distanceY);
  248.                         //判断有无超过预定大小
  249.                         //if (mept[mept.Length - 1].Center.X + ellipseW/2 + 10 > RealWidth)
  250.                         //{
  251.                         //    RealWidth = mept[mept.Length - 1].Center.X + ellipseW/2 +10;
  252.                         //}
  253.                         //if (mept[mept.Length - 1].Center.Y + ellipseH/2 +10 >RealHeight)
  254.                         //{
  255.                         //    RealHeight = mept[mept.Length - 1].Center.Y + ellipseH/2 + 10;
  256.                         //}
  257.                         if (mept[i].Center.X + ellipseW / 2 + 10 > RealWidth)
  258.                         {
  259.                             RealWidth = mept[i].Center.X + ellipseW / 2 + 10;
  260.                         }
  261.                         if (mept[i].Center.Y + ellipseH / 2 + 10 > RealHeight)
  262.                         {
  263.                             RealHeight = mept[i].Center.Y + ellipseH / 2 + 10;
  264.                         }
  265.                     } // exit for
  266.                 }
  267.                 else 
  268.                 {
  269.                     mept = new TaskPoint[al.Count];
  270.                     //有奇数个下级任务
  271.                     int c = (al.Count - 1) / 2;   //两侧各有几个椭圆
  272.                     line = new DLine(new Point(preX, preY + ellipseH / 2), new Point(preX, preY + ellipseH / 2 + distanceY / 2), Color.Black);
  273.                     line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
  274.                     drawingList.Add(line);
  275.                     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);
  276.                     drawingList.Add(line);
  277.                     for (i =0 ;i < al.Count;i++) 
  278.                     {
  279.                         tsk = al[i] as EtongFlyChouWFTask;
  280.                         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);
  281.                         line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
  282.                         drawingList.Add(line);
  283.                         ellipse = new DFilledEllipse(new Point(preX - (ellipseW + distanceX) * (c - i), preY + ellipseH + distanceY), new Size(ellipseW, ellipseH), Color.Black, Color.FromArgb(204, 255, 204));
  284.                         ellipse.Desc = tsk.TaskName;
  285.                         drawingList.Add(ellipse);
  286.                         //mept[mept.Length - 1].TaskID = tsk.TaskID;
  287.                         //mept[mept.Length - 1].Center = new Point(preX - (ellipseW + distanceX) * (c - i), preY + ellipseH + distanceY);
  288.                         mept[i].TaskID = tsk.TaskID;
  289.                         mept[i].Center = new Point(preX - (ellipseW + distanceX) * (c - i), preY + ellipseH + distanceY);
  290.                         //判断有无超过预定大小
  291.                         //if (mept[mept.Length - 1].Center.X + ellipseW / 2 + 10 > RealWidth)
  292.                         //{
  293.                         //    RealWidth = mept[mept.Length - 1].Center.X + ellipseW / 2 + 10;
  294.                         //}
  295.                         //if (mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10 > RealHeight)
  296.                         //{
  297.                         //    RealHeight = mept[mept.Length - 1].Center.Y + ellipseH / 2 + 10;
  298.                         //}
  299.                         if (mept[i].Center.X + ellipseW/2 + 10 > RealWidth)
  300.                         {
  301.                             RealWidth = mept[i].Center.X + ellipseW/2 +10;
  302.                         }
  303.                         if (mept[i].Center.Y + ellipseH/2 +10 > RealHeight)
  304.                         {
  305.                             RealHeight = mept[i].Center.Y + ellipseH/2 + 10;
  306.                         }
  307.                     } // exit for
  308.                 }//end al if
  309.                 //继续往下绘制
  310.                 //alold = al;
  311.                 //if (alold.Count > 0 && alold.Count != i) ;
  312.                 //else alold = al;
  313.                 for (i=0;i<al.Count;i++)
  314.                 {
  315.                     tsk = al[i] as EtongFlyChouWFTask;
  316.                     DrawProcess(tsk);
  317.                 }
  318.             } // end if
  319.          } // end if
  320.     }
  321.  
  322.     private bool TaskHasDraw(int TaskID)
  323.     {
  324.         int i;
  325.         if (mept == null) return false;
  326.         else 
  327.         {
  328.             for (i=0;i< mept.Length;i++) 
  329.             {
  330.                 if (mept[i].TaskID == TaskID) return true;
  331.             }
  332.             return false;
  333.         }
  334.     }
  335. }