コード例 #1
0
        void ViewController2_HandleCreated(object sender, EventArgs e)
        {
            // Вставка Layout
            if (AnalysisCriterionListAction.Items.Count == 0)
            {
                return;
            }

            //DevExpress.XtraEditors.PanelControl filterPanel = new DevExpress.XtraEditors.PanelControl();
            filterPanel             = new DevExpress.XtraEditors.PanelControl();
            filterPanel.Height      = 80;
            filterPanel.MinimumSize = new System.Drawing.Size(0, 0);
            filterPanel.Dock        = System.Windows.Forms.DockStyle.Top;
            filterPanel.AutoSize    = false;
            //filterPanel.GetPreferredSize(
            filterPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            //filterPanel.Hide();
            //filterPanel.Show();
            //filterPanel.Controls.Add(splitter);

            splitter          = new DevExpress.XtraEditors.SplitterControl();
            splitter.Height   = 50;
            splitter.Dock     = System.Windows.Forms.DockStyle.Top;
            splitter.AutoSize = false;
            //splitter.Hide();
            //splitter.Show();
            //splitter.Controls.Add(filterPanel);

            //DevExpress.XtraEditors.PanelControl dataPanel = new DevExpress.XtraEditors.PanelControl();
            dataPanel              = new DevExpress.XtraEditors.PanelControl();
            dataPanel.Height       = 50;
            dataPanel.MinimumSize  = new System.Drawing.Size(0, 0);
            dataPanel.Dock         = System.Windows.Forms.DockStyle.Fill;
            dataPanel.AutoSize     = false;
            dataPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            //dataPanel.Hide();
            //dataPanel.Show();
            //dataPanel.Controls.Add(splitter);

            if (((System.Windows.Forms.Control)sender).Parent == null)
            {
                return;
            }
            ((System.Windows.Forms.Control)sender).Parent.Controls.Add(dataPanel);
            ((System.Windows.Forms.Control)sender).Parent.Controls.Add(splitter);
            ((System.Windows.Forms.Control)sender).Parent.Controls.Add(filterPanel);

            // Находим контрол, показывающий DetailView
            System.Windows.Forms.Control ctrl = ((System.Windows.Forms.Control)sender).Parent.Controls[0];
            ctrl.Parent = dataPanel;

            // DetailView с фильтром
            IObjectSpace objectSpace = Application.CreateObjectSpace();

            // Находим 1-й элемент списка фильтров
            IModelDetailView node = AnalysisCriterionListAction.Items[0].Data as IModelDetailView;
            // Тип объекта-фильтра
            Type filterObjType = node.ModelClass.TypeInfo.Type;

            wp = objectSpace.CreateObject(filterObjType) as ICustomFilter;
            if (wp == null)
            {
                return;
            }

            string DetailViewId = frame.Application.FindDetailViewId(wp.GetType());
            //TargetWindow openMode = TargetWindow.Current;

            DetailView newView = frame.Application.CreateDetailView(objectSpace, DetailViewId, false, wp);

            newView.CreateControls();

            // Назначения:
            //DevExpress.ExpressApp.ListView listView = sender as DevExpress.ExpressApp.ListView;
            DevExpress.ExpressApp.DetailView detailView = View as DevExpress.ExpressApp.DetailView;
            if (detailView == null)
            {
                return;
            }
            // ((System.Windows.Forms.Control)sender).Parent.Parent.Parent.Parent.Parent  as DevExpress.ExpressApp.ListView
            DevExpress.ExpressApp.DC.ITypeInfo objectTypeInfo = detailView.ObjectTypeInfo;

            wp.LV = null;
            wp.DV = detailView;
            //wp.objectType = typeObjectOfListView;
            wp.objectTypeInfo     = objectTypeInfo;
            wp.CriteriaController = this;

            DevExpress.ExpressApp.Win.Layout.XafLayoutControl ctrlFilter = ((DevExpress.ExpressApp.Win.Layout.XafLayoutControl)newView.Control);

            filterPanel.Controls.Add(ctrlFilter);

            // Показ панели с фильтром
            FilterPanelShow(GetFilterHight(newView) + 30);
        }
コード例 #2
0
        private void MiniNavigationAction_Execute(object sender, SingleChoiceActionExecuteEventArgs e)
        {
            if (e.CurrentObject == null)
            {
                return;
            }

            if (MiniNavigationAction.SelectedItem == null)
            {
                return;
            }

            object currentObj = e.CurrentObject;

            Frame  frame = Frame;
            View   view  = View;
            string path  = e.SelectedChoiceActionItem.Id;
            //if (selId == path) return;
            String selId = path;

            if ((view as DetailView) != null & selId == "This")
            {
                return;
            }

            BaseObject obj = GetObjectOnPathEnd(path, (BaseObject)currentObj);

            if (obj == null)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(
                    CommonMethods.GetMessage(MiniNavigatorControllerMessages.SHOWING_OBJECT_NOT_DEFINED),
                    messageCaption,
                    System.Windows.Forms.MessageBoxButtons.OK,
                    System.Windows.Forms.MessageBoxIcon.Exclamation);
                return;
            }

            Type   ChoiceType = (System.Type)(obj.GetType());             //.UnderlyingSystemType;   //typeof(object);
            string ViewID     = Application.FindDetailViewId(ChoiceType); // По умолчанию - DetailView

            // Считывание из модели view, через которое надо показать объект и оно задано
            IModelView modelView = null;

            DevExpress.ExpressApp.ListView   listView   = view as DevExpress.ExpressApp.ListView;
            DevExpress.ExpressApp.DetailView detailView = view as DevExpress.ExpressApp.DetailView;

            //if (IsMiniNavigationDefined) {
            //    // Узел в модели
            //    IModelView node = null;
            //    node = View.Model.Application.Views[((listView != null) ? listView.Id : "") + ((detailView != null) ? detailView.Id : "")];
            //    if (node != null) {
            //        // Перебираем все подузлы
            //        // node.GetNode(1)	{ModelListViewFilters}	DevExpress.ExpressApp.Model.IModelNode {ModelListViewFilters}
            //        for (int i = 0; i < node.NodeCount; i++) {
            //IModelMiniNavigations miniNavigationNode = node.GetNode(i) as IModelMiniNavigations;
            IModelMiniNavigations miniNavigationNode = FindMiniNavigationModel(View);

            if (miniNavigationNode != null)
            {
                foreach (IModelMiniNavigationItem miniNavigationItem in miniNavigationNode.GetNodes <IModelMiniNavigationItem>())
                {
                    if (miniNavigationItem.NavigationPath == selId)
                    {
                        modelView = miniNavigationItem.View;
                        break;
                    }
                }
                //break;
            }
            //        }
            //    }
            //}


            Frame        resultFrame = frame; // Application.CreateFrame("new");
            TargetWindow openMode    = (TargetWindow)e.SelectedChoiceActionItem.Data;

            // Сбрасываем состояние списка
            MiniNavigationAction.SelectedItem  = null;
            MiniNavigationAction.SelectedIndex = 0;

            // Небольшая разборка с сочетанием значений openMode и типа текущего View - List или Detail - в целях
            // определения фрейма, в который грузить
            if (MasterDetailViewFrame != null && (openMode == TargetWindow.Current & (view as ListView) != null & ((frame as NestedFrame) != null | !view.IsRoot)))
            {
                // Тогда Current трактуем как корневое окно
                resultFrame = MasterDetailViewFrame;
                {
                    //IObjectSpace objectSpace = resultFrame.View.ObjectSpace;
                    IObjectSpace objectSpace       = resultFrame.Application.CreateObjectSpace(); // Всё равно предыдущий ObjectSpace теряется в этом случае
                    object       representativeObj = objectSpace.GetObject(obj);

                    View dv = null;

                    if (modelView != null)
                    {
                        if ((modelView as IModelDetailView) != null)
                        {
                            ViewID = (modelView as IModelDetailView).Id;
                            dv     = resultFrame.Application.CreateDetailView(objectSpace, ViewID, true, representativeObj) as DetailView;
                        }
                        else if ((modelView as IModelListView) != null)
                        {
                            ViewID = (modelView as IModelListView).Id;
                            //ListView dv = resultFrame.Application.CreateListView(objectSpace, ChoiceType, true);
                            CollectionSource colSource = new CollectionSource(objectSpace, ChoiceType);
                            if (!colSource.IsLoaded)
                            {
                                colSource.Reload();
                            }
                            dv = resultFrame.Application.CreateListView((modelView as IModelListView), colSource, true) as ListView;
                        }
                    }
                    else
                    {
                        ViewID = Application.FindDetailViewId(ChoiceType);
                        dv     = resultFrame.Application.CreateDetailView(objectSpace, ViewID, true, representativeObj) as DetailView;
                    }

                    resultFrame.SetView(dv, true, resultFrame);
                }
                return;
            }

            // Общий алгоритм
            {
                IObjectSpace objectSpace = null;

                // Анализ того, какой ObjectSpace нужен
                if ((frame as NestedFrame) != null | !view.IsRoot)
                {
                    objectSpace = resultFrame.View.ObjectSpace.CreateNestedObjectSpace();
                }
                //objectSpace = resultFrame.View.ObjectSpace.CreateNestedObjectSpace();
                if (objectSpace == null)
                {
                    objectSpace = resultFrame.Application.CreateObjectSpace();
                }

                object representativeObj = objectSpace.GetObject(obj);

                //ViewID = Application.FindDetailViewId(ChoiceType);
                //DetailView dv = frame.Application.CreateDetailView(objectSpace, ViewID, true, representativeObj);

                View dv = null;

                if (modelView != null)
                {
                    if ((modelView as IModelDetailView) != null)
                    {
                        ViewID = (modelView as IModelDetailView).Id;
                        dv     = resultFrame.Application.CreateDetailView(objectSpace, ViewID, true, representativeObj) as DetailView;
                    }
                    else if ((modelView as IModelListView) != null)
                    {
                        ViewID = (modelView as IModelListView).Id;
                        //ListView dv = resultFrame.Application.CreateListView(objectSpace, ChoiceType, true);
                        //objectSpace = resultFrame.Application.CreateObjectSpace();
                        CollectionSource colSource = new CollectionSource(objectSpace, ChoiceType);
                        if (!colSource.IsLoaded)
                        {
                            colSource.Reload();
                        }
                        dv = resultFrame.Application.CreateListView((modelView as IModelListView), colSource, true) as ListView;
                    }
                }
                else
                {
                    ViewID = Application.FindDetailViewId(ChoiceType);
                    dv     = resultFrame.Application.CreateDetailView(objectSpace, ViewID, true, representativeObj) as DetailView;
                }

                ShowViewParameters svp = new ShowViewParameters();
                svp.CreatedView          = dv;
                svp.TargetWindow         = openMode;
                svp.Context              = TemplateContext.View;
                svp.CreateAllControllers = true;

                e.ShowViewParameters.Assign(svp);
            }
        }