市长热线演示版

totalcallreport.aspx.cs 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Text;
  8. using System.Data;
  9. namespace HySoft.BaseCallCenter.Web.reportmanage
  10. {
  11. public partial class totalcallreport : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. if (Request.QueryString["action"] == "show")
  16. {
  17. string str = GetHighCharts("");
  18. Response.Write(str);
  19. Response.End();
  20. }
  21. }
  22. /// <summary>
  23. /// 获取HighCharts数据
  24. /// </summary>
  25. /// <returns></returns>
  26. public string GetHighCharts(string BeginYear)
  27. {
  28. DataTable dt = new BLL.T_Call_CallRecords().GetList("1=1").Tables[0];
  29. DateTime dtNow;
  30. if (string.IsNullOrEmpty(BeginYear))
  31. {
  32. dtNow = DateTime.Now;
  33. }
  34. else
  35. {
  36. dtNow = DateTime.Parse(BeginYear);
  37. }
  38. string result = "[";
  39. for (int i = 1; i <= 12; i++)
  40. {
  41. result += "{";
  42. DateTime beginTime = Convert.ToDateTime(dtNow.Year + "-" + i + "-01 00:00:00");
  43. int days = DateTime.DaysInMonth(dtNow.Year, beginTime.Month);
  44. DataRow[] dtRow = dt.Select("begintime >='" + beginTime.ToString() + "' and beginTime<'" + beginTime.AddDays(days).AddSeconds(-1) + "'");
  45. result += "y:" + dtRow.Length + ",";
  46. result += "color:colors[" + ((i - 1) / 3) + "],";
  47. result += "drilldown:{" + GetDrillDown(dtRow, beginTime, days) + "}";
  48. result += "},";
  49. }
  50. result = result.TrimEnd(',');
  51. result += "]";
  52. return result;
  53. }
  54. /// <summary>
  55. /// 获取月份中的天数数据
  56. /// </summary>
  57. /// <param name="dt"></param>
  58. /// <returns></returns>
  59. public string GetDrillDown(DataRow[] DataSource, DateTime SummaryDateTime, int Days)
  60. {
  61. string result = "";
  62. string categories = "[";
  63. string data = "[";
  64. result += "name:'" + SummaryDateTime.Month + "',";
  65. for (int i = 1; i <= Days; i++)
  66. {
  67. categories += "'" + i + "日',";
  68. if (DataSource.Count() > 0)
  69. data += DataSource.CopyToDataTable().Select("begintime >='" + SummaryDateTime.AddDays(i - 1) + "' and beginTime<'" + SummaryDateTime.AddDays(i).AddSeconds(-1) + "'").Length + ",";
  70. else
  71. data += "0" + ",";
  72. }
  73. categories = categories.TrimEnd(',') + "],";
  74. data = data.TrimEnd(',') + "],";
  75. result += "categories:" + categories;
  76. result += "data:" + data;
  77. result += "color:colors[" + (SummaryDateTime.Month - 1) / 3 + "]";
  78. return result;
  79. }
  80. /// <summary>
  81. /// 生成表格的标题和统计字段
  82. /// </summary>
  83. /// <param name="TableTitle">表格的标题</param>
  84. /// <param name="TableHead">表格统计字段</param>
  85. /// <returns></returns>
  86. public StringBuilder CreateTableTitleAndHead(string TableTitle, string beginYear, params object[] TableHead)
  87. {
  88. StringBuilder html = new StringBuilder();
  89. html.Append("<h1 style='font-size: 18px;font-weight: bold;color: #333333;text-align:center;width:100%;'><b>" + TableTitle + "</b></h1>");
  90. html.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"400\" align='center'>");
  91. html.Append("<tr style=\"text-align: center;\">");
  92. for (int i = 0; i < TableHead.Length; i++)
  93. {
  94. //标题第一行
  95. html.Append("<td class=\"formtabletitle1\"style=\"height: 25px;background-color: #D5EDFE;border-left: 1px solid #CCCCCC;border-right: 1px solid #CCCCCC;border-top: 1px solid #CCCCCC;border-bottom: 1px solid #CCCCCC;padding: 3px 3px 3px 3px;text-align:center;\">" + TableHead[i] + "</td>");
  96. }
  97. html.Append("</tr>");
  98. GetTabelData(html, beginYear);
  99. html.Append("</table>");
  100. return html;
  101. }
  102. /// <summary>
  103. /// 获取表格中的统计数据
  104. /// </summary>
  105. /// <returns></returns>
  106. public string GetTabelData(StringBuilder SB, string BeginYear)
  107. {
  108. DataTable dt = new BLL.T_Call_CallRecords().GetList("1=1").Tables[0];
  109. DateTime dtNow;
  110. int Count = 0;
  111. int DayCount = 0;
  112. string strHtml = "";
  113. if (string.IsNullOrEmpty(BeginYear))
  114. {
  115. dtNow = DateTime.Now;
  116. }
  117. else
  118. {
  119. dtNow = DateTime.Parse(BeginYear);
  120. }
  121. for (int i = 1; i <= 12; i++)
  122. {
  123. DateTime beginTime = Convert.ToDateTime(dtNow.Year + "-" + i + "-01 00:00:00");
  124. int days = DateTime.DaysInMonth(dtNow.Year, beginTime.Month);
  125. DataRow[] dtRow = dt.Select("begintime >='" + beginTime.ToString() + "' and beginTime<'" + beginTime.AddDays(days).AddSeconds(-1) + "'");
  126. if (dtRow.Length > 0)
  127. {
  128. Count += dtRow.Length;
  129. for (int j = 1; j <= days; j++)
  130. {
  131. if (dtRow.CopyToDataTable().Select("begintime >='" + beginTime.AddDays(j - 1) + "' and beginTime<'" + beginTime.AddDays(j).AddSeconds(-1) + "'").Length > 0)
  132. {
  133. DayCount += 1;
  134. strHtml += "<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">";
  135. strHtml += "<td class=\"formtable_td\" style=\"vertical-align: middle;border-top: 0px solid #CCCCCC;border-bottom: 1px solid #CCCCCC;border-left: 1px solid #CCCCCC;border-right: 1px solid #CCCCCC;padding-left: 2px;height: 25px;padding-top: 3px;padding-bottom: 3px;\">" + beginTime.AddDays(j - 1).ToShortDateString() + "&nbsp;</td>";
  136. strHtml += "<td class=\"formtable_td\" style=\"vertical-align: middle;border-top: 0px solid #CCCCCC;border-bottom: 1px solid #CCCCCC;border-left: 1px solid #CCCCCC;border-right: 1px solid #CCCCCC;padding-left: 2px;height: 25px;padding-top: 3px;padding-bottom: 3px;\">" + dtRow.CopyToDataTable().Select("begintime >='" + beginTime.AddDays(j - 1) + "' and beginTime<'" + beginTime.AddDays(j).AddSeconds(-1) + "'").Length + "&nbsp;</td>";
  137. strHtml += "</tr>";
  138. }
  139. }
  140. if (DayCount != 0)
  141. {
  142. SB.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
  143. SB.Append("<td class=\"formtable_td\" rowspan=\"" + (DayCount + 2) + "\" style=\"vertical-align: middle;border-top: 0px solid #CCCCCC;border-bottom: 1px solid #CCCCCC;border-left: 1px solid #CCCCCC;border-right: 1px solid #CCCCCC;padding-left: 2px;height: 25px;padding-top: 3px;padding-bottom: 3px;\">" + beginTime.Month + "月&nbsp;</td>");
  144. SB.Append(strHtml);
  145. SB.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
  146. SB.Append("<td class=\"formtable_td\" style=\"vertical-align: middle;border-top: 0px solid #CCCCCC;border-bottom: 1px solid #CCCCCC;border-left: 1px solid #CCCCCC;border-right: 1px solid #CCCCCC;padding-left: 2px;height: 25px;padding-top: 3px;padding-bottom: 3px;background-color: #e4d354;\">总计:&nbsp;</td>");
  147. SB.Append("<td class=\"formtable_td\" style=\"vertical-align: middle;border-top: 0px solid #CCCCCC;border-bottom: 1px solid #CCCCCC;border-left: 1px solid #CCCCCC;border-right: 1px solid #CCCCCC;padding-left: 2px;height: 25px;padding-top: 3px;padding-bottom: 3px;background-color: #e4d354;\">" + dtRow.Length + "&nbsp;</td>");
  148. SB.Append("</tr>");
  149. SB.Append("</tr>");
  150. }
  151. strHtml = "";
  152. DayCount = 0;
  153. }
  154. }
  155. SB.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
  156. SB.Append("<td class=\"formtable_td\" style=\"vertical-align: middle;border-top: 0px solid #CCCCCC;border-bottom: 1px solid #CCCCCC;border-left: 1px solid #CCCCCC;border-right: 1px solid #CCCCCC;padding-left: 2px;height: 25px;padding-top: 3px;padding-bottom: 3px;background-color: #D5EDFE;\">" + dtNow.Year + "年总计:&nbsp;</td>");
  157. SB.Append("<td class=\"formtable_td\" colspan=\"2\" style=\"vertical-align: middle;border-top: 0px solid #CCCCCC;border-bottom: 1px solid #CCCCCC;border-left: 1px solid #CCCCCC;border-right: 1px solid #CCCCCC;padding-left: 2px;height: 25px;padding-top: 3px;padding-bottom: 3px;background-color: #D5EDFE;\">" + Count + "&nbsp;</td>");
  158. SB.Append("</tr>");
  159. return SB.ToString();
  160. }
  161. }
  162. }