private void UpdateForm() { var enable = ListBoxUserConditions.SelectedItem is UserConditionVisualItem; ButtonCopyCurrent.IsEnabled = enable; ButtonDelete.IsEnabled = enable; ButtonMoveUp.IsEnabled = enable; ButtonMoveDown.IsEnabled = enable; if (!enable) { return; } _selectedPredefinedCondition = (UserConditionVisualItem)ListBoxUserConditions.SelectedItem; TextBoxCaption.Text = _selectedPredefinedCondition.Caption; TextBoxExpression.Text = _selectedPredefinedCondition.Condition; CheckBoxIsNeedEdit.IsChecked = _selectedPredefinedCondition.IsNeedEdit; foreach (var item in _selectedPredefinedCondition.ShowOnlyForDbTypes.Select(type => ComboboxDbTypes.Items.First(x => string.Equals(x.Content.ToString(), type.ToString(), StringComparison.InvariantCultureIgnoreCase)))) { item.IsChecked = true; } ButtonSave.IsEnabled = false; }
private void ResetForm() { _selectedPredefinedCondition = null; TextBoxCaption.Text = string.Empty; TextBoxExpression.Text = string.Empty; CheckBoxIsNeedEdit.IsChecked = false; foreach (var selectableItem in ComboboxDbTypes.Items) { selectableItem.IsChecked = false; } }
public void Load(IQueryView queryView) { _source.Clear(); _selectedPredefinedCondition = null; if (_queryView == null) { _queryView = queryView; } if (_queryView == null) { return; } foreach (var expression in _queryView.UserPredefinedConditions) { _source.Add(new UserConditionVisualItem(expression)); } }
private void ButtonCopyCurrent_OnClick(object sender, RoutedEventArgs e) { _selectedPredefinedCondition = ListBoxUserConditions.SelectedItem as UserConditionVisualItem; if (_selectedPredefinedCondition == null) { return; } var name = _selectedPredefinedCondition.Caption; var newName = ""; if (_source.All(x => string.Compare(x.Caption, $"{name} Copy", StringComparison.InvariantCultureIgnoreCase) != 0)) { newName = $"{name} Copy"; } else { for (var i = 1; i < 1000; i++) { if (_source.Any(x => string.Compare(x.Caption, $"{name} Copy ({i})", StringComparison.InvariantCultureIgnoreCase) == 0)) { continue; } newName = $"{name} Copy ({i})"; break; } } var newCopy = _selectedPredefinedCondition.Copy(newName); var index = _source.IndexOf(_selectedPredefinedCondition); _queryView.UserPredefinedConditions.Insert(index + 1, newCopy.PredefinedCondition); Load(null); ListBoxUserConditions.SelectedIndex = index + 1; }