| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Text;
- using XYFDRQ.DBUtility;
- using XYFDRQ.Common;
- public partial class HF_Report : BasePage
- {
-
- XYFDRQ.BLL.T_Sys_DictionaryValue bll_T_Sys_DictionaryValue = new XYFDRQ.BLL.T_Sys_DictionaryValue();
- XYFDRQ.BLL.T_Sys_Department bll_T_Sys_Department = new XYFDRQ.BLL.T_Sys_Department();
- XYFDRQ.BLL.T_Sys_UserAccount bll_T_Sys_UserAccount = new XYFDRQ.BLL.T_Sys_UserAccount();
- protected void Page_Load(object sender, EventArgs e)
- {
- AjaxPro.Utility.RegisterTypeForAjax(typeof(HF_Report));
- if (!this.IsPostBack)
- {
- BtnisEnable();
- InitData();
- }
-
- }
- public void InitData()
- {
- //绑定坐席
- this.ddlAccount.DataSource = bll_T_Sys_UserAccount.GetList("F_StateFlag=1 and F_IsSystemUser=1");
- this.ddlAccount.DataTextField = "F_UserName";
- this.ddlAccount.DataValueField = "F_UserId";
- this.ddlAccount.DataBind();
- this.ddlAccount.Items.Insert(0, new ListItem("--请选择--", ""));
- txtBeginDate.Value = DateTime.Now.ToString("yyyy-MM-01");//赋初值
- txtEndDate.Value = DateTime.Now.ToString("yyyy-MM-dd");//赋初值
- LoginUser p_LoginUser = new LoginUser(this.Context);
- this.hfDeptId.Value = p_LoginUser.DeptId.ToString();
- }
- private void BtnisEnable()
- {
- if (base.BtnIsEnable("ReportManage_bbtj_HF_Report_all"))
- {
- this.hfQX.Value = "全部";
- }
- }
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void btnExtWord_Click(object sender, EventArgs e)
- {
- string fileName = HttpUtility.UrlEncode("回访统计_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls", Encoding.UTF8).ToString();
- Response.Clear();
- Response.Charset = "UTF-8";
- Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
- Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
- Response.ContentType = "application/ms-excel";
- Response.Write(this.hfInfo.Value);
- Response.End();
-
-
- }
- /// <summary>
- /// 导出的Excel表
- /// </summary>
- /// <param name="searchItems"></param>
- /// <returns></returns>
- [AjaxPro.AjaxMethod()]
- public string GetReportTable(AjaxPro.JavaScriptArray searchItems)
- {
-
- StringBuilder strbld = new StringBuilder();
- string[] _operations = GetSearchItems(searchItems);
- strbld.Append("<h1 style='font-size: 18px;font-weight: bold;color: #333333;text-align:center;width:100%;'><b>回访统计表</b></h1>");
- strbld.Append("<div style='width:100%; text-align:right;height:25px;'>统计截止日期: " + _operations[0] + "—" + _operations[1] + " </div>");
- strbld.Append("<table cellspacing='0' cellpadding='0' border='1' width='100%'>");
- try
- {
- string strSql = @"select a.LastDealDeptId,a.LastDealUserId,
- (select COUNT(1) from T_Bus_WorkOrder as b where b.LastDealUserId=a.LastDealUserId and b.ReturnVisitState in(0,1)) as KHFCount,
- (select COUNT(1) from T_Bus_WorkOrder as c where c.LastDealUserId=a.LastDealUserId and c.ReturnVisitState=2) as YHFCount,
- (select COUNT(1) from T_Bus_WorkOrder as d where d.LastDealUserId=a.LastDealUserId ) as ALLCount,
- (select COUNT(1) from T_Bus_WorkOrder as e where e.LastDealUserId=a.LastDealUserId and e.ReturnVisitState=2 and e.ReturnVisitResult=1) as FCMYCount,
- (select COUNT(1) from T_Bus_WorkOrder as f where f.LastDealUserId=a.LastDealUserId and f.ReturnVisitState=2 and f.ReturnVisitResult=2) as MYCount,
- (select COUNT(1) from T_Bus_WorkOrder as g where g.LastDealUserId=a.LastDealUserId and g.ReturnVisitState=2 and g.ReturnVisitResult=3) as YBCount,
- (select COUNT(1) from T_Bus_WorkOrder as h where h.LastDealUserId=a.LastDealUserId and h.ReturnVisitState=2 and h.ReturnVisitResult=4) as BMYCount
- from T_Bus_WorkOrder as a
- where 1=1 ";
- if (!string.IsNullOrEmpty(_operations[0]))
- {
- strSql += " and DATEDIFF(d,a.LastDealTime,'" + _operations[0] + "')<=0";
- }
- if (!string.IsNullOrEmpty(_operations[1]))
- {
- strSql += " and DATEDIFF(d,a.LastDealTime,'" + _operations[1] + "')>=0";
- }
- if (!string.IsNullOrEmpty(_operations[4]))
- {
- //string ss = _operations[4].ToString();
- strSql += " and LastDealUserId=" + _operations[4] + "";
- }
- if (_operations[2] != "全部")
- {
- strSql += " and a.LastDealDeptId=" + _operations[3];
- }
- strSql += " group by a.LastDealDeptId,a.LastDealUserId";
- DataTable dt = XYFDRQ.DBUtility.DbHelperSQL.Query(strSql).Tables[0];
- //标题第一行
- strbld.Append("<tr>");
- strbld.Append("<td>处理部门</td>");
- strbld.Append("<td>处理人</td>");
- strbld.Append("<td>工单数</td>");
- strbld.Append("<td>可回访数</td>");
- strbld.Append("<td>已回访数</td>");
- strbld.Append("<td>回访比例</td>");
- strbld.Append("<td>评分</td>");
- strbld.Append("</tr>");
- if (dt != null && dt.Rows.Count > 0)
- {
- foreach (DataRow dr in dt.Rows)
- {
- strbld.Append("<tr height='20'>");
- strbld.Append("<td>" + bll_T_Sys_Department.GetDeptNameById(dr["LastDealDeptId"]) + "</td>");
- strbld.Append("<td>" + bll_T_Sys_UserAccount.GetUserNameByUserId(dr["LastDealUserId"]) + " </td>");
- strbld.Append("<td>" + dr["ALLCount"] + "</td>");
- strbld.Append("<td>" + dr["KHFCount"] + "</td>");
- strbld.Append("<td>" + dr["YHFCount"] + "</td>");
- if (GetPercent(dr["YHFCount"], dr["ALLCount"]).ToString().Length > 5)
- {
- if (GetPercent(dr["YHFCount"], dr["ALLCount"]).ToString().Substring(1, 1) == ".")
- {
- strbld.Append("<td>" + GetPercent(dr["YHFCount"], dr["ALLCount"]).ToString().Substring(0, 4) + "%</td>");
- }
- else
- {
- strbld.Append("<td>" + GetPercent(dr["YHFCount"], dr["ALLCount"]).ToString().Substring(0, 5) + "%</td>");
- }
- }
- else
- {
- strbld.Append("<td>" + GetPercent(dr["YHFCount"], dr["ALLCount"]) + "</td>");
- }
- if (GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]).ToString().Length > 5)
- {
- if (GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]).ToString().Substring(1, 1) == ".")
- {
- strbld.Append("<td>" + GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]).ToString().Substring(0, 4) + "%</td>");
- }
- else
- {
- strbld.Append("<td>" + GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]).ToString().Substring(0, 5) + "%</td>");
- }
- }
- else
- {
- strbld.Append("<td>" + GetAvg(dr["FCMYCount"], dr["MYCount"], dr["YBCount"], dr["BMYCount"], dr["YHFCount"]) + "</td>");
- }
- strbld.Append("</tr>");
- }
- }
- }
- catch (Exception ex)
- {
- SysLog.WriteLog(ex);
- }
- strbld.Append("</table>");
- return strbld.ToString();
- }
- /// <summary>
- /// 获取百分比
- /// </summary>
- /// <param name="min"></param>
- /// <param name="max"></param>
- /// <returns></returns>
- public string GetPercent(object min, object max)
- {
- string percent = "0%";
- if (min != null && !string.IsNullOrEmpty(min.ToString()) && max != null && !string.IsNullOrEmpty(max.ToString()))
- {
- if (Convert.ToDouble(max) != 0)
- {
- percent = Convert.ToDouble(min) / Convert.ToDouble(max) * 100 + "%";
- }
- }
- return percent;
- }
- /// <summary>
- /// 获取平均值
- /// </summary>
- /// <param name="min"></param>
- /// <param name="max"></param>
- /// <returns></returns>
- public string GetAvg(object fcmy, object jbmy,object yb,object bmy,object yhf)
- {
- string avg ="0";
- int fcmyz =Convert.ToInt32(GetNameFromDictionary("HFJG", "1"));
- int myz = Convert.ToInt32(GetNameFromDictionary("HFJG", "2"));
- int ybz = Convert.ToInt32(GetNameFromDictionary("HFJG", "3"));
- int bmyz = Convert.ToInt32(GetNameFromDictionary("HFJG", "4"));
- int allmark = fcmyz * Convert.ToInt32(fcmy) + myz * Convert.ToInt32(jbmy) + ybz * Convert.ToInt32(yb) + bmyz * Convert.ToInt32(bmy);
- if (Convert.ToInt32(yhf) != 0)
- {
- avg = (Convert.ToDouble(allmark) / Convert.ToInt32(yhf)).ToString();
- }
- return avg;
- }
- /// <summary>
- /// 从数据字典读取值
- /// </summary>
- /// <param name="ddl"></param>
- /// <param name="p_Condition"></param>
- private string GetNameFromDictionary(string p_Flag, string p_Code)
- {
- string p_Describe = string.Empty;
- DataTable dt = bll_T_Sys_DictionaryValue.GetList("F_DictionaryFlag='" + p_Flag + "' and F_ValueCode='" + p_Code + "' order by F_Sort").Tables[0];
- if (dt != null && dt.Rows.Count > 0)
- {
- p_Describe = dt.Rows[0]["F_Describe"].ToString();
- }
- return p_Describe;
- }
- private string[] GetSearchItems(AjaxPro.JavaScriptArray searchItems)
- {
- string[] operations = new string[searchItems.Count];
- int i = 0;
- foreach (Object obj in searchItems)
- {
- operations[i] = obj.ToString();
- i++;
- }
- return operations;
- }
- }
|