using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.SessionState;
using System.Text;
using System.Data;

namespace HySoft.BaseCallCenter.Web.reportmanage.operationdata.controls
{
    /// <summary>
    /// OneUserAPI 的摘要说明
    /// </summary>
    public class OneUserAPI : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request.QueryString["action"];

            switch (action)
            {
                case "getlist":
                    context.Response.Write(GetDataListHtml(context));//读取数据
                    break;
            }
        }
        public string GetDataListHtml(HttpContext context)
        {
            StringBuilder htmlReport = new StringBuilder();//存储生成的HTML
            //拼接表头
            htmlReport.Append("<table cellspacing='0' cellpadding='0' border='1' width='100%'><tr height='35'>");
            htmlReport.Append("<td style='height: 18px; 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;'>部门名称</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>工程师姓名</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>事件总数</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>一般事件响应及时数</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>紧急事件响应及时数</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>事件响应及时率</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>一般事件解决及时数</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>紧急事件解决及时数</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>事件解决及时率</td>");

            //htmlReport.Append("<td style='height: 18px; 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;'>紧急事件响应及时率</td>");

            //htmlReport.Append("<td style='height: 18px; 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;'>紧急事件解决及时率</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>事件解决数</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>事件解决率</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>事件平均解决时间（小时）</td>");

            htmlReport.Append("<td style='height: 18px; 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;'>回访评分总和</td>");
            htmlReport.Append("<td style='height: 18px; 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;'>回访事件总数</td>");

            htmlReport.Append("<td style='height: 18px; 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;'>客户评分</td>");
            htmlReport.Append("</tr>");
            try
            {
                //前台传来的开始时间结束时间
                string txtStartTime = context.Request.QueryString["txtStartTime"];
                string txtEndTime = context.Request.QueryString["txtEndTime"];
                //拼接时间查询语句
                string sqltimeHistory = "";
                if (txtStartTime != null && txtStartTime.Trim() != "")
                {
                    sqltimeHistory += " and CONVERT(varchar , F_OPTDATE, 120)>=CONVERT(varchar , '" + txtStartTime.Trim() + " 00:00:01', 120) ";
                }
                if (txtEndTime != null && txtEndTime.Trim() != "")
                {
                    sqltimeHistory += " and CONVERT(varchar , F_OPTDATE, 120)<=CONVERT(varchar , '" + txtEndTime.Trim() + " 23:59:59', 120) ";
                }
                string sqltimeTask = "";
                if (txtStartTime != null && txtStartTime.Trim() != "")
                {
                    sqltimeTask += " and CONVERT(varchar , F_CREATEDATE, 120)>=CONVERT(varchar , '" + txtStartTime.Trim() + " 00:00:01', 120)  ";
                }
                if (txtEndTime != null && txtEndTime.Trim() != "")
                {
                    sqltimeTask += "  and CONVERT(varchar , F_CREATEDATE, 120)<=CONVERT(varchar , '" + txtEndTime.Trim() + " 23:59:59', 120) ";
                }

                //定义总结时候的一些变量
                double zong1 = 0;
                double zong2 = 0;
                double zong3 = 0;
                double zong4 = 0;
                double zong5 = 0;
                double zong6 = 0;
                double zong7 = 0;
                double zong8 = 0;
                double zongtime = 0;
                int zongtimecount = 0;
                double zongfen = 0;
                int zongfencount = 0;
                int count = 0;

                int gerenfenshu = 0;
                int gerencount = 0;
                //定义是否及时处理的时间变量

                #region 查询在字典那块设置的时间
                string ybgdJDcaoshi = "15552000";
                string ybgdCLcaoshi = "15552000";
                string jjgdJDcaoshi = "15552000";
                string jjgdCLcaoshi = "15552000";

                string sqlybgd = "SELECT * from T_Sys_DictionaryValue where F_DictionaryFlag='ybgd' order by F_Sort ";
                DataTable dtybgd = DBUtility.DbHelperSQL.Query(sqlybgd).Tables[0];
                if (dtybgd.Rows.Count > 1)
                {
                    ybgdJDcaoshi = (Convert.ToInt32(dtybgd.Rows[0]["F_Name"]) * 3600).ToString();
                    ybgdCLcaoshi = (Convert.ToInt32(dtybgd.Rows[1]["F_Name"]) * 3600).ToString();
                }
                string sqljjgd = "SELECT * from T_Sys_DictionaryValue where F_DictionaryFlag='jjgd' order by F_Sort ";
                DataTable dtjjgd = DBUtility.DbHelperSQL.Query(sqljjgd).Tables[0];
                if (dtjjgd.Rows.Count > 1)
                {
                    jjgdJDcaoshi = (Convert.ToInt32(dtybgd.Rows[0]["F_Name"]) * 3600).ToString();
                    jjgdCLcaoshi = (Convert.ToInt32(dtybgd.Rows[1]["F_Name"]) * 3600).ToString();
                }
                #endregion

                #region 查询在告警超时那块设置的时间
                //string JDcaoshi = "15552000";
                //string CLcaoshi = "15552000";
                //string sqlCLcaoshi = "select * from T_Wo_StateAlarmDate where F_WorkOrderTypeId=16 and F_WorkOrderStateId=7";
                //DataTable dtCLcaoshi = DBUtility.DbHelperSQL.Query(sqlCLcaoshi).Tables[0];
                //if (dtCLcaoshi.Rows.Count > 0)
                //{
                //    if (Convert.ToInt32(dtCLcaoshi.Rows[0]["F_Ccount"]) > 0)
                //    {
                //        if (Convert.ToInt32(dtCLcaoshi.Rows[0]["F_Cunit"]) == 1)
                //        {
                //            CLcaoshi = (Convert.ToInt32(dtCLcaoshi.Rows[0]["F_Ccount"]) * 3600).ToString();
                //        }
                //        else if (Convert.ToInt32(dtCLcaoshi.Rows[0]["F_Cunit"]) == 2)
                //        {
                //            CLcaoshi = (Convert.ToInt32(dtCLcaoshi.Rows[0]["F_Ccount"]) * 3600 * 24).ToString();
                //        }
                //        else
                //        {
                //            CLcaoshi = (Convert.ToInt32(dtCLcaoshi.Rows[0]["F_Ccount"]) * 60).ToString();
                //        }
                //    }
                //}
                //string sqlcaoshi = "select * from T_Wo_StateAlarmDate where F_WorkOrderTypeId=16 and F_WorkOrderStateId=6";
                //DataTable dtJDcaoshi = DBUtility.DbHelperSQL.Query(sqlcaoshi).Tables[0];
                //if (dtJDcaoshi.Rows.Count > 0)
                //{
                //    if (Convert.ToInt32(dtJDcaoshi.Rows[0]["F_Ccount"]) > 0)
                //    {
                //        if (Convert.ToInt32(dtJDcaoshi.Rows[0]["F_Cunit"]) == 1)
                //        {
                //            JDcaoshi = (Convert.ToInt32(dtJDcaoshi.Rows[0]["F_Ccount"]) * 3600).ToString();
                //        }
                //        else if (Convert.ToInt32(dtJDcaoshi.Rows[0]["F_Cunit"]) == 2)
                //        {
                //            JDcaoshi = (Convert.ToInt32(dtJDcaoshi.Rows[0]["F_Ccount"]) * 3600 * 24).ToString();
                //        }
                //        else
                //        {
                //            JDcaoshi = (Convert.ToInt32(dtJDcaoshi.Rows[0]["F_Ccount"]) * 60).ToString();
                //        }
                //    }
                //}
                #endregion

                //查询出来所有部门，按照工单量的多少排序
                DataTable dtDept = new DataTable();
                string sqlDept = "SELECT  distinct(F_DeptId),(select COUNT(*) from T_Wo_WorkOrderTask where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and F_WORKORDERSTATEID=6 and F_OWNERID in(SELECT  F_UserId from T_Sys_UserAccount where F_DeptId=t.F_DeptId and F_RoleId=30)" + sqltimeTask + ") as counts,(SELECT F_DeptName  from T_Sys_Department where F_DeptId=t.F_DeptId) as deptname from T_Sys_UserAccount t where F_RoleId=30 order by counts desc  ";
                dtDept = DBUtility.DbHelperSQL.Query(sqlDept).Tables[0];
                for (int j = 0; j < dtDept.Rows.Count; j++)
                {
                    //工单量是0的跳出
                    if (dtDept.Rows[j]["counts"] == null || dtDept.Rows[j]["counts"].ToString() == "" || dtDept.Rows[j]["counts"].ToString() == "0")
                    {
                        continue;
                    }

                    DataTable dt = new DataTable();
                    //查询出来部门下的所有人员，按照工单量多少排序
                    string sql = "select t.* from (SELECT  *,(select COUNT(*) from T_Wo_WorkOrderTask where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=6 and F_OWNERID=T_Sys_UserAccount.F_UserId " + sqltimeTask + ") as counts from T_Sys_UserAccount where F_RoleId=30  and F_DeptId=" + dtDept.Rows[j]["F_DeptId"].ToString() + " ) t where t.counts>0 order by counts desc ";
                    dt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
                    int s = dt.Rows.Count + 1;
                    htmlReport.AppendFormat("<td rowspan='" + s + "' align='center' style='width:120px; 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: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", dtDept.Rows[j]["deptname"].ToString());
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //查出来该人员的总工单量，接收的工单量，处理的工单量，已处理完成的工单量
                        //sql = " select (select COUNT(*) from T_Wo_WorkOrderTask where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=6 and F_OWNERID=" + dt.Rows[i]["F_UserId"].ToString() + "" + sqltimeTask + ") as counts,";
                        //sql += "(select count(*) from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=6 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + " and F_ELAPSEDTIME<" + JDcaoshi + "" + sqltimeHistory + ") as ybgdjiedan,";
                        //sql += "(select count(*) from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=7 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + " and F_ELAPSEDTIME<" + CLcaoshi + "" + sqltimeHistory + ") as ybgdchuli,";
                        //sql += "(select count(*) from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=7 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + " and F_ELAPSEDTIME is not null" + sqltimeHistory + ") as jiejue ";
                        sql = " select (select COUNT(*) from T_Wo_WorkOrderTask where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=6 and F_OWNERID=" + dt.Rows[i]["F_UserId"].ToString() + "" + sqltimeTask + ") as counts,";
                        sql += "(select count(*) from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 and F_REPAIRLEVEL is null or F_REPAIRLEVEL!=396 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=6 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + " and F_ELAPSEDTIME<" + ybgdJDcaoshi + "" + sqltimeHistory + ") as ybgdjiedan,";
                        sql += "(select count(*) from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 and F_REPAIRLEVEL is null or F_REPAIRLEVEL!=396 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=7 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + " and F_ELAPSEDTIME<" + ybgdCLcaoshi + "" + sqltimeHistory + ") as ybgdchuli,";
                        sql += "(select count(*) from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 and F_REPAIRLEVEL=396 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=6 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + " and F_ELAPSEDTIME<" + jjgdJDcaoshi + "" + sqltimeHistory + ") as jjgdjiedan,";
                        sql += "(select count(*) from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 and F_REPAIRLEVEL=396 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=7 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + " and F_ELAPSEDTIME<" + jjgdCLcaoshi + "" + sqltimeHistory + ") as jjgdchuli,";
                        sql += "(select count(*) from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=7 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + " and F_ELAPSEDTIME is not null" + sqltimeHistory + ") as jiejue ";
                        DataTable dt1 = new DataTable();
                        dt1 = DBUtility.DbHelperSQL.Query(sql).Tables[0];

                        if (dt1.Rows[0]["counts"] == null || dt1.Rows[0]["counts"].ToString() == "" || dt1.Rows[0]["counts"].ToString() == "0")
                        {
                            continue;
                        }
                        count = count + 1;

                        //工单的处理时间，是接收时间加上处理的时间
                        sql = @"select sum(F_ELAPSEDTIME) as sum1,(select sum(F_ELAPSEDTIME) from T_Wo_WorkOrderHistory where F_WORKORDERSTATEID=6 and F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=7 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + ")" + sqltimeHistory + ") as sum2 from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=7 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + "" + sqltimeHistory + "";
                        DataTable dt2 = DBUtility.DbHelperSQL.Query(sql).Tables[0];
                        string time = "0";
                        if (dt2.Rows[0]["sum1"].ToString() == "" && dt2.Rows[0]["sum2"].ToString() != "")
                        {
                            time = (Convert.ToDouble(dt2.Rows[0]["sum2"]) / Convert.ToDouble(dt1.Rows[0]["counts"]) / 3600).ToString("f2");
                            zongtime += Convert.ToDouble(dt2.Rows[0]["sum2"]);
                            zongtimecount += Convert.ToInt32(dt1.Rows[0]["counts"]);
                        }
                        else if (dt2.Rows[0]["sum1"].ToString() != "" && dt2.Rows[0]["sum2"].ToString() == "")
                        {
                            time = (Convert.ToDouble(dt2.Rows[0]["sum1"]) / Convert.ToDouble(dt1.Rows[0]["counts"]) / 3600).ToString("f2");
                            zongtime += Convert.ToDouble(dt2.Rows[0]["sum1"]);
                            zongtimecount += Convert.ToInt32(dt1.Rows[0]["counts"]);
                        }
                        else if (dt2.Rows[0]["sum1"].ToString() != "" && dt2.Rows[0]["sum2"].ToString() != "")
                        {
                            time = ((Convert.ToDouble(dt2.Rows[0]["sum1"]) + Convert.ToDouble(dt2.Rows[0]["sum2"])) / Convert.ToDouble(dt1.Rows[0]["counts"]) / 3600).ToString("f2");
                            zongtime += Convert.ToDouble(dt2.Rows[0]["sum1"]) + Convert.ToDouble(dt2.Rows[0]["sum2"]);
                            zongtimecount += Convert.ToInt32(dt1.Rows[0]["counts"]);
                        }
                        //查出来客户评分
                        sql = "select count(*) as counts from T_Wo_WorkOrderHistoryInfo where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=7 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + ") and  F_CUSTOMERSCORE is not null and F_CUSTOMERSCORE!=''" + sqltimeHistory + "";
                        DataTable dt3 = DBUtility.DbHelperSQL.Query(sql).Tables[0];
                        sql = "select SUM(convert(int,F_CUSTOMERSCORE)) as sums  from T_Wo_WorkOrderHistoryInfo where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderHistory where F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderBase where 1=1 " + sqltimeTask + " ) and  F_WORKORDERSTATEID=7 and F_OPTUSERID=" + dt.Rows[i]["F_UserId"].ToString() + ") and  F_CUSTOMERSCORE is not null and F_CUSTOMERSCORE!=''" + sqltimeHistory + "";
                        DataTable dt4 = DBUtility.DbHelperSQL.Query(sql).Tables[0];
                        string fenshu = "0";
                        if (dt4.Rows[0]["sums"].ToString() != "")
                        {
                            fenshu = (Convert.ToInt32(dt4.Rows[0]["sums"]) / Convert.ToInt32(dt3.Rows[0]["counts"])).ToString();
                            zongfen += Convert.ToDouble(dt4.Rows[0]["sums"]);
                            zongfencount += Convert.ToInt32(dt3.Rows[0]["counts"]);

                            gerenfenshu = Convert.ToInt32(dt4.Rows[0]["sums"]);
                            gerencount = Convert.ToInt32(dt3.Rows[0]["counts"]);
                        }
                        else
                        {
                            gerenfenshu = 0;
                            gerencount = 0;
                        }
                        //拼接表数据
                        htmlReport.AppendFormat("<tr><td  align='center'style='border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", dt.Rows[i]["F_UserName"].ToString());
                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", dt1.Rows[0]["counts"].ToString());
                        zong1 += Convert.ToInt32(dt1.Rows[0]["counts"]);
                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", dt1.Rows[0]["ybgdjiedan"].ToString());
                        zong2 += Convert.ToInt32(dt1.Rows[0]["ybgdjiedan"]);
                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", dt1.Rows[0]["jjgdjiedan"].ToString());
                        zong7 += Convert.ToInt32(dt1.Rows[0]["jjgdjiedan"]);
                        if (dt1.Rows[0]["ybgdjiedan"] == null || dt1.Rows[0]["jjgdjiedan"] == null|| dt1.Rows[0]["counts"] == null || dt1.Rows[0]["counts"].ToString() == "0")
                        {
                            htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>0.00%</td>");
                        }
                        else
                        {
                            htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", ((Convert.ToDouble(dt1.Rows[0]["ybgdjiedan"])+Convert.ToDouble(dt1.Rows[0]["jjgdjiedan"])) / Convert.ToDouble(dt1.Rows[0]["counts"]) * 100).ToString("f2") + "%");
                        }
                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", dt1.Rows[0]["ybgdchuli"].ToString() + "&nbsp");
                        zong3 += Convert.ToInt32(dt1.Rows[0]["ybgdchuli"]);
                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", dt1.Rows[0]["jjgdchuli"].ToString() + "&nbsp");
                        zong8 += Convert.ToInt32(dt1.Rows[0]["jjgdchuli"]);
                        if (dt1.Rows[0]["ybgdchuli"] == null || dt1.Rows[0]["jjgdchuli"] == null || dt1.Rows[0]["counts"] == null || dt1.Rows[0]["counts"].ToString() == "0")
                        {
                            htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>0.00%</td>");
                        }
                        else
                        {
                            htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", ((Convert.ToDouble(dt1.Rows[0]["ybgdchuli"])+Convert.ToDouble(dt1.Rows[0]["jjgdchuli"])) / Convert.ToDouble(dt1.Rows[0]["counts"]) * 100).ToString("f2") + "%");
                        }
                        //紧急请求开始

                        //if (dt1.Rows[0]["jjgdjiedan"] == null || dt1.Rows[0]["jjgdjiedan"].ToString() == "0" || dt1.Rows[0]["counts"] == null || dt1.Rows[0]["counts"].ToString() == "0")
                        //{
                        //    htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>0.00%</td>");
                        //}
                        //else
                        //{
                        //    htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", (Convert.ToDouble(dt1.Rows[0]["jjgdjiedan"]) / Convert.ToDouble(dt1.Rows[0]["counts"]) * 100).ToString("f2") + "%");
                        //}

                        //if (dt1.Rows[0]["jjgdchuli"] == null || dt1.Rows[0]["jjgdchuli"].ToString() == "0" || dt1.Rows[0]["counts"] == null || dt1.Rows[0]["counts"].ToString() == "0")
                        //{
                        //    htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>0.00%</td>");
                        //}
                        //else
                        //{
                        //    htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", (Convert.ToDouble(dt1.Rows[0]["jjgdchuli"]) / Convert.ToDouble(dt1.Rows[0]["counts"]) * 100).ToString("f2") + "%");
                        //}
                        //紧急请求结束
                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", dt1.Rows[0]["jiejue"].ToString());
                        zong4 += Convert.ToInt32(dt1.Rows[0]["jiejue"]);
                        if (dt1.Rows[0]["jiejue"] == null || dt1.Rows[0]["jiejue"].ToString() == "0" || dt1.Rows[0]["counts"] == null || dt1.Rows[0]["counts"].ToString() == "0")
                        {
                            htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>0.00%</td>");
                        }
                        else
                        {
                            htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", (Convert.ToDouble(dt1.Rows[0]["jiejue"]) / Convert.ToDouble(dt1.Rows[0]["counts"]) * 100).ToString("f2") + "%");
                        }
                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", time);
                        zong5 += Convert.ToDouble(time);

                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", gerenfenshu);
                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", gerencount);

                        htmlReport.AppendFormat("<td align='center' style=' border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px; height: 18px; padding-top: 3px; padding-bottom: 3px;'>{0}</td>", fenshu);
                        zong6 += Convert.ToInt32(fenshu);
                        htmlReport.Append("</tr>");
                    }
                }

                //拼接表下部的总计
                htmlReport.Append("<tr height='35'>");
                htmlReport.AppendFormat("<td colspan='2'  style='height: 18px; 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;'>{0}</td>", "总计");
                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", zong1);
                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", zong2);
                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", zong7);
                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", (Convert.ToDouble((zong2+zong7) / zong1) * 100).ToString("f2") + "%");
                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", zong3);
                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", zong8);
                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", (Convert.ToDouble((zong3+zong8) / zong1) * 100).ToString("f2") + "%");


                //htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", (Convert.ToDouble(zong7 / zong1) * 100).ToString("f2") + "%");

                //htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", (Convert.ToDouble(zong8 / zong1) * 100).ToString("f2") + "%");

                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", zong4);
                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", (Convert.ToDouble(zong4 / zong1) * 100).ToString("f2") + "%");
                if (zongtimecount == 0)
                {
                    htmlReport.AppendFormat("<td style='height: 18px; 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;'>0.00%</td>");
                }
                else
                {
                    htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", Convert.ToDouble(zongtime / zongtimecount / 3600).ToString("f2"));
                }

                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", zongfen);
                htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", zongfencount);

                if (zongfencount == 0)
                {
                    htmlReport.AppendFormat("<td style='height: 18px; 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;'>0.00</td>");
                }
                else
                {
                    htmlReport.AppendFormat("<td style='height: 18px; 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;'>{0}</td>", (zongfen / zongfencount).ToString("f2"));
                }
                htmlReport.Append("</tr>");
                htmlReport.Append("</table>");
            }
            catch { }

            return htmlReport.ToString();
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}