using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using BLL;
namespace FineUIPro.Web.common
{
    public partial class mainProject : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Model.SGGLDB db = Funs.DB;
                //未遂事故
                var wsAccidentList1 = from x in db.Accident_AccidentPersonRecord
                                      join y in db.Base_AccidentType on x.AccidentTypeId equals y.AccidentTypeId
                                      where y.AccidentTypeName.Contains("未遂") && x.ProjectId == this.CurrUser.LoginProjectId
                                      select x;
                var wsAccidentList2 = from x in db.Accident_AccidentReportOther
                                      join y in db.Sys_Const on x.AccidentTypeId equals y.ConstValue
                                      where y.ConstText.Contains("未遂") && x.ProjectId == this.CurrUser.LoginProjectId
                                      select x;
                this.divWS.InnerHtml = (wsAccidentList1.Count() + wsAccidentList2.Count()).ToString();
                //隐患整改
                var getRectify = db.Check_RectifyNotices.Where(x => x.ProjectId == this.CurrUser.LoginProjectId);
                this.divYH.InnerHtml = getRectify.Count().ToString();
                //安全人工时
                int wHours = db.SitePerson_PersonInOutNumber.Where(x => x.ProjectId == this.CurrUser.LoginProjectId).Max(x => x.WorkHours) ?? 0;
                this.divRGS.InnerHtml = wHours.ToString();
                //教育培训
                var getTrainRecord = from x in db.EduTrain_TrainRecord where x.ProjectId == this.CurrUser.LoginProjectId select x;
                this.divPX.InnerHtml = getTrainRecord.Count().ToString();
                //质量问题
                var checkList = from x in db.Check_CheckControl where x.ProjectId == this.CurrUser.LoginProjectId select x;
                this.divZLWT.InnerHtml = checkList.Count().ToString();
                //质量共检数据
                var inspectionManagements = from x in db.ProcessControl_InspectionManagement where x.ProjectId == this.CurrUser.LoginProjectId select x;
                this.divZLGJ.InnerHtml = inspectionManagements.Count().ToString();
                //验收数据
                this.divYS.InnerHtml = inspectionManagements.Count(x => x.IsOnceQualified == true).ToString();
                //竣工资料
                this.divJGZL.InnerHtml = inspectionManagements.Count(x => x.IsOnceQualified == true).ToString();
                //NCR
                var NCRManagements = from x in db.Comprehensive_NCRManagement where x.ProjectId == this.CurrUser.LoginProjectId select x;
                this.divNCR.InnerHtml = NCRManagements.Count().ToString();
                //变更单
                var designChangeOrders = from x in db.Comprehensive_DesignChangeOrder where x.ProjectId == this.CurrUser.LoginProjectId select x;
                this.divBG.InnerHtml = designChangeOrders.Count().ToString();
                //工程量完成情况
                string date = string.Empty;
                var quantityCompletions = from x in Funs.DB.View_JDGL_QuantityCompletion where x.ProjectId == this.CurrUser.LoginProjectId orderby x.SortIndex, x.Name select x;
                if (quantityCompletions.Count() > 0)
                {
                    string quantityCompletionStr = "
序号
类型
单位
设计数量
计划完成
实际完成
计划完成率
累计计划完成
累计实际完成
累计计划完成率
总完成率
"
                                        + i + "
"
                                        + item.Name + "
"
                                        + item.Unit + "
"
                                        + (item.DesignNum != null ? item.DesignNum.Value.ToString("F0") : "0") + "
"
                                        + (item.PlanNum != null ? item.PlanNum.Value.ToString("F0") : "0") + "
"
                                        + (item.RealNum != null ? item.RealNum.Value.ToString("F0") : "0") + "
"
                                        + item.Rate + "
"
                                        + item.TotalPlanNum + "
"
                                        + item.TotalRealNum + "
"
                                        + item.TotalRate + "
"
                                        + item.SumRate + "
序号
储罐编号
类型
单位
设计数量
计划完成
实际完成
计划完成率
累计计划完成
累计实际完成
累计计划完成率
总完成率
"
                                        + i + "
"
                                        + item.Code + "
"
                                        + item.Name + "
"
                                        + item.Unit + "
"
                                        + (item.TotalNum != null ? item.TotalNum.Value.ToString("F0") : "0") + "
"
                                        + (item.PlanNum != null ? item.PlanNum.Value.ToString("F0") : "0") + "
"
                                        + (item.RealNum != null ? item.RealNum.Value.ToString("F0") : "0") + "
"
                                        + item.Rate + "
"
                                        + item.TotalPlanNum + "
"
                                        + item.TotalRealNum + "
"
                                        + item.TotalRate + "
"
                                        + item.SumRate + "
" + item.Detail + "
" + string.Format("{0:yyyy-MM-dd}", item.CreateDate) + "
" + item.Detail + "
" + string.Format("{0:yyyy-MM-dd}", item.CreateDate) + "
" + item.Detail + "
" + string.Format("{0:yyyy-MM-dd}", item.CreateDate) + "