Beispiel #1
0
        public Products GetProductByID(string productid)
        {
            var     dal = new ProductsDAL();
            DataSet ds  = dal.GetProductByID(productid);

            Products model = new Products();

            if (ds.Tables.Contains("Product") && ds.Tables["Product"].Rows.Count > 0)
            {
                model.FillData(ds.Tables["Product"].Rows[0]);
                model.Category = GetCategoryDetailByID(model.CategoryID);
                var bigunit = new ProductUnit();
                bigunit.FillData(ds.Tables["Unit"].Select("UnitID='" + model.BigUnitID + "'").FirstOrDefault());
                model.BigUnit = bigunit;

                var smallunit = new ProductUnit();
                smallunit.FillData(ds.Tables["Unit"].Select("UnitID='" + model.SmallUnitID + "'").FirstOrDefault());
                model.SmallUnit = smallunit;

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

                    Dictionary <string, string> attrs = new Dictionary <string, string>();
                    foreach (string attr in detail.SaleAttrValue.Split(','))
                    {
                        if (!string.IsNullOrEmpty(attr))
                        {
                            attrs.Add(attr.Split(':')[0], attr.Split(':')[1]);
                        }
                    }
                    detail.SaleAttrValueString = "";
                    foreach (var attr in model.Category.SaleAttrs)
                    {
                        if (attrs.ContainsKey(attr.AttrID))
                        {
                            detail.SaleAttrValueString += attr.AttrName + ":" + attr.AttrValues.Where(a => a.ValueID.ToLower() == attrs[attr.AttrID].ToLower()).FirstOrDefault().ValueName + ",";
                        }
                    }

                    if (detail.SaleAttrValueString.Length > 0)
                    {
                        detail.SaleAttrValueString = detail.SaleAttrValueString.Substring(0, detail.SaleAttrValueString.Length - 1);
                    }

                    model.ProductDetails.Add(detail);
                }
            }

            return(model);
        }
Beispiel #2
0
        public List <ProductUnit> GetClientUnits(string clientid)
        {
            var       dal = new ProductsDAL();
            DataTable dt  = dal.GetClientUnits(clientid);

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

            foreach (DataRow dr in dt.Rows)
            {
                ProductUnit model = new ProductUnit();
                model.FillData(dr);
                list.Add(model);
            }
            return(list);
        }
Beispiel #3
0
        public List <ProductUnit> GetUnits()
        {
            if (CacheUnits.Count() > 0)
            {
                return(CacheUnits);
            }

            foreach (DataRow dr in ProductsDAL.BaseProvider.GetUnits().Rows)
            {
                ProductUnit model = new ProductUnit();
                model.FillData(dr);
                CacheUnits.Add(model);
            }
            return(CacheUnits);
        }
Beispiel #4
0
        public ProductUnit GetUnitByID(string unitid)
        {
            var list = GetUnits();

            if (list.Where(m => m.UnitID.ToLower() == unitid.ToLower()).Count() > 0)
            {
                return(list.Where(m => m.UnitID.ToLower() == unitid.ToLower()).FirstOrDefault());
            }

            var       dal = new ProductsDAL();
            DataTable dt  = dal.GetUnitByID(unitid);

            ProductUnit model = new ProductUnit();

            if (dt.Rows.Count > 0)
            {
                model.FillData(dt.Rows[0]);
                list.Add(model);
            }
            return(model);
        }