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.reportmanage.operationdata
{
    public partial class YearContrastPic : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                for (int i = 2013; i < 2055; i++)
                {
                    this.dptBgn.Items.Add(new ListItem(i.ToString()));
                    this.dptEnd.Items.Add(new ListItem(i.ToString()));
                }
                this.dptBgn.SelectedValue = (System.DateTime.Now.Year - 1).ToString();
                this.dptEnd.SelectedValue = System.DateTime.Now.Year.ToString();
            }
        }

        //客户呼叫数
        public string GetKhCall(string strtime) 
        {
            DataTable dt = new DataTable();
            string str = "";
            for (int i = 1; i <= 12; i++)
            {
                string sqltimeCallRecords = "";
                string strmm = i.ToString();
                if (i <= 9)
                {
                    strmm = "0" + i;
                }
                if (strtime != "")
                {
                    sqltimeCallRecords += " and CONVERT(varchar , timecallin, 120)>=CONVERT(varchar , '" + strtime + "-" + strmm + "-01 00:00:01', 120) ";
                    sqltimeCallRecords += " and CONVERT(varchar , timecallin, 120)<=CONVERT(varchar , '" + strtime + "-" + strmm + "-31 23:59:59', 120) ";
                }

                dt = DBUtility.DbHelperSQL.Query("select COUNT(*) as ct from rep_trunk_call_in  where 1=1 " + sqltimeCallRecords).Tables[0];
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["ct"].ToString() != "")
                    {
                            str += dt.Rows[0]["ct"].ToString() + ",";
                    }
                    else
                    {
                        str += "0,";
                    }
                }
                else 
                {
                    str += "0,";
                }
            }
            if (str != "") 
            {
                str.Remove(str.Length - 1);
            }
            return str;
        }

        //坐席接听数
        public string GetZxJt(string strtime)
        {
            DataTable dt = new DataTable();
            string str = "";
            for (int i = 1; i <= 12; i++)
            {
                string sqltimeCallRecords = "";
                string strmm = i.ToString();
                if (i <= 9)
                {
                    strmm = "0" + i;
                }
                if (strtime != "")
                {
                    sqltimeCallRecords += " and CONVERT(varchar , timecallin, 120)>=CONVERT(varchar , '" + strtime + "-" + strmm + "-01 00:00:01', 120) ";
                    sqltimeCallRecords += " and CONVERT(varchar , timecallin, 120)<=CONVERT(varchar , '" + strtime + "-" + strmm + "-31 23:59:59', 120) ";
                }

                dt = DBUtility.DbHelperSQL.Query("select COUNT(*) as ct from rep_trunk_call_in where PeriodTalking>0 " + sqltimeCallRecords).Tables[0];
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["ct"].ToString() != "")
                    {
                        str += dt.Rows[0]["ct"].ToString() + ",";
                    }
                    else
                    {
                        str += "0,";
                    }
                }
                else
                {
                    str += "0,";
                }
            }
            if (str != "")
            {
                str.Remove(str.Length - 1);
            }
            return str;
        }



        //坐席接听率
        public string GetJTL(string strtime)
        {
            DataTable dt = new DataTable();
            string str = "";
            for (int i = 1; i <= 12; i++)
            {
                string sqltimeCallRecords = "";
                string strmm = i.ToString();
                if (i <= 9)
                {
                    strmm = "0" + i;
                }
                if (strtime != "")
                {
                    sqltimeCallRecords += " and CONVERT(varchar , timecallin, 120)>=CONVERT(varchar , '" + strtime + "-" + strmm + "-01 00:00:01', 120) ";
                    sqltimeCallRecords += " and CONVERT(varchar , timecallin, 120)<=CONVERT(varchar , '" + strtime + "-" + strmm + "-31 23:59:59', 120) ";
                }

                dt = DBUtility.DbHelperSQL.Query("select COUNT(*) as ct,(select COUNT(*) from rep_trunk_call_in where PeriodTalking>0 " + sqltimeCallRecords + ") as jt from rep_trunk_call_in  where 1=1  " + sqltimeCallRecords).Tables[0];

                int ibgnjt = 0;
                double ibgnjtl = 0.00;
                
                if (dt != null && dt.Rows.Count > 0)
                {

                    if (dt.Rows[0]["jt"].ToString() != "")
                    {
                        ibgnjt = int.Parse(dt.Rows[0]["jt"].ToString());
                    }

                    if (dt.Rows[0]["ct"].ToString() != "" && dt.Rows[0]["ct"].ToString() != "0")
                    {
                        ibgnjtl = ibgnjt / Convert.ToDouble(dt.Rows[0]["ct"].ToString());
                        str += (ibgnjtl * 100).ToString("0.00") + ",";
                    }
                    else
                    {
                        str += "0.00,";
                    }
                }
                else
                {
                    str += "0.00,";
                }
            }
            if (str != "")
            {
                str.Remove(str.Length - 1);
            }
            return str;
        }


    }
}