public List<CategoryItem> GetVendorCategoryMsg(CategoryItem pcb, List<CategoryItem> lscm) { StringBuilder sql = new StringBuilder(); try { sql.AppendFormat(@"SELECT category_id, category_name, depth FROM product_category_brand WHERE category_father_id='{0}' GROUP BY category_id, category_name, depth;", pcb.Id); DataTable dtVendorMsg = _access.getDataTable(sql.ToString()); if (dtVendorMsg.Rows.Count > 0)//再次調用自己 { for (int i = 0; i < dtVendorMsg.Rows.Count; i++) { CategoryItem cm = new CategoryItem(); cm.Id = dtVendorMsg.Rows[i]["category_id"].ToString(); cm.PId = pcb.Id; cm.Name = dtVendorMsg.Rows[i]["category_name"].ToString(); cm.Depth = Convert.ToInt32(dtVendorMsg.Rows[i]["depth"]) - 1; lscm.Add(cm); GetVendorCategoryMsg(cm, lscm); } } else { DataTable _dttwo = GetVendorBrandMsg(pcb); for (int j = 0; j < _dttwo.Rows.Count; j++) { CategoryItem cmtwo = new CategoryItem(); cmtwo.Id = _dttwo.Rows[j]["brand_id"].ToString(); cmtwo.PId = pcb.Id; cmtwo.Name = _dttwo.Rows[j]["brand_name"].ToString(); cmtwo.Depth = pcb.Depth + 1; lscm.Add(cmtwo); } } return lscm; } catch (Exception ex) { throw new Exception("RecommendedExcleDao-->GetVendorCategoryMsg" + ex.Message + sql.ToString(), ex); } }
public DataTable GetVendorBrandMsg(CategoryItem pcb) { StringBuilder sql = new StringBuilder(); try { sql.AppendFormat(@"SELECT v.brand_id, v.brand_name FROM vendor_brand AS v INNER JOIN product_category_brand AS p ON v.brand_id = p.brand_id WHERE p.category_id = '{0}' AND p.banner_cate_id = 754;", pcb.Id); DataTable dt = _access.getDataTable(sql.ToString()); return dt; } catch (Exception ex) { throw new Exception("RecommendedExcleDao-->GetVendorBrandMsg" + ex.Message + sql.ToString(), ex); } }
public DataTable GetVendorCategoryMsg() { try { StringBuilder str = new StringBuilder(); List<CategoryItem> lscm = new List<CategoryItem>(); CategoryItem foodItem = new CategoryItem()//食品館 { Id = "1162", PId = "0", Name = "食品館", Depth = 1 }; lscm.Add(foodItem); //導出XML List<CategoryItem> lssw = _iRecommendedExcleImplDao.GetVendorCategoryMsg(foodItem, lscm); CategoryItem stuffItem = new CategoryItem()//用品館 { Id = "1239", PId = "0", Name = "用品館", Depth = 1 }; lssw.Add(stuffItem); List<CategoryItem> lsswtwo = _iRecommendedExcleImplDao.GetVendorCategoryMsg(stuffItem, lscm); DataTable result = new DataTable(); result.Columns.Add("category_name", typeof(String)); result.Columns.Add("category_id", typeof(String)); result.Columns.Add("parent_id", typeof(String)); result.Columns.Add("level", typeof(String)); foreach (var ls in lsswtwo) { DataRow drfood = result.NewRow(); drfood[0] = ls.Name; drfood[1] = ls.Id; drfood[2] = ls.PId; drfood[3] = ls.Depth; result.Rows.Add(drfood); } return result; } catch (Exception ex) { throw new Exception("RecommendedExcleMgr-->GetVendorCategoryMsg" + ex.Message, ex); } }