コード例 #1
0
        private void ModuleBase_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(ModuleControl)))
            {
                ModuleControl sourceControl = e.Data.GetData(typeof(ModuleControl)) as ModuleControl;

                if (sourceControl.Parent == null)
                {
                    ((ProcessTabPage)this.Parent).AddModule(sourceControl, this);
                }
                else
                {
                    ((ProcessTabPage)this.Parent).MoveModule(sourceControl, this);
                }

                #region
                //if (sourceControl.Parent == null)
                //{   // 新建控件
                //    foreach (ModuleControl item in ((ProcessControl)Parent).Controls)
                //    {
                //        if (item.Location.Y >= this.Location.Y)
                //        {
                //            item.UnitIndex++;
                //            item.Location = new Point(item.Location.X, item.Location.Y + item.Height);
                //        }
                //    }
                //    sourceControl.UnitIndex = this.UnitIndex - 1;
                //    sourceControl.Location = new Point(sourceControl.Location.X, this.Location.Y - this.Height);
                //    sourceControl.Parent = this.Parent;
                //}
                //else if (this.Location.Y < sourceControl.Location.Y)
                //{   // 源控件上移
                //    foreach (ModuleControl item in ((ProcessControl)Parent).Controls)
                //    {
                //        if (item.Location.Y >= this.Location.Y && item.Location.Y < sourceControl.Location.Y)
                //        {
                //            item.UnitIndex++;
                //            item.Location = new Point(item.Location.X, item.Location.Y + item.Height);
                //        }
                //    }
                //    sourceControl.UnitIndex = this.UnitIndex - 1;
                //    sourceControl.Location = new Point(sourceControl.Location.X, this.Location.Y - this.Height);
                //}
                //else if (this.Location.Y > sourceControl.Location.Y)
                //{   // 源控件下移
                //    foreach (ModuleControl item in ((ProcessControl)Parent).Controls)
                //    {
                //        if (item.Location.Y <= this.Location.Y && item.Location.Y > sourceControl.Location.Y)
                //        {
                //            item.UnitIndex--;
                //            item.Location = new Point(item.Location.X, item.Location.Y - item.Height);
                //        }
                //    }
                //    sourceControl.UnitIndex = this.UnitIndex + 1;
                //    sourceControl.Location = new Point(sourceControl.Location.X, this.Location.Y + this.Height);
                //}
                #endregion
            }
        }
コード例 #2
0
        public void MoveModule(ModuleControl sourceControl, ModuleControl targetControl = null)
        {
            if (targetControl == null)
            {
                ModuleControl lastControl = LastModule();

                if (lastControl != sourceControl)
                {
                    foreach (ModuleControl item in Controls)
                    {
                        if (item.Location.Y > sourceControl.Location.Y)
                        {
                            item.Index--;
                            item.Location = new Point(item.Location.X, item.Location.Y - item.Height);
                        }
                    }

                    sourceControl.Index    = lastControl.Index + 1;
                    sourceControl.Location = new Point(sourceControl.Location.X, lastControl.Location.Y + lastControl.Height);
                }
            }
            else
            {
                if (targetControl.Location.Y < sourceControl.Location.Y)
                {   // 源控件上移
                    foreach (ModuleControl item in Controls)
                    {
                        if (item.Location.Y >= targetControl.Location.Y && item.Location.Y < sourceControl.Location.Y)
                        {
                            item.Index++;
                            item.Location = new Point(item.Location.X, item.Location.Y + item.Height);
                        }
                    }
                    sourceControl.Index    = targetControl.Index - 1;
                    sourceControl.Location = new Point(sourceControl.Location.X, targetControl.Location.Y - targetControl.Height);
                }
                else if (targetControl.Location.Y > sourceControl.Location.Y)
                {   // 源控件下移
                    foreach (ModuleControl item in Controls)
                    {
                        if (item.Location.Y <= targetControl.Location.Y && item.Location.Y > sourceControl.Location.Y)
                        {
                            item.Index--;
                            item.Location = new Point(item.Location.X, item.Location.Y - item.Height);
                        }
                    }
                    sourceControl.Index    = targetControl.Index + 1;
                    sourceControl.Location = new Point(sourceControl.Location.X, targetControl.Location.Y + targetControl.Height);
                }
            }

            SortModule();
        }
コード例 #3
0
        public void RemoveModule(ModuleControl sourceControl)
        {
            foreach (ModuleControl item in this.Controls)
            {
                if (sourceControl.Location.Y < item.Location.Y)
                {
                    item.Index--;
                    item.Location = new Point(item.Location.X, item.Location.Y - item.Height);
                }
            }

            Project.GetInstance().Items[Text].Items.Remove(sourceControl.Module);

            sourceControl.Dispose();

            SortModule();
        }
コード例 #4
0
        public ModuleControl LastModule()
        {
            if (this.Controls.Count == 0)
            {
                return(null);
            }

            ModuleControl lastControl = Controls[0] as ModuleControl;

            foreach (ModuleControl item in Controls)
            {
                if (lastControl.Location.Y < item.Location.Y)
                {
                    lastControl = item;
                }
            }

            return(lastControl);
        }
コード例 #5
0
        public void AddModule(ModuleControl sourceControl, ModuleControl targetControl = null)
        {
            if (targetControl == null)
            {
                ModuleControl lastControl = LastModule();

                if (lastControl == null)
                {
                    sourceControl.Index    = 1;
                    sourceControl.Location = new Point(0, 0);
                }
                else
                {
                    sourceControl.Index    = lastControl.Index + 1;
                    sourceControl.Location = new Point(sourceControl.Location.X, lastControl.Location.Y + lastControl.Height);
                }

                sourceControl.Parent = this;

                sourceControl.Module.Owner = Project.GetInstance()[Text];
                Project.GetInstance()[Text].Items.Add(sourceControl.Module);
            }
            else
            {
                foreach (ModuleControl item in Controls)
                {
                    if (item.Location.Y >= targetControl.Location.Y)
                    {
                        item.Index++;
                        item.Location = new Point(item.Location.X, item.Location.Y + item.Height);
                    }
                }
                sourceControl.Index    = targetControl.Index - 1;
                sourceControl.Location = new Point(sourceControl.Location.X, targetControl.Location.Y - targetControl.Height);

                sourceControl.Parent = this;

                sourceControl.Module.Owner = Project.GetInstance().Items[Text];
                Project.GetInstance().Items[Text].Items.Insert(sourceControl.Index, sourceControl.Module);

                SortModule();
            }
        }
コード例 #6
0
        private void Open(string fileName)
        {
            // 加载当前应用程序目录下的指定程序集
            DirectoryInfo info = new DirectoryInfo(Application.StartupPath);

            FileInfo[] files = info.GetFiles("*Module.dll");

            Dictionary <Type, Assembly> typeCollection = new Dictionary <Type, Assembly>();

            foreach (var file in files)
            {
                Assembly a     = Assembly.LoadFile(file.FullName);
                Type[]   types = a.GetExportedTypes();

                foreach (var type in types)
                {
                    ModuleAttribute attribute = (ModuleAttribute)type.GetCustomAttribute(typeof(ModuleAttribute));

                    if (attribute != null)
                    {
                        typeCollection.Add(type, a);
                    }
                }
            }

            // 从XML加载流程
            XmlDocument doc = new XmlDocument();

            doc.Load(fileName);

            XmlElement root = doc.DocumentElement;

            // 清理所有流程
            TabProcesses.TabPages.Clear();
            Project.GetInstance().Clear();
            Project.GetInstance().Name = root.GetAttribute("name");

            // 流程节点循环加载
            foreach (XmlElement page in root.ChildNodes)
            {
                // 增加流程
                ProcessTabPage tp = new ProcessTabPage(page.GetAttribute("name") /*, VisualProject*/);
                TabProcesses.TabPages.Add(tp);

                // 模块节点循环加载
                foreach (XmlElement unit in page.ChildNodes)
                {
                    foreach (var type in typeCollection)
                    {
                        // 获取类型自定义特性
                        ModuleAttribute des = (ModuleAttribute)type.Key.GetCustomAttribute(typeof(ModuleAttribute));

                        if (unit.GetAttribute("name") == des.Name)
                        {
                            // 增加模块
                            ModuleBase module = (ModuleBase)type.Value.CreateInstance(type.Key.FullName);
                            module.Owner = Project.GetInstance()[tp.Text];
                            module.Index = Convert.ToInt32(unit.GetAttribute("id"));
                            module.Load();

                            ModuleControl mc = new ModuleControl(module);
                            tp.AddModule(mc);
                        }
                    }
                }
            }

            // 设置主流程
            Project.GetInstance().MainProcess = Project.GetInstance()[root.GetAttribute("main")];
            TabProcesses.SelectTab(Project.GetInstance().MainProcess.Name);
        }
コード例 #7
0
        private void TabProcess_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(ModuleControl)))
            {
                #region
                //ModuleControl sourceControl = e.Data.GetData(typeof(ModuleControl)) as ModuleControl;

                //if (this.Controls.Count == 0)
                //{   // 没有控件
                //    sourceControl.UnitIndex = 1;
                //    sourceControl.Location = new Point(0, 0);
                //    sourceControl.Parent = this;

                //    return;
                //}

                //// 最后的控件
                //ModuleControl lastControl = this.Controls[0] as ModuleControl;
                //foreach (ModuleControl item in this.Controls)
                //{
                //    if (lastControl.Location.Y < item.Location.Y)
                //    {
                //        lastControl = item;
                //    }
                //}

                //if (lastControl.Location.Y > sourceControl.Location.Y  && sourceControl.Location.Y != -1)
                //{   // 移动控件
                //    foreach (ModuleControl item in this.Controls)
                //    {
                //        if (item.Location.Y > sourceControl.Location.Y)
                //        {
                //            item.UnitIndex--;
                //            item.Location = new Point(item.Location.X, item.Location.Y - item.Height);
                //        }
                //    }
                //    sourceControl.UnitIndex = lastControl.UnitIndex + 1;
                //    sourceControl.Location = new Point(sourceControl.Location.X, lastControl.Location.Y + lastControl.Height);
                //}
                //else if (sourceControl.Parent == null)
                //{   // 增加控件
                //    sourceControl.UnitIndex = lastControl.UnitIndex + 1;
                //    sourceControl.Location = new Point(sourceControl.Location.X, lastControl.Location.Y + lastControl.Height);
                //    sourceControl.Parent = this;

                //}
                #endregion


                ModuleControl sourceControl = e.Data.GetData(typeof(ModuleControl)) as ModuleControl;

                if (sourceControl.Parent == null)
                {
                    AddModule(sourceControl);
                }
                else
                {
                    MoveModule(sourceControl);
                }
            }
        }