예제 #1
0
 public int CompareTo(TrackedProject other)
 {
     return(ProjectString.CompareTo(other.ProjectString));
 }
예제 #2
0
        /// <summary>
        /// O Texto do Where ou do Having foi alterado
        /// </summary>
        /// <param name="sender">Textbox que foi alterado</param>
        /// <param name="e">Argumentos</param>
        private void WhereAndHavingTextChanged(object sender, EventArgs e)
        {
            // Pega o que foi escrito na tela
            string script = ((TextBox)sender).Text.Trim();
            // Posição no vetor de where
            int _indexPos = Convert.ToInt16(((TextBox)sender).Tag);

            List <Where> _whereToWork;

            if (_indexPos > 0 && _indexPos < 7) // É Where
            {
                _whereToWork = _selectedWhere[_indexPos];
            }
            else // é Having
            {
                _whereToWork = _selectecdHaving;
            }

            // Limpando o anterior
            _whereToWork.Clear();

            // Sem script não precisa continuar
            if (script == string.Empty)
            {
                if (RedrawWhere != null && !_noRedrawWhere)
                {
                    RedrawWhere(this, new EventArgs());
                }
                return;
            }

            // Se a coluna está no where não processa nada copia a coluna;
            if (_selectedColumn != null)
            {
                if (script.ToLower().Contains(_selectedColumn.Name.ToLower()))
                {
                    Where _where = new Where();
                    _where.Syntax = script;
                    _whereToWork.Add(_where);
                    if (RedrawWhere != null && !_noRedrawWhere)
                    {
                        RedrawWhere(this, new EventArgs());
                    }
                    return;
                }
            }


            ProjectString ps = new ProjectString();

            // Separar os comandos da expressão
            ProjectString.BreakExpressionInWordsMap[] map = ps.BreakExpressionInWords(script);

            const byte LEFT      = 0;
            const byte OPERATION = 1;
            const byte RIGHT     = 2;
            const byte JUNCTION  = 3;

            string _leftSide  = string.Empty;
            string _rightSide = string.Empty;
            string _operation = string.Empty;
            string _valueToSQL;
            int    _fase    = LEFT;
            bool   _between = false;

            //string _userVisualization
            foreach (ProjectString.BreakExpressionInWordsMap item in map)
            {
                string _wordToSQL = string.Empty;
                if (ReplaceReserveWord(item.Value, false, ref _wordToSQL))
                {
                    if (_wordToSQL == "NULL")
                    {
                        // Verifica se o valor é a esquerda ou a direita
                        if (_fase == OPERATION)
                        {
                            _fase = RIGHT;
                        }
                    }
                    else if (_wordToSQL == "BETWEEN")
                    {
                        _between = true;
                        _fase    = OPERATION;
                    }
                    else
                    {
                        if (_wordToSQL == "AND")
                        {
                            if (_between)
                            {
                                _between = false;
                            }
                            else
                            {
                                _fase = JUNCTION;
                            }
                        }
                        else if (_wordToSQL == "OR")
                        {
                            _fase = JUNCTION;
                        }
                        else
                        {
                            _fase = OPERATION;
                        }
                    }
                }
                else
                {
                    switch (_wordToSQL)
                    {
                    case "=":
                    case "<>":
                    case "<":
                    case ">":
                    case ">=":
                    case "<=":
                    case "!=":
                    case "^=":
                        _fase = OPERATION;
                        break;
                    }
                }

                switch (_fase)
                {
                case LEFT:
                    if (_leftSide != string.Empty)
                    {
                        _leftSide += " ";
                    }
                    _leftSide += _wordToSQL;
                    break;

                case OPERATION:
                    if (_operation != string.Empty)
                    {
                        _operation += " ";
                    }
                    _operation += _wordToSQL;
                    _fase       = RIGHT;
                    break;

                case RIGHT:
                    if (_rightSide != string.Empty)
                    {
                        _rightSide += " ";
                    }
                    _rightSide += _wordToSQL;
                    break;

                case JUNCTION:
                    ResolveWH(_whereToWork, _leftSide, _operation, _rightSide, _wordToSQL);
                    _leftSide  = string.Empty;
                    _operation = string.Empty;
                    _rightSide = string.Empty;
                    _fase      = LEFT;
                    break;
                }
            }
            ResolveWH(_whereToWork, _leftSide, _operation, _rightSide, string.Empty);

            if (_whereToWork.Count > 1)
            {
                _whereToWork[0].ParetesisBlockStart++;
                _whereToWork[_whereToWork.Count - 1].ParetesisBlockEnd++;
            }

            if (RedrawWhere != null && !_noRedrawWhere)
            {
                RedrawWhere(this, new EventArgs());
            }
        }