using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HySoft.Common;
using System.Data;
using System.Text;

namespace HySoft.BaseCallCenter.Web.qualitymanage.ajax
{
    /// <summary>
    /// qcedit 的摘要说明
    /// </summary>
    public class qcedit : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //取得处事类型
            string action = CommonRequest.GetQueryString("action");
            switch (action)
            {
                case "indexlist":
                    context.Response.Write(LoadIndexList(context));
                    break;
                case "indexlistshow":
                    context.Response.Write(LoadIndexListShow(context));
                    break;
                case "savedata":
                    context.Response.Write(savedata(context));
                    break;
            }
        }

        #region 获取数据
        private string LoadIndexList(HttpContext context)
        {
            StringBuilder res = new StringBuilder();
            #region 标题
            res.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" align='center'>");
            res.Append("<tr style=\"text-align: center;\"><td style=\"height: 22px; background-color: #D5EDFE; border-left: 1px solid #CCCCCC;");
            res.Append("border-right: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
            res.Append("padding: 3px 3px 3px 3px; text-align: center;\" colspan=\"2\">分类</td>");
            res.Append("<td style=\"height: 22px; background-color: #D5EDFE; border-left: 1px solid #CCCCCC;");
            res.Append("border-right: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
            res.Append("padding: 3px 3px 3px 3px; text-align: center;\">指标</td>");
            res.Append("<td style=\"height: 22px; width:60px; background-color: #D5EDFE; border-left: 1px solid #CCCCCC;");
            res.Append("border-right: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
            res.Append("padding: 3px 3px 3px 3px; text-align: center;\">分值</td>");
            res.Append("<td style=\"height: 22px; width:80px; background-color: #D5EDFE; border-left: 1px solid #CCCCCC;");
            res.Append("border-right: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
            res.Append("padding: 3px 3px 3px 3px; text-align: center;\">评分</td></tr>");
            #endregion
            DataTable dt = new DataTable();
            DataTable dtindex = new DataTable();
            DataTable dtres = new DataTable();
            try
            {
                dt = new BLL.T_QC_IndexCategory().GetList(" F_DeleteFlag=0 order by F_Sort ,F_CategoryId").Tables[0];
                dtindex = new BLL.T_QC_IndexBase().GetList(" F_DeleteFlag=0 order by F_Sort ,F_CategoryId").Tables[0];
                dtres = new BLL.T_QC_IndexRes().GetList(" CallRecordsId=" + CommonRequest.GetQueryString("id") + " ").Tables[0];
                int i = 0;
                int m = 0;
                int indexcount = 0;
                int allscore = 0;
                int childscore = 0;
                int childpf = 0;
                int allpf = 0;
                foreach (DataRow dr in dt.Select("F_ParentId=0"))
                {
                    i = 0;
                    indexcount = 0;
                    childscore = 0;
                    childpf = 0;
                    string categoryid = dr["F_CategoryId"].ToString().Trim();
                    res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" ");
                    res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
                    res.Append("<td rowspan=\"#indexcount#\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                    res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                    res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                    res.Append("" + dr["F_CategoryName"].ToString().Trim() + "&nbsp;</td>");
                    foreach (DataRow childdr in dt.Select("F_ParentId=" + categoryid + ""))
                    {
                        m = 0;
                        #region 子分类
                        string childcategoryid = childdr["F_CategoryId"].ToString().Trim();
                        DataRow[] arrchild=dtindex.Select("F_CategoryId=" + childcategoryid + "");
                        indexcount += arrchild.Length;
                        if (i == 0)
                        {
                            res.Append("<td rowspan=\""+arrchild.Length.ToString()+"\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                            res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                            res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                            res.Append("" + childdr["F_CategoryName"].ToString().Trim() + "&nbsp;</td>");
                        }
                        else
                        {
                            res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" ");
                            res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");

                            res.Append("<td rowspan=\""+arrchild.Length.ToString()+"\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                            res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                            res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                            res.Append("" + childdr["F_CategoryName"].ToString().Trim() + "&nbsp;</td>");
                        }
                        #endregion

                        foreach (DataRow indexdr in arrchild)
                        {
                            string indexid = indexdr["F_IndexId"].ToString().Trim();
                            string pf = "0";
                            try
                            {
                                childscore += Convert.ToInt32(indexdr["F_Score"].ToString().Trim());
                                allscore += Convert.ToInt32(indexdr["F_Score"].ToString().Trim());
                            }
                            catch
                            { }

                            try
                            {
                                pf = dtres.Select("F_IndexId=" + indexid + "")[0]["F_QCScore"].ToString().Trim();
                                childpf += Convert.ToInt32(pf);
                                allpf += Convert.ToInt32(pf);
                            }
                            catch
                            {
                            }

                            #region 指标
                            if (m == 0)
                            {
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("" + indexdr["F_Title"].ToString().Trim() + "&nbsp;</td>");
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("" + indexdr["F_Score"].ToString().Trim() + "&nbsp;</td>");
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("&nbsp;<input id='txtscore_" + categoryid + "_" + childcategoryid + "_" + indexid + "' name='txtscore' type='text' class='txtInput normal' style='width:50px; color:blue;' onblur=\"SetScore('" + categoryid + "','" + childcategoryid + "','" + indexid + "')\" onkeyup=\"this.value=this.value.replace(/[^\\d]/g,'');\" value='" + pf + "' /></td>");
                                res.Append("</tr>");
                            }
                            else
                            {
                                res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" ");
                                res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");

                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("" + indexdr["F_Title"].ToString().Trim() + "&nbsp;</td>");
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("" + indexdr["F_Score"].ToString().Trim() + "&nbsp;</td>");
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("&nbsp;<input id='txtscore_" + categoryid + "_" + childcategoryid + "_" + indexid + "' name='txtscore' type='text' class='txtInput normal' style='width:50px; color:blue;' onblur=\"SetScore('" + categoryid + "','" + childcategoryid + "','" + indexid + "')\" onkeyup=\"this.value=this.value.replace(/[^\\d]/g,'');\" value='" + pf + "' /></td>");
                                res.Append("</tr>");
                            }
                            #endregion
                            m++;
                        }
                        i++;
                    }

                    res = res.Replace("#indexcount#", indexcount.ToString());

                    res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\"");
                    res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
                    res.Append("<td colspan=\"3\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                    res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                    res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px; background-color: #e4d354;\">");
                    res.Append("【" + dr["F_CategoryName"].ToString().Trim() + "】合计：&nbsp;</td>");
                    res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                    res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                    res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px; background-color: #e4d354;\">");
                    res.Append("" + childscore.ToString().Trim() + "&nbsp;</td>");
                    res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                    res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                    res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px; background-color: #e4d354;\">");
                    res.Append("<span id=\"spanscore_" + categoryid + "\" style='color:red; font-weight:bold;'>" + childpf.ToString().Trim() + "</span>&nbsp;</td>");
                    res.Append("</tr>");
                }

                res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\"");
                res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
                res.Append("<td colspan=\"3\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                res.Append("height: 22px; padding-top: 3px; padding-bottom: 3px; background-color: #D5EDFE;\">");
                res.Append("总计：&nbsp;</td>");
                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                res.Append("height: 22px; padding-top: 3px; padding-bottom: 3px; background-color: #D5EDFE;\">");
                res.Append("" + allscore.ToString().Trim() + "&nbsp;</td>");
                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                res.Append("height: 22px; padding-top: 3px; padding-bottom: 3px; background-color: #D5EDFE;\">");
                res.Append("<span id=\"spanallscore\" style='color:red; font-weight:bold;'>" + allpf.ToString().Trim() + "</span>&nbsp;</td>");
                res.Append("</tr>");
            }
            catch (Exception err)
            {
                //res = err.ToString(); 
            }
            finally
            {
                dtindex.Clear();
                dtindex.Dispose();
                dt.Clear();
                dt.Dispose();
            }
            res.Append("</table>");
            return res.ToString();
        }
        #endregion

        #region 获取数据
        private string LoadIndexListShow(HttpContext context)
        {
            StringBuilder res = new StringBuilder();
            #region 标题
            res.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" align='center'>");
            res.Append("<tr style=\"text-align: center;\"><td style=\"height: 22px; background-color: #D5EDFE; border-left: 1px solid #CCCCCC;");
            res.Append("border-right: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
            res.Append("padding: 3px 3px 3px 3px; text-align: center;\" colspan=\"2\">分类</td>");
            res.Append("<td style=\"height: 22px; background-color: #D5EDFE; border-left: 1px solid #CCCCCC;");
            res.Append("border-right: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
            res.Append("padding: 3px 3px 3px 3px; text-align: center;\">指标</td>");
            res.Append("<td style=\"height: 22px; width:60px; background-color: #D5EDFE; border-left: 1px solid #CCCCCC;");
            res.Append("border-right: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
            res.Append("padding: 3px 3px 3px 3px; text-align: center;\">分值</td>");
            res.Append("<td style=\"height: 22px; width:80px; background-color: #D5EDFE; border-left: 1px solid #CCCCCC;");
            res.Append("border-right: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
            res.Append("padding: 3px 3px 3px 3px; text-align: center;\">评分</td></tr>");
            #endregion
            DataTable dt = new DataTable();
            DataTable dtindex = new DataTable();
            DataTable dtres = new DataTable();
            try
            {
                dt = new BLL.T_QC_IndexCategory().GetList(" F_DeleteFlag=0 order by F_Sort ,F_CategoryId").Tables[0];
                dtindex = new BLL.T_QC_IndexBase().GetList(" F_DeleteFlag=0 order by F_Sort ,F_CategoryId").Tables[0];
                dtres = new BLL.T_QC_IndexRes().GetList(" CallRecordsId=" + CommonRequest.GetQueryString("id") + " ").Tables[0];
                int i = 0;
                int m = 0;
                int indexcount = 0;
                int allscore = 0;
                int childscore = 0;
                int childpf=0;
                int allpf = 0;
                foreach (DataRow dr in dt.Select("F_ParentId=0"))
                {
                    i = 0;
                    indexcount = 0;
                    childscore = 0;
                    childpf = 0;
                    string categoryid = dr["F_CategoryId"].ToString().Trim();
                    res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" ");
                    res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
                    res.Append("<td rowspan=\"#indexcount#\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                    res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                    res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                    res.Append("" + dr["F_CategoryName"].ToString().Trim() + "&nbsp;</td>");
                    foreach (DataRow childdr in dt.Select("F_ParentId=" + categoryid + ""))
                    {
                        m = 0;
                        #region 子分类
                        string childcategoryid = childdr["F_CategoryId"].ToString().Trim();
                        DataRow[] arrchild = dtindex.Select("F_CategoryId=" + childcategoryid + "");
                        indexcount += arrchild.Length;
                        if (i == 0)
                        {
                            res.Append("<td rowspan=\"" + arrchild.Length.ToString() + "\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                            res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                            res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                            res.Append("" + childdr["F_CategoryName"].ToString().Trim() + "&nbsp;</td>");
                        }
                        else
                        {
                            res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" ");
                            res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");

                            res.Append("<td rowspan=\"" + arrchild.Length.ToString() + "\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                            res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                            res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                            res.Append("" + childdr["F_CategoryName"].ToString().Trim() + "&nbsp;</td>");
                        }
                        #endregion

                        foreach (DataRow indexdr in arrchild)
                        {
                            string indexid = indexdr["F_IndexId"].ToString().Trim();
                            string pf = "0";
                            try
                            {
                                childscore += Convert.ToInt32(indexdr["F_Score"].ToString().Trim());
                                allscore += Convert.ToInt32(indexdr["F_Score"].ToString().Trim());
                            }
                            catch
                            { }

                            try
                            {
                                pf = dtres.Select("F_IndexId=" + indexid + "")[0]["F_QCScore"].ToString().Trim();
                                childpf += Convert.ToInt32(pf);
                                allpf += Convert.ToInt32(pf);
                            }
                            catch
                            {
                            }

                            #region 指标
                            if (m == 0)
                            {
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("" + indexdr["F_Title"].ToString().Trim() + "&nbsp;</td>");
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("" + indexdr["F_Score"].ToString().Trim() + "&nbsp;</td>");
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("&nbsp;<input id='txtscore_" + categoryid + "_" + childcategoryid + "_" + indexid + "' name='txtscore' type='text' class='txtInput normal' style='width:50px; color:blue;' onblur=\"SetScore('" + categoryid + "','" + childcategoryid + "','" + indexid + "')\" onkeyup=\"this.value=this.value.replace(/[^\\d]/g,'');\" value='" + pf + "' /></td>");
                                res.Append("</tr>");
                            }
                            else
                            {
                                res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\" ");
                                res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");

                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("" + indexdr["F_Title"].ToString().Trim() + "&nbsp;</td>");
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("" + indexdr["F_Score"].ToString().Trim() + "&nbsp;</td>");
                                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                                res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px;\">");
                                res.Append("&nbsp;<input id='txtscore_" + categoryid + "_" + childcategoryid + "_" + indexid + "' name='txtscore' type='text' class='txtInput normal' style='width:50px; color:blue;' onblur=\"SetScore('" + categoryid + "','" + childcategoryid + "','" + indexid + "')\" onkeyup=\"this.value=this.value.replace(/[^\\d]/g,'');\" value='" + pf + "' /></td>");
                                res.Append("</tr>");
                            }
                            #endregion
                            m++;
                        }
                        i++;
                    }

                    res = res.Replace("#indexcount#", indexcount.ToString());

                    res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\"");
                    res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
                    res.Append("<td colspan=\"3\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                    res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                    res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px; background-color: #e4d354;\">");
                    res.Append("【" + dr["F_CategoryName"].ToString().Trim() + "】合计：&nbsp;</td>");
                    res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                    res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                    res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px; background-color: #e4d354;\">");
                    res.Append("" + childscore.ToString().Trim() + "&nbsp;</td>");
                    res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                    res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                    res.Append("height: 18px; padding-top: 3px; padding-bottom: 3px; background-color: #e4d354;\">");
                    res.Append("<span id=\"spanscore_" + categoryid + "\" style='color:red; font-weight:bold;'>" + childpf.ToString().Trim() + "</span>&nbsp;</td>");
                    res.Append("</tr>");
                }

                res.Append("<tr align=\"center\" valign=\"middle\" onmouseover=\"this.style.backgroundColor='#F6F6F6'\"");
                res.Append("onmouseout=\"this.style.backgroundColor='#ffffff'\" bgcolor=\"#ffffff\">");
                res.Append("<td colspan=\"3\" style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                res.Append("height: 22px; padding-top: 3px; padding-bottom: 3px; background-color: #D5EDFE;\">");
                res.Append("总计：&nbsp;</td>");
                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                res.Append("height: 22px; padding-top: 3px; padding-bottom: 3px; background-color: #D5EDFE;\">");
                res.Append("" + allscore.ToString().Trim() + "&nbsp;</td>");
                res.Append("<td style=\"vertical-align: middle; border-top: 0px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;");
                res.Append("border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; padding-left: 2px;");
                res.Append("height: 22px; padding-top: 3px; padding-bottom: 3px; background-color: #D5EDFE;\">");
                res.Append("<span id=\"spanallscore\" style='color:red; font-weight:bold;'>" + allpf.ToString().Trim() + "</span>&nbsp;</td>");
                res.Append("</tr>");
            }
            catch (Exception err)
            {
                //res = err.ToString(); 
            }
            finally
            {
                dtres.Clear();
                dtres.Dispose();
                dtindex.Clear();
                dtindex.Dispose();
                dt.Clear();
                dt.Dispose();
            }
            res.Append("</table>");
            return res.ToString();
        }
        #endregion

        private string savedata(HttpContext context)
        {
            string res = "";
            string type = "0";

            DataTable dt = new DataTable();
            try
            {
                string id = context.Request.Params["id"];
                string userid = context.Request.Params["userid"];
                string username = context.Request.Params["username"];
                string xmlinfo = context.Request.Params["xmlinfo"];
                dt = new BLL.T_QC_IndexRes().GetList(" CallRecordsId=" + id + " ").Tables[0];
                int allscore = 0;
                foreach (string scoreinfo in xmlinfo.Split(';'))
                {
                    //判断存在该指标评估则修改，无则添加
                    string indexid = scoreinfo.Split(':')[0];
                    if (dt.Select(" F_IndexId=" + indexid + " ").Length > 0)
                    {
                        Model.T_QC_IndexRes model = new Model.T_QC_IndexRes();
                        model.F_Id = Convert.ToInt32(dt.Select(" F_IndexId=" + indexid + " ")[0]["F_Id"].ToString());
                        model.CallRecordsId = Convert.ToInt32(id);
                        try
                        {
                            model.F_IndexId = Convert.ToInt32(indexid);
                        }
                        catch
                        { }
                        try
                        {
                            model.F_QCScore = Convert.ToInt32(scoreinfo.Split(':')[1]);
                            allscore += Convert.ToInt32(scoreinfo.Split(':')[1]);
                        }
                        catch
                        { }
                        new BLL.T_QC_IndexRes().Update(model);
                    }
                    else
                    {
                        Model.T_QC_IndexRes model = new Model.T_QC_IndexRes();
                        model.CallRecordsId = Convert.ToInt32(id);
                        try
                        {
                            model.F_IndexId = Convert.ToInt32(indexid);
                        }
                        catch
                        { }
                        try
                        {
                            model.F_QCScore = Convert.ToInt32(scoreinfo.Split(':')[1]);
                            allscore += Convert.ToInt32(scoreinfo.Split(':')[1]);
                        }
                        catch
                        { }
                        new BLL.T_QC_IndexRes().Add(model);
                    }
                }

                Model.T_Call_CallRecords_QC callmodel = new Model.T_Call_CallRecords_QC();
                callmodel.CallRecordsId = Convert.ToInt32(id);
                callmodel.F_QCState = 1;
                callmodel.F_QCScore = allscore;
                callmodel.F_QCUserId = Convert.ToInt32(userid);
                callmodel.F_QCUserName = username;
                callmodel.F_QCTime = DateTime.Now;
                callmodel.F_QCIsSelect = 0;
                callmodel.F_QCRemark = "";

                if (new BLL.T_Call_CallRecords_QC().UpdateQC(callmodel))
                {

                    res = "保存成功";
                    type = "1";
                }
                else
                {
                    res = "保存质检评分信息失败";
                }
                
            }
            catch (Exception ex)
            {
                res = ex.ToString();
            }
            finally
            {
                dt.Clear();
                dt.Dispose();
            }

            return "" + type + "|" + res + "";
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}