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 Products GetProductByIDForDetails(string productid, string clientid)
        {
            var dal = new ProductsDAL();
            DataSet ds = dal.GetProductByIDForDetails(productid, clientid);
           
            Products model = new Products();
            
            if (ds.Tables.Contains("Product") && ds.Tables["Product"].Rows.Count > 0)
            {
                model.FillData(ds.Tables["Product"].Rows[0]);

                model.SmallUnit = GetUnitByID(model.SmallUnitID);

                model.AttrLists = new List<ProductAttr>();
                model.SaleAttrs = new List<ProductAttr>();

                model.Providers = new ProvidersEntity();
                if (!string.IsNullOrEmpty(model.ProdiverID))
                {
                    model.Providers.FillData(ds.Tables["Providers"].Rows[0]);
                    if (!string.IsNullOrEmpty(model.Providers.CityCode))
                    {
                        var city = CommonBusiness.GetCityByCode(model.Providers.CityCode);
                        model.Providers.Address = city.Description + model.Providers.Address;
                    }
                }

                foreach (DataRow attrtr in ds.Tables["Attrs"].Rows)
                {
                    ProductAttr attrModel = new ProductAttr();
                    attrModel.FillData(attrtr);
                    attrModel.AttrValues = new List<AttrValue>();

                    //参数
                    if (attrModel.Type == (int)EnumAttrType.Parameter)
                    {
                        foreach (DataRow valuetr in ds.Tables["Values"].Select("AttrID='" + attrModel.AttrID + "'"))
                        {
                            AttrValue valueModel = new AttrValue();
                            valueModel.FillData(valuetr);
                            if (model.AttrValueList.IndexOf(valueModel.ValueID) >= 0)
                            {
                                attrModel.AttrValues.Add(valueModel);
                                model.AttrLists.Add(attrModel);
                                break;
                            }
                        }
                    }
                    else
                    {
                        model.SaleAttrs.Add(attrModel);
                    }
                }

                model.ProductDetails = new List<ProductDetail>();
                foreach (DataRow item in ds.Tables["Details"].Rows)
                {
                    ProductDetail detail = new ProductDetail();
                    detail.FillData(item);
                    model.ProductDetails.Add(detail);
                }
            }

            return model;
        }
        public ProductAttr GetTaskPlateAttrByCategoryID(string categoryid)
        {
            var dal = new ProductsDAL();
            DataSet ds = dal.GetTaskPlateAttrByCategoryID(categoryid);

            ProductAttr model = new ProductAttr();
            if (ds.Tables.Contains("Attrs") && ds.Tables["Attrs"].Rows.Count > 0)
            {
                model.FillData(ds.Tables["Attrs"].Rows[0]);
                model.AttrValues = new List<AttrValue>();
                foreach (DataRow item in ds.Tables["Values"].Rows)
                {
                    AttrValue attrValue = new AttrValue();
                    attrValue.FillData(item);
                    model.AttrValues.Add(attrValue);
                }
            }

            return model;
        }
        public ProductAttr GetAttrByID(string attrid)
        {
            var list = GetAttrs();

            if (list.Where(m => m.AttrID.ToLower() == attrid.ToLower()).Count() > 0)
            {
                var cache = list.Where(m => m.AttrID.ToLower() == attrid.ToLower()).FirstOrDefault();
                if (cache.AttrValues.Count > 0)
                {
                    return cache;
                }
                else
                {
                    DataTable dt = new ProductsDAL().GetAttrValuesByAttrID(attrid);
                    foreach (DataRow item in dt.Rows)
                    {
                        AttrValue attrValue = new AttrValue();
                        attrValue.FillData(item);
                        cache.AttrValues.Add(attrValue);
                    }
                    return cache;
                }
            }
            DataSet ds = new ProductsDAL().GetAttrByID(attrid);

            ProductAttr model = new ProductAttr();
            if (ds.Tables.Contains("Attrs") && ds.Tables["Attrs"].Rows.Count > 0)
            {
                model.FillData(ds.Tables["Attrs"].Rows[0]);
                model.AttrValues = new List<AttrValue>();
                foreach (DataRow item in ds.Tables["Values"].Rows)
                {
                    AttrValue attrValue = new AttrValue();
                    attrValue.FillData(item);
                    model.AttrValues.Add(attrValue);
                }
                CacheAttrs.Add(model);
            }

            return model;
        }
        public List<ProductAttr> GetAttrsByCategoryID(string categoryid)
        {
            var dal = new ProductsDAL();
            DataTable dt = dal.GetAttrsByCategoryID(categoryid);

            List<ProductAttr> list = new List<ProductAttr>();
            foreach (DataRow dr in dt.Rows)
            {
                ProductAttr model = new ProductAttr();
                model.FillData(dr);
                list.Add(model);
            }
            return list;
        }
        public List<ProductAttr> GetAttrList(string categoryid, string keyWords, int pageSize, int pageIndex, ref int totalCount, ref int pageCount)
        {
            var dal = new ProductsDAL();
            DataSet ds = dal.GetAttrList(categoryid, keyWords, pageSize, pageIndex, ref totalCount, ref pageCount);

            List<ProductAttr> list = new List<ProductAttr>();
            if (ds.Tables.Contains("Attrs"))
            {
                foreach (DataRow dr in ds.Tables["Attrs"].Rows)
                {
                    ProductAttr model = new ProductAttr();
                    model.FillData(dr);

                    //List<AttrValue> valueList = new List<AttrValue>();
                    //foreach (DataRow drValue in ds.Tables["Values"].Select("AttrID='" + model.AttrID + "'"))
                    //{
                    //    AttrValue valueModel = new AttrValue();
                    //    valueModel.FillData(drValue);
                    //    valueList.Add(valueModel);
                    //}
                    //model.AttrValues = valueList;

                    list.Add(model);
                }
            }
            return list;
        }
        public List<ProductAttr> GetAttrs()
        {
            if (CacheAttrs.Count > 0)
            {
                return CacheAttrs;
            }

            List<ProductAttr> list = new List<ProductAttr>();
            DataTable dt = new ProductsDAL().GetAttrs();
            foreach (DataRow dr in dt.Rows)
            {
                ProductAttr model = new ProductAttr();
                model.FillData(dr);
                model.AttrValues = new List<AttrValue>();
                CacheAttrs.Add(model);
            }
            return list;
        }