Example #1
0
 /// <summary>
 /// 若存在IndexField,则根据IndexField下移一位。
 /// </summary>
 public void MoveDown(Transaction trans)
 {
     if (IndexField != null)
     {
         var fn  = IndexField.Attribute.DbFieldName;
         var cur = GetValue(fn);
         var where = new Compare(CompareType.LessThan, fn, cur).ToWhere();
         where.AddOrder(fn, OrderType.Desc);
         _swap_with(where, fn, cur, trans);
     }
     else
     {
         throw new IndexFieldException("没有Index字段。", null);
     }
 }
Example #2
0
 public static Int64 GetNextIndex(Transaction trans)
 {
     if (IndexField != null)
     {
         try
         {
             var     fn  = IndexField.Attribute.DbFieldName;
             var     kn  = KeyField.Attribute.DbFieldName;
             Command cmd = DbProvider.CreateCommand(string.Format("select {0} from {1}", IndexField.EnsuredName, EnsuredTableName));
             Where where = new Compare(CompareType.LessThan, fn, TopLimit).ToWhere();
             where.AddOrder(fn, OrderType.Desc);
             Builder.AppendWhere(cmd, where, kn, DbProvider.Adapter);
             Builder.AppendPage(cmd, kn, TableName, new Page(0, 1), where, DbProvider.Adapter);
             return(Convert.ToInt64(
                        cmd.ExecuteScalar(trans)
                        ) + 1);
         }
         catch { return(StartIndex); }
     }
     else
     {
         throw new IndexFieldException("没有Index字段。", null);
     }
 }