www.pudn.com > WorkflowDesigner.rar > WfActivity.cs, change:2007-11-27,size:17817b


using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Drawing; 
using System.Drawing.Drawing2D; 
using System.Drawing.Imaging; 
using System.Xml; 
using System.Collections; 
namespace WorkflowDesigner.Designer 
{ 
    /// <summary> 
    /// 普通节点可视化对象 
    /// </summary> 
    public class WfActivity :WfAbstractActivity 
    { 
         #region 字段 
        /// <summary> 
        /// 角色对象 
        /// </summary> 
        private WfRole _role; 
 
        /// <summary> 
        /// 应用程序对象 
        /// </summary> 
        private IList<WfApplication> _appList = new List<WfApplication>(); 
 
      
        /// <summary> 
        /// 是否允许回退 
        /// </summary> 
        private int _isSendBack = 1; 
 
        /// <summary> 
        /// 是否允许岗位内提交 
        /// </summary> 
        private int _isSendSelf = 1; 
 
        /// <summary> 
        /// 时限(工作日) 
        /// </summary> 
        private double _workday = 0; 
 
        /// <summary> 
        /// 预警时间(工作日) 
        /// </summary> 
        private double _warning_time = 0; 
 
        /// <summary> 
        /// 选择用户类型 ISSELECTUSER 是否选择用户 0为选择用户 1为选择之前某个指定的节点用户 
        /// </summary> 
        private int _isSelectUser = 0; 
      
        /// <summary> 
        /// 接受前事件 
        /// </summary> 
        private String _beforeRecive_Event = ""; 
 
         
        /// <summary> 
        /// 发送后事件 
        /// </summary> 
        private String _afterSend_Event = ""; 
 
         
 
        /// <summary> 
        /// 之前节点 
        /// </summary> 
        private WfActivity _before_ActiveInfo; 
 
        /// <summary> 
        /// 之前节点 
        /// </summary> 
        public WfActivity Before_ActiveInfo 
        { 
            get { return _before_ActiveInfo; } 
            set { _before_ActiveInfo = value; } 
        } 
 
        
 
                 
        /// <summary> 
        /// 节点参数 
        /// </summary> 
        private IList<WfParam> _paramsInfo = new List<WfParam>(); 
 
         
        #endregion 
 
        #region 属性 
        /// <summary> 
        /// 角色对象 
        /// </summary> 
        public WfRole Role 
        { 
            get { return _role; } 
            set { _role = value; } 
        } 
        /// <summary> 
        /// 应用程序对象 
        /// </summary> 
        internal IList<WfApplication> AppList 
        { 
            get { return _appList; } 
            set { _appList = value; } 
        } 
        
 
        /// <summary> 
        /// 是否允许回退 
        /// </summary> 
        public int IsSendBack 
        { 
            get { return _isSendBack; } 
            set { _isSendBack = value; } 
        } 
 
        /// <summary> 
        /// 是否允许岗位内提交 
        /// </summary> 
        public int IsSendSelf 
        { 
            get { return _isSendSelf; } 
            set { _isSendSelf = 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; } 
        } 
 
 
        /// <summary> 
        /// 选择用户类型 ISSELECTUSER 是否选择用户 0为选择用户 1为选择之前某个指定的节点用户 
        /// </summary> 
        public int IsSelectUser 
        { 
            get { return _isSelectUser; } 
            set { _isSelectUser = value; } 
        } 
        /// <summary> 
        /// 发送后事件 
        /// </summary> 
        public String AfterSend_Event 
        { 
            get { return _afterSend_Event; } 
            set { _afterSend_Event = value; } 
        } 
        /// <summary> 
        /// 接受前事件 
        /// </summary> 
        public String BeforeRecive_Event 
        { 
            get { return _beforeRecive_Event; } 
            set { _beforeRecive_Event = value; } 
        } 
 
         
 
        /// <summary> 
        /// 节点参数 
        /// </summary> 
        public IList<WfParam> ParamsInfo 
        { 
            get { return _paramsInfo; } 
            set { _paramsInfo = value; } 
        } 
        #endregion 
 
        #region 构造函数 
        /// <summary> 
        /// 构造函数 
        /// </summary> 
        public WfActivity(int x, int y) 
            : base(x, y) 
        {  
         
        } 
        #endregion 
 
        #region 操作 
 
        #region 私有 
        #endregion 
 
        #region 保护 
 
 
        /// <summary> 
        /// 绘制 
        /// </summary> 
        /// <param name="g">绘图图面</param> 
        protected override void DrawIcon(System.Drawing.Graphics g) 
        { 
 
            Color c; 
            if (IsSelected) 
            { 
                c = Color.Red; 
            } 
            else 
            { 
                //c = Color.Blue; 
                c = Color.White; 
            } 
            using (Pen pen = new Pen(c)) 
            { 
                g.DrawRectangle(pen, _rect); 
            } 
            using (Brush brush = new SolidBrush(Color.White)) 
            { 
                g.FillRectangle(brush, _rect); 
            } 
            ImageAttributes imAtt = new ImageAttributes(); 
            //设置颜色键 
            imAtt.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255)); 
            // 画箭头 
            Bitmap arrowBitmap = WorkflowDesigner.Properties.Resources.active1; 
 
            int imgWidth = arrowBitmap.Width; 
            int imgHeight = arrowBitmap.Height; 
            GraphicsState gs = g.Save(); 
            //绘制图片 
            g.DrawImage(arrowBitmap, _rect, 
                0, 0, 
                imgWidth, 
                imgWidth, 
                GraphicsUnit.Pixel, 
                imAtt); 
            //释放 
            imAtt.Dispose(); 
            arrowBitmap.Dispose(); 
            //还原到原来的表示状态 
            g.Restore(gs); 
 
             
        } 
        /// <summary> 
        /// 得到节点类型 
        /// </summary> 
        /// <returns>该节点的类型</returns> 
        protected override string GetActivityType() 
        { 
            //类型0 开始 1 结束 2普通 3 分支 4聚合 
            return "2"; 
        } 
 
        /// <summary> 
        /// 在创建xml元素后 
        /// </summary> 
        /// <param name="actElement">节点xml元素</param> 
        protected override void  
            AfterCreateXmlElement(XmlElement actElement) 
        { 
            //需要改动 
            //XmlAttribute attr = new XmlAttribute(); 
             
            /*  
             XmlAttribute attr =   actElement.OwnerDocument.CreateAttribute("flowSelect"); 
            attr.Value = FlowSelect; 
            actElement.Attributes.Append(attr); 
 
            attr = actElement.OwnerDocument.CreateAttribute("userSelect"); 
            attr.Value = UserSelect; 
            actElement.Attributes.Append(attr); 
 
            */ 
            XmlAttribute attr = actElement.OwnerDocument.CreateAttribute("work_day"); 
            attr.Value = this.Workday.ToString(); 
            actElement.Attributes.Append(attr); 
 
 
            attr = actElement.OwnerDocument.CreateAttribute("warning_time"); 
            attr.Value = this.Warning_time.ToString(); 
            actElement.Attributes.Append(attr); 
 
            attr = actElement.OwnerDocument.CreateAttribute("issendself"); 
            attr.Value = this.IsSendSelf.ToString(); 
            actElement.Attributes.Append(attr); 
 
            attr = actElement.OwnerDocument.CreateAttribute("enablesendback"); 
            attr.Value = this.IsSendBack.ToString(); 
            actElement.Attributes.Append(attr); 
 
 
            attr = actElement.OwnerDocument.CreateAttribute("isselectuser"); 
            attr.Value = this.IsSelectUser.ToString(); 
            actElement.Attributes.Append(attr); 
 
            if (this.IsSelectUser == 0) 
            { 
                //创建角色元素 
                XmlElement roleElement = actElement.OwnerDocument.CreateElement("role"); 
                //创建角色参照属性 
                XmlAttribute roleattr= actElement.OwnerDocument.CreateAttribute("ref"); 
                if (Role == null) 
                { 
                    roleattr.Value = ""; 
                } 
                else 
                { 
                    roleattr.Value = Role.Name; 
                } 
                roleElement.Attributes.Append(roleattr); 
                actElement.AppendChild(roleElement); 
            } 
            else 
            { 
                XmlElement beforeactivElement = actElement.OwnerDocument.CreateElement("before_activ"); 
                XmlAttribute beforeactivattr = actElement.OwnerDocument.CreateAttribute("ref"); 
                if (this.Before_ActiveInfo == null) 
                { 
                    beforeactivattr.Value = ""; 
                } 
                else 
                { 
                    beforeactivattr.Value = this.Before_ActiveInfo.Name; 
                } 
                beforeactivElement.Attributes.Append(beforeactivattr); 
                actElement.AppendChild(beforeactivElement); 
 
            } 
 
 
 
 
            //创建应用程序集元素 
            XmlElement appsElement = actElement.OwnerDocument.CreateElement("applications"); 
            actElement.AppendChild(appsElement); 
            //循环增加应用程序元素 
            int j = 1; 
            foreach (WfApplication app in AppList) 
            { 
                XmlElement appElement = actElement.OwnerDocument.CreateElement("application"); 
 
                attr = actElement.OwnerDocument.CreateAttribute("ref"); 
                attr.Value = app.Name; 
                appElement.Attributes.Append(attr); 
 
                XmlAttribute apprankattr = actElement.OwnerDocument.CreateAttribute("rank"); 
                apprankattr.Value = j.ToString(); 
                appElement.Attributes.Append(apprankattr); 
 
                appsElement.AppendChild(appElement); 
                 
                j++; 
            } 
 
            //参数 
            XmlElement paramsElement = actElement.OwnerDocument.CreateElement("params"); 
            actElement.AppendChild(paramsElement); 
            //int j = 1; 
            foreach (WfParam param in this.ParamsInfo) 
            { 
                XmlElement paramElement = actElement.OwnerDocument.CreateElement("param"); 
 
                XmlAttribute paramattr = actElement.OwnerDocument.CreateAttribute("ref"); 
                paramattr.Value = param.Name; 
                paramElement.Attributes.Append(paramattr); 
 
                //XmlAttribute paramrankattr = actElement.OwnerDocument.CreateAttribute("rank"); 
                //paramrankattr.Value =j.ToString(); 
                //paramElement.Attributes.Append(paramrankattr); 
 
                paramsElement.AppendChild(paramElement); 
                //j++; 
            } 
 
            XmlElement eventsElement = actElement.OwnerDocument.CreateElement("events"); 
            actElement.AppendChild(eventsElement); 
            //接收前事件 
            XmlElement eventElement = actElement.OwnerDocument.CreateElement("event"); 
            XmlAttribute eventattr = actElement.OwnerDocument.CreateAttribute("eventtype"); 
            //收到前事件 
            eventattr.Value = "0"; 
            eventElement.Attributes.Append(eventattr); 
 
            //SQL 
            eventattr = actElement.OwnerDocument.CreateAttribute("excutetype"); 
            eventattr.Value = "0"; 
            eventElement.Attributes.Append(eventattr); 
 
 
            eventattr = actElement.OwnerDocument.CreateAttribute("content"); 
            eventattr.Value = this.BeforeRecive_Event; 
            eventElement.Attributes.Append(eventattr); 
            eventsElement.AppendChild(eventElement); 
             
            //发送后事件 
 
 
            XmlElement aftersendeventElement = actElement.OwnerDocument.CreateElement("event"); 
            XmlAttribute aftersendeventattr = actElement.OwnerDocument.CreateAttribute("eventtype"); 
            //收到前事件 
            aftersendeventattr.Value = "1"; 
            aftersendeventElement.Attributes.Append(aftersendeventattr); 
 
            //SQL 
            aftersendeventattr = actElement.OwnerDocument.CreateAttribute("excutetype"); 
            aftersendeventattr.Value = "0"; 
            aftersendeventElement.Attributes.Append(aftersendeventattr); 
 
 
            aftersendeventattr = actElement.OwnerDocument.CreateAttribute("content"); 
            aftersendeventattr.Value = this.AfterSend_Event; 
            aftersendeventElement.Attributes.Append(aftersendeventattr); 
            eventsElement.AppendChild(aftersendeventElement); 
 
        } 
        #endregion 
 
        #region 公用 
        /// <summary> 
        /// 打开对话框 
        /// </summary> 
        public override void OpenPropertyDialog() 
        { 
            ActivityInfoDlg dlg = new ActivityInfoDlg(this); 
            dlg.WfActivity = this; 
            dlg.ShowDialog(); 
            dlg.Dispose(); 
        } 
        private WfActivity GetActivityByName(String Name) 
        { 
            foreach (DesignerVisualObject vo in this.Flow.VisualObjectList) 
            { 
                if (vo is WfActivity) 
                { 
 
                    if ((vo as WfActivity).Name == Name) 
                    { 
                        return (WfActivity)vo; 
                    } 
                } 
            } 
            return null; 
        } 
        /// <summary> 
        /// 从xml初始化节点信息 
        /// </summary> 
        /// <param name="actElement">节点xml元素</param> 
        public override void InitFromXml(XmlElement actElement) 
        { 
            //需要改动 
            base.InitFromXml(actElement); 
           /*  if (actElement.Attributes["cycle"].Value == "true") 
            { 
                HasCycleTrans = true; 
            } 
            else 
            { 
                HasCycleTrans = false; 
            } 
            FlowSelect = actElement.Attributes["flowSelect"].Value; 
            UserSelect = actElement.Attributes["userSelect"].Value; 
            */ 
 
            String IsSelectUser = actElement.Attributes["isselectuser"].Value; 
            this.IsSelectUser = Convert.ToInt32(IsSelectUser); 
            this.IsSendBack = Convert.ToInt32(actElement.Attributes["enablesendback"].Value); 
            this.IsSendSelf = Convert.ToInt32(actElement.Attributes["issendself"].Value); 
            this.Workday = Convert.ToDouble(actElement.Attributes["work_day"].Value); 
            this.Warning_time = Convert.ToDouble(actElement.Attributes["warning_time"].Value); 
            if (IsSelectUser == "0") 
            { 
                //得到角色元素 
                XmlElement roleElement = actElement.SelectSingleNode("role") as XmlElement; 
                //角色名称 
                String roleName = roleElement.Attributes["ref"].Value; 
                if (roleName == "") 
                { 
                    Role = null; 
                } 
                else 
                { 
                    //根据角色名称得到角色 
                    Role = Program.WorkflowControl.WfPackageDocument.GetRoleByName(roleName); 
 
                } 
            } 
            else 
            { 
                XmlElement roleElement = actElement.SelectSingleNode("role") as XmlElement; 
                XmlElement beforeactivElement = actElement.SelectSingleNode("before_activ") as XmlElement; 
                String beforeactivName = beforeactivElement.Attributes["ref"].Value; 
                if (beforeactivName == "") 
                { 
                    this.Before_ActiveInfo = null; 
                } 
                else 
                { 
                    //根据角色名称得到角色 
                    Before_ActiveInfo = this.GetActivityByName(beforeactivName); 
 
                } 
            } 
 
 
            //循环得到饮用 
            foreach (XmlElement appElement in actElement.SelectNodes("applications/application")) 
            { 
                //得到应用程序名称 
                String appName = appElement.Attributes["ref"].Value; 
                //根据应用名称得到应用 
               AppList.Add(Program.WorkflowControl.WfPackageDocument.GetApplicationByName(appName)); 
            } 
 
            //循环参数 
            foreach (XmlElement paramElement in actElement.SelectNodes("params/param")) 
            { 
                //得到参数名称 
                String paramName = paramElement.Attributes["ref"].Value; 
                //根据应用名称得到应用 
                this.ParamsInfo.Add(Program.WorkflowControl.WfPackageDocument.GetParamByName(paramName)); 
            } 
 
            //得到参数类型 
            foreach (XmlElement paramElement in actElement.SelectNodes("events/event")) 
            { 
                String eventType = paramElement.Attributes["eventtype"].Value; 
                if (eventType == "0") 
                { 
                    this.BeforeRecive_Event = paramElement.Attributes["content"].Value; 
                    //接收前事件 
                } 
                else 
                { 
                    //发送后事件 
                    if (paramElement.Attributes["content"] != null) 
                    this.AfterSend_Event = paramElement.Attributes["content"].Value; 
                } 
            } 
        } 
 
        #endregion 
        #endregion 
    } 
}