예제 #1
0
        public long AddChild(String currentCode, String categoryName, long sortId)
        {
            try
            {
                dao.BeginTransaction();
                T_ProductCategory entity = new T_ProductCategory();
                entity.CategoryName = categoryName;
                entity.SortId = sortId;
                entity.CategoryCode = String.Empty;
                long Id = dao.Insert<long>(entity);

                string[] codes = currentCode.Split('-');
                entity.CategoryCode = currentCode + "-" + Id;

                entity.CategoryLevel = codes.Length;
                entity.ParentId = long.Parse(codes[codes.Length - 1]);
                dao.Update(entity);
                dao.CommitTransaction();
                return Id;
            }
            catch (Exception ex)
            {
                dao.RollBackTransaction();
                throw ex;
            }
        }
예제 #2
0
        /// <summary>
        /// 添加同级分类
        /// </summary>
        /// <param name="currentCode">当前选择的分类Code</param>
        /// <param name="categoryName"></param>
        /// <param name="sortId"></param>
        /// <returns></returns>
        public long Add(String currentCode, String categoryName, long sortId)
        {
            try
            {
                dao.BeginTransaction();
                T_ProductCategory entity = new T_ProductCategory();
                entity.CategoryName = categoryName;
                entity.SortId = sortId;
                entity.CategoryCode = String.Empty;

                long Id = dao.Insert<long>(entity);
                if (currentCode.IndexOf('-') > 0)
                {
                    string[] codes = currentCode.Split('-');
                    entity.CategoryCode = currentCode.Substring(0, currentCode.LastIndexOf('-')) + "-" + Id.ToString();
                    entity.ParentId = long.Parse(codes[codes.Length - 2]);
                }
                else
                {
                    entity.CategoryCode = Id.ToString();
                    entity.CategoryLevel = 0;
                }
                entity.CategoryLevel = entity.CategoryCode.Split('-').Length;
                entity.Id = Id;
                dao.Update(entity);
                dao.CommitTransaction();
                return Id;
            }
            catch (Exception ex)
            {
                dao.RollBackTransaction();
                throw ex;
            }
        }