public HttpResponseBase GetBannerCateBrand() { string json = "{success:true}"; _cateBrandMgr = new ProductCategoryBrandMgr(mySqlConnectionString); _productCategoryBannerImplMgr = new ProductCategoryBannerMgr(mySqlConnectionString); _parameterMgr = new ParameterMgr(mySqlConnectionString); try { if (!string.IsNullOrEmpty(Request.Params["banner_cateid"].ToString())) { uint isTryUint = 0; if (uint.TryParse(Request.Params["banner_cateid"].ToString(), out isTryUint)) { int banner_cateid = Convert.ToInt32(Request.Params["banner_cateid"].ToString()); //獲取新館類別 uint XGCateId = _productCategoryBannerImplMgr.GetXGCate().FirstOrDefault().category_id;//獲取754 prodCateMgr = new ProductCategoryMgr(mySqlConnectionString);//實例化對象mgr List<ProductCategory> category = prodCateMgr.QueryAll(new ProductCategory { category_display = 1 });//獲取所有的類別 包括隱藏和顯示的 List<ProductCategory> cateXGlist = new List<ProductCategory>();//設定對象保存新館所有類別 GetAllCategory_idList(category, XGCateId, ref cateXGlist);//獲取所有新館類別 List<Parametersrc> pali = _parameterMgr.GetElementType("banner_cate"); List<ProductCategoryBrand> XGCateBrandResult = new List<ProductCategoryBrand>(); if (pali.Count != 0) { if (cateXGlist != null) { List<ProductCategory> query = category.FindAll(p => p.category_id == banner_cateid).ToList();//判斷是否是類別專區 List<ProductCategoryBrand> ProList = new List<ProductCategoryBrand>(); if (query.Count != 0) //新館專區類別設定 { ProList = _cateBrandMgr.GetSaledProduct(XGCateId, banner_cateid);//獲取所有有效商品 以及對應的品牌和館別 } else { ProList = _cateBrandMgr.GetProductByCondi(XGCateId, banner_cateid); } //ProList = _cateBrandMgr.GetSaledProduct(XGCateId);//獲取所有有效商品 foreach (ProductCategoryBrand itemcate in ProList) { ProductCategory querySingle = cateXGlist.Find(p => p.category_id == itemcate.category_id); if (querySingle != null) { itemcate.category_name = querySingle.category_name; XGCateBrandResult.Add(itemcate); GetFatherCateBrand(cateXGlist, XGCateId, itemcate, ref XGCateBrandResult); } } json = "{success:true,item:" + JsonConvert.SerializeObject(XGCateBrandResult, Formatting.Indented) + "}";//返回json數據 } } } } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); json = "{success:false,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase GetProductByCategorySet() { string resultStr = "{success:false,msg:0,item:[]}"; try { _productCategoryBannerImplMgr = new ProductCategoryBannerMgr(mySqlConnectionString); if (!string.IsNullOrEmpty(Request.Params["banner_cateid"].ToString())) { uint isTryUint = 0; if (uint.TryParse(Request.Params["banner_cateid"].ToString(), out isTryUint)) { uint banner_cateid = Convert.ToUInt32(Request.Params["banner_cateid"].ToString()); //獲取新館類別 uint fatherid = _productCategoryBannerImplMgr.GetXGCate().FirstOrDefault().category_id;//獲取754 prodCateMgr = new ProductCategoryMgr(mySqlConnectionString);//實例化對象mgr List<ProductCategory> category = prodCateMgr.QueryAll(new ProductCategory { category_display = 0 });//獲取所有的類別 包括隱藏和顯示的 string cateStr = string.Empty;//設定對象保存新館所有類別 GetAllCategory_id(category, fatherid, ref cateStr);//獲取所有新館類別 if (!string.IsNullOrEmpty(cateStr))//專區類別處理數據 { DataTable dt = new DataTable(); List<ProductCategory> query = category.FindAll(p => p.category_id == banner_cateid).ToList();//判斷是否是類別專區 if (query.Count != 0) //新館專區類別設定 { dt = _productCategoryBannerImplMgr.isSaleProd(cateStr, banner_cateid);//獲取所有類別 } else//不是專區的類別數據 優惠專區999998 優惠專區頁999997 優惠專區頁999996 產地直送999995 { dt = _productCategoryBannerImplMgr.GetXGCateByBanner(cateStr, banner_cateid); } string cateStrs = string.Empty;//存儲所有新館類別樹狀結構數據 //根據新館子元素找父級元素 新館樹狀結構 if (dt.Rows.Count != 0) { bool isTrue = false; string cateStrTree = string.Empty; foreach (DataRow row in dt.Rows) { if (Convert.ToUInt32(Convert.ToUInt32(row["category_id"])) != banner_cateid) { GetFatherCategory_id(category, ref isTrue, fatherid, Convert.ToUInt32(row["category_id"]), ref cateStrTree); if (isTrue && cateStrTree != null) { cateStrs += Convert.ToUInt32(row["category_id"]); cateStrs += ","; } } } cateStrs += cateStrTree; if (!string.IsNullOrEmpty(cateStrs)) { cateStrs = cateStrs.Substring(0, cateStrs.Length - 1); List<ProductCategory> li = _productCategoryBannerImplMgr.GetProductCategoryInfo(cateStrs); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; resultStr = "{success:true,item:" + JsonConvert.SerializeObject(li, Formatting.Indented, timeConverter) + "}";//返回json數據 } } else { resultStr = "{success:true,totalCount:0,item:[]}"; } } } } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); resultStr = "{success:false,msg:0,item:[]}"; } this.Response.Clear(); this.Response.Write(resultStr); this.Response.End(); return this.Response; }