dev的documentManager,多个tab窗体

控件vs的menuStrip+dev的documentManager

private void CreateData(List<Funcation> modules)
        {
            modules.Add(new Funcation() { ID = 1, PID = -1, FunctionName = "统计数据", FunctionKey = "" });
            modules.Add(new Funcation() { ID = 2, PID = 1, FunctionName = "未打单统计数据", FunctionKey = "ClientGoodInfo.PlaySingleInfo.frmPlaySingleInfo" });
            modules.Add(new Funcation() { ID = 3, PID = 1, FunctionName = "Rides未打单统计", FunctionKey = "ClientGoodInfo.RedisData.frmPlaySingleInfo" });
        }

        private void LoadItemModules()
        {
            List<Funcation> modules = new List<Funcation>();
            CreateData(modules);
            LoadItemModules(modules, -1, menuItem.Items);
        }

        public void LoadItemModules(List<Funcation> modules, int parentModuleNO, ToolStripItemCollection items)
        {
            foreach (var module in modules)
            {
                if (module.PID != parentModuleNO) continue;
                var item = new ToolStripMenuItem();
                object runner = null;
                if (!string.IsNullOrWhiteSpace(module.FunctionKey))
                {
                    var typeFullNames = module.FunctionKey.Split(',');
                    foreach (var typeFullName in typeFullNames)
                    {
                        runner = ReflectFormType.Reflect(typeFullName);
                        if (runner != null) break;
                    }
                }
                if (runner == null && !modules.Any(m => m.PID == module.ID)) continue;
                item.Text = module.FunctionName;
                item.Tag = module;
                items.Add(item);
                item.Click += item_Click;
                LoadItemModules(modules, module.ID, item.DropDownItems);
            }
        }

        private void item_Click(object sender, EventArgs e)
        {
            var type = ((ToolStripMenuItem)sender).Tag as Funcation;
            if (type != null)
                AddDocument(type);
        }

        private void AddDocument(Funcation CurrentModel)
        {
            if (!string.IsNullOrWhiteSpace(CurrentModel.FunctionKey))
            {
                var typeFullNames = CurrentModel.FunctionKey.Split(',');
                foreach (var typeFullName in typeFullNames)
                {
                    var type = ReflectFormType.GetFrom(typeFullName);//反射窗体类型
                    if (type != null)
                    {
                        foreach (BaseDocument fdocument in tabbedView1.Documents)
                        {
                            if (fdocument.Tag == type)
                            {
                                tabbedView1.Controller.Activate(fdocument);//是否已经打开窗体
                                return;
                            }
                        }
                        tabbedView1.BeginUpdate();//开始加载窗体
                        tabbedView1.Manager.MdiParent = this;
                        BaseDocument document = tabbedView1.AddDocument(type);
                        document.Footer = Directory.GetCurrentDirectory();
                        document.Tag = type;
                        tabbedView1.Controller.Activate(document);
                        tabbedView1.EndUpdate();
                        break;
                    }
                }
            }
        }

 

posted @ 2018-09-28 09:57  世人皆萌  阅读(478)  评论(0编辑  收藏  举报