private bool SaveForm()
        {
            try
            {
                var result =
                    _queryView.Query.SQLContext.ParseLogicalExpression(TextBoxCondition.Text, false, false,
                                                                       out var token);
                if (result == null && token != null)
                {
                    throw new SQLParsingException(
                              string.Format(
                                  Helpers.Localizer.GetString(nameof(LocalizableConstantsUI.strInvalidCondition),
                                                              LocalizableConstantsUI.strInvalidCondition), TextBoxCondition.Text),
                              token);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, @"Invalid SQL", MessageBoxButtons.OK, MessageBoxIcon.Error);

                TextBoxCondition.Focus();
                return(false);
            }

            var listTypes = CheckComboBoxDbTypes.CheckedItems.OfType <DbType>().ToList();

            var userExpression = new PredefinedCondition(
                TextBoxCaption.Text,
                listTypes,
                TextBoxCondition.Text, CheckBoxIsNeedEdit.Checked
                );

            var index = -1;

            if (_selectedPredefinedCondition != null)
            {
                index = _queryView.UserPredefinedConditions.IndexOf(_selectedPredefinedCondition.PredefinedCondition);
                _queryView.UserPredefinedConditions.Remove(_selectedPredefinedCondition.PredefinedCondition);
            }

            if (_queryView.UserPredefinedConditions.Any(x =>
                                                        string.Compare(x.Caption, TextBoxCaption.Text, StringComparison.InvariantCultureIgnoreCase) == 0))
            {
                MessageBox.Show($"Condition with caption \"{TextBoxCaption.Text}\" already exist", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                TextBoxCaption.Focus();

                return(false);
            }

            try
            {
                if (index != -1)
                {
                    _queryView.UserPredefinedConditions.Insert(index, userExpression);
                }
                else
                {
                    _queryView.UserPredefinedConditions.Add(userExpression);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            LoadUserConditions(null);

            ResetForm();

            if (index >= 0)
            {
                ListBoxConditions.SelectedIndex = index;
            }
            return(true);
        }
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     ResetForm();
     ListBoxConditions.SelectedItem = null;
     TextBoxCaption.Focus();
 }