using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using BLL;
namespace FineUIPro.Web.TestRun
{
    public partial class DriverSchemeChart : PageBase
    {
        #region 加载页面
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            }
        }
        #endregion
        #region 统计
        /// 
        /// 统计分析
        /// 
        /// 
        /// 
        protected void BtnAnalyse_Click(object sender, EventArgs e)
        {
            this.AnalyseData();
        }
        /// 
        /// 统计方法
        /// 
        private void AnalyseData()
        {
            var forms = from x in Funs.DB.Solution_TestRunConstructSolution
                        where x.ProjectId == this.CurrUser.LoginProjectId
                        select x;
            if (!string.IsNullOrEmpty(this.txtStartTime.Text.Trim()))
            {
                forms = forms.Where(x => x.CompileDate >= Funs.GetNewDateTime(this.txtStartTime.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(this.txtEndTime.Text.Trim()))
            {
                forms = forms.Where(x => x.CompileDate <= Funs.GetNewDateTime(this.txtEndTime.Text.Trim()));
            }
            #region 按状态统计
            if (this.drpChartType.SelectedValue != "Pie")  //非饼形图
            {
                DataTable dtTime = new DataTable();
                dtTime.Columns.Add("状态", typeof(string));
                dtTime.Columns.Add("数量", typeof(string));
                DataRow rowTime1 = dtTime.NewRow();
                rowTime1["状态"] = "编制";
                rowTime1["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_Compile).Count();
                dtTime.Rows.Add(rowTime1);
                DataRow rowTime2 = dtTime.NewRow();
                rowTime2["状态"] = "审核";
                rowTime2["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_Audit).Count();
                dtTime.Rows.Add(rowTime2);
                DataRow rowTime3 = dtTime.NewRow();
                rowTime3["状态"] = "审批";
                rowTime3["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_Audit2).Count();
                dtTime.Rows.Add(rowTime3);
                DataRow rowTime4 = dtTime.NewRow();
                rowTime4["状态"] = "发布";
                rowTime4["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_Complete).Count();
                dtTime.Rows.Add(rowTime4);
                DataRow rowTime5 = dtTime.NewRow();
                rowTime5["状态"] = "重报";
                rowTime5["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_ReCompile).Count();
                dtTime.Rows.Add(rowTime5);
                this.ChartAccidentTime.CreateChart(BLL.ChartControlService.GetDataSourceChart(dtTime, "试车方案统计", this.drpChartType.SelectedValue, 1300, 550, this.ckbShow.Checked));
            }
            else   //饼形图
            {
                DataTable dtTime = new DataTable();
                dtTime.Columns.Add("状态", typeof(string));
                dtTime.Columns.Add("数量", typeof(string));
                DataRow rowTime1 = dtTime.NewRow();
                rowTime1["状态"] = "编制";
                rowTime1["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_Compile).Count();
                dtTime.Rows.Add(rowTime1);
                DataRow rowTime2 = dtTime.NewRow();
                rowTime2["状态"] = "审核";
                rowTime2["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_Audit).Count();
                dtTime.Rows.Add(rowTime2);
                DataRow rowTime3 = dtTime.NewRow();
                rowTime3["状态"] = "审批";
                rowTime3["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_Audit2).Count();
                dtTime.Rows.Add(rowTime3);
                DataRow rowTime4 = dtTime.NewRow();
                rowTime4["状态"] = "发布";
                rowTime4["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_Complete).Count();
                dtTime.Rows.Add(rowTime4);
                DataRow rowTime5 = dtTime.NewRow();
                rowTime5["状态"] = "重报";
                rowTime5["数量"] = forms.Where(x => x.State == Const.TestRunConstructSolution_ReCompile).Count();
                dtTime.Rows.Add(rowTime5);
                this.ChartAccidentTime.CreateChart(BLL.ChartControlService.GetDataSourceChart(dtTime, "试车方案统计", this.drpChartType.SelectedValue, 1300, 550, this.ckbShow.Checked));
            }
            #endregion
        }
        #endregion
        #region 图形
        /// 
        /// 图形变换 
        /// 
        /// 
        /// 
        protected void drpChartType_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.AnalyseData();
        }
        protected void ckbShow_CheckedChanged(object sender, CheckedEventArgs e)
        {
            this.AnalyseData();
        }
        #endregion
    }
}