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; }
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); model.BigUnit = GetUnitByID(model.UnitID, model.ClientID); model.SmallUnit = GetUnitByID(model.UnitID, model.ClientID); 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; }