Пример #1
0
        public static MonthValueFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource valueSource, bool setDefault, ControlKind requestedKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }

            var valMdl = new DateTimeValueModel(label, "", true, false);
            var mdl    = new MonthValueFilterModel();

            mdl.Label         = label;
            mdl.ValueSource   = valueSource;
            mdl.ViewModelType = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_SingleValueFilterViewModel.Find(frozenCtx);
            mdl.RequestedKind = requestedKind;
            mdl.FilterArguments.Add(new FilterArgumentConfig(
                                        valMdl,
                                        /*cfg.ArgumentViewModel ?? */ ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableMonthPropertyViewModel.Find(frozenCtx)));

            if (setDefault)
            {
                // Defaults to this month
                valMdl.Value = DateTime.Today.FirstMonthDay();
            }

            return(mdl);
        }
Пример #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);
        }
Пример #3
0
        public static DateRangeFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource valueSource, ControlKind requestedKind, bool setYearDefault, bool setQuaterDefault, bool setMonthDefault)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }

            var mdl = new DateRangeFilterModel();

            mdl.Label         = label;
            mdl.ValueSource   = valueSource;
            mdl.ViewModelType = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_DateRangeFilterViewModel.Find(frozenCtx);
            mdl.RequestedKind = requestedKind;

            var fromMdl = new DateTimeValueModel(FilterModelsResources.From, "", true, false, DateTimeStyles.Date);
            var toMdl   = new DateTimeValueModel(FilterModelsResources.To, "", true, false, DateTimeStyles.Date);

            mdl.FilterArguments.Add(new FilterArgumentConfig(
                                        fromMdl,
                                        /*cfg.ArgumentViewModel ?? */ ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDateTimePropertyViewModel.Find(frozenCtx)));
            mdl.FilterArguments.Add(new FilterArgumentConfig(
                                        toMdl,
                                        /*cfg.ArgumentViewModel ?? */ ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDateTimePropertyViewModel.Find(frozenCtx)));

            if (setYearDefault)
            {
                // Defaults to this month
                fromMdl.Value = DateTime.Today.FirstYearDay();
                toMdl.Value   = DateTime.Today.LastYearDay();
            }
            else if (setQuaterDefault)
            {
                // Defaults to this month
                fromMdl.Value = DateTime.Today.FirstQuaterDay();
                toMdl.Value   = DateTime.Today.LastQuaterDay();
            }
            else if (setMonthDefault)
            {
                // Defaults to this month
                fromMdl.Value = DateTime.Today.FirstMonthDay();
                toMdl.Value   = DateTime.Today.LastMonthDay();
            }

            return(mdl);
        }