Esempio n. 1
0
        /// <summary>
        /// Get table info.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public GXTableResponse Post(GXTableRequest request)
        {
            lock (Db)
            {
                if (request.Type == TableRequestType.RowCount)
                {
                    //Find last row number.
#if !SS4
                    SqlExpressionVisitor <GXAmiDataRow> ev = OrmLiteConfig.DialectProvider.ExpressionVisitor <GXAmiDataRow>();
#else
                    SqlExpression <GXAmiDataRow> ev = OrmLiteConfig.DialectProvider.SqlExpression <GXAmiDataRow>();
#endif
                    ev.Limit(1);
                    ev.Where(q => q.TableID == request.TableId);
                    ev.OrderByDescending(q => q.RowIndex);
                    List <GXAmiDataRow> items = Db.Select <GXAmiDataRow>(ev);
                    if (items.Count == 1)
                    {
                        return(new GXTableResponse(items[0].RowIndex));
                    }
                    //Table is empty.
                    return(new GXTableResponse(0));
                }
                else if (request.Type == TableRequestType.Rows)
                {
                    //We must know columns count to retreave right amount of rows.
                    int cnt = Db.Select <GXAmiProperty>(q => q.ParentID == request.TableId).Count;
                    //Get rows
#if !SS4
                    SqlExpressionVisitor <GXAmiDataRow> ev = OrmLiteConfig.DialectProvider.ExpressionVisitor <GXAmiDataRow>();
#else
                    SqlExpression <GXAmiDataRow> ev = OrmLiteConfig.DialectProvider.SqlExpression <GXAmiDataRow>();
#endif
                    if (request.Count != 0)
                    {
                        ev.Limit(cnt * request.Index, cnt * request.Count);
                    }
                    ev.OrderBy(q => q.RowIndex);
                    ev.Where(q => q.TableID == request.TableId);
                    List <GXAmiDataRow> items = Db.Select <GXAmiDataRow>(ev);
                    ulong tableId;
                    uint  startRow;
                    return(new GXTableResponse(ItemsToRows(items.ToArray(), out tableId, out startRow)));
                }
                throw new ArgumentOutOfRangeException("Type");
            }
        }
        /// <summary>
        /// Get table info.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public GXTableResponse Post(GXTableRequest request)
        {
            lock (Db)
            {
                if (request.Type == TableRequestType.RowCount)
                {
                    //Find last row number.
#if !SS4
                    SqlExpressionVisitor<GXAmiDataRow> ev = OrmLiteConfig.DialectProvider.ExpressionVisitor<GXAmiDataRow>();

#else
                    SqlExpression<GXAmiDataRow> ev = OrmLiteConfig.DialectProvider.SqlExpression<GXAmiDataRow>();
#endif                                                                
                    ev.Limit(1);
                    ev.Where(q => q.TableID == request.TableId);
                    ev.OrderByDescending(q => q.RowIndex);
                    List<GXAmiDataRow> items = Db.Select<GXAmiDataRow>(ev);
                    if (items.Count == 1)
                    {
                        return new GXTableResponse(items[0].RowIndex);
                    }
                    //Table is empty.
                    return new GXTableResponse(0);
                }
                else if (request.Type == TableRequestType.Rows)
                {
                    //We must know columns count to retreave right amount of rows.
                    int cnt = Db.Select<GXAmiProperty>(q => q.ParentID == request.TableId).Count;
                    //Get rows
#if !SS4
                    SqlExpressionVisitor<GXAmiDataRow> ev = OrmLiteConfig.DialectProvider.ExpressionVisitor<GXAmiDataRow>();
#else
                    SqlExpression<GXAmiDataRow> ev = OrmLiteConfig.DialectProvider.SqlExpression<GXAmiDataRow>();
#endif                                                                
                    if (request.Count != 0)
                    {
                        ev.Limit(cnt * request.Index, cnt * request.Count);
                    }
                    ev.OrderBy(q => q.RowIndex);
                    ev.Where(q => q.TableID == request.TableId);
                    List<GXAmiDataRow> items = Db.Select<GXAmiDataRow>(ev);
                    ulong tableId;
                    uint startRow;
                    return new GXTableResponse(ItemsToRows(items.ToArray(), out tableId, out startRow));
                }
                throw new ArgumentOutOfRangeException("Type");
            }
        }