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.dataanalysis
{
    public partial class WorkOrderDistribution : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        protected string getWorkOrderData()
        {
            //查询条件
            string starttime = txtStartTime.Text.Trim();
            string endtime = txtEndTime.Text.Trim();
            if (string.IsNullOrWhiteSpace(starttime)) { starttime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("yyyy-MM-dd"); txtStartTime.Text = starttime; }
            if (string.IsNullOrWhiteSpace(endtime)) { endtime = DateTime.Today.ToString("yyyy-MM-dd"); txtEndTime.Text = endtime; }
            int[] sum = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            for (DateTime dt = Convert.ToDateTime(starttime); dt <= Convert.ToDateTime(endtime); dt = dt.AddDays(1))
            {
                List<string[]> timepan = new List<string[]>();
                timepan.Add(new string[] { "8:40", "9:00" });
                timepan.Add(new string[] { "9:00", "10:00" });
                timepan.Add(new string[] { "10:00", "11:00" });
                timepan.Add(new string[] { "11:00", "12:00" });
                timepan.Add(new string[] { "12:00", "13:00" });

                timepan.Add(new string[] { "13:00", "14:00" });
                timepan.Add(new string[] { "14:00", "15:00" });
                timepan.Add(new string[] { "15:00", "16:00" });
                timepan.Add(new string[] { "16:00", "17:00" });
                timepan.Add(new string[] { "17:00", "17:30" });
                for (int i = 0; i < timepan.Count; i++)
                {
                    string sql = string.Format("F_WORKORDERTYPEID={0}", 16);
                    sql += " AND F_STARTTIME>='" + dt.ToShortDateString() + " " + timepan[i][0] + "'";
                    sql += " AND F_STARTTIME<'" + dt.ToShortDateString() + " " + timepan[i][1] + "'";
                    DataTable dtable = new BLL.T_Wo_WorkOrderBase().GetList(sql).Tables[0];
                    //今天某个时间段的工单总数
                    int count = dtable.Rows.Count;
                    dtable.Dispose();
                    sum[i] += count;
                }
            }
            string res = "[" + String.Join(",", sum) + "]";
            return res;
        }

        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            getWorkOrderData();
        }
    }
}