Пример #1
0
        private void SetDefaultValues()
        {
            ItemsSource = new ObservableCollection <object>();

            PageSizes.Clear();
            PageSizes.Add(10);
            PageSizes.Add(20);
            PageSizes.Add(50);
            PageSizes.Add(100);

            cmbPageSizes.IsEditable    = false;
            cmbPageSizes.SelectedIndex = 0;
        }
Пример #2
0
        protected override void Validate()
        {
            var fields  = GetAllFields().ToArray();
            var names   = new HashSet <string>(fields.Select(f => f.Name).Distinct());
            var aliases = new HashSet <string>(fields.Select(f => f.Alias));

            ValidateVersion(names, aliases);
            ValidateFilter(names, aliases);
            ValidateOrder(names, aliases);

            foreach (var field in GetAllFields().Where(f => !f.System))
            {
                if (Constants.InvalidFieldNames.Contains(field.Alias))
                {
                    Error($"{field.Alias} is a reserved word in {Alias}.  Please alias it (<a name='{field.Alias}' alias='{Alias}{field.Alias.Remove(0, 3)}' />).");
                }
            }

            foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField)))
            {
                if (GetField(field.SortField) == null)
                {
                    Error($"Can't find sort field {field.SortField} defined in field {field.Alias}.");
                }
            }

            if (Page > 0 && !PageSizes.Any())
            {
                PageSizes.Add(new PageSize {
                    Size = 10
                });
                PageSizes.Add(new PageSize {
                    Size = 15
                });
                PageSizes.Add(new PageSize {
                    Size = 20
                });
            }
        }
Пример #3
0
        private void BindProperties()
        {
            if (!IsPagingEnable)
            {
                return;
            }
            Binding propBinding;

            propBinding = new Binding(nameof(Page));
            propBinding.RelativeSource      = new RelativeSource(RelativeSourceMode.TemplatedParent);
            propBinding.Mode                = BindingMode.TwoWay;
            propBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            txtPage.SetBinding(TextBox.TextProperty, propBinding);

            //cmbPageSizes.ItemsSource = null;
            List <int> ps = PageSizes.Distinct().ToList();

            PageSizes.Clear();
            ps.ForEach((i) => { PageSizes.Add(i); });
            propBinding = new Binding(nameof(PageSizes));
            propBinding.RelativeSource      = new RelativeSource(RelativeSourceMode.TemplatedParent);
            propBinding.Mode                = BindingMode.OneTime;
            propBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            cmbPageSizes.SetBinding(ComboBox.ItemsSourceProperty, propBinding);
            //cmbPageSizes.ItemsSource = new ObservableCollection<int>() {10,50,100,150,200,500,1000};

            propBinding = new Binding(nameof(TotalPages));
            propBinding.RelativeSource      = new RelativeSource(RelativeSourceMode.TemplatedParent);
            propBinding.Mode                = BindingMode.TwoWay;
            propBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            txtTotalPage.SetBinding(TextBox.TextProperty, propBinding);

            propBinding = new Binding(nameof(ItemsData));
            propBinding.RelativeSource      = new RelativeSource(RelativeSourceMode.Self);
            propBinding.Mode                = BindingMode.TwoWay;
            propBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            SetBinding(ItemsSourceProperty, propBinding);
        }
Пример #4
0
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (InitialPageSize > 0)
            {
                if (!PageSizes.Contains(InitialPageSize))
                {
                    PageSizes.Add(InitialPageSize);
                }

                _activePageSize = InitialPageSize;
            }

            if (string.IsNullOrEmpty(InitialOrder))
            {
                if (OrderOptions.Count >= 1)
                {
                    _activeOrder = OrderOptions.First().Id;
                }
            }
            else
            {
                _activeOrder = InitialOrder;
            }

            ActionLauncher.OnShowDetailsRequested += ActionLauncher_OnShowDetailsRequested;
            ActionLauncher.OnShowMasterRequested  += ActionLauncher_OnShowMasterRequested;

            if (EventCallbacks != null)
            {
                EventCallbacks.OnFilterStatusChanged += EventCallbacks_OnFilterStatusChanged;
                EventCallbacks.OnStatusHasChanged    += EventCallbacks_OnStatusHasChanged;
                hasEventBinded = true;
            }
        }
Пример #5
0
        protected override void Validate()
        {
            var fields  = GetAllFields().ToArray();
            var names   = new HashSet <string>(fields.Select(f => f.Name).Distinct());
            var aliases = new HashSet <string>(fields.Select(f => f.Alias));

            ValidateVersion(names, aliases);
            ValidateFilter(names, aliases);
            ValidateOrder(names, aliases);

            foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField)))
            {
                if (GetField(field.SortField) == null)
                {
                    Error($"Can't find sort field {field.SortField} defined in field {field.Alias}.");
                }
            }

            // Paging Madness
            if (Page > 0)
            {
                if (PageSizes.Any())
                {
                    if (PageSizes.All(ps => ps.Size != PageSize))
                    {
                        var first = PageSizes.First().Size;
                        Warn($"The entity {Name} has an invalid PageSize of {PageSize}. Set to {first}.");
                        PageSize = first;
                    }
                }
                else
                {
                    if (PageSize > 0)
                    {
                        PageSizes.Add(new PageSize {
                            Size = PageSize
                        });
                    }
                    else
                    {
                        PageSizes.Add(new PageSize {
                            Size = 25
                        });
                        PageSizes.Add(new PageSize {
                            Size = 50
                        });
                        PageSizes.Add(new PageSize {
                            Size = 100
                        });
                        if (PageSize != 25 && PageSize != 50 && PageSize != 100)
                        {
                            PageSize = 25;
                        }
                    }
                }
            }
            else
            {
                if (PageSize > 0)
                {
                    PageSize = 0;
                }
            }
        }
Пример #6
0
        protected override void Validate()
        {
            // if validation has been defined, check to see if corresponding valid and message fields are present and create them if not
            var calculatedKeys = new HashSet <string>(CalculatedFields.Select(f => f.Alias ?? f.Name).Distinct(), StringComparer.OrdinalIgnoreCase);

            if (Fields.Any(f => f.Validators.Any()))
            {
                foreach (var field in Fields.Where(f => f.Validators.Any()))
                {
                    if (!calculatedKeys.Contains(field.ValidField))
                    {
                        CalculatedFields.Add(new Field {
                            Name         = field.ValidField,
                            Alias        = field.ValidField,
                            Input        = false,
                            Type         = "bool",
                            Default      = "true",
                            IsCalculated = true
                        });
                    }

                    if (!calculatedKeys.Contains(field.MessageField))
                    {
                        CalculatedFields.Add(new Field {
                            Name = field.MessageField, Alias = field.MessageField, Length = "255", Default = "", IsCalculated = true, Input = false
                        });
                    }
                }
                // create an entity-wide valid field if necessary
                if (ValidField == string.Empty)
                {
                    var valid = Alias + "Valid";
                    if (!CalculatedFields.Any(f => f.Name.Equals(valid)))
                    {
                        var add = new Field {
                            Name = valid, Alias = valid, Type = "bool", ValidField = valid, Input = false, IsCalculated = true
                        };
                        add.Validators.Add(new Operation {
                            Method     = "all",
                            Operator   = "equals",
                            Value      = "true",
                            Parameters = GetAllFields().Where(f => f.ValidField != string.Empty).Select(f => f.ValidField).Distinct().Select(n => new Parameter {
                                Field = n
                            }).ToList()
                        });
                        CalculatedFields.Add(add);
                        ValidField = valid;
                    }
                }
            }

            var fields  = GetAllFields().ToArray();
            var names   = new HashSet <string>(fields.Select(f => f.Name).Distinct());
            var aliases = new HashSet <string>(fields.Select(f => f.Alias));

            ValidateVersion(names, aliases);
            ValidateFilter(names, aliases);
            ValidateOrder(names, aliases);

            foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField)))
            {
                if (GetField(field.SortField) == null)
                {
                    Error($"Can't find sort field {field.SortField} defined in field {field.Alias}.");
                }
            }

            // Paging Madness
            if (Page > 0)
            {
                if (PageSizes.Any())
                {
                    if (PageSizes.All(ps => ps.Size != PageSize))
                    {
                        var first = PageSizes.First().Size;
                        Warn($"The entity {Name} has an invalid PageSize of {PageSize}. Set to {first}.");
                        PageSize = first;
                    }
                }
                else
                {
                    if (PageSize > 0)
                    {
                        PageSizes.Add(new PageSize {
                            Size = PageSize
                        });
                    }
                    else
                    {
                        PageSizes.Add(new PageSize {
                            Size = 25
                        });
                        PageSizes.Add(new PageSize {
                            Size = 50
                        });
                        PageSizes.Add(new PageSize {
                            Size = 100
                        });
                        if (PageSize != 25 && PageSize != 50 && PageSize != 100)
                        {
                            PageSize = 25;
                        }
                    }
                }
            }
            else
            {
                if (PageSize > 0)
                {
                    PageSize = 0;
                }
            }
        }