using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HySoft.BaseCallCenter.Web.qualitymanage
{
    public partial class QcResultList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtStartTime.Text = DateTime.Now.ToString("yyyy-MM-01");
            txtEndTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            if (!this.IsPostBack)
            {
                DataTable dt = DBUtility.DbHelperSQL.Query("select F_DeptId,F_DeptName,F_Remark from  T_Sys_Department where F_ParentId!=0 and F_State=0").Tables[0];
                this.dtDpt.DataTextField = "F_DeptName";
                this.dtDpt.DataValueField = "F_DeptId";
                this.dtDpt.DataSource = dt;
                this.dtDpt.DataBind();
                this.dtDpt.Items.Insert(0, new ListItem("请选择"));
                this.dtDpt.SelectedIndex = 0;
            }
        }


        public string GetColoms() 
        {
            string strColom = "";
            DataSet ds = DBUtility.DbHelperSQL.Query("select F_CategoryId,F_CategoryName,F_ParentId from T_QC_IndexCategory where F_DeleteFlag=0 order by F_CategoryId asc");
            DataTable dsConten = DBUtility.DbHelperSQL.Query("select F_IndexId,F_Content,F_Score,F_CategoryId from T_QC_IndexBase order by F_IndexId asc").Tables[0];
            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                DataRow[] drlist = dt.Select("F_ParentId=0");
                if(drlist!=null)
                {
                    for (int i = 0; i < drlist.Length; i++)
                    {
                        strColom += "{ display: '" + drlist[i]["F_CategoryName"] + "' ";
                        DataRow[] drlistnew = dt.Select("F_ParentId=" + drlist[i]["F_CategoryId"]);
                        if (drlistnew != null && drlist.Length > 0)
                        {
                            strColom += ",columns:[";
                            for (int n = 0; n < drlistnew.Length; n++) 
                            {
                                
                                strColom += "{ display: '" + drlistnew[n]["F_CategoryName"] + "' }";
                                DataRow[] drContent = dsConten.Select("F_CategoryId=" + drlistnew[n]["F_CategoryId"]);
                                if (drContent != null && drContent.Length > 0) 
                                {
                                    strColom += ",columns:[";
                                    for (int m = 0; m < drContent.Length; m++)
                                    {
                                        strColom += "{ display: '" + drContent[m]["F_Content"] + "',name: '_fqc" + drContent[m]["F_IndexId"] + "', width: 50 }";
                                        if (m < drContent.Length - 1)
                                        {//最后一个不要逗号
                                            strColom += ",";
                                        }
                                    }
                                    strColom += "] ";
                                }

                                if (n <drlistnew.Length - 1)
                                {//最后一个不要逗号
                                    strColom += ",";
                                }
                            }
                               
                            strColom += "] ";
                        }


                        strColom += " },{ display: '分项得分', name: '_item"+i+"', width: 50 },";
                    }

                }

            }

            return strColom;


        }

        protected void exportExcel_Click(object sender, EventArgs e)
        {
            string fileName = "质检报表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
            Response.Clear();
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
            Response.ContentType = "application/ms-excel";
            Response.Write(this.htHtmlReport.Value);
            Response.End();
        }



    }
}