예제 #1
0
 public static void Close(this IArchiveDetailForm detailWindow, bool force)
 {
     if (force)
     {
         detailWindow.Close();
     }
     else
     {
         detailWindow.Hide();
     }
 }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                this.DisposeWindowMenu();
                if (m_detailForm != null)
                {
                    m_detailForm.DisposeWindowMenu();
                }

                if (m_detailForm != null)
                {
                    m_detailForm.VisibleChanged -= new EventHandler(m_detailForm_VisibleChanged);

                    IArchiveDetailFormWithDetailGrids dfdg = m_detailForm as IArchiveDetailFormWithDetailGrids;
                    if (dfdg != null)
                    {
                        foreach (IBoundGrid grid in dfdg.DetailGrids)
                        {
                            if (grid.DisplayManager != null)
                            {
                            }
                        }
                    }
                    m_detailForm = null;
                }
            }
            base.Dispose(disposing);
        }
        private void Initialize(WindowInfo windowInfo)
        {
            this.Name = windowInfo.Name;
            this.Text = windowInfo.Text;

            IList<WindowTabInfo> tabInfos = ADInfoBll.Instance.GetWindowTabInfosByWindowId(windowInfo.Name);
            if (tabInfos == null)
            {
                throw new ArgumentException("there is no windowTab with windowId of " + windowInfo.Name);
            }
            if (tabInfos.Count == 0)
            {
                throw new ArgumentException("There should be at least one TabInfo in WindowInfo with name is " + windowInfo.Name + "!");
            }
            if (tabInfos.Count > 1)
            {
                throw new ArgumentException("There should be at most one TabInfo in WindowInfo with name is " + windowInfo.Name + "!");
            }

            ISearchManager smMaster = ServiceProvider.GetService<IManagerFactory>().GenerateSearchManager(tabInfos[0], null);
            IWindowControlManager cmMaster = ServiceProvider.GetService<IManagerFactory>().GenerateControlManager(tabInfos[0], smMaster) as IWindowControlManager;

            IBaseDao daoParent = ServiceProvider.GetService<IManagerFactory>().GenerateBusinessLayer(tabInfos[0]);
            cmMaster.Dao = daoParent;

            ((IArchiveGrid)base.MasterGrid).SetControlManager(cmMaster, tabInfos[0].GridName);

            // daoParent's subDao is inserted in detailForm
            if (base.MasterGrid is IBoundGridWithDetailGridLoadOnDemand)
            {
                ArchiveFormFactory.GenerateDetailGrids(base.MasterGrid as IBoundGridWithDetailGridLoadOnDemand, tabInfos[0]);
            }

            // Load Additional Menus
            IList<WindowMenuInfo> windowMenuInfos = ADInfoBll.Instance.GetWindowMenuInfo(windowInfo.Name);
            IList<WindowMenuInfo> masterWindowMenuInfos;
            IList<WindowMenuInfo> detailWindowMenuInfos;
            GeneratedArchiveSeeForm.SplitWindowMenu(windowMenuInfos, out masterWindowMenuInfos, out detailWindowMenuInfos);
            if (masterWindowMenuInfos.Count > 0)
            {
                this.GenerateWindowMenu(masterWindowMenuInfos);
            }

            if (windowInfo.GenerateDetailForm)
            {
                if (windowInfo.DetailForm != null)
                {
                    m_detailForm = ArchiveFormFactory.CreateForm(ADInfoBll.Instance.GetFormInfo(windowInfo.DetailForm.Name)) as IArchiveDetailForm;
                    if (windowInfo.DetailWindow == null)
                    {
                        ArchiveFormFactory.GenerateArchiveDetailForm(windowInfo, cmMaster, daoParent, null, m_detailForm);
                    }
                }
                // 和主窗体不关联
                else if (windowInfo.DetailWindow != null)
                {
                    WindowInfo detailWindowInfo = ADInfoBll.Instance.GetWindowInfo(windowInfo.DetailWindow.Name);
                    m_detailForm = ServiceProvider.GetService<IWindowFactory>().CreateWindow(detailWindowInfo) as IArchiveDetailForm;
                    var searchWindow = m_detailForm.GetCustomProperty(MyChildForm.SearchPanelName) as ArchiveSearchForm;
                    if (searchWindow != null)
                    {
                        searchWindow.EnableProgressForm = false;
                    }
                }
                else
                {
                    m_detailForm = ArchiveFormFactory.GenerateArchiveDetailForm(windowInfo, cmMaster, daoParent as IRelationalDao);
                }

                if (m_detailForm != null)
                {
                    //m_detailWindow.ParentArchiveForm = this;
                    // Generate DetailForm's Menu
                    if (detailWindowMenuInfos.Count > 0)
                    {
                        m_detailForm.GenerateWindowMenu(detailWindowMenuInfos);

                        m_detailForm.VisibleChanged += new EventHandler(m_detailForm_VisibleChanged);
                    }
                }
            }

            ArchiveSearchForm searchForm = null;
            this.SetSearchPanel(() =>
            {
                if (searchForm == null)
                {
                    searchForm = new ArchiveSearchForm(this, smMaster, tabInfos[0]);
                    if (cmMaster != null)
                    {
                        cmMaster.StateControls.Add(searchForm);
                    }
                }
                return searchForm;
            });

            m_attachmentForm = GeneratedArchiveSeeForm.CreateAttachmentWindow(this, windowInfo);

            GeneratedArchiveSeeForm.InitializeWindowProcess(windowInfo, this);

            m_windowInfo = windowInfo;
        }
        private void Initialize(WindowInfo windowInfo)
        {
            this.Name = windowInfo.Name;
            this.Text = windowInfo.Text;

            IList<WindowTabInfo> tabInfos = ADInfoBll.Instance.GetWindowTabInfosByWindowId(windowInfo.Name);
            if (tabInfos == null)
            {
                throw new ArgumentException("there is no windowTab with windowId of " + windowInfo.Name);
            }
            if (tabInfos.Count == 0)
            {
                throw new ArgumentException("There should be at least one TabInfo in WindowInfo with name is " + windowInfo.Name + "!");
            }
            if (tabInfos.Count > 1)
            {
                throw new ArgumentException("There should be at most one TabInfo in WindowInfo with name is " + windowInfo.Name + "!");
            }

            ISearchManager smMaster = ServiceProvider.GetService<IManagerFactory>().GenerateSearchManager(tabInfos[0], null);

            IDisplayManager dmMaster = ServiceProvider.GetService<IManagerFactory>().GenerateDisplayManager(tabInfos[0], smMaster);

            (base.MasterGrid as IBoundGrid).SetDisplayManager(dmMaster, tabInfos[0].GridName);

            if (base.MasterGrid is IBoundGridWithDetailGridLoadOnDemand)
            {
                ArchiveFormFactory.GenerateDetailGrids((IBoundGridWithDetailGridLoadOnDemand)base.MasterGrid, tabInfos[0]);
            }

            // Load Additional Menus
            IList<WindowMenuInfo> windowMenuInfos = ADInfoBll.Instance.GetWindowMenuInfo(windowInfo.Name);
            IList<WindowMenuInfo> masterWindowMenuInfos;
            IList<WindowMenuInfo> detailWindowMenuInfos;
            GeneratedArchiveSeeForm.SplitWindowMenu(windowMenuInfos, out masterWindowMenuInfos, out detailWindowMenuInfos);
            if (masterWindowMenuInfos.Count > 0)
            {
                this.GenerateWindowMenu(masterWindowMenuInfos);
            }

            if (windowInfo.GenerateDetailForm)
            {
                // 自定义窗体
                if (windowInfo.DetailForm != null)
                {
                    m_detailForm = ArchiveFormFactory.CreateForm(ADInfoBll.Instance.GetFormInfo(windowInfo.DetailForm.Name)) as IArchiveDetailForm;
                    if (windowInfo.DetailWindow == null)
                    {
                        ArchiveFormFactory.GenerateArchiveDetailForm(windowInfo, null, null, dmMaster, m_detailForm);
                    }
                }
                // 跟主DisplayManager无关的DetailForm
                else if (windowInfo.DetailWindow != null)
                {
                    WindowInfo detailWindowInfo = ADInfoBll.Instance.GetWindowInfo(windowInfo.DetailWindow.Name);
                    m_detailForm = ServiceProvider.GetService<IWindowFactory>().CreateWindow(detailWindowInfo) as IArchiveDetailForm;
                    var searchWindow = m_detailForm.GetCustomProperty(MyChildForm.SearchPanelName) as ArchiveSearchForm;
                    if (searchWindow != null)
                    {
                        searchWindow.EnableProgressForm = false;
                    }
                }
                else
                {
                    // 当DetailFormId有值的时候,不一定是DetailForm,而只是其中的一部分
                    // 和主表一致的明细窗体
                    m_detailForm = ArchiveFormFactory.GenerateArchiveDetailForm(windowInfo, dmMaster);
                }
                if (m_detailForm != null)
                {
                    //m_detailWindow.ParentArchiveForm = this;
                    //m_detailWindow = m_detailWindow;

                    // Generate DetailForm's Menu
                    if (detailWindowMenuInfos.Count > 0)
                    {
                        m_detailForm.GenerateWindowMenu(detailWindowMenuInfos);
                        m_detailForm.VisibleChanged += new EventHandler(m_detailForm_VisibleChanged);
                    }
                }
            }

            ArchiveSearchForm searchForm = null;
            this.SetSearchPanel(() =>
            {
                if (searchForm == null)
                {
                    searchForm = new ArchiveSearchForm(this, smMaster, tabInfos[0]);
                }
                return searchForm;
            });

            m_attachmentForm = CreateAttachmentWindow(this, windowInfo);

            GeneratedArchiveSeeForm.InitializeWindowProcess(windowInfo, this);

            m_windowInfo = windowInfo;
        }
예제 #5
0
        //private static void AddManualDetailForm(System.Windows.Forms.Form form, IArchiveDetailFormAuto detailFormAuto)
        //{
        //    form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        //    form.TopLevel = false;

        //    detailFormAuto.ReplaceFlowLayoutPanel(form);
        //}

        public static ArchiveDetailForm GenerateArchiveDetailForm(WindowInfo windowInfo, IWindowControlManager cmParent, IBaseDao daoParent, IDisplayManager dmParent, IArchiveDetailForm originalDetailForm = null)
        {
            ArchiveDetailForm     detailForm = originalDetailForm as ArchiveDetailForm;
            IList <WindowTabInfo> tabInfos   = ADInfoBll.Instance.GetWindowTabInfosByWindowId(windowInfo.Name);

            IList <WindowTabInfo> detailFormTabInfos  = new List <WindowTabInfo>();
            IList <WindowTabInfo> detailFormTabInfos2 = new List <WindowTabInfo>();

            foreach (WindowTabInfo subTabInfo in tabInfos[0].ChildTabs)
            {
                if (subTabInfo.IsInDetailForm)
                {
                    detailFormTabInfos.Add(subTabInfo);
                }
                else
                {
                    detailFormTabInfos2.Add(subTabInfo);
                }
            }

            //if (detailStyleForm == null && windowInfo.DetailForm != null)
            //{
            //    FormInfo formInfo = ADInfoBll.Instance.GetFormInfo(windowInfo.DetailForm.Name);
            //    if (formInfo == null)
            //    {
            //        throw new ArgumentException("There is no FormInfo with Name of " + windowInfo.DetailForm.Name);
            //    }
            //    detailStyleForm = CreateForm(formInfo);
            //}
            //if (detailStyleForm != null)
            //{
            //    ret = detailStyleForm as ArchiveDetailForm;
            //}

            // 当第二层的任何一个ControlManager为空时,DetailForm作为不可编辑的。
            bool isControlManagerEnable = cmParent != null;

            if (isControlManagerEnable)
            {
                for (int i = 0; i < detailFormTabInfos.Count; ++i)
                {
                    if (string.IsNullOrEmpty(detailFormTabInfos[i].ControlManagerClassName))
                    {
                        dmParent = cmParent.DisplayManager;
                        isControlManagerEnable = false;
                        break;
                    }
                }
            }

            if (detailForm == null)
            {
                if (detailFormTabInfos.Count == 0)
                {
                    if (isControlManagerEnable)
                    {
                        detailForm = new ArchiveDetailFormAuto(cmParent, tabInfos[0].GridName);
                    }
                    else
                    {
                        detailForm = new ArchiveDetailFormAuto(dmParent, tabInfos[0].GridName);
                    }
                }
                else if (detailFormTabInfos.Count == 1)
                {
                    if (isControlManagerEnable)
                    {
                        detailForm = new ArchiveDetailFormAutoWithDetailGrid(cmParent, tabInfos[0].GridName);
                    }
                    else
                    {
                        detailForm = new ArchiveDetailFormAutoWithDetailGrid(dmParent, tabInfos[0].GridName);
                    }
                }
                else
                {
                    string[] texts = new string[detailFormTabInfos.Count];
                    for (int i = 0; i < detailFormTabInfos.Count; ++i)
                    {
                        texts[i] = detailFormTabInfos[i].Text;
                    }

                    if (isControlManagerEnable)
                    {
                        detailForm = new ArchiveDetailFormAutoWithMultiDetailGrid(cmParent, tabInfos[0].GridName, detailFormTabInfos.Count, texts);
                    }
                    else
                    {
                        detailForm = new ArchiveDetailFormAutoWithMultiDetailGrid(dmParent, tabInfos[0].GridName, detailFormTabInfos.Count, texts);
                    }
                }

                //IArchiveDetailFormAuto detailFormAuto = ret as IArchiveDetailFormAuto;
                //if (detailStyleForm != null && detailFormAuto != null)
                //{
                //    AddManualDetailForm(detailStyleForm, detailFormAuto);
                //}
            }
            else
            {
                // Dao 在cmParent处已经设置了
                if (isControlManagerEnable)
                {
                    detailForm.SetControlMananger(cmParent, tabInfos[0].GridName);
                }
                else
                {
                    detailForm.SetDisplayManager(dmParent, tabInfos[0].GridName);
                }
            }

            detailForm.Name = windowInfo.Name;
            detailForm.Text = windowInfo.Text;

            // 只有2层可编辑。主层(控件)-第二层(grid)。再下去就是第二层grid的DetailGrid,不可编辑。
            IArchiveDetailFormWithDetailGrids detailFormWithGrids = detailForm as IArchiveDetailFormWithDetailGrids;

            if (detailFormWithGrids != null)
            {
                for (int i = 0; i < detailFormTabInfos.Count; ++i)
                {
                    if (i >= detailFormWithGrids.DetailGrids.Count)
                    {
                        break;
                    }
                    // 主是ControlManager,并不一定子也是ControlManager。
                    // 主可以在grid编辑,不能通过DetailForm编辑。此时DetailForm是另外显示的东西。
                    if (isControlManagerEnable)
                    {
                        var daoRelational = daoParent as IRelationalDao;
                        if (daoRelational == null)
                        {
                            throw new ArgumentException("IArchiveDetailFormWithDetailGrids must has IRelationalDao.");
                        }

                        ISearchManager        subSm = ServiceProvider.GetService <IManagerFactory>().GenerateSearchManager(detailFormTabInfos[i], cmParent.DisplayManager);
                        IWindowControlManager subCm = ServiceProvider.GetService <IManagerFactory>().GenerateControlManager(detailFormTabInfos[i], subSm) as IWindowControlManager;
                        subCm.Name = detailFormTabInfos[i].Name;
                        ((IArchiveGrid)detailFormWithGrids.DetailGrids[i]).SetControlManager(subCm, detailFormTabInfos[i].GridName);

                        ManagerFactory.GenerateBusinessLayer(daoParent as IRelationalDao, detailFormTabInfos[i]);

                        IBaseDao subDao = daoRelational.GetRelationalDao(i);
                        if (subDao is IMemoriedRelationalDao)
                        {
                            IMemoryDao subMemoryDao = ((IMemoriedRelationalDao)daoRelational.GetRelationalDao(i)).DetailMemoryDao;
                            subCm.Dao = subMemoryDao;

                            //subMemoryDao.AddSubDao(new MasterDetailMemoryDao<>(cmParent));
                            ((IMemoriedRelationalDao)daoRelational.GetRelationalDao(i)).AddRelationToMemoryDao(cmParent.DisplayManager);
                        }
                        else
                        {
                            subCm.Dao = subDao;
                        }
                    }
                    else
                    {
                        ISearchManager  subSm = ServiceProvider.GetService <IManagerFactory>().GenerateSearchManager(detailFormTabInfos[i], dmParent);
                        IDisplayManager subDm = ServiceProvider.GetService <IManagerFactory>().GenerateDisplayManager(detailFormTabInfos[i], subSm);
                        subDm.Name = detailFormTabInfos[i].Name;

                        detailFormWithGrids.DetailGrids[i].SetDisplayManager(subDm, detailFormTabInfos[i].GridName);
                    }
                    GenerateDetailGrids(detailFormWithGrids.DetailGrids[i], detailFormTabInfos[i]);
                }
            }

            if (isControlManagerEnable)
            {
                // Generate Other Daos
                for (int i = 0; i < detailFormTabInfos2.Count; ++i)
                {
                    if (!string.IsNullOrEmpty(detailFormTabInfos2[i].BusinessLayerClassName))
                    {
                        ManagerFactory.GenerateBusinessLayer(daoParent as IRelationalDao, detailFormTabInfos2[i]);
                    }
                }
            }

            // if Master Tab's IsInDetailForm=false, Invisible it
            if (!tabInfos[0].IsInDetailForm)
            {
                if (detailForm is IArchiveDetailFormAuto)
                {
                    (detailForm as IArchiveDetailFormAuto).RemoveControls();
                }
            }

            return(detailForm);
        }
예제 #6
0
        /// <summary>
        /// ShowArchiveDetailForm
        /// </summary>
        /// <param name="detailForm"></param>
        public void ShowArchiveDetailForm()
        {
            IArchiveDetailForm detailForm = this.ArchiveDetailForm;
            Form form = detailForm as Form;

            if (form == null)
            {
                return;
            }

            // 需要变换DetailForm状态
            //if (form.Visible)
            //{
            //    return;
            //}

            //TabbedMdiForm mdiForm = TabbedMdiForm.GetMainForm();
            //if (mdiForm != null)
            {
                form.Text = this.Text + "_详细";

                //// show in mdi
                //mdiForm.AddFormToGroup(form, 1);
                //form.InvisibleOnClosing = true;

                form.FormBorderStyle = FormBorderStyle.None;
                form.TopLevel        = false;
                form.Dock            = DockStyle.Fill;
                this.splitContainer1.Panel2.Controls.Add(form);
                // 如果是最大化,里面的控件不能随着Panel2大小改变而改变
                //form.WindowState = FormWindowState.Maximized;
                // 在还没Show之前,SplitterDistance是按照原大小来的,此时改变窗体大小,SplitterDistance会按比例改变。
                // 所以应该先改变大小,再读入SplitterDistance
                form.Size = new Size(this.Width, this.Height - this.splitContainer1.SplitterDistance);

                this.splitContainer1.Panel2Collapsed = false;

                if (detailForm.MenuStrip != null)
                {
                    detailForm.MenuStrip.Visible = false;
                }
            }
            //else
            //{
            //    form.TopLevel = true;
            //}

            form.VisibleChanged -= new EventHandler(detailForm_VisibleChanged);
            form.VisibleChanged += new EventHandler(detailForm_VisibleChanged);

            form.Show();

            detailForm.UpdateContent();
            //if (detailForm is ArchiveDetailForm)
            //{
            //    (detailForm as ArchiveDetailForm).UpdateContent();
            //}
            //else if (detailForm is ArchiveSeeForm)
            //{
            //    (detailForm as ArchiveSeeForm).UpdateContent();
            //}
            // 如果DisplayManager是BindingSource类型的,如果Cancel会导致 PositionChanged,所以只能Disable Grid
            //  && form.ControlManager != null
            //    && (form.ControlManager.State == StateType.Add || form.ControlManager.State == StateType.Edit)
            // 还不是很好,有问题。Todo
            IDisplayManagerContainer dmc = detailForm as IDisplayManagerContainer;

            if (this.MasterGrid != null && dmc != null && dmc.DisplayManager == this.DisplayManager)
            {
                this.MasterGrid.ReadOnly = true;
            }
        }
        //private static void AddManualDetailForm(System.Windows.Forms.Form form, IArchiveDetailFormAuto detailFormAuto)
        //{
        //    form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        //    form.TopLevel = false;
        //    detailFormAuto.ReplaceFlowLayoutPanel(form);
        //}
        public static ArchiveDetailForm GenerateArchiveDetailForm(WindowInfo windowInfo, IWindowControlManager cmParent, IBaseDao daoParent, IDisplayManager dmParent, IArchiveDetailForm originalDetailForm = null)
        {
            ArchiveDetailForm detailForm = originalDetailForm as ArchiveDetailForm;
            IList<WindowTabInfo> tabInfos = ADInfoBll.Instance.GetWindowTabInfosByWindowId(windowInfo.Name);

            IList<WindowTabInfo> detailFormTabInfos = new List<WindowTabInfo>();
            IList<WindowTabInfo> detailFormTabInfos2 = new List<WindowTabInfo>();
            foreach (WindowTabInfo subTabInfo in tabInfos[0].ChildTabs)
            {
                if (subTabInfo.IsInDetailForm)
                {
                    detailFormTabInfos.Add(subTabInfo);
                }
                else
                {
                    detailFormTabInfos2.Add(subTabInfo);
                }
            }

            //if (detailStyleForm == null && windowInfo.DetailForm != null)
            //{
            //    FormInfo formInfo = ADInfoBll.Instance.GetFormInfo(windowInfo.DetailForm.Name);
            //    if (formInfo == null)
            //    {
            //        throw new ArgumentException("There is no FormInfo with Name of " + windowInfo.DetailForm.Name);
            //    }
            //    detailStyleForm = CreateForm(formInfo);
            //}
            //if (detailStyleForm != null)
            //{
            //    ret = detailStyleForm as ArchiveDetailForm;
            //}

            // 当第二层的任何一个ControlManager为空时,DetailForm作为不可编辑的。
            bool isControlManagerEnable = cmParent != null;
            if (isControlManagerEnable)
            {
                for (int i = 0; i < detailFormTabInfos.Count; ++i)
                {
                    if (string.IsNullOrEmpty(detailFormTabInfos[i].ControlManagerClassName))
                    {
                        dmParent = cmParent.DisplayManager;
                        isControlManagerEnable = false;
                        break;
                    }
                }
            }

            if (detailForm == null)
            {
                if (detailFormTabInfos.Count == 0)
                {
                    if (isControlManagerEnable)
                    {
                        detailForm = new ArchiveDetailFormAuto(cmParent, tabInfos[0].GridName);
                    }
                    else
                    {
                        detailForm = new ArchiveDetailFormAuto(dmParent, tabInfos[0].GridName);
                    }
                }
                else if (detailFormTabInfos.Count == 1)
                {
                    if (isControlManagerEnable)
                    {
                        detailForm = new ArchiveDetailFormAutoWithDetailGrid(cmParent, tabInfos[0].GridName);
                    }
                    else
                    {
                        detailForm = new ArchiveDetailFormAutoWithDetailGrid(dmParent, tabInfos[0].GridName);
                    }
                }
                else
                {
                    string[] texts = new string[detailFormTabInfos.Count];
                    for (int i = 0; i < detailFormTabInfos.Count; ++i)
                    {
                        texts[i] = detailFormTabInfos[i].Text;
                    }

                    if (isControlManagerEnable)
                    {
                        detailForm = new ArchiveDetailFormAutoWithMultiDetailGrid(cmParent, tabInfos[0].GridName, detailFormTabInfos.Count, texts);
                    }
                    else
                    {
                        detailForm = new ArchiveDetailFormAutoWithMultiDetailGrid(dmParent, tabInfos[0].GridName, detailFormTabInfos.Count, texts);
                    }
                }

                //IArchiveDetailFormAuto detailFormAuto = ret as IArchiveDetailFormAuto;
                //if (detailStyleForm != null && detailFormAuto != null)
                //{
                //    AddManualDetailForm(detailStyleForm, detailFormAuto);
                //}
            }
            else
            {
                // Dao 在cmParent处已经设置了
                if (isControlManagerEnable)
                {
                    detailForm.SetControlMananger(cmParent, tabInfos[0].GridName);
                }
                else
                {
                    detailForm.SetDisplayManager(dmParent, tabInfos[0].GridName);
                }
            }

            detailForm.Name = windowInfo.Name;
            detailForm.Text = windowInfo.Text;

            // 只有2层可编辑。主层(控件)-第二层(grid)。再下去就是第二层grid的DetailGrid,不可编辑。
            IArchiveDetailFormWithDetailGrids detailFormWithGrids = detailForm as IArchiveDetailFormWithDetailGrids;
            if (detailFormWithGrids != null)
            {
                for (int i = 0; i < detailFormTabInfos.Count; ++i)
                {
                    if (i >= detailFormWithGrids.DetailGrids.Count)
                        break;
                    // 主是ControlManager,并不一定子也是ControlManager。
                    // 主可以在grid编辑,不能通过DetailForm编辑。此时DetailForm是另外显示的东西。
                    if (isControlManagerEnable)
                    {
                        var daoRelational = daoParent as IRelationalDao;
                        if (daoRelational == null)
                        {
                            throw new ArgumentException("IArchiveDetailFormWithDetailGrids must has IRelationalDao.");
                        }

                        ISearchManager subSm = ServiceProvider.GetService<IManagerFactory>().GenerateSearchManager(detailFormTabInfos[i], cmParent.DisplayManager);
                        IWindowControlManager subCm = ServiceProvider.GetService<IManagerFactory>().GenerateControlManager(detailFormTabInfos[i], subSm) as IWindowControlManager;
                        subCm.Name = detailFormTabInfos[i].Name;
                        ((IArchiveGrid)detailFormWithGrids.DetailGrids[i]).SetControlManager(subCm, detailFormTabInfos[i].GridName);

                        ManagerFactory.GenerateBusinessLayer(daoParent as IRelationalDao, detailFormTabInfos[i]);

                        IBaseDao subDao = daoRelational.GetRelationalDao(i);
                        if (subDao is IMemoriedRelationalDao)
                        {
                            IMemoryDao subMemoryDao = ((IMemoriedRelationalDao)daoRelational.GetRelationalDao(i)).DetailMemoryDao;
                            subCm.Dao = subMemoryDao;

                            //subMemoryDao.AddSubDao(new MasterDetailMemoryDao<>(cmParent));
                            ((IMemoriedRelationalDao)daoRelational.GetRelationalDao(i)).AddRelationToMemoryDao(cmParent.DisplayManager);
                        }
                        else
                        {
                            subCm.Dao = subDao;
                        }
                    }
                    else
                    {
                        ISearchManager subSm = ServiceProvider.GetService<IManagerFactory>().GenerateSearchManager(detailFormTabInfos[i], dmParent);
                        IDisplayManager subDm = ServiceProvider.GetService<IManagerFactory>().GenerateDisplayManager(detailFormTabInfos[i], subSm);
                        subDm.Name = detailFormTabInfos[i].Name;

                        detailFormWithGrids.DetailGrids[i].SetDisplayManager(subDm, detailFormTabInfos[i].GridName);
                    }
                    GenerateDetailGrids(detailFormWithGrids.DetailGrids[i], detailFormTabInfos[i]);
                }
            }

            if (isControlManagerEnable)
            {
                // Generate Other Daos
                for (int i = 0; i < detailFormTabInfos2.Count; ++i)
                {
                    if (!string.IsNullOrEmpty(detailFormTabInfos2[i].BusinessLayerClassName))
                    {
                        ManagerFactory.GenerateBusinessLayer(daoParent as IRelationalDao, detailFormTabInfos2[i]);
                    }
                }
            }

            // if Master Tab's IsInDetailForm=false, Invisible it
            if (!tabInfos[0].IsInDetailForm)
            {
                if (detailForm is IArchiveDetailFormAuto)
                {
                    (detailForm as IArchiveDetailFormAuto).RemoveControls();
                }
            }

            return detailForm;
        }