Exemplo n.º 1
0
        /// <summary>
        /// 取参照实体的最大order值。
        /// </summary>
        /// <param name="bag"></param>
        /// <param name="mode"></param>
        /// <param name="offset"></param>
        /// <param name="isolation"></param>
        /// <returns></returns>
        private int GetNewOrderNumber(EntityTreeUpdatingBag bag, EntityTreePosition mode, int offset = 0, Expression <Func <TEntity> > isolation = null)
        {
            if (bag == null)
            {
                return(GetNewOrderNumber(isolation));
            }

            switch (mode)
            {
            case EntityTreePosition.Children:
                var sql = string.Format("SELECT MAX({0}) FROM {1} WHERE {2} LIKE {3}",
                                        GetOrderExpression(),
                                        DbUtility.FormatByQuote(syntax, metadata.TableName),
                                        QuoteColumn(metaTree.InnerSign),
                                        syntax.FormatParameter("pm"));
                var innerId = bag.InnerId;

                var parameters = new ParameterCollection {
                    { "pm", innerId + new string('_', metaTree.SignLength) }
                };
                return(database.ExecuteScalar((SqlCommand)sql, parameters).To <int>() + 1 + offset);

            case EntityTreePosition.Before:
                return(bag.Order + offset);

            case EntityTreePosition.After:
                return(bag.Order + 1 + offset);
            }

            return(0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 使用 <see cref="EntityTreeUpdatingBag"/> 判断是否具有兄弟关系。
        /// </summary>
        /// <param name="bag1"></param>
        /// <param name="bag2"></param>
        /// <returns></returns>
        private bool IsBrotherly(EntityTreeUpdatingBag bag1, EntityTreeUpdatingBag bag2)
        {
            if ((bag1.InnerId.Length != bag2.InnerId.Length) || bag2.InnerId.Length < metaTree.SignLength)
            {
                return(false);
            }

            return(bag1.InnerId.Substring(0, bag1.InnerId.Length - metaTree.SignLength)
                   .Equals(bag2.InnerId.Substring(0, bag2.InnerId.Length - metaTree.SignLength)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 从 <see cref="IEntity"/> 中解析出各个树属性。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        private EntityTreeUpdatingBag ParseEntityData(IEntity entity)
        {
            var data = new EntityTreeUpdatingBag
            {
                InnerId = (string)entity.GetValue(metaTree.InnerSign),
            };

            if (metaTree.Order != null)
            {
                data.Order = (int)entity.GetValue(metaTree.Order);
            }
            else if (!string.IsNullOrEmpty(data.InnerId))
            {
                data.Order = int.Parse(data.InnerId.Right(metaTree.SignLength));
            }

            if (metaTree.Level != null)
            {
                data.Level = (int)entity.GetValue(metaTree.Level);
            }
            else if (!string.IsNullOrEmpty(data.InnerId))
            {
                data.Level = data.InnerId.Length / metaTree.SignLength;
            }

            if (metaTree.Name != null)
            {
                data.Name = (string)entity.GetValue(metaTree.Name);
            }

            if (metaTree.FullName != null)
            {
                data.FullName = (string)entity.GetValue(metaTree.FullName);
            }

            return(data);
        }