public HttpResponseBase GetCategory() { ICategoryImplMgr _IcategoryMgr = new CategoryMgr(mySqlConnectionString); List<CategoryQuery> stores = new List<CategoryQuery>(); string json = string.Empty; try { int totalCount = 0; stores = _IcategoryMgr.GetCategory(); foreach (var item in stores) { item.category_name = item.category_id + "-" + item.category_name; } json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(stores) + "}";//返回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:true,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase GetCategoryList() { List<CategoryQuery> stores = new List<CategoryQuery>(); string json = string.Empty; int sum = 0; try { CategoryQuery query = new CategoryQuery(); query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量 query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量 if (string.IsNullOrEmpty(Request.Params["serchs"])) { query.serchs = 0; } else { query.serchs = Convert.ToInt32(Request.Params["serchs"]); } query.seldate = Convert.ToInt32(Request.Params["seldate"] ?? "0"); query.brand_status = Convert.ToInt32(Request.Params["brand_status"] ?? "0"); query.starttime = Convert.ToInt32(CommonFunction.GetPHPTime(Request.Params["starttime"] ?? "0")); query.endtime = Convert.ToInt32(CommonFunction.GetPHPTime(Request.Params["endtime"] ?? "0")); ICategoryImplMgr _IcategoryMgr = new CategoryMgr(mySqlConnectionString); int totalCount = 0; stores = _IcategoryMgr.GetCategoryList(query, out totalCount); //sum = Int32.Parse(_IcategoryMgr.GetSum(query)); foreach (var item in stores) { //因為delivertime類型是int! sum += int.Parse(item.amo); } foreach (var item in stores) { //因為delivertime類型是int! item.amo = int.Parse(item.amo).ToString("###,###"); item.sum = sum.ToString("###,###"); } IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; //listUser是准备转换的对象 json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(stores, Formatting.Indented, timeConverter) + "}";//返回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:true,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }