Beispiel #1
0
        public override void OnMouseDown(int x, int y)
        {
            BaseActivity activity = CreateActivity(x, y);

            Ctrl.Document.ActivityList.Add(activity);
            Ctrl.RedrawAll();
            AfterActivityCreate();
        }
Beispiel #2
0
        public LineActivity(BaseActivity source, BaseActivity target)
        {
            _source      = source;
            _target      = target;
            _description = source.Description + "→" + target.Description;

            _x    = _target.X + (_source.X - _target.X) / 2;
            _y    = _target.Y + (_source.Y - _target.Y) / 2;
            _rect = new Rectangle(_x - 4, _y - 4, 8, 8);
        }
Beispiel #3
0
 BaseActivity GetNextActivity(BaseActivity currActivity, out LineActivity nextLine)
 {
     foreach (Activity act in _document.ActivityList)
     {
         if (act is LineActivity && (act as LineActivity).Source.ID == currActivity.ID)
         {
             nextLine = act as LineActivity;
             return((act as LineActivity).Target);
         }
     }
     nextLine = null;
     return(null);
 }
        public override void OnMouseDown(int x, int y)
        {
            HitTestResult start = Ctrl.Document.HitTest(x, y);

            if (null == start || !(start.activity is BaseActivity))
            {
                MessageBox.Show("必须从活动开始!");
                Ctrl.CurrentTool = new SelectorTool();
            }
            else if (start.activity is EndActivity)
            {
                MessageBox.Show("不能从结束活动开始!");
                Ctrl.CurrentTool = new SelectorTool();
            }
            else
            {
                startActivity = start.activity as BaseActivity;
                startMouseX   = x;
                startMouseY   = y;
                setEndMousePosition(x, y);
            }
        }
        public void CreateXml(XmlElement xmlElement)
        {
            XmlElement processElement = xmlElement.OwnerDocument.CreateElement("process");

            XmlAttribute attr = xmlElement.OwnerDocument.CreateAttribute("id");

            attr.Value = _id;
            processElement.Attributes.Append(attr);

            attr       = xmlElement.OwnerDocument.CreateAttribute("description");
            attr.Value = _description;
            processElement.Attributes.Append(attr);

            XmlElement actsElement = processElement.OwnerDocument.CreateElement("activities");

            processElement.AppendChild(actsElement);
            foreach (Activity activity in _activities)
            {
                if (!(activity is LineActivity))
                {
                    BaseActivity act = activity as BaseActivity;
                    act.CreateXml(actsElement);
                }
            }
            XmlElement linesElement = processElement.OwnerDocument.CreateElement("lines");

            processElement.AppendChild(linesElement);
            foreach (Activity activity in _activities)
            {
                if (activity is LineActivity)
                {
                    LineActivity line = activity as LineActivity;
                    line.CreateXml(linesElement);
                }
            }
            xmlElement.AppendChild(processElement);
        }
        public void CreateProcess()
        {
            XmlNodeList         activityNodes = _layout.SelectNodes("process/activities/activity");
            List <BaseActivity> activities    = new List <BaseActivity>();

            foreach (XmlNode activityNode in activityNodes)
            {
                BaseActivity activity = null;
                string       type     = activityNode.Attributes["type"].Value;
                int          x        = Convert.ToInt32(activityNode.Attributes["x"].Value);
                int          y        = Convert.ToInt32(activityNode.Attributes["y"].Value);
                decimal      time     = 0;
                if (null != activityNode.Attributes["time"])
                {
                    time = Convert.ToDecimal(activityNode.Attributes["time"].Value);
                }
                switch (type)
                {
                case "0":
                    activity = new StartActivity(x, y);
                    break;

                case "1":
                    activity = new EndActivity(x, y);
                    break;

                case "2":
                    activity = new ManualActivity(x, y);
                    (activity as ManualActivity).Time = time;
                    //roles
                    XmlNodeList roleNodes = activityNode.SelectNodes("roles/role");
                    if (null != roleNodes && roleNodes.Count > 0)
                    {
                        List <SYS_BUSINESSROLE> roles = new List <SYS_BUSINESSROLE>();
                        foreach (XmlNode node in roleNodes)
                        {
                            SYS_BUSINESSROLE role = new SYS_BUSINESSROLE();
                            role.ID       = Convert.ToInt32(node.Attributes["id"].Value);
                            role.ROLENAME = node.Attributes["name"].Value;
                            role.Selected = Convert.ToInt32(node.Attributes["selected"].Value);
                            roles.Add(role);
                        }
                        (activity as ManualActivity).Roles = roles;
                    }
                    //forms
                    XmlNodeList formNodes = activityNode.SelectNodes("forms/form");
                    if (null != formNodes && formNodes.Count > 0)
                    {
                        List <SYS_BUSINESSFORM> forms = new List <SYS_BUSINESSFORM>();
                        foreach (XmlNode node in formNodes)
                        {
                            SYS_BUSINESSFORM form = new SYS_BUSINESSFORM();
                            form.ID       = Convert.ToInt32(node.Attributes["id"].Value);
                            form.FORMNAME = node.Attributes["name"].Value;
                            form.Checked  = Convert.ToInt32(node.Attributes["checked"].Value);
                            forms.Add(form);
                        }
                        (activity as ManualActivity).Forms = forms;
                    }
                    break;

                default:
                    break;
                }

                if (activity != null)
                {
                    activity.ID          = activityNode.Attributes["id"].Value;
                    activity.Description = activityNode.Attributes["description"].Value;
                    activity.X           = x;
                    activity.Y           = y;
                    document.ActivityList.Add(activity);
                    activities.Add(activity);
                }
            }
            XmlNodeList lineNodes = _layout.SelectNodes("process/lines/line");

            foreach (XmlNode lineNode in lineNodes)
            {
                int          x        = Convert.ToInt32(lineNode.Attributes["x"].Value);
                int          y        = Convert.ToInt32(lineNode.Attributes["y"].Value);
                string       sourceId = lineNode.Attributes["source"].Value;
                string       targetId = lineNode.Attributes["target"].Value;
                BaseActivity source   = null;
                BaseActivity target   = null;
                foreach (BaseActivity act in activities)
                {
                    if (act.ID == sourceId)
                    {
                        source = act;
                        continue;
                    }
                    if (act.ID == targetId)
                    {
                        target = act;
                        continue;
                    }
                }

                LineActivity activity = new LineActivity(source, target);
                if (activity != null)
                {
                    activity.ID          = lineNode.Attributes["id"].Value;
                    activity.Description = lineNode.Attributes["description"].Value;
                    activity.X           = x;
                    activity.Y           = y;
                    document.Lines.Add(activity);
                    document.ActivityList.Add(activity);
                }
            }
        }
Beispiel #7
0
        private void cmsiArrange_Click(object sender, EventArgs e)
        {
            StartActivity startActivity = null;

            foreach (Activity act in _document.ActivityList)
            {
                if (act is BaseActivity)
                {
                    BaseActivity bAct = act as BaseActivity;
                    if (bAct.GetActivityType() == "0")
                    {
                        startActivity = bAct as StartActivity;
                    }
                }
            }

            LineActivity nextLine     = null;
            BaseActivity nextActivity = null;
            BaseActivity currActivity = startActivity;
            int          i            = 1;
            string       direction    = "right";

            while ((nextActivity = GetNextActivity(currActivity, out nextLine)) != null)
            {
                if (i % 4 == 0)
                {
                    if (direction == "right")
                    {
                        direction = "left";
                    }
                    else
                    {
                        direction = "right";
                    }

                    nextLine.X     = currActivity.X;
                    nextLine.Y     = currActivity.Y + 50;
                    nextActivity.X = currActivity.X;
                    nextActivity.Y = currActivity.Y + 100;
                    currActivity   = nextActivity;
                }
                else
                {
                    if (direction == "right")
                    {
                        nextLine.X     = currActivity.X + 100;
                        nextLine.Y     = currActivity.Y;
                        nextActivity.X = currActivity.X + 200;
                        nextActivity.Y = currActivity.Y;
                        currActivity   = nextActivity;
                    }
                    else
                    {
                        nextLine.X     = currActivity.X - 100;
                        nextLine.Y     = currActivity.Y;
                        nextActivity.X = currActivity.X - 200;
                        nextActivity.Y = currActivity.Y;
                        currActivity   = nextActivity;
                    }
                }
                i++;
            }

            RedrawAll();
        }