Esempio n. 1
0
        private void NewMethod()
        {
            CollectionSourceBase collectionSource = application.CreateCollectionSource(objectSpace, type, ListViewId);
            string criteria = application.Model.Views[ListViewId].GetValue <string>("Criteria");

            collectionSource.SetCriteria("Filter1", criteria);
            var count = collectionSource.GetCount();

            this.label1.Text = count.ToString();
            if (count > 0 && ShowColor)
            {
                this.BackColor = Color.FromArgb(203, 46, 2);
            }
        }
 public ListView CreateListView(XafApplication application, IObjectSpace objectSpace, ISupportSequenceObject supportSequenceObject) {
     var nestedObjectSpace = (XPNestedObjectSpace)objectSpace.CreateNestedObjectSpace();
     var objectType = XafTypesInfo.Instance.FindBussinessObjectType<ISequenceReleasedObject>();
     var collectionSource = application.CreateCollectionSource(nestedObjectSpace, objectType, application.FindListViewId(objectType));
     collectionSource.Criteria["ShowReleasedSequences"] = CriteriaOperator.Parse("TypeName=?", supportSequenceObject.Prefix + supportSequenceObject.ClassInfo.FullName);
     return application.CreateListView(nestedObjectSpace, objectType, true);
 }
 private static IObservable <Unit> WhenOrganizationLookupView(this XafApplication application)
 => application.WhenDetailViewCreated().Where(t => t.e.View.Model == application.Model.TenantManager().StartupView)
 .SelectMany(t => t.e.View.GetItems <LookupPropertyEditor>().Where(editor => editor.MemberInfo.MemberType == application.Model.TenantManager().OrganizationType).ToObservable()
             .SelectMany(editor => editor.GetFieldValue("helper").WhenEvent(nameof(LookupEditorHelper.CustomCreateCollectionSource))
                         .Select(pattern => pattern.EventArgs).Cast <CustomCreateCollectionSourceEventArgs>()
                         .Do(e => {
     var collectionSourceBase = application.CreateCollectionSource(
         application.CreateNonSecuredObjectSpace(), editor.MemberInfo.MemberType,
         editor.View.Id);
     collectionSourceBase.Criteria[nameof(TenantManagerService)] = CriteriaOperator.Parse(application.Model.TenantManager().Registration);
     e.CollectionSource = collectionSourceBase;
 })))
 // => application.WhenFrameCreated().WhenFrame(Nesting.Nested).Where(frame => frame.Context==TemplateContext.LookupControl)
 //     .SelectMany(frame => application.WhenListViewCreating(application.Model.TenantManager().OrganizationType)
 //         .Do(t => {
 //             var modelListView = (IModelListView)application.Model.Views[t.e.ViewID];
 //             var nonSecuredObjectSpace = application.CreateNonSecuredObjectSpace();
 //             t.e.View = application.CreateListView(modelListView, application.CreateCollectionSource(nonSecuredObjectSpace,modelListView.ModelClass.TypeInfo.Type,modelListView.Id),true);
 //         })
 //         .To(frame))
 // .WhenFrame(frame => frame.Application.Model.TenantManager().OrganizationType)
 // .Cast<NestedFrame>()
 // .Where(frame => frame.Application.Model.TenantManager().StartupView==frame.ViewItem.View.Model)
 // .Do(frame => {
 //
 //     frame.GetController<NewObjectViewController>().NewObjectAction.Active[nameof(TenantManagerService)] = false;
 //     frame.View.AsListView().CollectionSource.Criteria[nameof(TenantManagerService)]= CriteriaOperator.Parse(frame.View.Model.Application.TenantManager().Registration)
 //         ;
 // })
 .FirstAsync()
 // .TraceTenantManager(t => t?.View?.Id)
 .ToUnit();
        public ListView CreateListView(XafApplication application, IObjectSpace objectSpace, ISupportSequenceObject supportSequenceObject)
        {
            var nestedObjectSpace = (XPNestedObjectSpace)objectSpace.CreateNestedObjectSpace();
            var objectType        = XafTypesInfo.Instance.FindBussinessObjectType <ISequenceReleasedObject>();
            var collectionSource  = application.CreateCollectionSource(nestedObjectSpace, objectType, application.FindListViewId(objectType));

            collectionSource.Criteria["ShowReleasedSequences"] = CriteriaOperator.Parse("TypeName=?", supportSequenceObject.Prefix + supportSequenceObject.ClassInfo.FullName);
            return(application.CreateListView(nestedObjectSpace, objectType, true));
        }
Esempio n. 5
0
        public static ObjectView NewObjectView(this XafApplication application,
                                               Type viewType, Type objectType)
        {
            if (viewType == typeof(ListView))
            {
                var listViewId       = application.FindListViewId(objectType);
                var collectionSource = application.CreateCollectionSource(application.CreateObjectSpace(), objectType, listViewId);
                return(application.CreateListView((IModelListView)application.Model.Views[listViewId], collectionSource, true));
            }
            var modelDetailView = application.Model.BOModel.GetClass(objectType).DefaultDetailView;

            return(application.CreateDetailView(application.CreateObjectSpace(), modelDetailView, true));
        }
Esempio n. 6
0
        PivotGridControl GetPivotGridControl(IGrouping <IModelListView, IModelSeries> grouping)
        {
            var modelListView = grouping.Key;

            if (modelListView != null)
            {
                var objectSpace      = _application.CreateObjectSpace(modelListView.ModelClass.TypeInfo.Type);
                var collectionSource = _application.CreateCollectionSource(objectSpace, modelListView.ModelClass.TypeInfo.Type, modelListView.Id);
                var listView         = _application.CreateListView(modelListView, collectionSource, true);
                var window           = _application.CreateWindow(TemplateContext.View, null, true, false);
                window.SetView(listView);
                return(((PivotGridListEditor)listView.Editor).PivotGridControl);
            }
            return(null);
        }
        static IObservable <(string viewId, string objects)> CreateClientDataSource(this XafApplication application, IModelListView modelListView)
        {
            string GetDisplayText(object editValue, string nullText, string format)
            {
                if (editValue != null)
                {
                    var result = editValue;
                    if (!string.IsNullOrEmpty(format))
                    {
                        result = string.Format(format, result);
                    }
                    return(result.ToString());
                }
                return(nullText);
            }

            var modelColumns = modelListView.VisibleMemberViewItems().OrderForView();

            return(Observable.Start(() => {
                using (var objectSpace = application.CreateObjectSpace()){
                    using (var collectionSource = application.CreateCollectionSource(objectSpace,
                                                                                     modelListView.ModelClass.TypeInfo.Type, modelListView.Id, false, CollectionSourceMode.Normal)){
                        var objects = new[] { (object)null }.Concat(collectionSource.List.Cast <object>())
                        .Select(o => {
                            var columns = string.Join("&", modelColumns.Select(column => {
                                var value = column.ParentView.AsObjectView.ModelClass.TypeInfo.FindMember(column.PropertyName).GetValue(o);
                                return HttpUtility.UrlEncode(GetDisplayText(value, NA, null));
                            }));
                            return new{
                                Key = o == null ? null : collectionSource.ObjectSpace.GetObjectHandle(o),
                                Columns = columns
                            };
                        })
                        .ToArray();
                        objects = new[] {
                            new{
                                Key = FieldNames,
                                Columns = string.Join("&", modelColumns.Select(column => HttpUtility.UrlEncode(column.Caption)))
                            }
                        }.Concat(objects).ToArray();
                        return (uniqueId: modelListView.Id, objects: Convert.ToBase64String(JsonConvert.SerializeObject(objects).Zip()));
                    }
                }
            }));
        }
Esempio n. 8
0
        public override void Setup(CollectionSourceBase collectionSource, XafApplication application)
        {
            base.Setup(collectionSource, application);
            AutoLoad = false;
            IObjectSpace objectSpace = collectionSource.ObjectSpace;

            objectSpace.Reloaded += new EventHandler(this.ObjectSpace_Reloaded);
            ITypeInfo objectTypeInfo = collectionSource.ObjectTypeInfo;
            var       customSetting  = ObjectTypeInfo.FindAttribute <CategorySettingAttribute>();

            Setting = customSetting;
            Type memberType = null;

            if (customSetting == null)
            {
                IMemberInfo info2 = objectTypeInfo.FindMember("Category");
                if (info2 == null)
                {
                    throw new InvalidOperationException(string.Format("The {0} type does not declare the public {1} property.", objectTypeInfo.FullName, "Category"));
                }
                memberType = info2.MemberType;
            }
            else
            {
                memberType           = customSetting.CategoryType;
                CategoryPropertyName = Setting.PropertyName;
            }

            this.categoriesListViewId = application.FindListViewId(memberType);
            if (string.IsNullOrEmpty(this.categoriesListViewId))
            {
                throw new InvalidOperationException(string.Format("Cannot find ListView for the Category property type {0} in the Application Model. Make sure the property is of the business object type registered in the application.", memberType.FullName));
            }
            if ((base.Model != null) && (this.categoriesListViewId == base.Model.Id))
            {
                throw new InvalidOperationException(string.Format("The default category ListView ({0}) is the same as the container ListView. To avoid recursion, provide different EditorType settings for it.", this.categoriesListViewId));
            }
            this.categoriesDataSource    = application.CreateCollectionSource(objectSpace, memberType, this.categoriesListViewId);
            this.criteriaPropertyName    = "Category." + objectSpace.GetKeyPropertyName(memberType);
            this.typeDescriptionProvider = new CategorizedListEditorTypeDescriptionProvider(objectTypeInfo.Type);
            this.typeDescriptionProvider.AddProvider();
        }
Esempio n. 9
0
        static View CreateView(this XafApplication application, IModelView viewModel, IObjectSpace objectSpace)
        {
            View view = null;

            switch (viewModel)
            {
            case IModelListView listViewModel: {
                var collectionSource = application.CreateCollectionSource(objectSpace, listViewModel.ModelClass.TypeInfo.Type, listViewModel.Id);
                view = application.CreateListView(listViewModel, collectionSource, true);
                break;
            }

            case IModelDetailView detailViewModel:
                view = application.CreateDetailView(objectSpace, detailViewModel, true);
                break;

            case IModelDashboardView _:
                view = application.CreateDashboardView(objectSpace, viewModel.Id, true);
                break;
            }
            return(view);
        }