public AutoCompleteView()
        {
            InitializeComponent();
            entText.TextChanged += (s, e) =>
            {
                Text = e.NewTextValue;
            };
            btnSearch.Clicked += (s, e) =>
            {
                if (SearchCommand != null && SearchCommand.CanExecute(Text))
                {
                    SearchCommand.Execute(Text);
                }
            };
            lstSugestions.ItemSelected += (s, e) =>
            {
                entText.Text = GetSearchString(e.SelectedItem);

                AvailableSugestions.Clear();
                ShowHideListbox(false);
                SelectedCommand.Execute(e);
                if (ExecuteOnSugestionClick &&
                    SearchCommand != null && SearchCommand.CanExecute(Text))
                {
                    SearchCommand.Execute(e);
                }
            };
            AvailableSugestions = new ObservableCollection <object>();
            this.ShowHideListbox(false);
            lstSugestions.ItemsSource = this.AvailableSugestions;
            //lstSugestions.ItemTemplate = this.SugestionItemDataTemplate;
        }
Exemple #2
0
        public SearchViewModel()
        {
            ContentId = ToolContentId;

            loader = new JsonOptionsLoader();

            QueryEditor = new QueryEditorViewModel(Session, () =>
            {
                if (SearchCommand.CanExecute(null))
                {
                    SearchCommand.Execute(null);
                }
            });
            QueryEditor.SendToSearchCommand.IsVisible = false;

            var ests = EntityQuery <Estimator> .All(Session)();

            Estimators        = new ObservableCollection <Estimator>(ests);
            SelectedEstimator = ests.FirstOrDefault();

            emh.Add(
                this.Subscribe(Event.SendToSearch, (e) =>
            {
                object pack = null;
                try
                {
                    pack = e.GetValue <object>(MessageKeys.ToSearchPackage);
                }
                catch
                {
                    return;
                }

                OpenHrSearch();

                var hrs  = pack as IEnumerable <HealthRecord>;
                var hios = pack as IEnumerable <ConfWithHio>;
                var opt  = pack as SearchOptions;

                if (hrs != null && hrs.Any())
                {
                    RecieveHealthRecords(hrs);
                }
                else if (hios != null && hios.Any())
                {
                    RecieveHrItemObjects(hios);
                }
                else if (opt != null)
                {
                    RecieveOptions(opt);
                }

                Contract.Assume(LastRecieverQueryBlock != null);
                Activate();
            })

                );

            ControlsVisible = true;
        }
        public AutoCompleteView()
        {
            //InitializeComponent();
            stkBase = new StackLayout();
            var innerLayout = new StackLayout();

            entText = new Entry()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Start
            };
            btnSearch = new Button()
            {
                VerticalOptions = LayoutOptions.Center,
                Text            = "Search"
            };

            lstSugestions = new ListView()
            {
                HeightRequest = 250,
                HasUnevenRows = true
            };

            innerLayout.Children.Add(entText);
            innerLayout.Children.Add(btnSearch);
            stkBase.Children.Add(innerLayout);
            stkBase.Children.Add(lstSugestions);

            Content = stkBase;


            entText.TextChanged += (s, e) =>
            {
                Text = e.NewTextValue;
            };
            btnSearch.Clicked += (s, e) =>
            {
                if (SearchCommand != null && SearchCommand.CanExecute(Text))
                {
                    SearchCommand.Execute(Text);
                }
            };
            lstSugestions.ItemSelected += (s, e) =>
            {
                entText.Text = GetSearchString(e.SelectedItem);

                AvailableSugestions.Clear();
                ShowHideListbox(false);
                SelectedCommand.Execute(e);
                if (ExecuteOnSugestionClick &&
                    SearchCommand != null && SearchCommand.CanExecute(Text))
                {
                    SearchCommand.Execute(e);
                }
            };
            AvailableSugestions = new ObservableCollection <object>();
            this.ShowHideListbox(false);
            lstSugestions.ItemsSource = this.AvailableSugestions;
            //lstSugestions.ItemTemplate = this.SugestionItemDataTemplate;
        }
        /// <summary>
        ///     Edits the action.
        /// </summary>
        /// <param name="model">The model.</param>
        public void EditAction(T model)
        {
            if (model == null)
            {
                MessageBox.Show("请选择要编辑的记录", "失败", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            var w = AppEx.Container.GetInstance <IViewModel>(EditViewModeKey);

            w.Model = model;
            BeforeEdit(w, model);
            if (w.View.ShowDialog() == true)
            {
                IBaseDataService <T> service   = GetDataService();
                ResultMsg            resultMsg = service.Edit((T)w.Model);
                if (resultMsg.IsSuccess)
                {
                    _Collection.Clear();
                    if (SearchCommand.CanExecute(null))
                    {
                        SearchCommand.Execute(null);
                    }
                }
                else
                {
                    MessageBox.Show("修改失败", "失败", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        /// <summary>
        ///     Adds the action.
        /// </summary>
        public virtual void AddAction()
        {
            var w = AppEx.Container.GetInstance <IViewModel>(AddViewModeKey);

            if (!BeforeAdd((T)w.Model))
            {
                return;
            }
            if (w.View.ShowDialog() == true)
            {
                IBaseDataService <T> service   = GetDataService();
                ResultMsg            resultMsg = service.Add((T)w.Model);
                if (resultMsg.IsSuccess)
                {
                    _Collection.Clear();
                    if (SearchCommand.CanExecute(null))
                    {
                        SearchCommand.Execute(null);
                    }
                }
                else
                {
                    MessageBox.Show("添加失败", "失败", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AutoCompleteView"/> class.
        /// </summary>
        public AutoCompleteView()
        {
            _availableSuggestions = new ObservableCollection <object>();
            _stkBase = new StackLayout();
            var innerLayout = new StackLayout();

            _entText = new Entry {
                HorizontalOptions = TextHorizontalOptions,
                VerticalOptions   = TextVerticalOptions,
                TextColor         = TextColor,
                BackgroundColor   = TextBackgroundColor
            };
            _btnSearch = new Button {
                VerticalOptions   = SearchVerticalOptions,
                HorizontalOptions = SearchHorizontalOptions,
                Text = SearchText
            };

            _lstSuggestions = new ListView {
                HeightRequest = SuggestionsHeightRequest,
                HasUnevenRows = true
            };

            innerLayout.Children.Add(_entText);
            innerLayout.Children.Add(_btnSearch);
            _stkBase.Children.Add(innerLayout);
            _stkBase.Children.Add(_lstSuggestions);

            Content = _stkBase;


            _entText.TextChanged += (s, e) => {
                Text = e.NewTextValue;
                OnTextChanged(e);
            };
            _btnSearch.Clicked += (s, e) => {
                if (SearchCommand != null && SearchCommand.CanExecute(Text))
                {
                    SearchCommand.Execute(Text);
                }
            };
            _lstSuggestions.ItemSelected += (s, e) => {
                _entText.Text = e.SelectedItem.ToString();

                _availableSuggestions.Clear();
                ShowHideListbox(false);
                OnSelectedItemChanged(e.SelectedItem);

                if (ExecuteOnSuggestionClick &&
                    SearchCommand != null &&
                    SearchCommand.CanExecute(Text))
                {
                    SearchCommand.Execute(e);
                }
            };
            ShowHideListbox(false);
            _lstSuggestions.ItemsSource = _availableSuggestions;
        }
        private void OnSearch()
        {
            RaiseEvent(new RoutedEventArgs(SearchEvent));

            if (SearchCommand.CanExecute(null))
            {
                SearchCommand.Execute(null);
            }
        }
Exemple #8
0
 private bool ExecuteCommand(string text)
 {
     if (!string.IsNullOrEmpty(text) && SearchCommand != null)
     {
         if (SearchCommand.CanExecute(text))
         {
             SearchCommand.Execute(text);
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Handles the key down event.
        /// </summary>
        /// <param name="e">The event data.</param>
        protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            base.OnPreviewKeyDown(e);

            var textBox = Template.FindName("PART_TextBox", this) as TextBox;
            var popup   = Template.FindName("PART_AutocompletePopup", this) as Popup;
            var listBox = Template.FindName("PART_AutocompleteListBox", this) as ListBox;

            switch (e.Key)
            {
            case Key.Down:
                if (textBox != null && textBox.IsFocused)
                {
                    var item = listBox.FindDescendents <ListBoxItem>().FirstOrDefault(o => o.IsSelected);
                    if (item != null)
                    {
                        item.Focus();
                        e.Handled = true;
                    }
                }
                break;

            case Key.Escape:
                if (popup.IsOpen && textBox != null)
                {
                    popup.IsOpen = false;
                    textBox.Focus();
                    e.Handled = true;
                }
                break;

            case Key.Enter:
                if (popup.IsOpen && (e.KeyboardDevice.IsKeyDown(Key.LeftShift) || e.KeyboardDevice.IsKeyDown(Key.RightShift)))
                {
                    listBox.SelectedIndex = 0;
                    Replase();
                    e.Handled = true;
                }
                else if (textBox != null && textBox.IsFocused)
                {
                    if (SearchCommand != null && SearchCommand.CanExecute(textBox.Text))
                    {
                        SearchCommand.Execute(textBox.Text);
                    }
                    else if (SearchExecuted != null)
                    {
                        SearchExecuted(this, new SearchExecutedEventArgs(textBox.Text));
                    }
                    popup.IsOpen = false;
                }
                break;
            }
        }
Exemple #10
0
        public void OnLostFocus(object sender, RoutedEventArgs e)
        {
            TextBox txt = sender as TextBox;

            if (txt != null)
            {
                Text = txt.Text;
                UpdatePlaceholderTextVisibility(Text);
            }
            if (SearchCommand != null && !SearchCommand.CanExecute(Text))
            {
                HideSearchText();
            }
        }
Exemple #11
0
        private async void EndSearch()
        {
            if (!string.IsNullOrWhiteSpace(Query) && SearchCommand.CanExecute(Query))
            {
                _blockFocus = true;
                ((PhoneApplicationPage)((PhoneApplicationFrame)Application.Current.RootVisual).Content).Focus();

                SearchCommand.Execute(Query);

                await Task.Delay(500);

                _blockFocus = false;
            }
        }
Exemple #12
0
        private void DoSearch()
        {
            if (!string.IsNullOrWhiteSpace(SearchTerm))
            {
                m_searchTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));

                SearchEventArgs eventArgs = new SearchEventArgs(SearchEvent, this, SearchTerm);
                RaiseEvent(eventArgs);

                if (SearchCommand != null && SearchCommand.CanExecute(SearchTerm))
                {
                    SearchCommand.Execute(SearchTerm);
                }
            }
        }
Exemple #13
0
        public SearchBar()
        {
            TextChanged += (e, a) =>
            {
                if (TextChangedCommand != null && TextChangedCommand.CanExecute(null))
                {
                    TextChangedCommand.Execute(null);
                }
            };

            TextChanged += (e, a) =>
            {
                if (AutoSearch)
                {
                    if (SearchCommand != null && SearchCommand.CanExecute(null))
                    {
                        SearchCommand.Execute(null);
                    }
                }
            };
        }
Exemple #14
0
        private void HandleCommandLineArgs()
        {
            string[] args      = Environment.GetCommandLineArgs();
            bool     show_help = false;
            int      repeat    = 1;

            var p = new OptionSet()
            {
                {
                    "s|seq|sequence=",
                    "the {SEQUENCE} to look for in each file",
                    v => SearchSequence = v
                },
                {
                    "d|deep|deepSearch|deepsearch|DeepSearch", "Is it going to be a deep search?",
                    v => DeepSearch = v != null
                },
            };

            try
            {
                p.Parse(args);
                if (SearchCommand.CanExecute(this))
                {
                    SearchCommand.Execute(this);
                }
            }
            catch (OptionException e)
            {
                MessageBox.Show("You entered incorrect parameters\n" + e.Message);
                var str = new StringBuilder();
                using (var writer = new StringWriter(str))
                {
                    p.WriteOptionDescriptions(writer);
                    MessageBox.Show(str.ToString());
                }
            }
        }
Exemple #15
0
 public void Invalid_Parameter_Value_To_CanExecute(object value)
 {
     Assert.IsFalse(_fixture.CanExecute(value));
 }