Ejemplo n.º 1
0
        protected void ComputeClientOnChanged()
        {
            string prefix = this.totalPrefix;

            if (constraints == null || constraints.Length == 0)
            {
                return;
            }
            StringBuilder sb           = new StringBuilder();
            string        fatherPrefix = BasicHtmlHelper.PreviousPrefix(prefix);

            foreach (DateRangeAttribute c in constraints)
            {
                c.RetriveDynamicDelays(htmlHelper.ViewData.Model, fatherPrefix);
                if (!string.IsNullOrWhiteSpace(c.DynamicMaximum) && c.RangeAction == RangeAction.Propagate)
                {
                    string controlId =
                        BasicHtmlHelper.IdFromName(
                            (fatherPrefix.Length != 0 ? fatherPrefix + "." + c.DynamicMaximum : c.DynamicMaximum) + ".$");
                    long delay = 0;
                    if (c.MaximumDelay != null && c.MaximumDelay.HasValue)
                    {
                        delay =
                            c.MaximumDelay.Value.Ticks / 10000L;
                    }
                    sb.Append(string.Format("SetDateInput('{0}', date - {1}, 2); ", controlId, delay));
                }
                if (!string.IsNullOrWhiteSpace(c.DynamicMinimum) && c.RangeAction == RangeAction.Propagate)
                {
                    string controlId =
                        BasicHtmlHelper.IdFromName(
                            (fatherPrefix.Length != 0 ? fatherPrefix + "." + c.DynamicMinimum : c.DynamicMinimum) + ".$");
                    long delay = 0;
                    if (c.MinimumDelay != null && c.MinimumDelay.HasValue)
                    {
                        delay =
                            c.MinimumDelay.Value.Ticks / 10000L;
                    }
                    sb.Append(string.Format("SetDateInput('{0}', date - {1}, 1); ", controlId, delay));
                }
            }
            clientOnChanged = sb.ToString();
        }
Ejemplo n.º 2
0
        protected void ComputeClientRangeScript()
        {
            if (constraints == null || constraints.Length == 0)
            {
                return;
            }
            StringBuilder sbMin        = new StringBuilder();
            StringBuilder sbMax        = new StringBuilder();
            StringBuilder sUp          = new StringBuilder();
            string        prefix       = this.totalPrefix;
            string        fatherPrefix = BasicHtmlHelper.PreviousPrefix(prefix);

            currMin = min;
            currMax = max;
            string myClientId = BasicHtmlHelper.IdFromName(BasicHtmlHelper.AddField(prefix, "$"));

            foreach (DateRangeAttribute c in constraints)
            {
                c.RetriveDynamicDelays(htmlHelper.ViewData.Model, fatherPrefix);
                if (!string.IsNullOrWhiteSpace(c.DynamicMaximum) && c.RangeAction == RangeAction.Verify)
                {
                    bool             isMilestone        = false;
                    string           path               = (fatherPrefix.Length != 0 ? fatherPrefix + "." + c.DynamicMaximum : c.DynamicMaximum);
                    string           clientId           = BasicHtmlHelper.IdFromName(BasicHtmlHelper.AddField(path, "$"));
                    PropertyAccessor dynamicMaximumProp = new PropertyAccessor(htmlHelper.ViewData.Model,
                                                                               path, false);
                    TimeSpan delay = new TimeSpan(0L);
                    if (c.MaximumDelay != null && c.MaximumDelay.HasValue)
                    {
                        delay = c.MaximumDelay.Value;
                    }
                    if (dynamicMaximumProp != null && dynamicMaximumProp.Value != null)
                    {
                        MileStoneAttribute[] ma = dynamicMaximumProp[typeof(MileStoneAttribute)] as MileStoneAttribute[];
                        if (ma != null && ma.Length > 0)
                        {
                            isMilestone = true;
                            if (dynamicMaximumProp.Property.PropertyType == typeof(DateTime))
                            {
                                if (max == null || !max.HasValue || (((DateTime)dynamicMaximumProp.Value).Add(delay) < max))
                                {
                                    max = ((DateTime)dynamicMaximumProp.Value).Add(delay);
                                }
                            }
                            else if (dynamicMaximumProp.Property.PropertyType == typeof(Nullable <DateTime>))
                            {
                                Nullable <DateTime> pmax = dynamicMaximumProp.Value as Nullable <DateTime>;
                                if (pmax.HasValue)
                                {
                                    pmax = pmax.Value.Add(delay);
                                }
                                if (pmax.HasValue && (max == null || !max.HasValue || pmax < currMax))
                                {
                                    currMax = pmax;
                                }
                            }
                        }
                        if (dynamicMaximumProp.Property.PropertyType == typeof(DateTime))
                        {
                            if (currMax == null || !currMax.HasValue || (((DateTime)dynamicMaximumProp.Value).Add(delay) < currMax))
                            {
                                currMax = ((DateTime)dynamicMaximumProp.Value).Add(delay);
                            }
                        }
                        else if (dynamicMaximumProp.Property.PropertyType == typeof(Nullable <DateTime>))
                        {
                            Nullable <DateTime> pmax = dynamicMaximumProp.Value as Nullable <DateTime>;
                            if (pmax.HasValue)
                            {
                                pmax = pmax.Value.Add(delay);
                            }
                            if (pmax.HasValue && (currMax == null || !currMax.HasValue || pmax < currMax))
                            {
                                currMax = pmax;
                            }
                        }
                        else
                        {
                            throw (new InvalidDynamicRangeException(AnnotationsRsources.InvalidUpperDynamicRange));
                        }
                    }
                    if (!isMilestone)
                    {
                        string varId =
                            BasicHtmlHelper.IdFromName(
                                (fatherPrefix.Length != 0 ? fatherPrefix + "." + c.DynamicMaximum : c.DynamicMaximum) + ".$.Curr");

                        sbMax.Append(string.Format("if ({0} != null){{ cmax = new Date({0}.getTime()+{1});  if (max == null || cmax < max) max = cmax;}}",
                                                   varId, delay.Ticks / 10000));
                        sUp.Append(string.Format(updateSchema, clientId, myClientId));
                    }
                }
                if (!string.IsNullOrWhiteSpace(c.DynamicMinimum) && c.RangeAction == RangeAction.Verify)
                {
                    bool             isMilestone        = false;
                    string           path               = (fatherPrefix.Length != 0 ? fatherPrefix + "." + c.DynamicMinimum : c.DynamicMinimum);
                    string           clientId           = BasicHtmlHelper.IdFromName(BasicHtmlHelper.AddField(path, "$"));
                    PropertyAccessor dynamicMinimumProp = new PropertyAccessor(htmlHelper.ViewData.Model,
                                                                               path, false);
                    TimeSpan delay = new TimeSpan(0L);
                    if (c.MinimumDelay != null && c.MinimumDelay.HasValue)
                    {
                        delay = c.MinimumDelay.Value;
                    }
                    if (dynamicMinimumProp != null && dynamicMinimumProp.Value != null)
                    {
                        MileStoneAttribute[] ma = dynamicMinimumProp[typeof(MileStoneAttribute)] as MileStoneAttribute[];
                        if (ma != null && ma.Length > 0)
                        {
                            isMilestone = true;
                            if (dynamicMinimumProp.Property.PropertyType == typeof(DateTime))
                            {
                                if (min == null || !min.HasValue || (((DateTime)dynamicMinimumProp.Value).Add(delay) > min))
                                {
                                    min = ((DateTime)dynamicMinimumProp.Value).Add(delay);
                                }
                            }
                            else if (dynamicMinimumProp.Property.PropertyType == typeof(Nullable <DateTime>))
                            {
                                Nullable <DateTime> pmin = dynamicMinimumProp.Value as Nullable <DateTime>;
                                if (pmin.HasValue)
                                {
                                    pmin = pmin.Value.Add(delay);
                                }
                                if (pmin.HasValue && (min == null || !min.HasValue || pmin > min))
                                {
                                    min = pmin;
                                }
                            }
                        }
                        if (dynamicMinimumProp.Property.PropertyType == typeof(DateTime))
                        {
                            if (currMin == null || !currMin.HasValue || (((DateTime)dynamicMinimumProp.Value).Add(delay) > currMin))
                            {
                                currMin = ((DateTime)dynamicMinimumProp.Value).Add(delay);
                            }
                        }
                        else if (dynamicMinimumProp.Property.PropertyType == typeof(Nullable <DateTime>))
                        {
                            Nullable <DateTime> pmin = dynamicMinimumProp.Value as Nullable <DateTime>;
                            if (pmin.HasValue)
                            {
                                pmin = pmin.Value.Add(delay);
                            }
                            if (pmin.HasValue && (currMin == null || !currMin.HasValue || pmin > currMin))
                            {
                                currMin = pmin;
                            }
                        }
                        else
                        {
                            throw (new InvalidDynamicRangeException(AnnotationsRsources.InvalidUpperDynamicRange));
                        }
                    }
                    if (!isMilestone)
                    {
                        string varId =
                            BasicHtmlHelper.IdFromName(
                                (fatherPrefix.Length != 0 ? fatherPrefix + "." + c.DynamicMinimum : c.DynamicMinimum) + ".$.Curr");

                        sbMin.Append(string.Format("if ({0} != null){{ cmin = new Date({0}.getTime()+{1});  if (min == null || cmin > min) min = cmin;}}",
                                                   varId, delay.Ticks / 10000));

                        sUp.Append(string.Format(updateSchema, clientId, myClientId));
                    }
                }
            }
            if (currMin != null && currMin.HasValue && curr != null && curr.HasValue && curr < currMin)
            {
                curr = currMin;
            }
            if (currMax != null && currMax.HasValue && curr != null && curr.HasValue && curr > currMax)
            {
                curr = currMax;
            }
            clientMinScript            = sbMin.ToString();
            clientMaxScript            = sbMax.ToString();
            clientRefreshRegistrations = sUp.ToString();
        }