public override ItemSearchPresenterResult Run(ItemSearchPresenterArgs itemSearchPresenterArgs)
        {
            this.searchArguments = itemSearchPresenterArgs;
            View.SetViewInfo(itemSearchPresenterArgs.Title);

            List <ItemTypeItem> itemTypes;

            if (!string.IsNullOrEmpty(searchArguments.ItemTypeName))
            {
                itemTypes = new List <ItemTypeItem>()
                {
                    new ItemTypeItem()
                    {
                        itemTypeName = searchArguments.ItemTypeName, itemTypeSingularLabel = searchArguments.ItemTypeSingularLabel
                    }
                };
            }
            else
            {
                itemTypes = searcher.GetItemTypes();
                searchArguments.ItemTypeName = itemTypes.First().itemTypeName;
            }

            selectedType = itemTypes.First(it => it.itemTypeName == searchArguments.ItemTypeName);
            View.SetItemTypes(itemTypes, selectedType);

            LoadSearchSettings();

            var savedSearches = searcher.GetSavedSearches(selectedType.itemTypeName);

            View.SetSavedSearch(savedSearches);
            SetSearchColumns(selectedType, searchArguments.PredefinedPropertyValues);

            View.SearchValueChanged  += View_SearchValueChanged;
            View.ItemTypeChanged     += View_ItemTypeChanged;
            View.PageSizeChanged     += View_PageSizeChanged;
            View.SavedSearchChanged  += View_SavedSearchChanged;
            View.SelectedItemChanged += View_SelectedItemChanged;
            View.RunSearch           += View_RunSearch;
            View.ClearSearch         += View_ClearSearch;
            View.Cancel       += View_Cancel;
            View.Ok           += View_Ok;
            View.NextPage     += View_NextPage;
            View.PreviousPage += View_PreviousPage;

            View.ShowAsDialog();

            return(new ItemSearchPresenterResult()
            {
                ItemId = selectedIds.First(),
                ItemType = selectedType.itemTypeName,
                DialogResult = View.DialogResult,
                LastSavedSearch = this.currentSearch.SavedSearchProperties.Cast <PropertyInfo>().ToList(),
            });
        }
        private void View_ItemTypeChanged(ItemTypeItem itemType)
        {
            selectedType = itemType;

            LoadSearchSettings();

            var savedSearches = searcher.GetSavedSearches(itemType.itemTypeName);

            View.SetSavedSearch(savedSearches);

            SetSearchColumns(itemType, searchArguments.PredefinedPropertyValues);
        }
        public void SetItemTypes(List <ItemTypeItem> itemTypes, ItemTypeItem selectedItem)
        {
            itemTypeBox.Items.Clear();
            itemTypeBox.Items.AddRange(itemTypes.ToArray());
            itemTypeBox.SelectedItem = selectedItem;

            itemTypeLabel.Visible = true;
            itemTypeBox.Visible   = true;

            if (itemTypes.Count == 1)
            {
                itemTypeBox.Enabled = false;
            }
        }
        private void SetSearchColumns(ItemTypeItem itemType, List <PropertyInfo> predefinedPropertyValues)
        {
            //get properties by item type and  Apply layout settings
            var properiesForSearch = searcher.GetPropertiesForSearch(itemType.itemTypeName);

            //update by PredefinedPropertyValues
            foreach (var prop in predefinedPropertyValues)
            {
                var foundedProperty = properiesForSearch.FirstOrDefault(pi => pi.PropertyName == prop.PropertyName);
                if (foundedProperty != null)
                {
                    foundedProperty.PropertyValue = prop.PropertyValue;
                    foundedProperty.IsReadonly    = prop.IsReadonly;
                }
            }

            currentSearch.SavedSearchProperties = properiesForSearch;
            View.SetSearchColumns(currentSearch.SavedSearchProperties);
        }