Ejemplo n.º 1
0
    private void ShowChart(DateTime date)
    {
        if (date.ToShortDateString() != DateTime.Now.ToShortDateString())
        {
            Btn_Totay.Visible = true;
        }
        //大于今天
        if (DateTime.Parse(date.ToShortDateString()) > DateTime.Parse(DateTime.Now.ToShortDateString()))
        {
            TB_Start.Text = HF_Date.Value;
            return;
        }
        VisitService          visitDal = new VisitService();
        IList <HourTotalInfo> list     = visitDal.GetHourPVTotal(Encrypt(HttpUtility.UrlDecode(Request.Cookies["nick"].Value)), date);
        IList <HourTotalInfo> ipList   = visitDal.GetHourIPTotal(Encrypt(HttpUtility.UrlDecode(Request.Cookies["nick"].Value)), date);

        SeriseText = "[{name:'PV量', data:[";
        string iptotal = ",{name:'IP量',data:[";
        string avg     = ",{name:'人均浏览次数',data:[";

        DateText = "[";
        int nowhour = 23;

        if (date.ToShortDateString() == DateTime.Now.ToShortDateString())
        {
            nowhour = date.Hour;
        }
        for (int h = 0; h <= nowhour; h++)
        {
            DateText += "'" + h + "',";
            IList <HourTotalInfo> thisInfo   = list.Where(o => o.Hour == h).ToList();
            IList <HourTotalInfo> thisIpInfo = ipList.Where(o => o.Hour == h).ToList();

            if (thisIpInfo.Count == 0)
            {
                iptotal += "0,";
            }
            else
            {
                iptotal += thisIpInfo[0].PVCount + ",";
            }

            if (thisInfo.Count == 0)
            {
                SeriseText += "0,";
            }
            else
            {
                SeriseText += thisInfo[0].PVCount + ",";
            }

            if (thisIpInfo.Count == 0)
            {
                avg += "0,";
            }
            else
            {
                avg += ((double)thisInfo[0].PVCount / thisIpInfo[0].PVCount).ToString(".00") + ",";
            }
        }
        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 = date.ToShortDateString();
        HF_Date.Value = date.ToShortDateString();
    }