예제 #1
0
        public static FilterModel FromProperty(IFrozenContext frozenCtx, IEnumerable <Property> props)
        {
            var last  = props.Last();
            var label = string.Join(", ", props.Select(i => i.GetLabel()).ToArray());

            if (last is DateTimeProperty)
            {
                return(RangeFilterModel.Create(frozenCtx, label, FilterValueSource.FromProperty(props), typeof(DateTime), null, null));
            }
            else if (last is IntProperty)
            {
                return(RangeFilterModel.Create(frozenCtx, label, FilterValueSource.FromProperty(props), typeof(int), null, null));
            }
            else if (last is DecimalProperty)
            {
                return(RangeFilterModel.Create(frozenCtx, label, FilterValueSource.FromProperty(props), typeof(decimal), null, null));
            }
            else if (last is DoubleProperty)
            {
                return(RangeFilterModel.Create(frozenCtx, label, FilterValueSource.FromProperty(props), typeof(double), null, null));
            }
            else
            {
                return(SingleValueFilterModel.Create(frozenCtx, label, props));
            }
        }
예제 #2
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);
        }