Ejemplo n.º 1
0
        public SearchPanel(EntityModel model, IEnumerable<string> searchFields)
        {
            this.InitializeComponent();

            this.Model = model;
            this.SearchFields = searchFields.ToArray();

            int currentFieldIndex = 2;

            this.FormBinding = new FormBinding(model.ModelName, searchForm: true);
            this.ListBinding = new ListBinding<JObjectEntityDisplay>(this.ResultsList, x => new JObjectFuncDisplay(x, model.DisplayConverter), "Display");

            foreach (string field in this.SearchFields)
            {
                SearchFieldModel searchField = this.Model.GetSearchField(field);
                FieldBinding binding = FieldBindingHelper.CreateBindingField(searchField.FieldType, fieldName: field);
                this.FormBinding.AddBinding(field, binding);
                ++this.SearchParamsTable.RowCount;
                this.SearchParamsTable.Controls.Add(new Label()
                {
                    Text = field.SymbolToNatural(),
                    Dock = DockStyle.Fill
                }, 0, currentFieldIndex);
                this.SearchParamsTable.Controls.Add(binding.BoundControl, 1, currentFieldIndex);
                binding.BoundControl.Dock = DockStyle.Fill;
                ++currentFieldIndex;
            }

            this.SearchButton = new Button()
            {
                Text = "Search",
                Dock = DockStyle.Fill,
            };

            ++this.SearchParamsTable.RowCount;
            this.SearchButton.Click += this.SearchButton_Click;
            this.SearchParamsTable.Controls.Add(this.SearchButton, 1, currentFieldIndex);
            this.BasicSearchButton.Click += this.BasicSearchButton_Click;

            this.FormBinding.AddAssociatedControl(this.SearchButton);
            this.FormBinding.AddAssociatedControl(this.BasicSearchButton);
            this.FormBinding.AddAssociatedControl(this.BasicSearchText);

            this.ListBinding.OnSelection += (selections) =>
            {
                if (this.OnSelect != null)
                    this.OnSelect.Invoke(this.GetSelections());
            };
        }
Ejemplo n.º 2
0
        public EntityModel(string modelName, Dictionary<string, FieldModel> typeMapping, Dictionary<string, SearchFieldModel> searchFields, Func<JObject, string> defaultDisplayConverter, EntityModel parent = null)
        {
            this.ModelName = modelName;
            this.TypeMapping = typeMapping;
            this.SearchFields = searchFields;
            this.DisplayConverter = defaultDisplayConverter;
            this.Parent = parent;

            if (this.Parent != null)
            {
                foreach (var type in this.Parent.TypeMapping)
                {
                    if (!this.TypeMapping.ContainsKey(type.Key))
                        this.TypeMapping[type.Key] = type.Value;
                }

                foreach (var type in this.Parent.SearchFields)
                {
                    if (!this.SearchFields.ContainsKey(type.Key))
                        this.SearchFields[type.Key] = type.Value;
                }
            }
        }