using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

namespace HySoft.BaseCallCenter.Web.reportmanage
{
    public partial class acceptancereport : System.Web.UI.Page
    {
        BLL.T_Report bll_T_Report = new BLL.T_Report();
        BLL.T_Sys_DictionaryValue bll_T_Sys_DictionaryValue = new BLL.T_Sys_DictionaryValue();
        BLL.T_Sys_UserAccount bll_T_Sys_UserAccount = new BLL.T_Sys_UserAccount();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
        }
    }
       


     public StringBuilder GetReportTable(string TableTitle,string userCode, string BeginTime, string EndTime, params object[] TableHead)
      {
        StringBuilder html = new StringBuilder();
        string reportsql = "";
        DataTable dt = new DataTable();
        DataTable dtdgd = new DataTable();
        DataTable dtyhf = new DataTable();
     
        html.Append("<h1 style='font-size: 18px;font-weight: bold;color: #333333;text-align:center;width:100%;'><b>" + TableTitle + "</b></h1>");
        //html.Append("<div style='width:100%; text-align:right; height:25px;'>统计截止日期： " + _operations[0] + "—" + _operations[1] + " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>");
        html.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" >");
        try
        {
            //开始时间
            if (!string.IsNullOrEmpty(BeginTime))
            {
                reportsql += " and DATEDIFF(d,AddTime,'" + BeginTime + "')<=0";
            }
            //结束时间
            if (!string.IsNullOrEmpty(EndTime))
            {
                reportsql += " and DATEDIFF(d,AddTime,'" + EndTime + "')>=0";
            }
            if (!string.IsNullOrEmpty(userCode))
            {
                reportsql += " and UserCode=" + userCode;
            }
            dt = bll_T_Report.GetAgentBusinessReport(reportsql);

            //标题第一行

            html.Append("<tr style=\"text-align: center;\">");
            for (int i = 0; i < TableHead.Length; i++)
            {
                //标题第一行
                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>");
            }
            html.Append("</tr>");
            int allCount = 0;
            int dgdCount = 0;
            int yhfCount = 0;
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    html.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
                    //坐席员名称
                    html.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;\">" + dt.Rows[i]["UserName"].ToString() + "&nbsp;</td>");
                    //数量
                    html.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;\">" + dt.Rows[i]["TotalCount"].ToString() + "&nbsp;</td>");
                    //待归档数量
                    string dgdsql = reportsql + " and State=2 and UserName='" + dt.Rows[i]["UserName"].ToString() + "'";
                    dtdgd = bll_T_Report.GetAgentBusinessReport(dgdsql);
                    if (dtdgd == null || dtdgd.Rows.Count == 0)
                    {
                        html.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;\">0</td>");
                    }
                    else
                    {
                        html.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;\">" + dtdgd.Rows[0]["TotalCount"].ToString() + "&nbsp;</td>");
                        //待归档总数
                        dgdCount += Convert.ToInt32(dtdgd.Rows[0]["TotalCount"].ToString());
                    }
                    //已回访数量
                    string yhfsql = reportsql + " and ReturnVisitState=2 and UserName='" + dt.Rows[i]["UserName"].ToString() + "'";
                    dtyhf = bll_T_Report.GetAgentBusinessReport(yhfsql);
                    if (dtyhf == null || dtyhf.Rows.Count == 0)
                    {
                        html.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;\">0</td>");
                    }
                    else
                    {
                        html.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;\">" + dtyhf.Rows[0]["TotalCount"].ToString() + "&nbsp;</td>");
                        //待归档总数
                        yhfCount += Convert.ToInt32(dtyhf.Rows[0]["TotalCount"].ToString());
                    }
                    //html.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;\">" + dtyhf.Rows[i]["TotalCount"].ToString() + "&nbsp;+" + i + "@@@@</td>");
                    //总数
                    allCount += Convert.ToInt32(dt.Rows[i]["TotalCount"].ToString());

                    //yhfCount += Convert.ToInt32(dtyhf.Rows[i]["TotalCount"].ToString());
                    html.Append("</tr>");
                }
            }
            //合计
            html.Append("<tr style=\"text-align: center;\"><td class=\"formtabletitle3\" style=\"height: 35px;background-color: #D5EDFE;border-left: 1px solid #CCCCCC;border-right: 1px solid #CCCCCC;border-top: 0px solid #CCCCCC;border-bottom: 1px solid #CCCCCC;padding: 3px 10px 3px 2px;text-align:center;\">总计:</td>");
            html.Append("<td class=\"formtabletitle2\" style=\"height: 25px;background-color: #D5EDFE;border-left: 0px solid #FFFFFF;border-right: 1px solid #CCCCCC;border-top: 0px solid #FFFFFF;border-bottom: 1px solid #CCCCCC;padding: 3px 3px 3px 3px;text-align:center;\">" + allCount + "&nbsp;</td>");
            html.Append("<td class=\"formtabletitle2\" style=\"height: 25px;background-color: #D5EDFE;border-left: 0px solid #FFFFFF;border-right: 1px solid #CCCCCC;border-top: 0px solid #FFFFFF;border-bottom: 1px solid #CCCCCC;padding: 3px 3px 3px 3px;text-align:center;\">" + dgdCount + "&nbsp;</td>");
            html.Append("<td class=\"formtabletitle2\" style=\"height: 25px;background-color: #D5EDFE;border-left: 0px solid #FFFFFF;border-right: 1px solid #CCCCCC;border-top: 0px solid #FFFFFF;border-bottom: 1px solid #CCCCCC;padding: 3px 3px 3px 3px;text-align:center;\">" + yhfCount + "&nbsp;</td>");
            html.Append("</tr>");
        }
        catch
        { }
        finally
        {
            dt.Clear();
            dt.Dispose();

        }
        html.Append("</table>");
        return html;
       
    }


    }
}