public ContentResult TrendsCount() { DataSet ds1 = new DataSet(); string stime = string.IsNullOrEmpty(Request["stime"]) ? DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") : Request["stime"]; //开始时间 string etime = string.IsNullOrEmpty(Request["etime"]) ? DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") : Request["etime"]; //结束时间 string where = "1=1"; JMP.BLL.jmp_trends blltrends = new JMP.BLL.jmp_trends(); if (!string.IsNullOrEmpty(stime)) { where += " and convert(varchar(10),t_time,120)>=convert(varchar(10),'" + stime + "',120) "; } if (!string.IsNullOrEmpty(etime)) { where += " and convert(varchar(10),t_time,120)<=convert(varchar(10),'" + etime + "',120) "; } where += " order by t_time "; int searchType = 2; string searchname = UserInfo.UserNo; string a_name = string.IsNullOrEmpty(Request["a_name"]) ? "" : Request["a_name"]; if (!string.IsNullOrEmpty(a_name) && a_name != "所有应用") { searchType = 1; searchname = a_name; } ds1 = blltrends.GetListSet(stime, etime, searchType, searchname); return(Content(JsonConvert.SerializeObject(new { Data = ds1 }), "application/json")); }
public string NewUserCount() { string stime = string.IsNullOrEmpty(Request["stime"]) ? DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") : Request["stime"]; //开始时间 string etime = string.IsNullOrEmpty(Request["etime"]) ? DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") : Request["etime"]; //结束时间 int searchType = string.IsNullOrEmpty(Request["searchType"]) ? 0 : Int32.Parse(Request["searchType"]); //查询条件 string searchname = string.IsNullOrEmpty(Request["searchname"]) ? "" : Request["searchname"]; //查询内容 string htmls = "{\"chart\":{\"caption\":\"\",\"paletteColors\":\"#0075c2,#1aaf5d\",\"xAxisNameFontSize\":\"12\",\"subcaptionFontSize\":\"14\",\"subcaptionFontBold\":\"0\",\"showBorder\":\"0\",\"bgColor\":\"#ffffff\",\"baseFont\":\"Helvetica Neue,Arial\",\"showCanvasBorder\":\"0\",\"showShadow\":\"0\",\"showAlternateHGridColor\":\"0\",\"canvasBgColor\":\"#ffffff\",\"forceAxisLimits\":\"1\",\"pixelsPerPoint\":\"0\",\"pixelsPerLabel\":\"30\",\"lineThickness\":\"1\",\"compactdatamode\":\"1\",\"dataseparator\":\"|\",\"labelHeight\":\"70\",\"scrollheight\":\"10\",\"flatScrollBars\":\"1\",\"scrollShowButtons\":\"0\",\"scrollColor\":\"#cccccc\",\"legendBgAlpha\":\"0\",\"legendBorderAlpha\":\"0\",\"legendShadow\":\"0\",\"legendItemFontSize\":\"10\",\"legendItemFontColor\":\"#666666\",\"showToolTip\":\"true\"},"; //string htmls = "{\"chart\":{\"caption\":\"\",\"numberprefix\":\"\",\"plotgradientcolor\":\"\",\"bgcolor\":\"ffffff\",\"showalternatehgridcolor\":\"0\",\"divlinecolor\":\"cccccc\",\"showvalues\":\"0\",\"showcanvasborder\":\"0\",\"canvasborderalpha\":\"0\",\"canvasbordercolor\":\"cccccc\",\"canvasborderthickness\":\"1\",\"yaxismaxvalue\":\"\",\"captionpadding\":\"50\",\"linethickness\":\"3\",\"yaxisvaluespadding\":\"30\",\"legendshadow\":\"0\",\"legendborderalpha\":\"0\",\"palettecolors\":\"#008ee4\",\"showborder\":\"0\",\"toolTipSepChar\":\"\",\"formatNumberScale\":\"0\"},"; JMP.BLL.jmp_trends blltrends = new JMP.BLL.jmp_trends(); DataTable dt = blltrends.GetListDataTable(stime, etime, searchType, searchname); #region 组装json格式 htmls += "\"categories\": ["; htmls += "{"; //htmls += "\"category\": ["; htmls += "\"category\":\" "; string type = string.IsNullOrEmpty(Request["type"]) ? "" : Request["type"];//获取显示类型 #region 构建坐标 #region 天需要组装的条件 DateTime ksstime = DateTime.Parse(stime); DateTime jsetime = DateTime.Parse(etime); int zbcs = Int32.Parse((DateTime.Parse(etime) - DateTime.Parse(stime)).TotalDays.ToString()); #endregion #region 周需要组装的条件 ArrayList kssjfw = JMP.TOOL.WeekDateTime.WeekMonday(DateTime.Parse(stime), DateTime.Parse(etime)); //根据时间返回获取每周周一 ArrayList jssjfw = JMP.TOOL.WeekDateTime.WeekDay(DateTime.Parse(stime), DateTime.Parse(etime)); //根据时间返回获取每周星期天 #endregion #region 月需要组装的条件 DateTime ksmonth = DateTime.Parse(stime); int xsmonth = Int32.Parse(DateTime.Parse(etime).ToString("yyyyMM")) - Int32.Parse(DateTime.Parse(stime).ToString("yyyyMM")); #endregion string seriesName = "每日新增用户"; string labelvalue = "";//显示值 switch (type) { case "day": //天 for (int j = 0; j <= zbcs; j++) { //htmls += "{\"label\": \"" + ksstime.ToString("yyyy-MM-dd") + "\"},"; htmls += ksstime.ToString("yyyy-MM-dd") + "|"; ksstime = ksstime.AddDays(1); } seriesName = "每日新增用户"; break; case "week": //周 for (int k = 0; k < kssjfw.Count; k++) { labelvalue = DateTime.Parse(kssjfw[k].ToString()).ToString("yy-MM-dd") + "至" + DateTime.Parse(jssjfw[k].ToString()).ToString("yy-MM-dd"); //htmls += "{\"label\": \"" + labelvalue + "\"},"; htmls += labelvalue + "|"; } seriesName = "每周新增用户"; break; case "month": //月 for (int i = 0; i <= xsmonth; i++) { //htmls += "{\"label\": \"" + ksmonth.ToString("yyyy-MM") + "\"},"; htmls += ksmonth.ToString("yyyy-MM") + "|"; ksmonth = ksmonth.AddMonths(1); } seriesName = "每月新增用户"; break; } htmls = htmls.TrimEnd('|'); //htmls += "]"; htmls += "\""; htmls += "}"; htmls += "],"; #endregion #region 构建数据 htmls += "\"dataset\": ["; htmls += "{"; htmls += "\"seriesName\":\"" + seriesName + "\","; // htmls += "\"data\": ["; htmls += "\"data\": \""; switch (type) { case "day": //天 #region 天显示 if (dt.Rows.Count > 0) { if ((zbcs + 1) == dt.Rows.Count) { for (int i = 0; i < dt.Rows.Count; i++) { //htmls += "{\"value\": \"" + dt.Rows[i]["t_newcount"] + "\"},"; htmls += dt.Rows[i]["t_newcount"] + "|"; } } else { DateTime ksstimes = DateTime.Parse(stime); for (int m = 0; m <= zbcs; m++) { DataRow[] ddt = dt.Select("t_time>='" + ksstimes.ToString("yyyy-MM-dd") + " 00:00:00" + "' and t_time<='" + ksstimes.ToString("yyyy-MM-dd") + " 23:59:59" + "'"); if (ddt.Length == 1) { //htmls += "{\"value\": \"" + ddt[0]["t_newcount"] + "\"},"; htmls += ddt[0]["t_newcount"] + "|"; } else { //htmls += "{\"value\": \"0\"},"; htmls += "0|"; } ksstimes = ksstimes.AddDays(1); } } } else { return("0"); } #endregion break; case "week": //周 #region 周 if (dt.Rows.Count > 0) { for (int kw = 0; kw < kssjfw.Count; kw++) { DataTable kwdt = JMP.TOOL.MdlList.TableSelect(dt, "t_time>='" + kssjfw[kw] + " 00:00:00" + "' and t_time<='" + jssjfw[kw] + " 23:59:59" + "'"); if (kwdt != null) { if (kwdt.Rows.Count > 0) { object sumObject = kwdt.Compute("sum(t_newcount)", "TRUE"); //根据DataTable列求和 // htmls += "{\"value\": \"" + sumObject + "\"},"; htmls += sumObject + "|"; } else { //htmls += "{\"value\": \"0\"},"; htmls += "0|"; } } else { //htmls += "{\"value\": \"0\"},"; htmls += "0|"; } } } else { return("0"); } #endregion break; case "month": //月 #region 月 if (dt.Rows.Count > 0) { DateTime monthtime = DateTime.Parse(stime); for (int mm = 0; mm <= xsmonth; mm++) { DataTable mdt = JMP.TOOL.MdlList.TableSelect(dt, "t_time>='" + monthtime.ToString("yyyy-MM-01") + " 00:00:00" + "' and t_time<='" + monthtime.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd") + " 23:59:59" + "'"); if (mdt != null) { if (mdt.Rows.Count > 0) { object sumObject = mdt.Compute("sum(t_newcount)", "TRUE"); //根据DataTable列求和 // htmls += "{\"value\": \"" + sumObject + "\"},"; htmls += sumObject + "|"; } else { //htmls += "{\"value\": \"0\"},"; htmls += "0|"; } } else { // htmls += "{\"value\": \"0\"},"; htmls += "0|"; } monthtime = monthtime.AddMonths(1); } } else { return("0"); } #endregion break; } //htmls = htmls.TrimEnd(','); htmls = htmls.TrimEnd('|'); // htmls += "]"; htmls += "\""; htmls += "}"; htmls += "]"; htmls += "}"; #endregion #endregion return(htmls); }