Example #1
0
        public bool LastFinished(Token token, bool knowLast = false)
        {
            if (this.Count() == 0)
            {
                return(true);
            }
            var last = this.Last;

            if (FieldSegment.GetType(last.Keyname) != Field.Type.NONE)
            {
                return(true);
            }
            if (last.Data == "")
            {
                return(false);
            }
            if (knowLast)
            {
                if (token.CannotCloseWith())
                {
                    return(false);
                }
            }
            var lastsym = last.Data[last.Data.Length - 1];

            if (BracketProcessor.IsValidEnd(lastsym) && BracketProcessor.BracketCheck(last.Data) != BracketProcessor.ERRORTYPE.UNCLOSED)
            {
                return(true);
            }
            return(false);
        }
 private Type GetFieldType(FieldSegment segment, QueryBuildInfo buildInfo)
 {
     if (segment.EntityType != null)
     {
         return(segment.EntityType);
     }
     else
     {
         var values = buildInfo.Aliases.Values;
         foreach (Object value in values)
         {
             if (value is Type)
             {
                 var     targetType = (Type)value;
                 var     columns    = FindColumnsForType(targetType);
                 IColumn column     = FindColumn(segment.Field, columns);
                 if (column != null)
                 {
                     return(targetType);
                 }
             }
         }
         return(null);
     }
 }
        public string GetGroupFunction(GroupFunctionSegment groupSegment, bool withAlias, QueryBuildInfo buildInfo)
        {
            FieldSegment fieldSegment = groupSegment.SegmentToGroup;
            string       sql          = GetFieldName(fieldSegment, false, buildInfo);

            switch (groupSegment.GroupFunctionMode)
            {
            case GroupFunctionSegmentMode.Count:
                sql = " COUNT(" + sql + ") ";
                break;

            case GroupFunctionSegmentMode.Sum:
                sql = " SUM(" + sql + ") ";
                break;

            case GroupFunctionSegmentMode.CustFunc:
                sql = " " + groupSegment.CustFunction + "(" + sql + ") ";
                break;
            }
            if (withAlias)
            {
                sql = AppendAlias(sql, fieldSegment);
            }
            return(sql);
        }
        public string GetFieldName(FieldSegment fieldSegment, bool withAlias, QueryBuildInfo buildInfo)
        {
            var    fieldSegmentType = GetFieldType(fieldSegment, buildInfo);
            string tableAlias       = buildInfo.GetAlias(fieldSegmentType);

            if (!string.IsNullOrEmpty(fieldSegment.TypeAlias))
            {
                tableAlias = fieldSegment.TypeAlias;
            }
            tableAlias = (tableAlias == null) ? "" : tableAlias + ".";
            IColumn column = GetColumn(fieldSegment, buildInfo);

            if (column != null)
            {
                string sql = tableAlias + column.ColumnName;
                if (withAlias)
                {
                    sql = AppendAlias(sql, fieldSegment);
                }
                return(sql);
            }
            else
            {
                return("<incorrect column for " + fieldSegment.Field + ">");
            }
        }
        public IColumn GetColumn(FieldSegment segment, QueryBuildInfo buildInfo)
        {
            var fieldType = GetFieldType(segment, buildInfo);
            var columns   = FindColumnsForType(fieldType);

            return(FindColumn(segment.Field, columns));
        }
Example #6
0
        private string GetColumnName(FieldSegment fieldSegment, QueryBuildInfo buildInfo)
        {
            string alias  = fieldSegment.Alias;
            string column = !string.IsNullOrEmpty(alias) ? alias : _processor.GetColumn(fieldSegment, buildInfo).ColumnName;

            return(column);
        }
Example #7
0
        public object Retrieve(IDataReader rs, ITransaction tx, QueryBuildInfo buildInfo)
        {
            try
            {
                string   column      = null;
                ISegment rootSegment = Expr.RootSegment;

                FieldSegment fieldSegment = null;
                switch (rootSegment.SegmentType)
                {
                case SegmentType.Group:
                    fieldSegment = ((GroupFunctionSegment)rootSegment).SegmentToGroup;
                    column       = GetColumnName(fieldSegment, buildInfo);
                    break;

                case SegmentType.Field:
                    fieldSegment = (FieldSegment)rootSegment;
                    column       = GetColumnName(fieldSegment, buildInfo);
                    break;

                case SegmentType.Query:
                    var querySegment = (QuerySegment)rootSegment;
                    column = querySegment.Alias;
                    break;
                }

                int    ordinal = rs.GetOrdinal(column);
                Object obj     = rs.GetValue(ordinal);
                return(obj);
            }
            catch (Exception ex)
            {
                throw new RetrievalException(ex.Message, ex);
            }
        }
Example #8
0
        public void Process()
        {
            var res = new MajorSegmentList();

            foreach (var token in tokens)
            {
                if (FieldSegment.GetType(token.Keyname) != Field.Type.NONE)
                {
                    res.Add(new FieldSegment(token.Keyname, token.Data, FieldSegment.GetType(token.Keyname)));
                }
                else if (KeywordSegment.GetType(token.Keyname) != Keyword.Type.NONE)
                {
                    if (KeywordSegment.IsEquality(token.Data))
                    {
                        res.Add(new EqKeyword(token.Keyname, token.Data, KeywordSegment.GetType(token.Keyname)));
                    }
                    else
                    {
                        res.Add(new FixedKeyword(token.Keyname, token.Data, KeywordSegment.GetType(token.Keyname)));
                    }
                }
                else
                {
                    res.Add(new ExpressionSegment(token.Keyname, token.Data));
                }
            }
            segms = res;
        }
 private string AppendAlias(string sql, FieldSegment fieldSegment)
 {
     if (!string.IsNullOrEmpty(fieldSegment.Alias))
     {
         return(sql + " AS " + fieldSegment.Alias + " ");
     }
     return(sql);
 }
Example #10
0
        protected T BaseField <TU>(Expression <Func <TU, object> > prop, string typeAlias, string alias)
        {
            var entityType = typeof(TU);
            var fieldName  = ReflectionUtils.GetPropertyNameFromExpression(prop);
            var segment    = new FieldSegment(entityType, typeAlias, fieldName, alias);

            return(AddSegment(segment));
        }
Example #11
0
        public static void Initialize()
        {
            for (int row = 0; row < Constants.FieldRows; row++)
            {
                GameField[row] = new FieldSegment[Constants.FieldCols];

                for (int col = 0; col < Constants.FieldCols; col++)
                {
                    GameField[row][col] =
                        new FieldSegment(Constants.FieldSegmentSize * col, Constants.FieldSegmentSize * row);
                }
            }

            SetPathOccupation();
            Render();
        }
        private void ProcessField(StringBuilder sb, FieldSegment segment, QueryBuildInfo buildInfo)
        {
            string fieldName = GetFieldName(segment, false, buildInfo);

            sb.Append(fieldName);
        }
Example #13
0
        public void GameFieldMouseLeftButtonDown(object sender, MouseEventArgs e)
        {
            if (!(sender is Rectangle))
            {
                return;
            }

            Rectangle    model        = (Rectangle)sender;
            FieldSegment fieldSegment = null;

            for (int row = 0; row < Constants.FieldRows; row++)
            {
                for (int col = 0; col < Constants.FieldCols; col++)
                {
                    if (GameFieldController.GameField[row][col].Model.Equals(model))
                    {
                        if (GameFieldController.GameField[row][col].IsOccupied)
                        {
                            return;
                        }
                    }
                }
            }

            for (int col = 0; col < Constants.FieldCols; col++)
            {
                var selection = GameFieldController.GameField.Select(f => f[col]).Where(f => f.Model == model);
                if (selection.Any())
                {
                    fieldSegment = selection.First();
                    break;
                }
            }

            if (fieldSegment == null || fieldSegment.FieldType != FieldType.Regular)
            {
                return;
            }

            double x            = Canvas.GetLeft(model);
            double y            = Canvas.GetTop(model);
            bool   hasGenerated = TowerController.GenerateTower(x, y);

            if (hasGenerated)
            {
                TowerController.Towers[TowerController.Towers.Count - 1].Model.MouseLeftButtonDown += this.TowerMouseButtonDown;

                for (int row = 0; row < Constants.FieldRows; row++)
                {
                    for (int col = 0; col < Constants.FieldCols; col++)
                    {
                        if (GameFieldController.GameField[row][col].Model.Equals(model))
                        {
                            if (GameFieldController.GameField[row][col].IsOccupied)
                            {
                                return;
                            }
                            else
                            {
                                GameFieldController.GameField[row][col].IsOccupied = true;
                            }
                        }
                    }
                }
            }
        }
Example #14
0
        protected T BaseField(Type entityType, string typeAlias, string field, string alias)
        {
            var segment = new FieldSegment(entityType, typeAlias, field, alias);

            return(AddSegment(segment));
        }
Example #15
0
        protected T BaseField(Type entityType, string field)
        {
            var segment = new FieldSegment(entityType, field);

            return(AddSegment(segment));
        }
Example #16
0
        protected T BaseField(string field, string alias)
        {
            var segment = new FieldSegment(field, alias);

            return(AddSegment(segment));
        }