private void ShowChart(DateTime start, DateTime end) { //两个时间差 if (start > end) { Page.RegisterStartupScript("error", "<script>alert('时间选择有误!');</script>"); return; } TaoBaoGoodsOrderService orderDal = new TaoBaoGoodsOrderService(); IList <BackTotalInfo> list = orderDal.GetAllBackTotalList(start, end, HttpUtility.UrlDecode(Request.Cookies["nick"].Value)); SeriseText = "[{name:'完成订单量', data:["; string iptotal = ",{name:'回头客数量',data:["; string avg = ",{name:'回头客占比',data:["; DateText = "["; for (DateTime i = start; i <= end; i = i.AddDays(1)) { DateText += "'" + i.ToString("yyyyMMdd").Substring(6, 2) + "',"; IList <BackTotalInfo> mylist = list.Where(o => o.PDate == i.ToString("yyyyMMdd")).ToList(); if (mylist.Count > 0) { BackTotalInfo info = mylist[0]; iptotal += info.PCount + ","; SeriseText += info.AllCount + ","; if (info.AllCount == 0) { avg += "0,"; } else { avg += ((double)info.PCount / info.AllCount).ToString(".00") + ","; } } else { iptotal += "0,"; SeriseText += "0,"; avg += "0,"; } } SeriseText = SeriseText.Substring(0, SeriseText.Length - 1); SeriseText += "]}"; iptotal = iptotal.Substring(0, iptotal.Length - 1); iptotal += "]}"; avg = iptotal + avg.Substring(0, avg.Length - 1); SeriseText += avg + "]}]"; DateText = DateText.Substring(0, DateText.Length - 1); DateText += "]"; TB_Start.Text = start.ToShortDateString(); TB_End.Text = end.ToShortDateString(); }
public IList <BackTotalInfo> GetAllBackTotalList(DateTime start, DateTime end, string nick) { SqlParameter[] param = new[] { new SqlParameter("@start", start), new SqlParameter("@end", end), new SqlParameter("@nick", nick) }; DataTable dt = DBHelper.ExecuteDataTable(SQL_SELECT_BACK_TOTAL, param); IList <BackTotalInfo> list = new List <BackTotalInfo>(); foreach (DataRow dr in dt.Rows) { BackTotalInfo info = new BackTotalInfo(); info.AllCount = int.Parse(dr["allcount"].ToString()); info.PCount = int.Parse(dr["pcount"].ToString()); info.PDate = dr["pdate"].ToString(); list.Add(info); } IList <BackTotalInfo> rlist = list.OrderBy(o => o.PDate).ToList(); return(rlist); }