public string AddCategory(string categoryCode, string categoryName, string pid, int type, int status, List<string> attrlist, List<string> saleattr, string description, string operateid)
 {
     var dal = new ProductsDAL();
     string guid = dal.AddCategory(categoryCode, categoryName, pid, type, status, string.Join(",", attrlist), string.Join(",", saleattr), description, operateid);
     if (!string.IsNullOrEmpty(guid))
     {
         if (string.IsNullOrEmpty(pid))
         {
             CacheCategory.Add(new Category()
             {
                 CategoryID = guid.ToLower(),
                 CategoryCode = categoryCode,
                 CategoryName = categoryName,
                 CategoryType = type,
                 Layers = 1,
                 PID = pid,
                 Status = status,
                 Description = description,
                 ChildCategory = new List<Category>()
             });
         }
         else
         {
             var PModel = GetCategoryByID(pid);
             var model = new Category()
             {
                 CategoryID = guid.ToLower(),
                 CategoryCode = categoryCode,
                 CategoryName = categoryName,
                 CategoryType = type,
                 Layers = PModel.Layers + 1,
                 PID = pid,
                 Status = status,
                 Description = description
             };
             CacheCategory.Add(model);
             PModel.ChildCategory.Add(model);
         }
         
     }
     return guid;
 }
        public Category GetOrderCategoryDetailsByID(string categoryid, string orderid)
        {
            var dal = new ProductsDAL();
            DataSet ds = dal.GetOrderCategoryDetailsByID(categoryid, orderid);

            Category model = new Category();
            if (ds.Tables.Contains("Category") && ds.Tables["Category"].Rows.Count > 0)
            {
                model.FillData(ds.Tables["Category"].Rows[0]);
                List<ProductAttr> salelist = new List<ProductAttr>();
                List<ProductAttr> attrlist = new List<ProductAttr>();

                foreach (DataRow attr in ds.Tables["Attrs"].Rows)
                {

                    ProductAttr modelattr = new ProductAttr();
                    modelattr.FillData(attr);
                    if (modelattr.Type == 1)
                    {
                        attrlist.Add(modelattr);
                    }
                    else if (modelattr.Type == 2)
                    {
                        salelist.Add(modelattr);
                    }
                    modelattr.AttrValues = new List<AttrValue>();
                    foreach (DataRow value in ds.Tables["Values"].Select("AttrID='" + modelattr.AttrID + "'"))
                    {
                        AttrValue valuemodel = new AttrValue();
                        valuemodel.FillData(value);
                        modelattr.AttrValues.Add(valuemodel);
                    }
                }

                model.SaleAttrs = salelist;
                model.AttrLists = attrlist;
            }

            return model;
        }
        public Category GetCategoryByID(string categoryid)
        {
            var cacheList = GetCategorys();
            if (cacheList.Where(m => m.CategoryID.ToLower() == categoryid.ToLower()).Count() > 0)
            {
                return cacheList.Where(m => m.CategoryID.ToLower() == categoryid.ToLower()).FirstOrDefault();
            }

            var dal = new ProductsDAL();
            DataTable dt = dal.GetCategoryByID(categoryid);

            Category model = new Category();
            if (dt.Rows.Count > 0)
            {
                model.FillData(dt.Rows[0]);
                model.ChildCategory = new List<Category>();
                CacheCategory.Add(model);
            }

            return model;
        }
        public List<Category> GetClientCategorysByPID(string categoryid, EnumCategoryType type, string clientid)
        {
            var dal = new ProductsDAL();
            DataTable dt = dal.GetClientCategorysByPID(categoryid, (int)type, clientid);

            List<Category> list = new List<Category>();

            foreach (DataRow dr in dt.Rows)
            {
                Category model = new Category();
                model.FillData(dr);
                list.Add(model);

            }
            return list;
        }
        public List<Category> GetChildCategorysByID(string categoryid, EnumCategoryType type)
        {
            var cacheList = GetCategorys();
            if (cacheList.Where(m => m.PID.ToLower() == categoryid.ToLower() && m.CategoryType == (int)type).Count() > 0)
            {
                return cacheList.Where(m => m.PID.ToLower() == categoryid.ToLower() && m.CategoryType == (int)type).ToList();
            }

            DataTable dt = ProductsDAL.BaseProvider.GetChildCategorysByID(categoryid, (int)type);

            List<Category> list = new List<Category>();

            foreach (DataRow dr in dt.Rows)
            {
                Category model = new Category();
                model.FillData(dr);
                model.ChildCategory = new List<Category>();
                list.Add(model);

                CacheCategory.Add(model);
                
            }
            return list;
        }
        public List<Category> GetCategorys()
        {
            if (CacheCategory.Count() > 0)
            {
                return CacheCategory;
            }

            DataTable dt = ProductsDAL.BaseProvider.GetCategorys();

            List<Category> list = new List<Category>();

            foreach (DataRow dr in dt.Rows)
            {
                Category model = new Category();
                model.FillData(dr);
                model.ChildCategory = new List<Category>();
                list.Add(model);

                CacheCategory.Add(model);
            }
            return list;

        }