Няма описание

HF_Report.aspx.cs 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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.Data;
  8. using System.Text;
  9. using XYFDRQ.DBUtility;
  10. using XYFDRQ.Common;
  11. public partial class HF_Report : BasePage
  12. {
  13. XYFDRQ.BLL.T_Sys_DictionaryValue bll_T_Sys_DictionaryValue = new XYFDRQ.BLL.T_Sys_DictionaryValue();
  14. XYFDRQ.BLL.T_Sys_Department bll_T_Sys_Department = new XYFDRQ.BLL.T_Sys_Department();
  15. XYFDRQ.BLL.T_Sys_UserAccount bll_T_Sys_UserAccount = new XYFDRQ.BLL.T_Sys_UserAccount();
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. AjaxPro.Utility.RegisterTypeForAjax(typeof(HF_Report));
  19. if (!this.IsPostBack)
  20. {
  21. BtnisEnable();
  22. InitData();
  23. }
  24. }
  25. public void InitData()
  26. {
  27. //绑定坐席
  28. this.ddlAccount.DataSource = bll_T_Sys_UserAccount.GetList("F_StateFlag=1 and F_IsSystemUser=1");
  29. this.ddlAccount.DataTextField = "F_UserName";
  30. this.ddlAccount.DataValueField = "F_UserId";
  31. this.ddlAccount.DataBind();
  32. this.ddlAccount.Items.Insert(0, new ListItem("--请选择--", ""));
  33. txtBeginDate.Value = DateTime.Now.ToString("yyyy-MM-01");//赋初值
  34. txtEndDate.Value = DateTime.Now.ToString("yyyy-MM-dd");//赋初值
  35. LoginUser p_LoginUser = new LoginUser(this.Context);
  36. this.hfDeptId.Value = p_LoginUser.DeptId.ToString();
  37. }
  38. private void BtnisEnable()
  39. {
  40. if (base.BtnIsEnable("ReportManage_bbtj_HF_Report_all"))
  41. {
  42. this.hfQX.Value = "全部";
  43. }
  44. }
  45. /// <summary>
  46. /// 导出Excel
  47. /// </summary>
  48. /// <param name="sender"></param>
  49. /// <param name="e"></param>
  50. protected void btnExtWord_Click(object sender, EventArgs e)
  51. {
  52. string fileName = HttpUtility.UrlEncode("回访统计_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls", Encoding.UTF8).ToString();
  53. Response.Clear();
  54. Response.Charset = "UTF-8";
  55. Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
  56. Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
  57. Response.ContentType = "application/ms-excel";
  58. Response.Write(this.hfInfo.Value);
  59. Response.End();
  60. }
  61. /// <summary>
  62. /// 导出的Excel表
  63. /// </summary>
  64. /// <param name="searchItems"></param>
  65. /// <returns></returns>
  66. [AjaxPro.AjaxMethod()]
  67. public string GetReportTable(AjaxPro.JavaScriptArray searchItems)
  68. {
  69. StringBuilder strbld = new StringBuilder();
  70. string[] _operations = GetSearchItems(searchItems);
  71. strbld.Append("<h1 style='font-size: 18px;font-weight: bold;color: #333333;text-align:center;width:100%;'><b>回访统计表</b></h1>");
  72. strbld.Append("<div style='width:100%; text-align:right;height:25px;'>统计截止日期: " + _operations[0] + "—" + _operations[1] + " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>");
  73. strbld.Append("<table cellspacing='0' cellpadding='0' border='1' width='100%'>");
  74. try
  75. {
  76. string strSql = @"select a.LastDealDeptId,a.LastDealUserId,
  77. (select COUNT(1) from T_Bus_WorkOrder as b where b.LastDealUserId=a.LastDealUserId and b.ReturnVisitState in(0,1)) as KHFCount,
  78. (select COUNT(1) from T_Bus_WorkOrder as c where c.LastDealUserId=a.LastDealUserId and c.ReturnVisitState=2) as YHFCount,
  79. (select COUNT(1) from T_Bus_WorkOrder as d where d.LastDealUserId=a.LastDealUserId ) as ALLCount,
  80. (select COUNT(1) from T_Bus_WorkOrder as e where e.LastDealUserId=a.LastDealUserId and e.ReturnVisitState=2 and e.ReturnVisitResult=1) as FCMYCount,
  81. (select COUNT(1) from T_Bus_WorkOrder as f where f.LastDealUserId=a.LastDealUserId and f.ReturnVisitState=2 and f.ReturnVisitResult=2) as MYCount,
  82. (select COUNT(1) from T_Bus_WorkOrder as g where g.LastDealUserId=a.LastDealUserId and g.ReturnVisitState=2 and g.ReturnVisitResult=3) as YBCount,
  83. (select COUNT(1) from T_Bus_WorkOrder as h where h.LastDealUserId=a.LastDealUserId and h.ReturnVisitState=2 and h.ReturnVisitResult=4) as BMYCount
  84. from T_Bus_WorkOrder as a
  85. where 1=1 ";
  86. if (!string.IsNullOrEmpty(_operations[0]))
  87. {
  88. strSql += " and DATEDIFF(d,a.LastDealTime,'" + _operations[0] + "')<=0";
  89. }
  90. if (!string.IsNullOrEmpty(_operations[1]))
  91. {
  92. strSql += " and DATEDIFF(d,a.LastDealTime,'" + _operations[1] + "')>=0";
  93. }
  94. if (!string.IsNullOrEmpty(_operations[4]))
  95. {
  96. //string ss = _operations[4].ToString();
  97. strSql += " and LastDealUserId=" + _operations[4] + "";
  98. }
  99. if (_operations[2] != "全部")
  100. {
  101. strSql += " and a.LastDealDeptId=" + _operations[3];
  102. }
  103. strSql += " group by a.LastDealDeptId,a.LastDealUserId";
  104. DataTable dt = XYFDRQ.DBUtility.DbHelperSQL.Query(strSql).Tables[0];
  105. //标题第一行
  106. strbld.Append("<tr>");
  107. strbld.Append("<td>处理部门</td>");
  108. strbld.Append("<td>处理人</td>");
  109. strbld.Append("<td>工单数</td>");
  110. strbld.Append("<td>可回访数</td>");
  111. strbld.Append("<td>已回访数</td>");
  112. strbld.Append("<td>回访比例</td>");
  113. strbld.Append("<td>评分</td>");
  114. strbld.Append("</tr>");
  115. if (dt != null && dt.Rows.Count > 0)
  116. {
  117. foreach (DataRow dr in dt.Rows)
  118. {
  119. strbld.Append("<tr height='20'>");
  120. strbld.Append("<td>" + bll_T_Sys_Department.GetDeptNameById(dr["LastDealDeptId"]) + "</td>");
  121. strbld.Append("<td>" + bll_T_Sys_UserAccount.GetUserNameByUserId(dr["LastDealUserId"]) + "&nbsp</td>");
  122. strbld.Append("<td>" + dr["ALLCount"] + "</td>");
  123. strbld.Append("<td>" + dr["KHFCount"] + "</td>");
  124. strbld.Append("<td>" + dr["YHFCount"] + "</td>");
  125. if (GetPercent(dr["YHFCount"], dr["ALLCount"]).ToString().Length > 5)
  126. {
  127. if (GetPercent(dr["YHFCount"], dr["ALLCount"]).ToString().Substring(1, 1) == ".")
  128. {
  129. strbld.Append("<td>" + GetPercent(dr["YHFCount"], dr["ALLCount"]).ToString().Substring(0, 4) + "%</td>");
  130. }
  131. else
  132. {
  133. strbld.Append("<td>" + GetPercent(dr["YHFCount"], dr["ALLCount"]).ToString().Substring(0, 5) + "%</td>");
  134. }
  135. }
  136. else
  137. {
  138. strbld.Append("<td>" + GetPercent(dr["YHFCount"], dr["ALLCount"]) + "</td>");
  139. }
  140. if (GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]).ToString().Length > 5)
  141. {
  142. if (GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]).ToString().Substring(1, 1) == ".")
  143. {
  144. strbld.Append("<td>" + GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]).ToString().Substring(0, 4) + "%</td>");
  145. }
  146. else
  147. {
  148. strbld.Append("<td>" + GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]).ToString().Substring(0, 5) + "%</td>");
  149. }
  150. }
  151. else
  152. {
  153. strbld.Append("<td>" + GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]) + "</td>");
  154. }
  155. strbld.Append("</tr>");
  156. }
  157. }
  158. }
  159. catch (Exception ex)
  160. {
  161. SysLog.WriteLog(ex);
  162. }
  163. strbld.Append("</table>");
  164. return strbld.ToString();
  165. }
  166. /// <summary>
  167. /// 获取百分比
  168. /// </summary>
  169. /// <param name="min"></param>
  170. /// <param name="max"></param>
  171. /// <returns></returns>
  172. public string GetPercent(object min, object max)
  173. {
  174. string percent = "0%";
  175. if (min != null && !string.IsNullOrEmpty(min.ToString()) && max != null && !string.IsNullOrEmpty(max.ToString()))
  176. {
  177. if (Convert.ToDouble(max) != 0)
  178. {
  179. percent = Convert.ToDouble(min) / Convert.ToDouble(max) * 100 + "%";
  180. }
  181. }
  182. return percent;
  183. }
  184. /// <summary>
  185. /// 获取平均值
  186. /// </summary>
  187. /// <param name="min"></param>
  188. /// <param name="max"></param>
  189. /// <returns></returns>
  190. public string GetAvg(object fcmy, object jbmy,object yb,object bmy,object yhf)
  191. {
  192. string avg ="0";
  193. int fcmyz =Convert.ToInt32(GetNameFromDictionary("HFJG", "1"));
  194. int myz = Convert.ToInt32(GetNameFromDictionary("HFJG", "2"));
  195. int ybz = Convert.ToInt32(GetNameFromDictionary("HFJG", "3"));
  196. int bmyz = Convert.ToInt32(GetNameFromDictionary("HFJG", "4"));
  197. int allmark = fcmyz * Convert.ToInt32(fcmy) + myz * Convert.ToInt32(jbmy) + ybz * Convert.ToInt32(yb) + bmyz * Convert.ToInt32(bmy);
  198. if (Convert.ToInt32(yhf) != 0)
  199. {
  200. avg = (Convert.ToDouble(allmark) / Convert.ToInt32(yhf)).ToString();
  201. }
  202. return avg;
  203. }
  204. /// <summary>
  205. /// 从数据字典读取值
  206. /// </summary>
  207. /// <param name="ddl"></param>
  208. /// <param name="p_Condition"></param>
  209. private string GetNameFromDictionary(string p_Flag, string p_Code)
  210. {
  211. string p_Describe = string.Empty;
  212. DataTable dt = bll_T_Sys_DictionaryValue.GetList("F_DictionaryFlag='" + p_Flag + "' and F_ValueCode='" + p_Code + "' order by F_Sort").Tables[0];
  213. if (dt != null && dt.Rows.Count > 0)
  214. {
  215. p_Describe = dt.Rows[0]["F_Describe"].ToString();
  216. }
  217. return p_Describe;
  218. }
  219. private string[] GetSearchItems(AjaxPro.JavaScriptArray searchItems)
  220. {
  221. string[] operations = new string[searchItems.Count];
  222. int i = 0;
  223. foreach (Object obj in searchItems)
  224. {
  225. operations[i] = obj.ToString();
  226. i++;
  227. }
  228. return operations;
  229. }
  230. }