public ProductAttr GetProductAttrByID(string attrid, string clientid) { var list = GetAttrs(clientid); if (list.Where(m => m.AttrID == attrid).Count() > 0) { return list.Where(m => m.AttrID == attrid).FirstOrDefault(); } var dal = new ProductsDAL(); DataSet ds = dal.GetProductAttrByID(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); } } ClientAttrs[clientid].Add(model); return model; }
/// <summary> /// 获取产品信息(加入购物车页面) /// </summary> /// <param name="productid"></param> /// <returns></returns> public Products GetProductByIDForDetails(string productid) { var dal = new ProductsDAL(); DataSet ds = dal.GetProductByIDForDetails(productid); Products model = new Products(); if (ds.Tables.Contains("Product") && ds.Tables["Product"].Rows.Count > 0) { model.FillData(ds.Tables["Product"].Rows[0]); //单位 model.BigUnit = new ProductUnit(); model.BigUnit.FillData(ds.Tables["Unit"].Select("UnitID='" + model.BigUnitID + "'").FirstOrDefault()); model.SmallUnit = new ProductUnit(); model.SmallUnit.FillData(ds.Tables["Unit"].Select("UnitID='" + model.SmallUnitID + "'").FirstOrDefault()); model.AttrLists = new List<ProductAttr>(); model.SaleAttrs = new List<ProductAttr>(); 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); //填充存在的规格 foreach (var attrModel in model.SaleAttrs) { foreach (DataRow valuetr in ds.Tables["Values"].Select("AttrID='" + attrModel.AttrID + "'")) { AttrValue valueModel = new AttrValue(); valueModel.FillData(valuetr); if (detail.AttrValue.IndexOf(valueModel.ValueID) >= 0) { if (attrModel.AttrValues.Where(v => v.ValueID == valueModel.ValueID).Count() == 0) { attrModel.AttrValues.Add(valueModel); } break; } } } model.ProductDetails.Add(detail); } } return model; }
/// <summary> /// 获取产品分类详情(包括属性和值) /// </summary> public Category GetCategoryDetailByID(string categoryid) { var dal = new ProductsDAL(); DataSet ds = dal.GetCategoryDetailByID(categoryid); 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 List<ProductAttr> GetAttrs(string clientid) { if (ClientAttrs.ContainsKey(clientid)) { return ClientAttrs[clientid]; } List<ProductAttr> list = new List<ProductAttr>(); DataSet ds = new ProductsDAL().GetAttrs(clientid); foreach (DataRow dr in ds.Tables["Attrs"].Rows) { ProductAttr model = new ProductAttr(); model.FillData(dr); model.AttrValues = new List<AttrValue>(); foreach (DataRow item in ds.Tables["Values"].Rows) { AttrValue attrValue = new AttrValue(); attrValue.FillData(item); model.AttrValues.Add(attrValue); } } ClientAttrs.Add(clientid, list); return list; }
/// <summary> /// 获取属性列表(包括属性值列表) /// </summary> public List<ProductAttr> GetAttrList(string categoryid, string keyWords, int pageSize, int pageIndex, ref int totalCount, ref int pageCount, string agentid, string clientid) { var dal = new ProductsDAL(); DataSet ds = dal.GetAttrList(categoryid, keyWords, pageSize, pageIndex, ref totalCount, ref pageCount, clientid); 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); model.CreateUser = OrganizationBusiness.GetUserByUserID(model.CreateUserID, agentid); 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; }
/// <summary> /// 根据属性ID获取属性 /// </summary> /// <param name="attrID"></param> /// <returns></returns> public ProductAttr GetProductAttrByID(string attrID) { var dal = new ProductsDAL(); DataSet ds = dal.GetProductAttrByID(attrID); ProductAttr model = new ProductAttr(); if (ds.Tables.Contains("Attrs") && ds.Tables["Attrs"].Rows.Count > 0) { model.FillData(ds.Tables["Attrs"].Rows[0]); List<AttrValue> list = new List<AttrValue>(); foreach (DataRow item in ds.Tables["Values"].Rows) { AttrValue attrValue = new AttrValue(); attrValue.FillData(item); list.Add(attrValue); } model.AttrValues = list; } return model; }
/// <summary> /// 获取属性列表(包括属性值列表) /// </summary> /// <param name="keyWords"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="totalCount"></param> /// <param name="pageCount"></param> /// <returns></returns> public List<ProductAttr> GetAttrList(string categoryid, string keyWords, int pageSize, int pageIndex, ref int totalCount, ref int pageCount, string clientid) { var dal = new ProductsDAL(); DataSet ds = dal.GetAttrList(categoryid, keyWords, pageSize, pageIndex, ref totalCount, ref pageCount, clientid); 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>(); StringBuilder build = new StringBuilder(); foreach (DataRow drValue in ds.Tables["Values"].Select("AttrID='" + model.AttrID + "'")) { AttrValue valueModel = new AttrValue(); valueModel.FillData(drValue); valueList.Add(valueModel); build.Append(valueModel.ValueName + ","); } model.AttrValues = valueList; if (string.IsNullOrEmpty(build.ToString())) { model.ValuesStr = "暂无属性值(单击添加)"; } else { if (build.ToString().Length > 50) { if (build.ToString().Substring(49, 1).ToString() != ",") { model.ValuesStr = build.ToString() + "..."; } else { model.ValuesStr = build.ToString().Substring(0, 49) + " ..."; } } else { model.ValuesStr = build.ToString().Substring(0, build.ToString().Length - 1); } } list.Add(model); } } return list; }