예제 #1
0
        public static RangeFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource predicate, Type type, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var rfmdl = new RangeFilterModel()
            {
                Label         = label,
                ValueSource   = predicate,
                ViewModelType = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_RangeFilterViewModel.Find(frozenCtx),
                RequestedKind = requestedKind,
            };

            ViewModelDescriptor vDesc = null;
            BaseValueModel      mdl1  = null;
            BaseValueModel      mdl2  = null;

            if (type == typeof(decimal))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDecimalPropertyViewModel.Find(frozenCtx);
                mdl1  = new DecimalValueModel("", "", true, false, requestedArgumentKind);
                mdl2  = new DecimalValueModel("", "", true, false, requestedArgumentKind);
            }
            else if (type == typeof(int))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Int32_.Find(frozenCtx);
                mdl1  = new NullableStructValueModel <int>("", "", true, false, requestedArgumentKind);
                mdl2  = new NullableStructValueModel <int>("", "", true, false, requestedArgumentKind);
            }
            else if (type == typeof(double))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Double_.Find(frozenCtx);
                mdl1  = new NullableStructValueModel <double>("", "", true, false, requestedArgumentKind);
                mdl2  = new NullableStructValueModel <double>("", "", true, false, requestedArgumentKind);
            }
            else if (type == typeof(DateTime))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDateTimePropertyViewModel.Find(frozenCtx);
                mdl1  = new DateTimeValueModel("", "", true, false, DateTimeStyles.Date, requestedArgumentKind);
                mdl2  = new DateTimeValueModel("", "", true, false, DateTimeStyles.Date, requestedArgumentKind);
            }
            else
            {
                throw new NotSupportedException(string.Format("Rangefilters of Type {0} are not supported yet", type.Name));
            }

            rfmdl.FilterArguments.Add(new FilterArgumentConfig(mdl1, vDesc));
            rfmdl.FilterArguments.Add(new FilterArgumentConfig(mdl2, vDesc));

            return(rfmdl);
        }
예제 #2
0
        public static SingleValueFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource predicate, Type propType, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }
            if (propType == null)
            {
                throw new ArgumentNullException("propType");
            }

            var fmdl = new SingleValueFilterModel()
            {
                Label                  = label,
                ValueSource            = predicate,
                Operator               = FilterOperators.Equals,
                ViewModelType          = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_SingleValueFilterViewModel.Find(frozenCtx),
                RequestedKind          = requestedKind,
                RefreshOnFilterChanged = false,
            };

            ViewModelDescriptor vDesc = null;
            BaseValueModel      mdl   = null;

            if (propType == typeof(decimal))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDecimalPropertyViewModel.Find(frozenCtx);
                mdl   = new DecimalValueModel(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(int))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Int32_.Find(frozenCtx);
                mdl   = new NullableStructValueModel <int>(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(double))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Double_.Find(frozenCtx);
                mdl   = new NullableStructValueModel <double>(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(bool))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableBoolPropertyViewModel.Find(frozenCtx);
                fmdl.RefreshOnFilterChanged = true;
                if (requestedArgumentKind == null)
                {
                    requestedArgumentKind = NamedObjects.Gui.ControlKinds.Zetbox_App_GUI_DropdownBoolKind.Find(frozenCtx);
                }
                mdl = new BoolValueModel(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(string))
            {
                vDesc         = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_ClassValueViewModel_1_System_String_.Find(frozenCtx);
                mdl           = new ClassValueModel <string>(label, "", true, false, requestedArgumentKind);
                fmdl.Operator = FilterOperators.Contains;
            }
            else
            {
                throw new NotSupportedException(string.Format("Singlevalue filters of Type {0} are not supported yet", propType.Name));
            }

            fmdl.FilterArguments.Add(new FilterArgumentConfig(mdl, vDesc));
            return(fmdl);
        }