using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Newtonsoft.Json.Linq;
namespace FineUIPro.Web.CQMS.ManageReportNew
{
    public partial class MonthReportNewEdit2 : PageBase
    {
        #region 定义项
        /// 
        /// 主键
        /// 
        public string ReportId
        {
            get
            {
                return (string)ViewState["ReportId"];
            }
            set
            {
                ViewState["ReportId"] = value;
            }
        }
        public string AddOrUpdate
        {
            get
            {
                return (string)ViewState["AddOrUpdate"];
            }
            set
            {
                ViewState["AddOrUpdate"] = value;
            }
        }
        #endregion
        #region 列表集合
        private static List detailsGrid1 = new List();
        /// 
        /// 18.本月质量问题处理情况
        /// (1)原材料问题
        /// 
        private static List rowMaterialProblemLists = new List();
        /// 
        /// 18.本月质量问题处理情况
        /// (2)施工过程问题
        /// 
        private static List constructionProblemsLists = new List();
        /// 
        /// 19.下月质量控制重点
        /// 
        private static List nextQualityControlLists = new List();
        #endregion
        #region 加载页面
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BLL.UnitService.InitUnitNameByProjectIdUnitTypeDropDownList(this.drpUnitId, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, false);
                BLL.UnitService.InitUnitDownListByText(this.drpUnitIdGrid9, this.CurrUser.LoginProjectId, true);
                this.EnableViewState = true;
                this.lblProjectName.Text = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId).ProjectName;
                this.ReportId = Request.Params["reportId"];
                if (!string.IsNullOrEmpty(Request.Params["view"]))
                {
                    this.Button1.Visible = false;
                    this.Button2.Visible = false;
                }
                if (!string.IsNullOrEmpty(this.ReportId))
                {
                    Model.Report_WeekAndMonthReport_New weekAndMonthReport = WeekAndMonthReportNewService.Detail(this.ReportId);
                    if (weekAndMonthReport != null)
                    {
                        if (weekAndMonthReport.SortId != null)
                        {
                            this.txtPeriod.Text = Convert.ToString(weekAndMonthReport.SortId);
                        }
                        if (weekAndMonthReport.StartDate != null)
                        {
                            this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", weekAndMonthReport.StartDate);
                        }
                        if (weekAndMonthReport.EndDate != null)
                        {
                            this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", weekAndMonthReport.EndDate);
                        }
                    }
                    AddOrUpdate = "update";
                    #region 加载本月质量目标管理情况 
                    detailsGrid1.Clear();
                    detailsGrid1 = (from x in Funs.DB.Report_CqmsTarget
                                    where x.ReportId == this.ReportId
                                    orderby x.SortId
                                    select x).ToList();
                    if (detailsGrid1.Count > 0)
                    {
                        Grid1.Hidden = false;
                        Grid1.DataSource = detailsGrid1;
                        Grid1.DataBind();
                    }
                    #endregion
                    #region 加载7.2 PQR/WPS报验情况
                    var detailsGrid9 = (from x in Funs.DB.Report_Construction_Plan
                                        where x.ReportId == ReportId && x.ReType == "5"
                                        select x).ToList();
                    if (detailsGrid9.Count > 0)
                    {
                        Grid9.Hidden = false;
                        Grid9.DataSource = detailsGrid9;
                        Grid9.DataBind();
                    }
                    if (!string.IsNullOrEmpty(Request.Params["view"]))
                    {
                        //查看页面
                        Button4.Hidden = true;
                        Button3.Hidden = true;
                        //合计
                        OutPutSummaryGrid9();
                        Grid1.FindColumn("Delete1").Hidden = true;
                        Grid9.FindColumn("Delete9").Hidden = true;
                    }
                    #endregion
                    #region 加载18.本月质量问题处理情况
                    //(1)原材料问题
                    rowMaterialProblemLists.Clear();
                    rowMaterialProblemLists = (from x in Funs.DB.Report_RowMaterialProblem
                                               where x.ReportId == this.ReportId
                                               select x).ToList();
                    if (rowMaterialProblemLists.Count > 0)
                    {
                        gvRowMaterialProblem.Hidden = false;
                        gvRowMaterialProblem.DataSource = rowMaterialProblemLists;
                        gvRowMaterialProblem.DataBind();
                    }
                    //(2)施工过程问题
                    constructionProblemsLists.Clear();
                    constructionProblemsLists = (from x in Funs.DB.Report_ConstructionProblems
                                                 where x.ReportId == this.ReportId
                                                 select x).ToList();
                    if (constructionProblemsLists.Count > 0)
                    {
                        gvConstructionProblems.Hidden = false;
                        gvConstructionProblems.DataSource = constructionProblemsLists;
                        gvConstructionProblems.DataBind();
                    }
                    #endregion
                    #region 加载19.下月质量控制重点
                    nextQualityControlLists.Clear();
                    nextQualityControlLists = (from x in Funs.DB.Report_NextQualityControl
                                               where x.ReportId == this.ReportId
                                               select x).ToList();
                    if (nextQualityControlLists.Count > 0)
                    {
                        gvNextQualityControl.Hidden = false;
                        gvNextQualityControl.DataSource = nextQualityControlLists;
                        gvNextQualityControl.DataBind();
                    }
                    #endregion
                    #region 加载文本框内容
                    var txtReportList = Funs.DB.Report_TextBoxContent.Where(x => x.ReportId == ReportId).ToList();
                    txtAre0.Text = txtReportList.FirstOrDefault(x => x.ContentType == "0").ContentText;
                    txtAre1.Text = txtReportList.FirstOrDefault(x => x.ContentType == "1").ContentText;
                    txtAre2.Text = txtReportList.FirstOrDefault(x => x.ContentType == "2").ContentText;
                    txtAre20.Text = txtReportList.FirstOrDefault(x => x.ContentType == "20").ContentText;
                    txtAre21.Text = txtReportList.FirstOrDefault(x => x.ContentType == "21").ContentText;
                    txtAre22.Text = txtReportList.FirstOrDefault(x => x.ContentType == "22").ContentText;
                    txtAre8.Text = txtReportList.FirstOrDefault(x => x.ContentType == "8").ContentText;
                    #endregion
                    //加载所有grid
                    lodAllGrid("1");
                }
                else
                {
                    this.txtStartDate.Text = string.IsNullOrEmpty(Request.Params["startdate"]) ? string.Format("{0:yyyy-MM-dd}", DateTime.Now) : Request.Params["startdate"];
                    this.txtEndDate.Text = string.IsNullOrEmpty(Request.Params["enddate"]) ? string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(this.txtStartDate.Text).AddMonths(1).AddDays(-1)) : Request.Params["enddate"];
                    //给个新的主键
                    ReportId = Guid.NewGuid().ToString();
                    AddOrUpdate = "add";
                    //加载所有grid
                    lodAllGrid("0");
                }
                Grid10.EmptyText = "无数据
";
                gvTj.EmptyText = "无数据
";
                GvSb.EmptyText = "无数据
";
                GvGD.EmptyText = "无数据
";
                GvDq.EmptyText = "无数据
";
                GvYb.EmptyText = "无数据
";
                GvFf.EmptyText = "无数据
";
                GvXf.EmptyText = "无数据
";
                hidReportId.Value = ReportId;
            }
        }
        /// 
        /// 加载grid
        /// 
        /// 
        void lodAllGrid(string objType)
        {
            //3.1 加载一般施工方案审批情况
            loadGeneralPlanApproval(objType);
            //3.2 加载危大工程方案审批情况
            loadMajorPlanApproval(objType);
            //3.3 质量控制点或检验试验计划(ITP)情况
            loadInspectionTestPlan(objType);
            //4 加载设计交底管理情况
            loadDesignDetailsApprove(objType);
            //5 加载图纸会审管理情况
            loadReviewDrawings(objType);
            //6 加载设计变更管理情况
            loadDesignChangeOrder();
            //7.1 加载合格焊工管理情况
            loadPassWelder();
            //7.3 加载无损检测管理
            loadProcessControl_NondestructiveTest_New();
            //8 设备报验管理Grid11
            LoadInspectionEquipment(objType);
            //加载9.计量器具报验管理情况
            loadMeasuringInspection(objType);
            //加载10.现场质量共检数据
            loadInspectionDataInspection(objType);
            //加载11.压力管道监检情况
            loadPressureInspection(objType);
            //加载12.管道试压包管理情况
            loadPipingInspection(objType);
            //加载13.特种设备监检情况
            loadSpecialInspection(objType);
            ////加载14.NCR管理情况
            loadNcrManagementInspection();
            //加载15.质量巡检情况
            loadQualityInspection(objType);
            //加载16.质量专项检查情况
            loadSpecialCheck(objType);
            //加载17.质量文件上报情况
            loadFileReport(objType);
        }
        #endregion
        #region 时间选择事件
        /// 
        /// 开始时间选择事件
        /// 
        /// 
        /// 
        protected void txtStartDate_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()))
            {
                string url = Request.Url.ToString();
                if (url.Contains("?"))
                {
                    url = Request.Url.ToString().Substring(0, Request.Url.ToString().LastIndexOf('?'));
                }
                Response.Redirect(url + "?startdate=" + txtStartDate.Text + "&enddate=" + txtEndDate.Text);
            }
        }
        protected void TextBox_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()) && !string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
            {
                if (Funs.GetNewDateTime(this.txtStartDate.Text.Trim()) > Funs.GetNewDateTime(this.txtEndDate.Text.Trim()))
                {
                    Alert.ShowInTop("开始时间不能大于结束时间!", MessageBoxIcon.Warning);
                    return;
                }
                if (AddOrUpdate == "update")
                {
                    lodAllGrid("1");
                }
                else
                {
                    lodAllGrid("0");
                }
            }
        }
        #endregion
        #region 本月质量目标管理情况 Grid1方法
        protected void btnAddGrid1_Click(object sender, EventArgs e)
        {
            Grid1.Hidden = false;
            JArray teamGroupData = Grid1.GetMergedData();
            List list = new List();
            foreach (JObject teamGroupRow in teamGroupData)
            {
                JObject values = teamGroupRow.Value("values");
                values.Add("Id", teamGroupRow.Value("id"));
                list.Add(values);
            }
            JObject defaultObj = new JObject
                {   { "Id",Guid.NewGuid() },
                    { "ReportId", ReportId },
                    { "ProStage", "" },
                    { "ProDescribe",""},
                    { "TargetValue", "" },
                    { "MonthPer","" },
                    { "Remarks", "" },
                    { "SortId","" },
                    { "Delete1", String.Format(" ", GetDeleteScriptGrid1(), IconHelper.GetResolvedIconUrl(Icon.Delete)) }
                };
            list.Add(defaultObj);
            Grid1.DataSource = list;
            Grid1.DataBind();
        }
        protected void Grid1_PreDataBound(object sender, EventArgs e)
        {
            // 设置LinkButtonField的点击客户端事件
            LinkButtonField deleteField = Grid1.FindColumn("Delete1") as LinkButtonField;
            deleteField.OnClientClick = GetDeleteScriptGrid1();
        }
        /// 
        /// 删除提示
        /// 
        /// 
        private string GetDeleteScriptGrid1()
        {
            return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty);
        }
        #endregion
        #region 3.1一般施工方案审批情况 Grid2方法
        /// 
        /// 加载一般施工审批情况
        /// 
        void loadGeneralPlanApproval(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            //加载所有单位
            var units = from x in Funs.DB.Project_ProjectUnit
                        join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
                        where x.ProjectId == this.CurrUser.LoginProjectId && (x.UnitType == BLL.Const.ProjectUnitType_2 || x.UnitType == BLL.Const.ProjectUnitType_1)
                        orderby y.UnitCode
                        select new { x.UnitId, y.UnitName };
            foreach (var item in units)
            {
                var query = from c in db.Comprehensive_GeneralPlanApproval
                            join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin
                            from u in unitJoin.DefaultIfEmpty()
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.UnitId == item.UnitId
                            select new
                            {
                                c.ApprovalDate,
                                c.ProjectId,
                                u.UnitId,
                                u.UnitName,
                                c.CompileDate
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.ApprovalDate >= Convert.ToDateTime(startDate) && x.ApprovalDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.UnitName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.UnitName && x.ReType == "0");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                i++;
            }
            Grid2.DataSource = list;
            Grid2.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            Grid2.SummaryData = summary;
        }
        #endregion
        #region 3.2 危大工程方案审批情况 Grid3方法
        /// 
        /// 加载一般施工审批情况
        /// 
        void loadMajorPlanApproval(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            int Quantity3Sum = 0;
            //加载所有单位
            var units = from x in Funs.DB.Project_ProjectUnit
                        join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
                        where x.ProjectId == this.CurrUser.LoginProjectId && (x.UnitType == BLL.Const.ProjectUnitType_2 || x.UnitType == BLL.Const.ProjectUnitType_1)
                        orderby y.UnitCode
                        select new { x.UnitId, y.UnitName };
            foreach (var item in units)
            {
                var query = from c in db.Comprehensive_MajorPlanApproval
                            join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin
                            from u in unitJoin.DefaultIfEmpty()
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.UnitId == item.UnitId
                            select new
                            {
                                c.ApprovalDate,
                                c.ProjectId,
                                u.UnitId,
                                u.UnitName,
                                c.ExpertReviewMan,
                                c.IsReview,
                                c.CompileDate
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.ApprovalDate >= Convert.ToDateTime(startDate) && x.ApprovalDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.UnitName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.Quantity3 = AllList.Where(x => x.IsReview ==true).ToList().Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.UnitName && x.ReType == "1");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                Quantity3Sum += Convert.ToInt32(model.Quantity3);
                i++;
            }
            Grid3.DataSource = list;
            Grid3.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            summary.Add("Quantity3", Quantity3Sum.ToString());
            Grid3.SummaryData = summary;
        }
        #endregion
        #region 3.3 质量控制点或检验试验计划(ITP)情况 Grid4方法
        /// 
        /// 加载一般施工审批情况
        /// 
        void loadInspectionTestPlan(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            //加载所有专业
            var CNProfessionals = from x in Funs.DB.Base_CNProfessional
                                  where x.CNProfessionalId != BLL.Const.CNProfessionalConstructId
                                  && x.CNProfessionalId!= BLL.Const.ComprehensiveId
                                  orderby x.SortIndex
                                  select new
                                  {
                                      x.CNProfessionalId,
                                      x.ProfessionalName
                                  };
            foreach (var item in CNProfessionals)
            {
                var query = from c in db.Inspection_Test_Plan
                            join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin
                            from u in unitJoin.DefaultIfEmpty()
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.CNProfessionalId == item.CNProfessionalId
                            select new
                            {
                                c.ApprovalDate,
                                c.ProjectId,
                                u.UnitId,
                                u.UnitName,
                                c.CreateDate
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.CreateDate >= Convert.ToDateTime(startDate) && x.CreateDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.ProfessionalName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.ProfessionalName && x.ReType == "2");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                i++;
            }
            Grid4.DataSource = list;
            Grid4.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            Grid4.SummaryData = summary;
        }
        #endregion
        #region 4 设计交底管理情况 Grid5方法
        /// 
        /// 加载一般施工审批情况
        /// 
        void loadDesignDetailsApprove(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            //加载所有专业
            var CNProfessionals = from x in Funs.DB.Base_CNProfessional
                                  where x.CNProfessionalId != BLL.Const.CNProfessionalConstructId
                                  && x.CNProfessionalId != BLL.Const.ComprehensiveId
                                  orderby x.SortIndex
                                  select new
                                  {
                                      x.CNProfessionalId,
                                      x.ProfessionalName
                                  };
            foreach (var item in CNProfessionals)
            {
                var query = from c in db.Comprehensive_DesignDetails
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.CNProfessionalId == item.CNProfessionalId
                            && c.Status == "3"
                            select new
                            {
                                c.Status,
                                c.CompileDate,
                                c.ProjectId,
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.CompileDate >= Convert.ToDateTime(startDate) && x.CompileDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.ProfessionalName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.ProfessionalName && x.ReType == "3");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                i++;
            }
            Grid5.DataSource = list;
            Grid5.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            Grid5.SummaryData = summary;
        }
        #endregion
        #region 5 图纸会审管理情况 Grid6方法
        /// 
        /// 加载一图纸会审管理情况
        /// 
        void loadReviewDrawings(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            //加载所有专业
            var CNProfessionals = from x in Funs.DB.Base_CNProfessional
                                  where x.CNProfessionalId != BLL.Const.CNProfessionalConstructId
                                  && x.CNProfessionalId != BLL.Const.ComprehensiveId
                                  orderby x.SortIndex
                                  select new
                                  {
                                      x.CNProfessionalId,
                                      x.ProfessionalName
                                  };
            foreach (var item in CNProfessionals)
            {
                var query = from c in db.Comprehensive_ReviewDrawings
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.CNProfessionalId == item.CNProfessionalId
                            && c.Status == "3"
                            select new
                            {
                                c.Status,
                                c.ReviewDate,
                                c.ProjectId,
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.ReviewDate >= Convert.ToDateTime(startDate) && x.ReviewDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.ProfessionalName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.ProfessionalName && x.ReType == "4");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                i++;
            }
            Grid6.DataSource = list;
            Grid6.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            Grid6.SummaryData = summary;
        }
        #endregion
        #region 6 设计变更管理情况 Grid7方法
        /// 
        /// 加载设计变更管理情况
        /// 
        void loadDesignChangeOrder()
        {
            int Quantity1Sum = 0, Quantity2Sum = 0, Quantity3Sum = 0, Quantity4Sum = 0, Quantity5Sum = 0, Quantity6Sum = 0;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            DateTime projectStartDate = Convert.ToDateTime("2015-01-01");
            List StatisticsList = new List();
            Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
            if (project != null)
            {
                if (project.StartDate != null)
                {
                    projectStartDate = Convert.ToDateTime(project.StartDate);
                }
            }
            int i = 1;
            var cNProfessionals = from x in Funs.DB.Base_CNProfessional where x.CNProfessionalId != BLL.Const.CNProfessionalConstructId
                                  && x.CNProfessionalId != BLL.Const.ComprehensiveId
                                  orderby x.SortIndex select x;
            foreach (var item in cNProfessionals)
            {
                //专业下所有集合
                List totalManagementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, item.CNProfessionalId, projectStartDate, DateTime.Now);
                //专业下当期集合
                List managementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, item.CNProfessionalId, startDate, endDate);
                Model.CheckStatisc checkStatisc = new Model.CheckStatisc();
                checkStatisc.Num = i;
                checkStatisc.WorkName = item.ProfessionalName;
                checkStatisc.CheckNum = managementList.Count();
                checkStatisc.TotalCheckNum = totalManagementList.Count();
                checkStatisc.OKNum = managementList.Count(x => x.ApprovalDate != null);
                checkStatisc.TotalOKNum = totalManagementList.Count(x => x.ApprovalDate != null);
                checkStatisc.OneOKRate = managementList.Count(x => x.Status == "3").ToString();       //当期完成数
                checkStatisc.TotalOneOKRate = totalManagementList.Count(x => x.Status == "3").ToString();    //累计完成数
                StatisticsList.Add(checkStatisc);
                Quantity1Sum += checkStatisc.CheckNum;
                Quantity2Sum += checkStatisc.TotalCheckNum;
                Quantity3Sum += checkStatisc.OKNum;
                Quantity4Sum += checkStatisc.TotalOKNum;
                Quantity5Sum += Convert.ToInt32(checkStatisc.OneOKRate);
                Quantity6Sum += Convert.ToInt32(checkStatisc.TotalOneOKRate);
            }
            Grid7.DataSource = StatisticsList;
            Grid7.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("WorkName", "合计");
            summary.Add("CheckNum", Quantity1Sum.ToString());
            summary.Add("TotalCheckNum", Quantity2Sum.ToString());
            summary.Add("OKNum", Quantity3Sum.ToString());
            summary.Add("TotalOKNum", Quantity4Sum.ToString());
            summary.Add("OneOKRate", Quantity5Sum.ToString());
            summary.Add("TotalOneOKRate", Quantity6Sum.ToString());
            Grid7.SummaryData = summary;
        }
        #endregion
        #region 7.1 合格焊工管理情况 Grid8方法
        /// 
        /// 加载合格焊工管理情况
        /// 
        void loadPassWelder()
        {
            int Quantity1Sum = 0, Quantity2Sum = 0, Quantity3Sum = 0, Quantity4Sum = 0, Quantity5Sum = 0, Quantity6Sum = 0, Quantity7Sum = 0, Quantity8Sum = 0;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            DateTime projectStartDate = Convert.ToDateTime("2015-01-01");
            List StatisticsList = new List();
            Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
            if (project != null)
            {
                if (project.StartDate != null)
                {
                    projectStartDate = Convert.ToDateTime(project.StartDate);
                }
            }
            int i = 1;
            var units = from x in Funs.DB.Project_ProjectUnit
                        join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
                        where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitType == BLL.Const.ProjectUnitType_2
                        orderby y.UnitCode
                        select new { x.UnitId, y.UnitName };
            var db = Funs.DB;
            foreach (var item in units)
            {
                var query = from c in db.Comprehensive_InspectionPerson
                            join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin
                            from u in unitJoin.DefaultIfEmpty()
                            join cn in db.Base_CNProfessional on c.CNProfessionalId equals cn.CNProfessionalId into cnJoin
                            from cn in cnJoin.DefaultIfEmpty()
                            join p in db.Base_Post on c.PostId equals p.PostId into postJoin
                            from p in postJoin.DefaultIfEmpty()
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.UnitId == item.UnitId
                            select new
                            {
                                c.InspectionPersonId,
                                c.ProjectId,
                                u.UnitId,
                                u.UnitName,
                                c.PersonName,
                                c.ApprovalTime,
                                cn.ProfessionalName,
                                p.PostName
                            };
                //单位下所有集合
                // List totalWelderList = BLL.PersonManageService.GetWelderListByUnitId(this.CurrUser.LoginProjectId, item.UnitId);
                //List welderList = BLL.PersonManageService.GetWelderListByUnitIdAndDate(this.CurrUser.LoginProjectId, item.UnitId, startDate, endDate); 
                var totalWelderList = query.ToList();
                var welderList = query
                    .Where(x => (x.ApprovalTime >= Convert.ToDateTime(startDate) && x.ApprovalTime <= Convert.ToDateTime(endDate)));
                Model.PassWelderStatisc passWelderStatisc = new Model.PassWelderStatisc();
                passWelderStatisc.Num = i;
                passWelderStatisc.UnitName = item.UnitName;
                passWelderStatisc.PipeMountGuard = welderList.Count(x => x.ProfessionalName == "管道" && x.PostName == "焊工");
                passWelderStatisc.PipeTotal = totalWelderList.Count(x => x.ProfessionalName == "管道" && x.PostName == "焊工");
                passWelderStatisc.SteelStructureMountGuard = welderList.Count(x => x.ProfessionalName == "土建" && x.PostName == "焊工");
                passWelderStatisc.SteelStructureTotal = totalWelderList.Count(x => x.ProfessionalName == "土建" && x.PostName == "焊工");
                passWelderStatisc.EquipmentMountGuard = welderList.Count(x => x.ProfessionalName == "设备" && x.PostName == "焊工");
                passWelderStatisc.EquipmentTotal = totalWelderList.Count(x => x.ProfessionalName == "设备" && x.PostName == "焊工");
                passWelderStatisc.OtherMountGuard = welderList.Count(x => x.ProfessionalName != "管道" && x.ProfessionalName != "土建" && x.ProfessionalName != "设备" && x.PostName == "焊工");
                passWelderStatisc.OtherTotal = totalWelderList.Count(x => x.ProfessionalName != "管道" && x.ProfessionalName != "土建" && x.ProfessionalName != "设备" && x.PostName == "焊工");
                StatisticsList.Add(passWelderStatisc);
                i++;
                Quantity1Sum += passWelderStatisc.PipeMountGuard;
                Quantity2Sum += passWelderStatisc.PipeTotal;
                Quantity3Sum += passWelderStatisc.SteelStructureMountGuard;
                Quantity4Sum += passWelderStatisc.SteelStructureTotal;
                Quantity5Sum += passWelderStatisc.EquipmentMountGuard;
                Quantity6Sum += passWelderStatisc.EquipmentTotal;
                Quantity7Sum += passWelderStatisc.OtherMountGuard;
                Quantity8Sum += passWelderStatisc.OtherTotal;
            }
            Grid8.DataSource = StatisticsList;
            Grid8.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitName", "合计");
            summary.Add("PipeMountGuard", Quantity1Sum.ToString());
            summary.Add("PipeTotal", Quantity2Sum.ToString());
            summary.Add("SteelStructureMountGuard", Quantity3Sum.ToString());
            summary.Add("SteelStructureTotal", Quantity4Sum.ToString());
            summary.Add("EquipmentMountGuard", Quantity5Sum.ToString());
            summary.Add("EquipmentTotal", Quantity6Sum.ToString());
            summary.Add("OtherMountGuard", Quantity7Sum.ToString());
            summary.Add("OtherTotal", Quantity8Sum.ToString());
            Grid8.SummaryData = summary;
        }
        #endregion
        #region 7.2 PQR/WPS报验情况 Grid9方法
        protected void btnAddGrid9_Click(object sender, EventArgs e)
        {
            Grid9.Hidden = false;
            JArray teamGroupData = Grid9.GetMergedData();
            List list = new List();
            foreach (JObject teamGroupRow in teamGroupData)
            {
                JObject values = teamGroupRow.Value("values");
                values.Add("Id", teamGroupRow.Value("id"));
                list.Add(values);
            }
            JObject defaultObj = new JObject
                {   { "Id",Guid.NewGuid() },
                    { "ReportId", ReportId },
                    { "ReType", "2" },
                    { "UnitOrMajor",""},
                    { "Quantity1", "" },
                    { "Quantity2","" },
                    { "Remarks", "" },
                    { "Delete9", String.Format("
", GetDeleteScriptGrid1(), IconHelper.GetResolvedIconUrl(Icon.Delete)) }
                };
            list.Add(defaultObj);
            Grid1.DataSource = list;
            Grid1.DataBind();
        }
        protected void Grid1_PreDataBound(object sender, EventArgs e)
        {
            // 设置LinkButtonField的点击客户端事件
            LinkButtonField deleteField = Grid1.FindColumn("Delete1") as LinkButtonField;
            deleteField.OnClientClick = GetDeleteScriptGrid1();
        }
        /// 
        /// 删除提示
        /// 
        /// 
        private string GetDeleteScriptGrid1()
        {
            return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty);
        }
        #endregion
        #region 3.1一般施工方案审批情况 Grid2方法
        /// 
        /// 加载一般施工审批情况
        /// 
        void loadGeneralPlanApproval(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            //加载所有单位
            var units = from x in Funs.DB.Project_ProjectUnit
                        join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
                        where x.ProjectId == this.CurrUser.LoginProjectId && (x.UnitType == BLL.Const.ProjectUnitType_2 || x.UnitType == BLL.Const.ProjectUnitType_1)
                        orderby y.UnitCode
                        select new { x.UnitId, y.UnitName };
            foreach (var item in units)
            {
                var query = from c in db.Comprehensive_GeneralPlanApproval
                            join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin
                            from u in unitJoin.DefaultIfEmpty()
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.UnitId == item.UnitId
                            select new
                            {
                                c.ApprovalDate,
                                c.ProjectId,
                                u.UnitId,
                                u.UnitName,
                                c.CompileDate
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.ApprovalDate >= Convert.ToDateTime(startDate) && x.ApprovalDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.UnitName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.UnitName && x.ReType == "0");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                i++;
            }
            Grid2.DataSource = list;
            Grid2.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            Grid2.SummaryData = summary;
        }
        #endregion
        #region 3.2 危大工程方案审批情况 Grid3方法
        /// 
        /// 加载一般施工审批情况
        /// 
        void loadMajorPlanApproval(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            int Quantity3Sum = 0;
            //加载所有单位
            var units = from x in Funs.DB.Project_ProjectUnit
                        join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
                        where x.ProjectId == this.CurrUser.LoginProjectId && (x.UnitType == BLL.Const.ProjectUnitType_2 || x.UnitType == BLL.Const.ProjectUnitType_1)
                        orderby y.UnitCode
                        select new { x.UnitId, y.UnitName };
            foreach (var item in units)
            {
                var query = from c in db.Comprehensive_MajorPlanApproval
                            join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin
                            from u in unitJoin.DefaultIfEmpty()
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.UnitId == item.UnitId
                            select new
                            {
                                c.ApprovalDate,
                                c.ProjectId,
                                u.UnitId,
                                u.UnitName,
                                c.ExpertReviewMan,
                                c.IsReview,
                                c.CompileDate
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.ApprovalDate >= Convert.ToDateTime(startDate) && x.ApprovalDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.UnitName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.Quantity3 = AllList.Where(x => x.IsReview ==true).ToList().Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.UnitName && x.ReType == "1");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                Quantity3Sum += Convert.ToInt32(model.Quantity3);
                i++;
            }
            Grid3.DataSource = list;
            Grid3.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            summary.Add("Quantity3", Quantity3Sum.ToString());
            Grid3.SummaryData = summary;
        }
        #endregion
        #region 3.3 质量控制点或检验试验计划(ITP)情况 Grid4方法
        /// 
        /// 加载一般施工审批情况
        /// 
        void loadInspectionTestPlan(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            //加载所有专业
            var CNProfessionals = from x in Funs.DB.Base_CNProfessional
                                  where x.CNProfessionalId != BLL.Const.CNProfessionalConstructId
                                  && x.CNProfessionalId!= BLL.Const.ComprehensiveId
                                  orderby x.SortIndex
                                  select new
                                  {
                                      x.CNProfessionalId,
                                      x.ProfessionalName
                                  };
            foreach (var item in CNProfessionals)
            {
                var query = from c in db.Inspection_Test_Plan
                            join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin
                            from u in unitJoin.DefaultIfEmpty()
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.CNProfessionalId == item.CNProfessionalId
                            select new
                            {
                                c.ApprovalDate,
                                c.ProjectId,
                                u.UnitId,
                                u.UnitName,
                                c.CreateDate
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.CreateDate >= Convert.ToDateTime(startDate) && x.CreateDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.ProfessionalName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.ProfessionalName && x.ReType == "2");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                i++;
            }
            Grid4.DataSource = list;
            Grid4.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            Grid4.SummaryData = summary;
        }
        #endregion
        #region 4 设计交底管理情况 Grid5方法
        /// 
        /// 加载一般施工审批情况
        /// 
        void loadDesignDetailsApprove(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            //加载所有专业
            var CNProfessionals = from x in Funs.DB.Base_CNProfessional
                                  where x.CNProfessionalId != BLL.Const.CNProfessionalConstructId
                                  && x.CNProfessionalId != BLL.Const.ComprehensiveId
                                  orderby x.SortIndex
                                  select new
                                  {
                                      x.CNProfessionalId,
                                      x.ProfessionalName
                                  };
            foreach (var item in CNProfessionals)
            {
                var query = from c in db.Comprehensive_DesignDetails
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.CNProfessionalId == item.CNProfessionalId
                            && c.Status == "3"
                            select new
                            {
                                c.Status,
                                c.CompileDate,
                                c.ProjectId,
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.CompileDate >= Convert.ToDateTime(startDate) && x.CompileDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.ProfessionalName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.ProfessionalName && x.ReType == "3");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                i++;
            }
            Grid5.DataSource = list;
            Grid5.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            Grid5.SummaryData = summary;
        }
        #endregion
        #region 5 图纸会审管理情况 Grid6方法
        /// 
        /// 加载一图纸会审管理情况
        /// 
        void loadReviewDrawings(string objType)
        {
            var db = Funs.DB;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            var list = new List();
            int i = 1;
            int Quantity1Sum = 0;
            int Quantity2Sum = 0;
            //加载所有专业
            var CNProfessionals = from x in Funs.DB.Base_CNProfessional
                                  where x.CNProfessionalId != BLL.Const.CNProfessionalConstructId
                                  && x.CNProfessionalId != BLL.Const.ComprehensiveId
                                  orderby x.SortIndex
                                  select new
                                  {
                                      x.CNProfessionalId,
                                      x.ProfessionalName
                                  };
            foreach (var item in CNProfessionals)
            {
                var query = from c in db.Comprehensive_ReviewDrawings
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.CNProfessionalId == item.CNProfessionalId
                            && c.Status == "3"
                            select new
                            {
                                c.Status,
                                c.ReviewDate,
                                c.ProjectId,
                            };
                var AllList = query.ToList();
                var monethCount = query
                    .Where(x => (x.ReviewDate >= Convert.ToDateTime(startDate) && x.ReviewDate <= Convert.ToDateTime(endDate)));
                Model.Report_Construction_Plan model = new Model.Report_Construction_Plan();
                model.Id = Guid.NewGuid().ToString();
                model.UnitOrMajor = item.ProfessionalName;
                model.Quantity1 = monethCount.Count();
                model.Quantity2 = AllList.Count();
                model.ReportId = ReportId;
                //如果是修改,查询表中数据
                if (objType == "1")
                {
                    var NewModel = db.Report_Construction_Plan.FirstOrDefault(x => x.ReportId == ReportId && x.UnitOrMajor == item.ProfessionalName && x.ReType == "4");
                    if (NewModel != null)
                    {
                        model.Remarks = NewModel.Remarks;
                    }
                }
                list.Add(model);
                Quantity1Sum += monethCount.Count();
                Quantity2Sum += AllList.Count();
                i++;
            }
            Grid6.DataSource = list;
            Grid6.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Sum.ToString());
            summary.Add("Quantity2", Quantity2Sum.ToString());
            Grid6.SummaryData = summary;
        }
        #endregion
        #region 6 设计变更管理情况 Grid7方法
        /// 
        /// 加载设计变更管理情况
        /// 
        void loadDesignChangeOrder()
        {
            int Quantity1Sum = 0, Quantity2Sum = 0, Quantity3Sum = 0, Quantity4Sum = 0, Quantity5Sum = 0, Quantity6Sum = 0;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            DateTime projectStartDate = Convert.ToDateTime("2015-01-01");
            List StatisticsList = new List();
            Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
            if (project != null)
            {
                if (project.StartDate != null)
                {
                    projectStartDate = Convert.ToDateTime(project.StartDate);
                }
            }
            int i = 1;
            var cNProfessionals = from x in Funs.DB.Base_CNProfessional where x.CNProfessionalId != BLL.Const.CNProfessionalConstructId
                                  && x.CNProfessionalId != BLL.Const.ComprehensiveId
                                  orderby x.SortIndex select x;
            foreach (var item in cNProfessionals)
            {
                //专业下所有集合
                List totalManagementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, item.CNProfessionalId, projectStartDate, DateTime.Now);
                //专业下当期集合
                List managementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, item.CNProfessionalId, startDate, endDate);
                Model.CheckStatisc checkStatisc = new Model.CheckStatisc();
                checkStatisc.Num = i;
                checkStatisc.WorkName = item.ProfessionalName;
                checkStatisc.CheckNum = managementList.Count();
                checkStatisc.TotalCheckNum = totalManagementList.Count();
                checkStatisc.OKNum = managementList.Count(x => x.ApprovalDate != null);
                checkStatisc.TotalOKNum = totalManagementList.Count(x => x.ApprovalDate != null);
                checkStatisc.OneOKRate = managementList.Count(x => x.Status == "3").ToString();       //当期完成数
                checkStatisc.TotalOneOKRate = totalManagementList.Count(x => x.Status == "3").ToString();    //累计完成数
                StatisticsList.Add(checkStatisc);
                Quantity1Sum += checkStatisc.CheckNum;
                Quantity2Sum += checkStatisc.TotalCheckNum;
                Quantity3Sum += checkStatisc.OKNum;
                Quantity4Sum += checkStatisc.TotalOKNum;
                Quantity5Sum += Convert.ToInt32(checkStatisc.OneOKRate);
                Quantity6Sum += Convert.ToInt32(checkStatisc.TotalOneOKRate);
            }
            Grid7.DataSource = StatisticsList;
            Grid7.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("WorkName", "合计");
            summary.Add("CheckNum", Quantity1Sum.ToString());
            summary.Add("TotalCheckNum", Quantity2Sum.ToString());
            summary.Add("OKNum", Quantity3Sum.ToString());
            summary.Add("TotalOKNum", Quantity4Sum.ToString());
            summary.Add("OneOKRate", Quantity5Sum.ToString());
            summary.Add("TotalOneOKRate", Quantity6Sum.ToString());
            Grid7.SummaryData = summary;
        }
        #endregion
        #region 7.1 合格焊工管理情况 Grid8方法
        /// 
        /// 加载合格焊工管理情况
        /// 
        void loadPassWelder()
        {
            int Quantity1Sum = 0, Quantity2Sum = 0, Quantity3Sum = 0, Quantity4Sum = 0, Quantity5Sum = 0, Quantity6Sum = 0, Quantity7Sum = 0, Quantity8Sum = 0;
            DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
            DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            DateTime projectStartDate = Convert.ToDateTime("2015-01-01");
            List StatisticsList = new List();
            Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
            if (project != null)
            {
                if (project.StartDate != null)
                {
                    projectStartDate = Convert.ToDateTime(project.StartDate);
                }
            }
            int i = 1;
            var units = from x in Funs.DB.Project_ProjectUnit
                        join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
                        where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitType == BLL.Const.ProjectUnitType_2
                        orderby y.UnitCode
                        select new { x.UnitId, y.UnitName };
            var db = Funs.DB;
            foreach (var item in units)
            {
                var query = from c in db.Comprehensive_InspectionPerson
                            join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin
                            from u in unitJoin.DefaultIfEmpty()
                            join cn in db.Base_CNProfessional on c.CNProfessionalId equals cn.CNProfessionalId into cnJoin
                            from cn in cnJoin.DefaultIfEmpty()
                            join p in db.Base_Post on c.PostId equals p.PostId into postJoin
                            from p in postJoin.DefaultIfEmpty()
                            where c.ProjectId == this.CurrUser.LoginProjectId && c.UnitId == item.UnitId
                            select new
                            {
                                c.InspectionPersonId,
                                c.ProjectId,
                                u.UnitId,
                                u.UnitName,
                                c.PersonName,
                                c.ApprovalTime,
                                cn.ProfessionalName,
                                p.PostName
                            };
                //单位下所有集合
                // List totalWelderList = BLL.PersonManageService.GetWelderListByUnitId(this.CurrUser.LoginProjectId, item.UnitId);
                //List welderList = BLL.PersonManageService.GetWelderListByUnitIdAndDate(this.CurrUser.LoginProjectId, item.UnitId, startDate, endDate); 
                var totalWelderList = query.ToList();
                var welderList = query
                    .Where(x => (x.ApprovalTime >= Convert.ToDateTime(startDate) && x.ApprovalTime <= Convert.ToDateTime(endDate)));
                Model.PassWelderStatisc passWelderStatisc = new Model.PassWelderStatisc();
                passWelderStatisc.Num = i;
                passWelderStatisc.UnitName = item.UnitName;
                passWelderStatisc.PipeMountGuard = welderList.Count(x => x.ProfessionalName == "管道" && x.PostName == "焊工");
                passWelderStatisc.PipeTotal = totalWelderList.Count(x => x.ProfessionalName == "管道" && x.PostName == "焊工");
                passWelderStatisc.SteelStructureMountGuard = welderList.Count(x => x.ProfessionalName == "土建" && x.PostName == "焊工");
                passWelderStatisc.SteelStructureTotal = totalWelderList.Count(x => x.ProfessionalName == "土建" && x.PostName == "焊工");
                passWelderStatisc.EquipmentMountGuard = welderList.Count(x => x.ProfessionalName == "设备" && x.PostName == "焊工");
                passWelderStatisc.EquipmentTotal = totalWelderList.Count(x => x.ProfessionalName == "设备" && x.PostName == "焊工");
                passWelderStatisc.OtherMountGuard = welderList.Count(x => x.ProfessionalName != "管道" && x.ProfessionalName != "土建" && x.ProfessionalName != "设备" && x.PostName == "焊工");
                passWelderStatisc.OtherTotal = totalWelderList.Count(x => x.ProfessionalName != "管道" && x.ProfessionalName != "土建" && x.ProfessionalName != "设备" && x.PostName == "焊工");
                StatisticsList.Add(passWelderStatisc);
                i++;
                Quantity1Sum += passWelderStatisc.PipeMountGuard;
                Quantity2Sum += passWelderStatisc.PipeTotal;
                Quantity3Sum += passWelderStatisc.SteelStructureMountGuard;
                Quantity4Sum += passWelderStatisc.SteelStructureTotal;
                Quantity5Sum += passWelderStatisc.EquipmentMountGuard;
                Quantity6Sum += passWelderStatisc.EquipmentTotal;
                Quantity7Sum += passWelderStatisc.OtherMountGuard;
                Quantity8Sum += passWelderStatisc.OtherTotal;
            }
            Grid8.DataSource = StatisticsList;
            Grid8.DataBind();
            //合计
            JObject summary = new JObject();
            summary.Add("UnitName", "合计");
            summary.Add("PipeMountGuard", Quantity1Sum.ToString());
            summary.Add("PipeTotal", Quantity2Sum.ToString());
            summary.Add("SteelStructureMountGuard", Quantity3Sum.ToString());
            summary.Add("SteelStructureTotal", Quantity4Sum.ToString());
            summary.Add("EquipmentMountGuard", Quantity5Sum.ToString());
            summary.Add("EquipmentTotal", Quantity6Sum.ToString());
            summary.Add("OtherMountGuard", Quantity7Sum.ToString());
            summary.Add("OtherTotal", Quantity8Sum.ToString());
            Grid8.SummaryData = summary;
        }
        #endregion
        #region 7.2 PQR/WPS报验情况 Grid9方法
        protected void btnAddGrid9_Click(object sender, EventArgs e)
        {
            Grid9.Hidden = false;
            JArray teamGroupData = Grid9.GetMergedData();
            List list = new List();
            foreach (JObject teamGroupRow in teamGroupData)
            {
                JObject values = teamGroupRow.Value("values");
                values.Add("Id", teamGroupRow.Value("id"));
                list.Add(values);
            }
            JObject defaultObj = new JObject
                {   { "Id",Guid.NewGuid() },
                    { "ReportId", ReportId },
                    { "ReType", "2" },
                    { "UnitOrMajor",""},
                    { "Quantity1", "" },
                    { "Quantity2","" },
                    { "Remarks", "" },
                    { "Delete9", String.Format(" ", GetDeleteScriptGrid9(), IconHelper.GetResolvedIconUrl(Icon.Delete)) }
                };
            list.Add(defaultObj);
            Grid9.DataSource = list;
            Grid9.DataBind();
        }
        protected void Grid9_PreDataBound(object sender, EventArgs e)
        {
            // 设置LinkButtonField的点击客户端事件
            LinkButtonField deleteField = Grid9.FindColumn("Delete9") as LinkButtonField;
            deleteField.OnClientClick = GetDeleteScriptGrid9();
        }
        /// 
        /// 删除提示
        /// 
        /// 
        private string GetDeleteScriptGrid9()
        {
            return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid9.GetDeleteSelectedRowsReference(), String.Empty);
        }
        /// 
        /// 为grid9合计行
        /// 
        void OutPutSummaryGrid9()
        {
            DataTable source = ObjectToTable(Grid9.DataSource);
            int Quantity1Total = 0, Quantity2Total = 0;
            foreach (DataRow row in source.Rows)
            {
                Quantity1Total += Convert.ToInt32(row["Quantity1"]);
                Quantity2Total += Convert.ToInt32(row["Quantity2"]);
            }
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Total.ToString());
            summary.Add("Quantity2", Quantity2Total.ToString());
            Grid9.SummaryData = summary;
        }
        public static DataTable ObjectToTable(object obj)
        {
            try
            {
                Type t;
                if (obj.GetType().IsGenericType)
                {
                    t = obj.GetType().GetGenericTypeDefinition();
                }
                else
                {
                    t = obj.GetType();
                }
                if (t == typeof(List<>) ||
                    t == typeof(IEnumerable<>))
                {
                    DataTable dt = new DataTable();
                    IEnumerable
", GetDeleteScriptGrid9(), IconHelper.GetResolvedIconUrl(Icon.Delete)) }
                };
            list.Add(defaultObj);
            Grid9.DataSource = list;
            Grid9.DataBind();
        }
        protected void Grid9_PreDataBound(object sender, EventArgs e)
        {
            // 设置LinkButtonField的点击客户端事件
            LinkButtonField deleteField = Grid9.FindColumn("Delete9") as LinkButtonField;
            deleteField.OnClientClick = GetDeleteScriptGrid9();
        }
        /// 
        /// 删除提示
        /// 
        /// 
        private string GetDeleteScriptGrid9()
        {
            return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid9.GetDeleteSelectedRowsReference(), String.Empty);
        }
        /// 
        /// 为grid9合计行
        /// 
        void OutPutSummaryGrid9()
        {
            DataTable source = ObjectToTable(Grid9.DataSource);
            int Quantity1Total = 0, Quantity2Total = 0;
            foreach (DataRow row in source.Rows)
            {
                Quantity1Total += Convert.ToInt32(row["Quantity1"]);
                Quantity2Total += Convert.ToInt32(row["Quantity2"]);
            }
            JObject summary = new JObject();
            summary.Add("UnitOrMajor", "合计");
            summary.Add("Quantity1", Quantity1Total.ToString());
            summary.Add("Quantity2", Quantity2Total.ToString());
            Grid9.SummaryData = summary;
        }
        public static DataTable ObjectToTable(object obj)
        {
            try
            {
                Type t;
                if (obj.GetType().IsGenericType)
                {
                    t = obj.GetType().GetGenericTypeDefinition();
                }
                else
                {
                    t = obj.GetType();
                }
                if (t == typeof(List<>) ||
                    t == typeof(IEnumerable<>))
                {
                    DataTable dt = new DataTable();
                    IEnumerable