Esempio n. 1
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;
            }
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
0
        public ActionResult PcategoryTreeListPartialAddNew(string PdCategoryName, string partid)
        {
            var model = db.T_ProductCategory;

            if (ModelState.IsValid)
            {
                try
                {
                    ObjectParameter output = new ObjectParameter("CurrentSequenceStr", typeof(string));

                    if (partid != null && partid != "")
                    {
                        string[] st = partid.Split(',');
                        foreach (var p in st)
                        {
                            if (p != "")
                            {
                                ProjectAnalysis.Models.T_ProductCategory item = new T_ProductCategory();
                                db.p_sys_GenSequence("T_ProductCategory_pdCatetoryID", output);
                                var result1 = output.Value;
                                item.pdCatetoryID    = long.Parse(result1.ToString());
                                item.ParentCatgoryID = long.Parse(p);
                                model.Add(item);
                                db.SaveChanges();
                            }
                        }
                    }
                    else
                    {
                        ProjectAnalysis.Models.T_ProductCategory item = new T_ProductCategory();
                        db.p_sys_GenSequence("T_ProductCategory_pdCatetoryID", output);
                        var result = output.Value;
                        item.pdCatetoryID    = long.Parse(result.ToString());
                        item.ParentCatgoryID = 0;
                        model.Add(item);
                        db.SaveChanges();
                    }
                    return(Content("<script>alert('录入成功');location.href='/Manage/ProductCategory'</script>"));
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                    return(Content("<script>alert('" + e.Message + "');location.href='/Manage/ProductCategory'</script>"));
                }
            }
            else
            {
                //ViewData["EditError"] = "Please, correct all errors.";
                return(Content("<script>alert('Please, correct all errors.');location.href='/Manage/ProductCategory'</script>"));
            }
            return(View());
        }