www.pudn.com > WorkflowDesigner.rar > WfFlowDocument.cs, change:2007-12-17,size:11779b


using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Drawing; 
using System.Xml; 
namespace WorkflowDesigner.Designer 
{ 
    /// <summary> 
    /// 工作流设计器文档 
    /// </summary> 
    public class WfFlowDocument 
    { 
        #region 字段 
 
        /// <summary> 
        /// 文档上存在的可视化对象集合 
        /// </summary> 
        private IList<DesignerVisualObject> _visualObjectList; 
 
        /// <summary> 
        /// 文档名称 
        /// </summary> 
        private String _name; 
 
        /// <summary> 
        /// 时限 
        /// </summary> 
        private double _term = -1; 
 
        /// <summary> 
        ///  
        /// </summary> 
        private int _materia_templet_id; 
 
        /// <summary> 
        /// 时限(工作日) 
        /// </summary> 
        private double _workday = 0; 
 
        
        /// <summary> 
        /// 预警时间(工作日) 
        /// </summary> 
        private double _warning_time = 0; 
 
 
        /// <summary> 
        /// 创建角色 
        /// </summary> 
        private WfRole _role ; 
 
        
         
        #endregion 
 
        #region 属性 
 
        /// <summary> 
        /// 创建角色 
        /// </summary> 
        public WfRole Role 
        { 
            get { return _role; } 
            set { _role = value; } 
        } 
        /// <summary> 
        /// 文档上存在的可视化对象集合 
        /// </summary> 
        public IList<DesignerVisualObject> VisualObjectList 
        { 
            get 
            { 
                return _visualObjectList; 
            } 
        } 
        /// <summary> 
        /// 文档名称 
        /// </summary> 
        public String Name 
        { 
            get { return _name; } 
            set { _name = value; } 
        } 
        /// <summary> 
        /// 时限(可以把一些业务上的东西保存在文档上) 
        /// </summary> 
        public double Term 
        { 
            get { return _term; } 
            set { _term = value; } 
        } 
 
        /// <summary> 
        /// 时限(工作日) 
        /// </summary> 
        public double Workday 
        { 
            get { return _workday; } 
            set { _workday = value; } 
        } 
 
        /// <summary> 
        /// 预警时间(工作日) 
        /// </summary> 
        public double Warning_time 
        { 
            get { return _warning_time; } 
            set { _warning_time = value; } 
        } 
 
        #endregion 
 
        #region 构造函数 
        /// <summary> 
        /// 构造函数 
        /// </summary> 
        public WfFlowDocument() 
        { 
            _visualObjectList = new List<DesignerVisualObject>(); 
        } 
        #endregion 
 
        #region 操作 
 
        #region 私有 
        #endregion 
 
        #region 保护 
 
        #endregion 
 
        #region 公用 
        /// <summary> 
        /// 判断鼠标点击出是否有可视化对象 
        /// </summary> 
        /// <param name="x">鼠标所在位置的x轴坐标</param> 
        /// <param name="y">鼠标所在位置的y轴坐标</param> 
        /// <returns>点击出的可视化对象</returns> 
        public HitTestResult HitTest(int x, int y) 
        { 
            foreach (DesignerVisualObject vo in VisualObjectList) 
            { 
                HitTestState state = vo.HitTest(x, y); 
                if (state != HitTestState.None) 
                { 
                    HitTestResult result = new HitTestResult(); 
                    result.state = state; 
                    result.result = vo; 
                    return result; 
                } 
            } 
            return null; 
        } 
        /// <summary> 
        /// 取消所有被选择的可视化对象 
        /// </summary> 
        public void ResetSelected() 
        { 
            foreach (DesignerVisualObject vo in VisualObjectList) 
            { 
                vo.IsSelected = false; 
            } 
        } 
 
        /// <summary> 
        /// 移动被选择的可视化对象 
        /// </summary> 
        /// <param name="offX">最新位置的x轴坐标</param> 
        /// <param name="offY">最新位置的y轴坐标</param> 
        public void MoveSelected(int offX, int offY) 
        { 
            foreach (DesignerVisualObject vo in VisualObjectList) 
            { 
                if (vo.IsSelected) 
                { 
                    vo.Move(offX, offY); 
                } 
            } 
        } 
 
        /// <summary> 
        /// 将画布上所有对象对齐到表格 
        /// </summary> 
        public void AlignToGrid() 
        { 
            //循环画布上所有的可视化对象 
            foreach (DesignerVisualObject vo in VisualObjectList) 
            { 
                //可视化对象对齐到画布上的表格中去 
                vo.AlignToGrid(); 
            } 
        } 
        /// <summary> 
        /// 框选可视化对象 
        /// </summary> 
        /// <param name="rect">选中的矩形范围</param> 
        public void RangeSelect(Rectangle rect) 
        { 
            //循环画布上所有的可视化对象 
            foreach (DesignerVisualObject vo in VisualObjectList) 
            { 
                //可视化对象框选 
                vo.RangeSelect(rect); 
            } 
             
        } 
 
        /// <summary> 
        /// 根据节点名称得到节点 
        /// </summary> 
        /// <param name="name">节点名称</param> 
        /// <returns>返回查询到的节点,如果没有找到符合条件的节点则返回null</returns> 
        public WfAbstractActivity GetActivityByName(String name) 
        { 
             
            //循环画布上所有的可视化对象 
            foreach (DesignerVisualObject vo in VisualObjectList) 
            { 
                if (vo is WfAbstractActivity) 
                {  
                    WfAbstractActivity act = vo as WfAbstractActivity; 
                    if(act.Name == name) 
                    { 
                        return act; 
                    } 
                } 
            } 
            return null; 
        } 
        /// <summary> 
        /// 保存成xml 
        /// </summary> 
        /// <param name="flowsElement">业务元素</param> 
        public void SaveToXmlElement(XmlElement flowsElement) 
        { 
            //创建业务元素 
            XmlElement flowElement = flowsElement.OwnerDocument.CreateElement("process"); 
            //创建名称属性 
            XmlAttribute attr = flowsElement.OwnerDocument.CreateAttribute("name"); 
            attr.Value = Name; 
            flowElement.Attributes.Append(attr); 
 
            //创建角色属性 
            attr = flowsElement.OwnerDocument.CreateAttribute("role"); 
            if (this.Role!=null) 
                attr.Value = this.Role.Name; 
            else 
                attr.Value = ""; 
            flowElement.Attributes.Append(attr); 
            //创建时限属性 
            attr = flowsElement.OwnerDocument.CreateAttribute("term"); 
            attr.Value = Term.ToString(); 
            flowElement.Attributes.Append(attr); 
 
            // sm modify 2007-10-11 增加了两个属性 
            //创建时间限制 
            attr = flowsElement.OwnerDocument.CreateAttribute("WORK_DAY"); 
            attr.Value = this.Workday.ToString(); 
            flowElement.Attributes.Append(attr); 
 
            //创建预警时间限制 
            attr = flowsElement.OwnerDocument.CreateAttribute("WARNING_TIME"); 
            attr.Value = this.Warning_time.ToString(); 
            flowElement.Attributes.Append(attr); 
            
 
            //节点 
            XmlElement actsElement = flowElement.OwnerDocument.CreateElement("activities"); 
            flowElement.AppendChild(actsElement); 
            //遍历可视化对象 
            foreach (DesignerVisualObject vo in VisualObjectList) 
            { 
                if (vo is WfAbstractActivity) 
                { 
                    WfAbstractActivity act = vo as WfAbstractActivity; 
                    //保存成xml 
                    act.SaveToXmlElement(actsElement); 
                } 
            } 
 
            flowsElement.AppendChild(flowElement); 
        } 
 
        /// <summary> 
        /// 删除被选择 
        /// </summary> 
        /// <returns>返回要删除的可视化对象集合</returns> 
        public IList<DesignerVisualObject> DeleteSelected() 
        { 
            //返回要删除的可视化对象集合 
            IList<DesignerVisualObject> result = new List<DesignerVisualObject>(); 
            //是否删除过 
            bool hasModify = true; 
            while (hasModify) 
            { 
                hasModify = false; 
                //因为流转必须和两个节点相联系 所以必须先删除流转,再删除节点,因为考虑到时必选先删流转再删除节点,所以]如果一点有删除对象需要重新遍历 
                //遍历可视化对象 
                foreach (DesignerVisualObject vo in VisualObjectList) 
                { 
                    //如果是流转 
                    if (vo is WfTransition) 
                    { 
                        WfTransition t = vo as WfTransition; 
                        //如果流转的开始节点被选中 或者结束节点被选中 或者本身被选中 
                        if (t.StartActivity.IsSelected || t.EndActivity.IsSelected || t.IsSelected) 
                        { 
                            //删除流转 
                            VisualObjectList.Remove(t); 
                            //将删除对象增加到删除对象的集合众 
                            result.Add(t); 
                            hasModify = true; 
                            break; 
                        } 
                    } 
                } 
 
                foreach (DesignerVisualObject vo in VisualObjectList) 
                { 
                    //如果是流转 
                    if (vo is WfBackTransition) 
                    { 
                        WfBackTransition t = vo as WfBackTransition; 
                        //如果流转的开始节点被选中 或者结束节点被选中 或者本身被选中 
                        if (t.StartActivity.IsSelected || t.EndActivity.IsSelected || t.IsSelected) 
                        { 
                            //删除流转 
                            VisualObjectList.Remove(t); 
                            //将删除对象增加到删除对象的集合众 
                            result.Add(t); 
                            hasModify = true; 
                            break; 
                        } 
                    } 
                } 
 
 
                //遍历可视化对象 
                foreach (DesignerVisualObject vo in VisualObjectList) 
                { 
                   //如果不是流转 
                    if ((!(vo is WfTransition))&&(!(vo is WfBackTransition))) 
                    { 
                        //如果是节点 
                        WfAbstractActivity a = vo as WfAbstractActivity; 
                        //如果被选中 
                        if (a.IsSelected) 
                        { 
                            VisualObjectList.Remove(a); 
                            result.Add(a); 
                            hasModify = true; 
                            break; 
                        } 
                    } 
                } 
            } 
            return result; 
        } 
 
        /// <summary> 
        /// 打开对话框 
        /// </summary> 
        /// <param name="x">鼠标所在位置的x轴坐标</param> 
        /// <param name="y">鼠标所在位置的y轴坐标</param> 
        public void OpenPropertyDialogAtPoint(int x, int y) 
        { 
            HitTestResult result = HitTest(x, y); 
            if (result != null && result.state == HitTestState.Center) 
            { 
                result.result.OpenPropertyDialog(); 
            } 
            else 
            { 
            } 
        } 
        #endregion 
        #endregion 
 
 
 
 
         
    } 
}