UU跑腿标准版

ZuoXiManYiDu.aspx.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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.operationdata
  10. {
  11. public partial class ZuoXiManYiDu : System.Web.UI.Page
  12. {
  13. protected string TableHtml = "";
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. OutputTable();
  17. }
  18. private void OutputTable()
  19. {
  20. //查询条件
  21. string starttime = txtStartTime.Text.Trim();
  22. string endtime = txtEndTime.Text.Trim();
  23. if (string.IsNullOrWhiteSpace(starttime)) { starttime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("yyyy-MM-dd"); txtStartTime.Text = starttime; }
  24. if (string.IsNullOrWhiteSpace(endtime)) { endtime = DateTime.Today.ToString("yyyy-MM-dd"); txtEndTime.Text = endtime; }
  25. string tabletitle = "坐席满意度评价情况报表";
  26. //string[] tablehead = new string[] { "角色","工号","坐席姓名", "非常满意", "非常满意占比", "基本满意", "基本满意占比", "不满意", "不满意占比", "未评价", "未评价占比" };
  27. string[] tablehead = new string[] { "角色", "工号", "坐席姓名", "满意", "一般", "不满意", "评价总量", "满意率", "评价率" };
  28. TableHtml = createTable(tabletitle, tablehead, starttime, endtime);
  29. }
  30. protected void btnConfirm_Click(object sender, EventArgs e)
  31. {
  32. OutputTable();
  33. }
  34. protected void btnExport_Click(object sender, EventArgs e)
  35. {
  36. string fileName = "坐席满意度评价情况报表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
  37. Response.Clear();
  38. Response.Charset = "GB2312";
  39. Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
  40. Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
  41. Response.ContentType = "application/ms-excel";
  42. Response.Write(TableHtml);
  43. Response.End();
  44. }
  45. private string createTable(string title, string[] head, string starttime, string endtime)
  46. {
  47. StringBuilder sb = new StringBuilder();
  48. //表名称
  49. sb.Append(createTableTitle(title));
  50. //表列名
  51. sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' align='center'>");
  52. sb.Append(createTableHead(head));
  53. //表内容
  54. sb.Append(createTableBody(starttime, endtime));
  55. sb.Append("</table>");
  56. return sb.ToString();
  57. }
  58. /// <summary>
  59. /// 表名称
  60. /// </summary>
  61. /// <param name="title">表名</param>
  62. /// <returns></returns>
  63. protected string createTableTitle(string title)
  64. {
  65. StringBuilder sb = new StringBuilder();
  66. sb.Append("<h1 style='font-size: 18px; font-weight: bold; color: #333333; text-align: center;width: 100%;'><b>" + title + "</b></h1>");
  67. return sb.ToString();
  68. }
  69. /// <summary>
  70. /// 表头(表列名)
  71. /// </summary>
  72. /// <param name="head"></param>
  73. /// <returns></returns>
  74. protected string createTableHead(string[] head)
  75. {
  76. StringBuilder sb = new StringBuilder();
  77. sb.Append("<tr 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;\">");
  78. for (int i = 0; i < head.Length; i++)
  79. {
  80. //if (i == 0) sb.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;\">" + head[i] + "</td>");
  81. //else
  82. sb.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;\">" + head[i] + "</td>");
  83. }
  84. sb.Append("</tr>");
  85. return sb.ToString();
  86. }
  87. /// <summary>
  88. /// 表体(内容)
  89. /// </summary>
  90. /// <param name="starttime"></param>
  91. /// <param name="endtime"></param>
  92. /// <returns></returns>
  93. private string createTableBody(string starttime, string endtime)
  94. {
  95. string time = "";
  96. if (starttime != null && starttime.Trim() != "")
  97. {
  98. time += " and CONVERT(varchar , BeginTime, 120)>=CONVERT(varchar , '" + starttime.Trim() + " 00:00:01', 120) ";
  99. }
  100. if (endtime != null && endtime.Trim() != "")
  101. {
  102. time += " and CONVERT(varchar , BeginTime, 120)<=CONVERT(varchar , '" + endtime.Trim() + " 23:59:59', 120) ";
  103. }
  104. //存储数据
  105. Dictionary<string, List<List<string>>> body = new Dictionary<string, List<List<string>>>();
  106. //坐席
  107. DataTable dtable = new BLL.T_Sys_UserAccount().GetList("F_RoleId in (1,4,17,28,29)").Tables[0];//客服坐席、班长坐席、售前坐席、投诉坐席
  108. int allcount = dtable.Rows.Count;
  109. for (int i = 0; i < allcount; i++)
  110. {
  111. int userid = Convert.ToInt32(dtable.Rows[i]["F_UserId"].ToString());
  112. List<string> bodyitem = new List<string>();
  113. string[] UNDN = getRoleNameAndUserName(userid);
  114. bodyitem.Add(UNDN[1]);
  115. bodyitem.Add(UNDN[2]);
  116. //bodyitem.Add(UNDN[3]);
  117. DataTable dt = new BLL.T_Call_CallRecords().GetList("UserId='" + userid + "'" + time).Tables[0];
  118. string[] cp = getMYDCountAndPercent1(dt);
  119. bodyitem.AddRange(cp);
  120. ////1非常满意、2基本满意、3不满意、4未评价
  121. //for (int j = 1; j <= 4; j++)
  122. //{
  123. // string[] cp = getMYDCountAndPercent(dt, j);
  124. // bodyitem.AddRange(cp);
  125. //}
  126. if (body.ContainsKey(UNDN[0]))
  127. {
  128. body[UNDN[0]].Add(bodyitem);
  129. }
  130. else
  131. {
  132. List<List<string>> bodylist = new List<List<string>>();
  133. bodylist.Add(bodyitem);
  134. body.Add(UNDN[0], bodylist);
  135. }
  136. }
  137. StringBuilder sb = new StringBuilder();
  138. foreach (string key in body.Keys)
  139. {
  140. bool bb = true;
  141. int count = body[key].Count;
  142. foreach (List<string> listiteam in body[key])
  143. {
  144. sb.Append("<tr style=\"text-align: center;\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" onmouseout=\"this.style.backgroundColor='#ffffff'\">");
  145. if (bb)
  146. {
  147. sb.Append("<td rowspan=\"" + count + "\" class=\"formtabletitle1\"style=\"height: 25px;background-color: #fff;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;\">" + key + "</td>");
  148. bb = false;
  149. }
  150. foreach (string item in listiteam)
  151. {
  152. sb.Append("<td class=\"formtabletitle1\"style=\"height: 25px;background-color: #fff;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;\">" + item + "</td>");
  153. }
  154. sb.Append("</tr>");
  155. }
  156. }
  157. return sb.ToString();
  158. }
  159. private string createTableBody1(string starttime, string endtime)
  160. {
  161. //存储数据
  162. List<List<string>> body = new List<List<string>>();
  163. //坐席
  164. DataTable dtable = new BLL.T_Sys_UserAccount().GetList("F_RoleId in (1,4,28,29)").Tables[0];//客服坐席、班长坐席、售前坐席、投诉坐席
  165. int count = dtable.Rows.Count;
  166. for (int i = 0; i < count; i++)
  167. {
  168. //1非常满意、2基本满意、3不满意
  169. List<string> bodyitem = new List<string>();
  170. int userid = Convert.ToInt32(dtable.Rows[i]["F_UserId"].ToString());
  171. string sqlwhere = string.Format("UserId={0} AND EndTime>='{1}' AND EndTime<'{2}'", userid, starttime, endtime);
  172. DataTable dt = new BLL.T_Call_CallRecords().GetList(sqlwhere).Tables[0];
  173. string[] UNDN = getRoleNameAndUserName(userid);
  174. bodyitem.AddRange(UNDN);
  175. for (int j = 0; j < 4; j++)
  176. {
  177. string[] cp = getMYDCountAndPercent(dt, j);
  178. bodyitem.AddRange(cp);
  179. }
  180. body.Add(bodyitem);
  181. }
  182. body.Sort(new ListCompare());
  183. StringBuilder sb = new StringBuilder();
  184. foreach (var list in body)
  185. {
  186. sb.Append("<tr style=\"text-align: center;\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" onmouseout=\"this.style.backgroundColor='#ffffff'\">");
  187. foreach (var listiteam in list)
  188. {
  189. sb.Append("<td class=\"formtabletitle1\"style=\"height: 25px;background-color: #fff;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;\">" + listiteam + "</td>");
  190. }
  191. sb.Append("</tr>");
  192. }
  193. return sb.ToString();
  194. }
  195. /// <summary>
  196. /// 每种满意度的个数和占比
  197. /// </summary>
  198. /// <param name="dt"></param>
  199. /// <param name="type"></param>
  200. /// <returns></returns>
  201. private string[] getMYDCountAndPercent(DataTable dt, int type)
  202. {
  203. int allcount = dt.Rows.Count;
  204. int typecount = 0;
  205. if (type == 4) typecount = dt.Select("MYD IS NULL").Count();
  206. else typecount = dt.Select("MYD=" + type).Count();
  207. string percent = "0.00";
  208. if (allcount > 0) percent = (typecount * 1.0 / allcount).ToString("0.00");
  209. return new string[] { typecount.ToString(), percent };
  210. }
  211. private string[] getMYDCountAndPercent1(DataTable dt)
  212. {
  213. int allcount = dt.Rows.Count;
  214. int my = 0;//满意
  215. int yb = 0;//一般
  216. int myc = 0;//满意总量
  217. int bmy = 0;//不满意
  218. int pjc = 0;//评价量
  219. string myl = "0";//满意率
  220. string pjl = "0";//评价率
  221. my = dt.Select("MYD=1").Count();
  222. yb = dt.Select("MYD=2").Count();
  223. myc = my + yb;
  224. bmy= dt.Select("MYD=3").Count();
  225. pjc= dt.Select("MYD IS not NULL").Count();
  226. if (pjc > 0) myl = (myc * 100.0 / pjc).ToString("0.00") + "%";
  227. if (allcount > 0) pjl= (pjc * 100.0 / allcount).ToString("0.00") + "%";
  228. return new string[] { my.ToString(), yb.ToString(), bmy.ToString(), pjc.ToString(), myl, pjl };
  229. }
  230. /// <summary>
  231. /// 通过UserId得到角色和姓名
  232. /// </summary>
  233. /// <param name="userid"></param>
  234. /// <returns></returns>
  235. private string[] getRoleNameAndUserName(int userid)
  236. {
  237. var user = new BLL.T_Sys_UserAccount().GetModel(userid);
  238. string[] resarr = new string[3];
  239. if (user != null)
  240. {
  241. var role = new BLL.T_Sys_RoleInfo().GetModel(user.F_RoleId);
  242. if (role != null)
  243. {
  244. resarr[0] = role.F_RoleName;
  245. }
  246. resarr[1] = user.F_UserCode;
  247. resarr[2] = user.F_UserName;
  248. //var dept = new BLL.T_Sys_Department().GetModel(user.F_DeptId);
  249. //if (dept != null)
  250. //{
  251. // resarr[3] = dept.F_DeptName;
  252. //}
  253. }
  254. return resarr;
  255. }
  256. }
  257. class ListCompare : IComparer<List<string>>
  258. {
  259. public int Compare(List<string> a, List<string> b)
  260. {
  261. return a[0].CompareTo(b[0]);
  262. }
  263. }
  264. }