using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web.UI.WebControls;

namespace FineUIPro.Web.CQMS.DataBase
{
    public partial class DataBaseProject : PageBase
    {
        /// <summary>
        /// 操作文件的类型(Normal-普通文件类型,WBS-WBS文件类型)
        /// </summary>
        public string Type
        {
            get
            {
                return (string)ViewState["Type"];
            }
            set
            {
                ViewState["Type"] = value;
            }
        }

        #region 加载
        /// <summary>
        /// 加载页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetButtonPower();//权限设置
                DataTypeInitDataBind();//加载资料库类别树
            }
        }
        #endregion

        #region 绑定资料库类别
        /// <summary>
        /// 绑定资料库树节点
        /// </summary>
        private void DataTypeInitDataBind()
        {
            this.tvDataTypeInit.Nodes.Clear();
            TreeNode newNode = new TreeNode();
            newNode.Text = "资料库";
            newNode.NodeID = "0";
            newNode.Expanded = true;
            this.tvDataTypeInit.Nodes.Add(newNode);
            var list = this.GetNodes();
            foreach (var item in list)
            {
                newNode.Nodes.Add(item);
            }
        }

        private List<TreeNode> GetNodes()
        {
            var dataType = (from x in BLL.Funs.DB.DataBase_DataTypeProject
                            where x.ProjectId == this.CurrUser.LoginProjectId
                            orderby x.SortIndex
                            select x).ToList();
            List<TreeNode> treeNodes = new List<TreeNode>();
            TreeNode constructNode = null;

            foreach (var q in dataType)
            {
                if (string.IsNullOrEmpty(q.UnitWorkId))
                {
                    TreeNode newNode = new TreeNode();
                    newNode.ToolTip = q.SuperDataTypeId;
                    newNode.Text = q.DataTypeName;
                    newNode.NodeID = q.DataTypeProjectId;
                    newNode.EnableClickEvent = true;
                    treeNodes.Add(newNode);
                    if (q.SourceDataTypeId == Const.DataTypeNewConstructId)
                    {
                        constructNode = newNode;
                    }
                }
            }
            foreach (var q in treeNodes)
            {
                foreach (var p in treeNodes)
                {
                    if (q.ToolTip == p.NodeID)
                    {
                        p.Nodes.Add(q);
                    }
                }
            }

            if (constructNode != null)
            {
                var unitWorkList = BLL.UnitWorkService.GetUnitWorkLists(this.CurrUser.LoginProjectId);
                foreach (var installtion in unitWorkList)
                {
                    TreeNode newNode = new TreeNode();
                    newNode.ToolTip = Const.DataTypeNewConstructId;
                    newNode.Text = installtion.UnitWorkName;
                    newNode.NodeID = installtion.UnitWorkId;
                    newNode.EnableClickEvent = true;
                    constructNode.Nodes.Add(newNode);
                    processChildList(newNode, dataType, installtion.UnitWorkId, constructNode.NodeID);
                }
            }
            List<TreeNode> res = new List<TreeNode>();
            foreach (var q in treeNodes)
            {
                if ("0" == q.ToolTip)
                {
                    res.Add(q);
                }
                q.ToolTip = q.Text;
            }
            return res;
        }

        private void processChildList(TreeNode node, List<Model.DataBase_DataTypeProject> dataBase_DataTypeProject, string installionId, string superId)
        {
            var dataType = dataBase_DataTypeProject.Where(p => p.UnitWorkId == installionId);
            List<TreeNode> treeNodes = new List<TreeNode>();

            foreach (var q in dataType)
            {
                TreeNode newNode = new TreeNode();
                newNode.ToolTip = q.SuperDataTypeId;
                newNode.Text = q.DataTypeName;
                newNode.NodeID = q.DataTypeProjectId;
                newNode.EnableClickEvent = true;
                treeNodes.Add(newNode);
            }
            foreach (var q in treeNodes)
            {
                foreach (var p in treeNodes)
                {
                    if (q.ToolTip == p.NodeID)
                    {
                        p.Nodes.Add(q);
                    }
                }
            }
            //List<TreeNode> res = new List<TreeNode>();
            foreach (var q in treeNodes)
            {
                if (superId == q.ToolTip)
                {
                    node.Nodes.Add(q);
                }
                q.ToolTip = q.Text;
            }
        }
        #endregion

        #region 维护资料库类别
        /// <summary>
        /// 增加资料库类别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnMenuAdd_Click(object sender, EventArgs e)
        {
            string id = this.tvDataTypeInit.SelectedNodeID;
            if (!string.IsNullOrEmpty(id))
            {
                PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DataTypeProjectEdit.aspx?dataTypeProjectId={0}&&type={1}", id, "add", "编辑 - ")));
            }
        }

        /// <summary>
        /// 修改资料库类别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnMenuModify_Click(object sender, EventArgs e)
        {
            string id = this.tvDataTypeInit.SelectedNodeID;
            if (!string.IsNullOrEmpty(id) && id != "0")
            {
                PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DataTypeProjectEdit.aspx?dataTypeProjectId={0}&&type={1}", id, "edit", "编辑 - ")));
            }
            else
            {
                Alert.ShowInTop("请选择资料类别", MessageBoxIcon.Warning);
                return;
            }
        }

        /// <summary>
        /// 删除资料库类别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnMenuDel_Click(object sender, EventArgs e)
        {
            string id = this.tvDataTypeInit.SelectedNodeID;
            if (!string.IsNullOrEmpty(id) && id != "0")
            {
                Model.DataBase_DataTypeProject division = BLL.DataTypeProjectService.GetDataTypeProjectById(id);
                if (division != null)
                {
                    List<Model.DataBase_DataTypeProject> dataTypes = BLL.DataTypeProjectService.GetDataTypeProjectsBySuperDataTypeProjectId(id);
                    if (dataTypes.Count > 0)     //含有子类别
                    {
                        DeleteDetail(dataTypes);
                    }
                    BLL.DataTypeService.DeleteDataTypeById(id);
                }
            }
            else
            {
                Alert.ShowInTop("请选择资料类别", MessageBoxIcon.Warning);
                return;
            }
            DataTypeInitDataBind();
        }

        /// <summary>
        /// 循环删除子级类别
        /// </summary>
        /// <param name="dataTypes"></param>
        private void DeleteDetail(List<Model.DataBase_DataTypeProject> dataTypes)
        {
            foreach (var d in dataTypes)
            {
                List<Model.DataBase_DataTypeProject> childDataTypes = BLL.DataTypeProjectService.GetDataTypeProjectsBySuperDataTypeProjectId(d.DataTypeProjectId);
                if (childDataTypes.Count > 0)
                {
                    DeleteDetail(childDataTypes);
                }
                BLL.DataTypeProjectService.DeleteDataTypeProject(d.DataTypeProjectId);
            }
        }
        #endregion

        #region 关闭弹出窗口
        /// <summary>
        /// 关闭编辑资料库类别弹出窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Window1_Close(object sender, WindowCloseEventArgs e)
        {
            DataTypeInitDataBind();
        }

        /// <summary>
        /// 关闭弹出窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Window2_Close(object sender, WindowCloseEventArgs e)
        {
            BindGridStartWorkReport();
            BindGridFile();
            BindGridUnit4();
            BindDataPhoto();
        }
        #endregion

        #region 树点击事件
        /// <summary>
        /// 资料库类别树点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void tvDataTypeInit_NodeCommand(object sender, TreeCommandEventArgs e)
        {
            this.panel3.Hidden = true;
            this.btnNew.Hidden = true;
            this.tvUnit3.Hidden = true;
            this.tvUnit2.Hidden = true;
            this.tvUnit4.Hidden = true;
            this.tvUnit.Hidden = true;
            this.tvWBS.Hidden = true;
            this.tvWBS2.Hidden = true;
            this.tvCN.Hidden = true;
            this.gvFile5.Hidden = true;
            this.gvFile.Hidden = true;
            this.gvFile3.Hidden = true;
            this.gvUnit3.Hidden = true;
            this.gvUnit2.Hidden = true;
            this.gvUnit4.Hidden = true;
            this.gvUnit.Hidden = true;
            this.gvFile2.Hidden = true; 
            this.gvWBS2.Hidden = true;
            this.gvCN.Hidden = true;
            this.gvPhoto.Hidden = true;
            this.gvInspectionPerson.Hidden = true;
            this.gvNCRManagement.Hidden = true;
            this.gvQualityAccident.Hidden = true;
            this.gvGeneralPlanApproval.Hidden = true;
            this.gvDesignDetails.Hidden = true;
            this.gvDesignChangeOrder.Hidden = true;
            this.gvMajorPlanApproval.Hidden = true;
            this.gvInspectionManagement.Hidden = true;
            this.gvInspectionEquipment.Hidden = true;

            string dataTypeProjectId = this.tvDataTypeInit.SelectedNodeID;
            if (this.tvDataTypeInit.SelectedNode.Nodes.Count == 0)
            {
                if (this.tvDataTypeInit.SelectedNode.ParentNode != null)
                {
                    Model.DataBase_DataTypeProject dataTypeProject = BLL.DataTypeProjectService.GetDataTypeProjectById(dataTypeProjectId);
                    Model.DataBase_DataTypeProject parentDataTypeProject = BLL.DataTypeProjectService.GetDataTypeProjectById(this.tvDataTypeInit.SelectedNode.ParentNode.NodeID);
                    if (dataTypeProject != null)
                    {
                        if (dataTypeProject.IsRelatedWBS == true)   //关联WBS文件类型
                        {
                            if (parentDataTypeProject != null)
                            {
                                this.panel3.Hidden = false;
                                this.tvWBS.Hidden = false;
                                this.gvFile2.Hidden = false;
                                this.Type = "WBS";
                                if (parentDataTypeProject.DataTypeName.Contains("建筑工程施工册"))
                                {
                                    this.WBSDataBind("Construct");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("设备安装施工册"))
                                {
                                    this.WBSDataBind("EQ");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("管道安装施工册"))
                                {
                                    this.WBSDataBind("PP");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("电气安装施工册"))
                                {
                                    this.WBSDataBind("EL");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("电信安装施工册"))
                                {
                                    this.WBSDataBind("TC");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("仪表安装施工册"))
                                {
                                    this.WBSDataBind("IN");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("消防工程施工册"))
                                {
                                    this.WBSDataBind("XF");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("防腐绝热工程施工册"))
                                {
                                    this.WBSDataBind("FF");
                                }
                            }
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("分项工程质量验收记录"))//验收
                        {
                            if (parentDataTypeProject.DataTypeName.Contains("建筑工程施工册"))
                            {
                                this.Type = "WBSYellow";
                                this.panel3.Hidden = false;
                                this.tvWBS.Hidden = false;
                                this.gvFile2.Hidden = false;
                                this.WBSDataBind("Construct");
                            }
                            else
                            {
                                this.panel3.Hidden = false;
                                this.tvWBS2.Hidden = false;
                                this.gvWBS2.Hidden = false;
                                if (parentDataTypeProject.DataTypeName.Contains("设备安装施工册"))
                                {
                                    this.WBSDataBind2("EQ");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("管道安装施工册"))
                                {
                                    this.WBSDataBind2("PP");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("电气安装施工册"))
                                {
                                    this.WBSDataBind2("EL");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("电信安装施工册"))
                                {
                                    this.WBSDataBind2("TC");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("仪表安装施工册"))
                                {
                                    this.WBSDataBind2("IN");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("消防工程施工册"))
                                {
                                    this.WBSDataBind2("XF");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("防腐绝热工程施工册"))
                                {
                                    this.WBSDataBind2("FF");
                                }
                            }
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("总包单位及人员资质报验")) //总包单位及人员资质报验
                        {
                            this.gvFile3.Hidden = false;
                            BindGridFile3();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("材料报审文件(报审表 SH/T 3903-A9)"))
                        {
                            if (parentDataTypeProject != null)
                            {
                                this.panel3.Hidden = false;
                                this.tvUnit.Hidden = false;
                                this.gvUnit.Hidden = false;
                                if (parentDataTypeProject.DataTypeName.Contains("建筑工程材料册"))
                                {
                                    this.UnitDataBind("Construct");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("设备安装材料册"))
                                {
                                    this.UnitDataBind("FE");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("管道安装材料册"))
                                {
                                    this.UnitDataBind("PD");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("电气电信安装材料册"))
                                {
                                    this.UnitDataBind("EH");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("仪表安装材料册"))
                                {
                                    this.UnitDataBind("EA");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("消防工程材料册"))
                                {
                                    this.UnitDataBind("XF");
                                }
                                else if (parentDataTypeProject.DataTypeName.Contains("防腐绝热工程材料册"))
                                {
                                    this.UnitDataBind("FF");
                                }
                            }
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("现场原貌") || this.tvDataTypeInit.SelectedNode.Text.Contains("开工典礼") || this.tvDataTypeInit.SelectedNode.Text.Contains("过程实体记录") || this.tvDataTypeInit.SelectedNode.Text.Contains("过程活动记录") || this.tvDataTypeInit.SelectedNode.Text.Contains("验收(现场检查、竣工验收会)") || this.tvDataTypeInit.SelectedNode.Text.Contains("新貌(室内、外及周边环境等)"))
                        {
                            this.Type = "Photo";
                            this.gvPhoto.Hidden = false;
                            this.btnNew.Hidden = false;
                            BindDataPhoto();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("施工项目部管理人员名单"))
                        {
                            this.gvInspectionPerson.Hidden = false;
                            this.hdPostId.Text = Const.PostMangerId;
                            BindDataInspectionPerson();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("特种作业人员名单"))
                        {
                            this.gvInspectionPerson.Hidden = false;
                            BindDataInspectionPerson();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("不合格项处置记录"))
                        {
                            this.gvNCRManagement.Hidden = false;
                            BindDataNCRManagement();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("建设工程质量事故调(勘)查记录"))
                        {
                            this.gvQualityAccident.Hidden = false;
                            BindDataQualityAccident();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("建设工程质量事故报告书"))
                        {
                            this.gvQualityAccident.Hidden = false;
                            BindDataQualityAccident();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("工程技术文件报审表"))
                        {
                            this.gvGeneralPlanApproval.Hidden = false;
                            this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                            BindDataGeneralPlanApproval();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("设计交底记录"))
                        {
                            this.gvDesignDetails.Hidden = false;
                            this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                            BindDataDesignDetails();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("图纸会审记录"))
                        {
                            this.gvDesignDetails.Hidden = false;
                            this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                            BindDataDesignDetails();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("设计变更通知单"))
                        {
                            this.gvDesignChangeOrder.Hidden = false;
                            this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                            BindDataDesignChangeOrder();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("工程洽商记录"))
                        {
                            this.gvDesignChangeOrder.Hidden = false;
                            this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                            BindDataDesignChangeOrder();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("危险性较大分部分项工程施工方案专家论证表"))
                        {
                            this.gvMajorPlanApproval.Hidden = false;
                            this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                            BindDataMajorPlanApproval();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("钢材出厂合格证、试验报告核查要录"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "1";
                            BindDataInspectionEquipment();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("钢筋机械连接、焊接接头检验报告核查要录"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "2";
                            BindDataInspectionEquipment();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("水泥合格证、试验报告核查要录"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "3";
                            BindDataInspectionEquipment();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("砖石(砌块)合格证、试验报告核查要录"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "4";
                            BindDataInspectionEquipment();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("防水材料合格证、检验报告核查要录"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "5";
                            BindDataInspectionEquipment();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("其它材料、构件合格证、试验报告核查要录"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "6";
                            BindDataInspectionEquipment();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("混凝土、砂浆试件抗压强度试验报告核查要录"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "7";
                            BindDataInspectionEquipment();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("混凝土抗渗试件试验报告核查要录"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "8";
                            BindDataInspectionEquipment();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("商品混凝土进场验收记录"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "9";
                            BindDataInspectionEquipment();
                        }
                        else if (this.tvDataTypeInit.SelectedNode.Text.Contains("试样/试件台账"))
                        {
                            this.gvInspectionEquipment.Hidden = false;
                            this.hdAttribute.Text = "10";
                            BindDataInspectionEquipment();
                        }
                        else if (parentDataTypeProject.SourceDataTypeId == Const.DataTypeCConstructId)
                        {
                            if (dataTypeProject.DataTypeName.Contains("工程定位测量记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("地基验槽记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId2);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("桩位测量放线检查记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId3);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("楼层放线记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId4);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("楼层标高抄测记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId5);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("沉降观测记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId6);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("建筑物垂直度、标高测量记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId7);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("钢结构主体结构整体垂直度、平面弯曲、标高观测记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId8);
                            }
                        }
                        else if (parentDataTypeProject.SourceDataTypeId == Const.DataTypeDConstructId)
                        {
                            if (dataTypeProject.DataTypeName.Contains("隐蔽工程检查记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId9);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("地基处理记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId10);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("地基钎探记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId11);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("桩开孔通知书"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId12);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("钻孔灌注桩施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId13);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("钻孔灌注桩后注浆施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId14);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("钻孔灌注桩施工记录汇总表"))
                            {
                                this.btnNew.Hidden = false;
                                this.gvFile.Hidden = false;
                                this.Type = "Normal";    //普通文件类型
                                BindGridFile();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("钻孔灌注桩终孔验收记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId15);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("人工挖孔桩隐蔽工程记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId16);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("振动(锤击)沉管灌注桩施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId17);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("夯扩桩施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId18);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("长螺旋成孔压灌桩施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId19);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("深层搅拌桩施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId20);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("静压混凝土预制桩、钢桩施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId21);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("锤击混凝土预制桩、钢桩施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId22);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("人工挖孔桩施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId23);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("桩位偏差验收记录表"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId24);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("工程试打桩记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId25);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("混凝土施工记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId26);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("混凝土坍落度测量记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId27);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("混凝土养护测温记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId28);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("大体积混凝土测温记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId29);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("同条件养护试块测温记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId30);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("标养室温湿度记录"))
                            {
                                this.btnNew.Hidden = false;
                                this.gvFile.Hidden = false;
                                this.Type = "Normal";    //普通文件类型
                                BindGridFile();

                            }
                            else if (dataTypeProject.DataTypeName.Contains("混凝土开盘鉴定"))
                            {
                                this.btnNew.Hidden = false;
                                this.gvFile.Hidden = false;
                                this.Type = "Normal";    //普通文件类型
                                BindGridFile();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("预应力筋张拉记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId31);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("有粘结预应力结构灌浆记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId32);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("混凝土拆模申请单"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId33);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("钢结构安装检查记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId34);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("幕墙打胶检查记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId35);
                            }
                        }
                        else if (parentDataTypeProject.SourceDataTypeId == Const.DataTypeEConstructId)
                        {
                            if (dataTypeProject.DataTypeName.Contains("混凝土结构子分部工程结构实体位置与尺寸偏差检验记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId36);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("混凝土试块强度统计、评定记录表"))
                            {
                                this.btnNew.Hidden = false;
                                this.gvFile.Hidden = false;
                                this.Type = "Normal";    //普通文件类型
                                BindGridFile();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("砌筑砂浆试块强度统计、评定记录"))
                            {
                                this.btnNew.Hidden = false;
                                this.gvFile.Hidden = false;
                                this.Type = "Normal";    //普通文件类型
                                BindGridFile();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("防水工程试水检查记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId37);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("地下工程防水效果检查记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId38);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("幕墙淋水检查记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId39);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("绝热材料点燃试验记录"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId40);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("复合地基载荷试验检测报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId41);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("基桩竖向抗压静载荷试验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId42);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("桩体质量检测--基桩反射波法检测报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId43);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("土工击实试验检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId44);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("土工环刀法测密度检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId45);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("钢结构焊缝超声波探伤检测报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId46);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("超声波探伤记录"))
                            {
                                this.btnNew.Hidden = false;
                                this.gvFile.Hidden = false;
                                this.Type = "Normal";    //普通文件类型
                                BindGridFile();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("后置埋件试验检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject,Const.SourceBreakdownId47);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("高强度螺栓连接摩擦面抗滑移系数检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId48);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("扭剪型高强度螺栓连接副紧固预拉力检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId49);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("高强度螺栓连接副扭矩系数检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId50);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("螺栓实物最小荷载检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId51);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("钢结构涂料涂层厚度检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId52);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("主体结构实体检验报告(混凝土强度检测、钢筋分布检测、楼板厚度检测、拉结筋抗拔力检测)"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId53);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("混凝土中钢筋保护层厚度检验检测报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId54);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("建筑外窗检测报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId55);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("饰面砖粘结强度检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId56);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("外墙饰面层粘结质量(红外法)检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId57);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("硅酮结构胶相容性检验报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId58);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("室内环境质量检测报告"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId59);
                            }
                        }
                        else if (parentDataTypeProject.SourceDataTypeId == Const.DataTypeGConstructId)
                        {
                            if (dataTypeProject.DataTypeName.Contains("单位(子单位)工程质量竣工验收"))
                            {
                                GetInspectionManagement(dataTypeProject, Const.SourceBreakdownId60);
                            }
                            else if (dataTypeProject.DataTypeName.Contains("地基与基础分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId1) + "," + getChildDivideIds(Const.DivisionId2);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');

                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("主体结构分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId3) + "," + getChildDivideIds(Const.DivisionId4);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("建筑装饰装修分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId5) + "," + getChildDivideIds(Const.DivisionId6);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("屋面分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId7) + "," + getChildDivideIds(Const.DivisionId8);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("建筑给水排水及供暖分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId9) + "," + getChildDivideIds(Const.DivisionId10);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("通风与空调分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId11);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("建筑电气分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId12);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("智能建筑分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId13);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("建筑节能分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId14);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                            else if (dataTypeProject.DataTypeName.Contains("电梯分部工程质量验收"))
                            {
                                this.gvInspectionManagement.Hidden = false;
                                string ids = getChildDivideIds(Const.DivisionId15);
                                ids = getBreakDownIds(ids);
                                var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, ids);
                                if (breakdownProjects != null)
                                {
                                    string breakdownProjectIds = "";
                                    foreach (var item in breakdownProjects)
                                    {
                                        breakdownProjectIds += item.BreakdownProjectId + ",";
                                    }
                                    this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
                                }
                                else
                                {
                                    this.hdControlPointType.Text = "";
                                }
                                this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
                                BindGridInspectionManagement();
                            }
                        }
                        else
                        {
                            if (this.tvDataTypeInit.SelectedNode.Text.Contains("施工设计交底管理"))
                            {
                                this.gvFile3.Hidden = false;
                                BindGridFile3();
                            }
                            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("设备报审文件 (报审表 SH/T 3903-A9)"))
                            {
                                this.panel3.Hidden = false;
                                this.tvCN.Hidden = false;
                                this.gvCN.Hidden = false;
                                this.CNDataBind();
                            }
                            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("施工单位和特种作业人员资质证明文件"))
                            {
                                this.panel3.Hidden = false;
                                this.tvUnit2.Hidden = false;
                                this.gvUnit2.Hidden = false;
                                BindUnit2();
                            }
                            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("专业工程重大质量事故处理鉴定报告"))
                            {
                                this.panel3.Hidden = false;
                                this.tvUnit2.Hidden = false;
                                this.gvUnit2.Hidden = false;
                                BindUnit2();
                            }
                            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("施工技术方案、施工技术措施(包括冬季施工措施)、施工作业指导书等报批文件"))
                            {
                                this.panel3.Hidden = false;
                                this.tvUnit2.Hidden = false;
                                this.gvUnit2.Hidden = false;
                                BindUnit2();
                            }
                            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("施工设备、机具和检测量器具等报审报批文件"))
                            {
                                this.panel3.Hidden = false;
                                this.tvUnit2.Hidden = false;
                                this.gvUnit2.Hidden = false;
                                BindUnit2();
                            }
                            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("专业设计变更文件"))
                            {
                                this.gvFile3.Hidden = false;
                                BindGridFile3();
                            }
                            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("设计技术交底和设计图纸会审纪要"))
                            {
                                this.panel3.Hidden = false;
                                this.tvUnit2.Hidden = false;
                                this.gvUnit2.Hidden = false;
                                BindUnit2();
                            }
                            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("开工报告"))
                            {
                                this.btnNew.Hidden = false;
                                this.Type = "StartWork";
                                if (parentDataTypeProject.DataTypeName.Contains("综合卷"))
                                {
                                    this.gvFile5.Hidden = false;
                                    BindGridStartWorkReport();//绑定开工报告
                                }
                                else
                                {
                                    this.panel3.Hidden = false;
                                    this.tvUnit3.Hidden = false;
                                    this.gvUnit3.Hidden = false;
                                    BindUnit3();
                                }
                            }
                            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("施工技术交底或/和会审记录") || this.tvDataTypeInit.SelectedNode.Text.Contains("综合性工程技术专题会议记录、纪要、备忘录") || this.tvDataTypeInit.SelectedNode.Text.Contains("专业技术总结"))
                            {
                                this.panel3.Hidden = false;
                                this.tvUnit4.Hidden = false;
                                this.gvUnit4.Hidden = false;
                                this.Type = "Normal4";    //普通文件类型4
                                BindUnit4();
                            }
                            else
                            {
                                this.btnNew.Hidden = false;
                                this.gvFile.Hidden = false;
                                this.Type = "Normal";    //普通文件类型
                                BindGridFile();//不关联WBS文件类型
                            }
                        }
                    }
                }
            }
        }

        
        private void GetInspectionManagement(Model.DataBase_DataTypeProject dataTypeProject,string sourceBreakdownId)
        {
            this.gvInspectionManagement.Hidden = false;
            var breakdownProjects = BLL.BreakdownProjectService.GetBreakdownProjectsBySourceBreakdownId(this.CurrUser.LoginProjectId, dataTypeProject.UnitWorkId, sourceBreakdownId);
            if (breakdownProjects != null)
            {
                string breakdownProjectIds = "";
                foreach (var item in breakdownProjects)
                {
                    breakdownProjectIds += item.BreakdownProjectId + ",";
                }
                this.hdControlPointType.Text = breakdownProjectIds.TrimEnd(',');
            }
            else
            {
                this.hdControlPointType.Text = "";
            }
            this.hdUnitWorkId.Text = dataTypeProject.UnitWorkId;
            BindGridInspectionManagement();
        }

        private string getChildDivideIds(string id)
        {
            string ids = "";
            var divisions = (from x in BLL.Funs.DB.WBS_Division
                             orderby x.SortIndex
                             select x).ToList();
            List<TreeNode> nodes = new List<TreeNode>();
            foreach (var q in divisions)
            {
                TreeNode newNode = new TreeNode();
                newNode.ToolTip = q.SuperDivisionId;
                newNode.Text = q.DivisionName;
                newNode.NodeID = q.DivisionId;
                nodes.Add(newNode);
            }
            foreach (var q in nodes)
            {
                foreach (var p in nodes)
                {
                    if (q.NodeID == p.ToolTip)
                    {
                        q.Nodes.Add(p);
                    }
                }
            }
            foreach (TreeNode q in nodes)
            {
                if (q.NodeID == id)
                {
                    ids = getChildIds(q);
                }
            }
            return ids;
        }

        private string getChildIds(TreeNode newNode)
        {
            string res = "";
            res = newNode.NodeID;
            if (newNode.Nodes.Count > 0)
            {
                foreach (TreeNode item in newNode.Nodes)
                    res += "," + getChildIds(item);
            }
            return res;
        }

        private string getBreakDownIds(string ids)
        {
            string res = "";
            string[] i = ids.Split(',');
            var divisions = (from x in BLL.Funs.DB.WBS_Breakdown
                             where i.Contains(x.DivisionId)
                             orderby x.SortIndex
                             select x.BreakdownId).ToList();
            foreach (var s in divisions)
            {
                res += s + ",";
            }
            res = res.TrimEnd(',');
            return res;
        }

        #endregion

        #region 增加
        /// <summary>
        /// 增加文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnNew_Click(object sender, EventArgs e)
        {
            if (this.tvDataTypeInit.SelectedNode != null && tvDataTypeInit.SelectedNode.Nodes.Count == 0)
            {
                string dataTypeProjectId = this.tvDataTypeInit.SelectedNodeID;
                if (this.Type == "Normal")
                {
                    PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("FileEdit.aspx?dataTypeProjectId={0}", dataTypeProjectId, "编辑 - ")));
                }
                else if (this.Type == "Normal4")
                {
                    PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("FileEdit.aspx?dataTypeProjectId={0}&&unitId={1}", dataTypeProjectId, this.tvUnit4.SelectedNodeID, "编辑 - ")));
                }
                else if (this.Type == "Photo")
                {
                    PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("PhotoEdit.aspx?dataTypeProjectId={0}", dataTypeProjectId, "编辑 - ")));
                }
                else if (this.Type == "StartWork")
                {
                    PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("StartWorkEdit.aspx?type={0}&&dataTypeProjectId={1}&&cNProfessionalId={2}", "add", dataTypeProjectId, GetCNId(this.tvDataTypeInit.SelectedNode.ParentNode.Text), "编辑 - ")));
                }
                else if (this.Type == "WBS")
                {
                    if (BLL.DivisionProjectService.GetDivisionProjectById(this.tvWBS.SelectedNodeID) == null)
                    {
                        Alert.ShowInTop("请选择分部!", MessageBoxIcon.Warning);
                        return;
                    }
                    PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("WBSFileEdit.aspx?dataTypeProjectId={0}&&divisionProjectId={1}", dataTypeProjectId, this.tvWBS.SelectedNode.NodeID, "编辑 - ")));
                }
                else if (this.Type == "WBSYellow")
                {
                    if (BLL.DivisionProjectService.GetDivisionProjectById(this.tvWBS.SelectedNodeID) == null)
                    {
                        Alert.ShowInTop("请选择分部!", MessageBoxIcon.Warning);
                        return;
                    }
                    PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("WBSFileEdit.aspx?dataTypeProjectId={0}&&divisionProjectId={1}&&yellow={2}", dataTypeProjectId, this.tvWBS.SelectedNode.NodeID, "Yellow", "编辑 - ")));
                }
                else if (this.Type == "分项工程质量验收记录")
                {
                    if (BLL.DivisionProjectService.GetDivisionProjectById(this.tvWBS2.SelectedNodeID) == null)
                    {
                        Alert.ShowInTop("请选择分部!", MessageBoxIcon.Warning);
                        return;
                    }
                    PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("WBS2FileEdit.aspx?dataTypeProjectId={0}&&divisionProjectId={1}", dataTypeProjectId, this.tvWBS.SelectedNode.NodeID, "编辑 - ")));
                }
                else
                {
                    PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("FileEdit2.aspx?dataTypeProjectId={0}&&divisionProjectId={1}&&unitWorkId={2}", dataTypeProjectId, this.tvWBS.SelectedNode.NodeID, this.hdUnitWorkId.Text.Trim(), "编辑 - ")));
                }
            }
            else
            {
                Alert.ShowInTop("请选择子分部工程!", MessageBoxIcon.Warning);
                return;
            }
        }
        #endregion

        #region 开工报告
        /// <summary>
        /// 开工报告数据绑定
        /// </summary>
        private void BindGridStartWorkReport()
        {
            string strSql = @"SELECT StartWorkReport.StartWorkReportId,
                                     StartWorkReport.ProjectId,
                                     StartWorkReport.DataTypeProjectId,
                                     StartWorkReport.FileCode,
                                     StartWorkReport.FileContent,
                                     StartWorkReport.CNProfessionalId,
                                     StartWorkReport.UnitWorkIds,
                                     StartWorkReport.UnitIds,
                                     StartWorkReport.Remark,
                                     StartWorkReport.AttachUrl,
                                     StartWorkReport.CompileMan,
                                     StartWorkReport.CompileDate,
                                     CNPro.ProfessionalName AS ProfessionalName,
                                    STUFF(( SELECT ',' + UnitWorkName FROM WBS_UnitWork
                                            where PATINDEX('%,' + RTRIM(WBS_UnitWork.UnitWorkId) + ',%',',' + StartWorkReport.UnitWorkIds + ',')>0
                                            ORDER BY PATINDEX('%,' + RTRIM(StartWorkReport.UnitWorkIds) + ',%',',' + StartWorkReport.UnitWorkIds + ',')
                                    FOR XML PATH('')), 1, 1,'') AS UnitWorkNameS,
                                    STUFF(( SELECT ',' + UnitName FROM Base_Unit
                                            where PATINDEX('%,' + RTRIM(Base_Unit.UnitId) + ',%',',' + StartWorkReport.UnitIds + ',')>0
                                            ORDER BY PATINDEX('%,' + RTRIM(StartWorkReport.UnitIds) + ',%',',' + StartWorkReport.UnitIds + ',')
                                    FOR XML PATH('')), 1, 1,'') AS UnitNameS "
                               + @" FROM DataBase_StartWorkReport AS StartWorkReport "
                               + @" LEFT JOIN Base_CNProfessional AS CNPro ON CNPro.CNProfessionalId = StartWorkReport.CNProfessionalId"
                               + @" WHERE StartWorkReport.ProjectId=@projectId AND StartWorkReport.DataTypeProjectId=@dataTypeProjectId ";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@dataTypeProjectId", this.tvDataTypeInit.SelectedNodeID));
            if (!string.IsNullOrEmpty(this.tvDataTypeInit.SelectedNode.ParentNode.Text))
            {
                var result = GetCNId(this.tvDataTypeInit.SelectedNode.ParentNode.Text);
                if (result != "0")
                {
                    strSql += "  AND StartWorkReport.CNProfessionalId=@CNProfessionalId";
                    listStr.Add(new SqlParameter("@CNProfessionalId", result));
                }
            }
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvFile5.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvFile5, tb);
            gvFile5.DataSource = table;
            gvFile5.DataBind();
        }

        #region 分页、排序
        protected void gvFile5_Sort(object sender, GridSortEventArgs e)
        {
            gvFile5.SortDirection = e.SortDirection;
            gvFile5.SortField = e.SortField;
            BindGridStartWorkReport();
        }

        protected void gvFile5_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvFile5.PageIndex = e.NewPageIndex;
            BindGridStartWorkReport();
        }

        protected void ddlgv5PageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvFile5.PageSize = Convert.ToInt32(ddlgv5PageSize.SelectedValue);
            BindGridStartWorkReport();
        }
        #endregion

        /// <summary>
        /// 编辑
        /// </summary>
        private void EditDataStartWorkReport()
        {
            if (gvFile5.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
                return;
            }
            PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("StartWorkEdit.aspx?startWorkReportId={0}", gvFile5.SelectedRowID, "编辑 - ")));
        }

        /// <summary>
        /// 开工报告行双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvFile5_RowDoubleClick(object sender, GridRowClickEventArgs e)
        {
            EditDataStartWorkReport();
        }

        /// <summary>
        /// 开工报告行点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvFile5_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvFile5.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }

        /// <summary>
        /// 开工报告右键编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnMenuEdit2_Click(object sender, EventArgs e)
        {
            EditDataStartWorkReport();
        }

        /// <summary>
        /// 开工报告右键删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnMenuDel2_Click(object sender, EventArgs e)
        {
            if (gvFile5.SelectedRowIndexArray.Length > 0)
            {
                foreach (int rowIndex in gvFile5.SelectedRowIndexArray)
                {
                    string rowID = gvFile5.DataKeys[rowIndex][0].ToString();
                    var startWorkReport = BLL.StartWorkReportService.GetStartWorkReportById(rowID);
                    if (startWorkReport != null)
                    {
                        BLL.StartWorkReportService.DeleteStartWorkReportById(rowID);
                    }
                }
                BindGridStartWorkReport();
                ShowNotify("删除数据成功!", MessageBoxIcon.Success);
            }
        }
        #endregion

        #region File
        /// <summary>
        /// 绑定gvFile
        /// </summary>
        private void BindGridFile()
        {
            string strSql = @"SELECT Files.FileId,
                                     Files.ProjectId,
                                     Files.DataTypeProjectId,
                                     Files.FileCode,
                                     Files.FileName,
                                     Files.Pages,
                                     Files.Remark,
                                     Files.CompileDate,
                                     Files.CompileMan,
                                     Files.AttachUrl,
                                     Files.UnitWorkId,
                                     Files.DivisionProjectId,
                                     Files.UnitId,
                                     Files.FileType,
                                     U.UserName AS CompileManName,
                                     Unit.UnitName,
                                     UnitWork.UnitWorkName "
                               + @" FROM DataBase_File AS Files "
                               + @" LEFT JOIN Sys_User AS U ON U.UserId = Files.CompileMan "
                               + @" LEFT JOIN Base_Unit AS Unit ON Unit.UnitId = Files.UnitId "
                               + @" LEFT JOIN WBS_UnitWork AS UnitWork ON UnitWork.UnitWorkId = Files.UnitWorkId "
                               + @" WHERE Files.ProjectId=@projectId AND Files.DataTypeProjectId=@dataTypeProjectId ";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@dataTypeProjectId", this.tvDataTypeInit.SelectedNodeID));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvFile.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvFile, tb);
            gvFile.DataSource = table;
            gvFile.DataBind();
        }

        #region 分页、排序
        protected void gvFile_Sort(object sender, GridSortEventArgs e)
        {
            gvFile.SortDirection = e.SortDirection;
            gvFile.SortField = e.SortField;
            BindGridFile();
        }

        protected void gvFile_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvFile.PageIndex = e.NewPageIndex;
            BindGridFile();
        }

        protected void ddlgvFilePageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvFile.PageSize = Convert.ToInt32(ddlgvFilePageSize.SelectedValue);
            BindGridFile();
        }
        #endregion

        /// <summary>
        /// 编辑
        /// </summary>
        private void EditDataFile()
        {
            if (gvFile.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
                return;
            }
            PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("FileEdit.aspx?fileId={0}", gvFile.SelectedRowID, "编辑 - ")));
        }

        /// <summary>
        /// gvFile行双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvFile_RowDoubleClick(object sender, GridRowClickEventArgs e)
        {
            EditDataFile();
        }

        protected void btnMenuFileEdit_Click(object sender, EventArgs e)
        {
            EditDataFile();
        }

        protected void btnMenuFileDel_Click(object sender, EventArgs e)
        {
            if (gvFile.SelectedRowIndexArray.Length > 0)
            {
                foreach (int rowIndex in gvFile.SelectedRowIndexArray)
                {
                    string rowID = gvFile.DataKeys[rowIndex][0].ToString();
                    var database = BLL.FileService.GetFileById(rowID);
                    if (database != null)
                    {
                        BLL.FileService.DeleteFileById(rowID);
                    }
                }
                BindGridFile();
                ShowNotify("删除数据成功!", MessageBoxIcon.Success);
            }
        }

        /// <summary>
        /// gvFile行点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvFile_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvFile.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region File3
        private void BindGridFile3()
        {
            string strSql = @"SELECT D.DataBaseId,
                                     D.ProjectId,
                                     D.UnitId,
                                     D.CNProfessionalId,
                                     D.FileCode,
                                     D.FileNames,
                                     D.FileType,
                                     D.Dates,
                                     D.Man,
                                     D.Url,
                                     D.Major "
                               + @" FROM View_DataBaseProject D "
                               + @" WHERE D.ProjectId=@projectId  ";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            if (this.tvDataTypeInit.SelectedNode.Text.Contains("施工技术方案、施工技术措施(包括冬季施工措施)、施工作业指导书等报批文件"))
            {
                strSql += "  AND D.FileType=@FileType";
                listStr.Add(new SqlParameter("@FileType", "施工技术方案、施工技术措施(包括冬季施工措施)、施工作业指导书等报批文件"));
            }
            else if (this.tvDataTypeInit.SelectedNode.Text.Contains("总包单位及人员资质报验"))
            {
                strSql += "  AND D.FileType=@FileType";
                listStr.Add(new SqlParameter("@FileType", "施工单位和特种作业人员资质证明文件"));
            }
            else
            {
                strSql += "  AND D.FileType=@FileType";
                listStr.Add(new SqlParameter("@FileType", this.tvDataTypeInit.SelectedNode.Text));
            }
            if (!string.IsNullOrEmpty(this.GetCN(this.tvDataTypeInit.SelectedNode.ParentNode.Text)))
            {
                strSql += "  AND D.Major=@Major";
                listStr.Add(new SqlParameter("@Major", this.GetCN(this.tvDataTypeInit.SelectedNode.ParentNode.Text)));
            }
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvFile3.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvFile3, tb);
            gvFile3.DataSource = table;
            gvFile3.DataBind();
        }

        protected void gvFile3_Sort(object sender, GridSortEventArgs e)
        {
            gvFile3.SortDirection = e.SortDirection;
            gvFile3.SortField = e.SortField;
            BindGridFile3();
        }

        protected void gvFile3_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvFile.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }

        protected void gvFile3_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvFile3.PageIndex = e.NewPageIndex;
            BindGridFile3();
        }

        protected void ddlgvFile3PageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvFile3.PageSize = Convert.ToInt32(ddlgvFile3PageSize.SelectedValue);
            BindGridFile3();
        }
        #endregion

        #region 获取按钮权限
        /// <summary>
        /// 获取按钮权限
        /// </summary>
        /// <param name="button"></param>
        /// <returns></returns>
        private void GetButtonPower()
        {
            var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DataBaseProjectMenuId);
            if (buttonList.Count() > 0)
            {
                if (buttonList.Contains(BLL.Const.BtnAdd))
                {
                    this.btnMenuAdd.Hidden = false;
                    //this.btnNew.Hidden = false;
                }
                if (buttonList.Contains(BLL.Const.BtnModify))
                {
                    this.btnMenuModify.Hidden = false;
                    this.btnMenuEdit2.Hidden = false;
                    this.btnMenuEditUnit4.Hidden = false;
                    this.btnMenuFileEdit.Hidden = false;
                    this.btnMenuUnit3Edit.Hidden = false;
                    this.btnMenuWBS2Edit.Hidden = false;
                    this.btnMenuPhotoEdit.Hidden = false;
                }
                if (buttonList.Contains(BLL.Const.BtnDelete))
                {
                    this.btnMenuDel.Hidden = false;
                    this.btnMenuDel2.Hidden = false;
                    this.btnMenuDelUnit4.Hidden = false;
                    this.btnMenuFileDel.Hidden = false;
                    this.btnMenuUnit3Del.Hidden = false;
                    this.btnMenuWBS2Del.Hidden = false;
                    this.btnMenuPhotoDel.Hidden = false;
                }
            }
        }

        #endregion

        #region 获取专业
        /// <summary>
        /// 根据选择的树节点查找对应的专业
        /// </summary>
        /// <param name="parentText"></param>
        /// <returns></returns>
        private string GetCNId(string parentText)
        {
            var cns = from x in Funs.DB.Base_CNProfessional select x;
            string cNProfessionalId = string.Empty;
            if (parentText.Contains("综合卷"))
            {
                cNProfessionalId = "0";
            }
            else if (parentText.Contains("建筑工程综合册"))
            {
                cNProfessionalId = cns.First(x => x.ProfessionalName == "建筑工程").CNProfessionalId;
            }
            else if (parentText.Contains("设备安装综合册"))
            {
                cNProfessionalId = cns.First(x => x.ProfessionalName == "设备").CNProfessionalId;
            }
            else if (parentText.Contains("管道安装综合册"))
            {
                cNProfessionalId = cns.First(x => x.ProfessionalName == "管道").CNProfessionalId;
            }
            else if (parentText.Contains("电气电信安装综合册"))
            {
                cNProfessionalId = cns.First(x => x.ProfessionalName == "电气").CNProfessionalId;
            }
            else if (parentText.Contains("仪表安装综合册"))
            {
                cNProfessionalId = cns.First(x => x.ProfessionalName == "仪表").CNProfessionalId;
            }
            else if (parentText.Contains("消防工程综合册"))
            {
                cNProfessionalId = cns.First(x => x.ProfessionalName == "消防").CNProfessionalId;
            }
            else if (parentText.Contains("防腐绝热工程综合册"))
            {
                cNProfessionalId = cns.First(x => x.ProfessionalName == "防腐").CNProfessionalId;
            }
            return cNProfessionalId;
        }
        #endregion

        #region 根据上级节点返回对应专业
        /// <summary>
        /// 根据上级节点返回对应专业
        /// </summary>
        private string GetCN(string parentName)
        {
            string cn = string.Empty;
            if (parentName.Contains("建筑工程"))
            {
                cn = "建筑工程";
            }
            else if (parentName.Contains("设备安装"))
            {
                cn = "设备";
            }
            else if (parentName.Contains("管道安装"))
            {
                cn = "管道";
            }
            else if (parentName.Contains("电气安装"))
            {
                cn = "电气";
            }
            else if (parentName.Contains("仪表安装"))
            {
                cn = "仪表";
            }
            else if (parentName.Contains("消防工程"))
            {
                cn = "消防";
            }
            else if (parentName.Contains("防腐绝热工程"))
            {
                cn = "防腐";
            }
            return cn;
        }
        #endregion

        #region gvUnit3
        private void BindUnit3()
        {
            Model.DataBase_DataTypeProject parentDataTypeProject = BLL.DataTypeProjectService.GetDataTypeProjectById(this.tvDataTypeInit.SelectedNode.ParentNode.NodeID);
            if (parentDataTypeProject.DataTypeName.Contains("建筑工程综合册"))
            {
                this.UnitDataBind3("建筑工程");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("设备安装综合册"))
            {
                this.UnitDataBind3("设备");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("管道安装综合册"))
            {
                this.UnitDataBind3("管道");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("电气电信安装综合册"))
            {
                this.UnitDataBind3("电气");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("仪表安装综合册"))
            {
                this.UnitDataBind3("仪表");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("消防工程综合册"))
            {
                this.UnitDataBind3("消防");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("防腐绝热工程综合册"))
            {
                this.UnitDataBind3("防腐");
            }
        }

        /// <summary>
        /// 绑定树节点
        /// </summary>
        private void UnitDataBind3(string cNProfessionalName)
        {
            this.tvUnit3.Nodes.Clear();
            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 == Const.ProjectUnitType_1 || x.UnitType == Const.ProjectUnitType_2)
                         orderby y.UnitCode
                         select y).ToList();
            foreach (var q in units)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = q.UnitName;
                newNode.NodeID = q.UnitId;
                newNode.EnableClickEvent = true;
                this.tvUnit3.Nodes.Add(newNode);
            }
        }

        protected void tvUnit3_NodeCommand(object sender, TreeCommandEventArgs e)
        {
            if (this.tvUnit3.SelectedNode.Nodes.Count == 0)
            {
                this.btnNew.Hidden = false;
                this.gvUnit3.Hidden = false;
                BindDataUnit3();
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindDataUnit3()
        {
            string strSql = @"SELECT StartWorkReport.StartWorkReportId,
                                     StartWorkReport.ProjectId,
                                     StartWorkReport.DataTypeProjectId,
                                     StartWorkReport.FileCode,
                                     StartWorkReport.FileContent,
                                     StartWorkReport.CNProfessionalId,
                                     StartWorkReport.UnitWorkIds,
                                     StartWorkReport.UnitIds,
                                     StartWorkReport.Remark,
                                     StartWorkReport.AttachUrl,
                                     StartWorkReport.CompileMan,
                                     StartWorkReport.CompileDate,
                                     CNPro.ProfessionalName AS ProfessionalName,
                                    STUFF(( SELECT ',' + UnitWorkName FROM WBS_UnitWork
                                            where PATINDEX('%,' + RTRIM(WBS_UnitWork.UnitWorkId) + ',%',',' + StartWorkReport.UnitWorkIds + ',')>0
                                            ORDER BY PATINDEX('%,' + RTRIM(StartWorkReport.UnitWorkIds) + ',%',',' + StartWorkReport.UnitWorkIds + ',')
                                    FOR XML PATH('')), 1, 1,'') AS UnitWorkNameS,
                                    STUFF(( SELECT ',' + UnitName FROM Base_Unit
                                            where PATINDEX('%,' + RTRIM(Base_Unit.UnitId) + ',%',',' + StartWorkReport.UnitIds + ',')>0
                                            ORDER BY PATINDEX('%,' + RTRIM(StartWorkReport.UnitIds) + ',%',',' + StartWorkReport.UnitIds + ',')
                                    FOR XML PATH('')), 1, 1,'') AS UnitNameS "
                               + @" FROM DataBase_StartWorkReport AS StartWorkReport "
                               + @" LEFT JOIN Base_CNProfessional AS CNPro ON CNPro.CNProfessionalId = StartWorkReport.CNProfessionalId"
                               + @" WHERE StartWorkReport.ProjectId=@projectId AND StartWorkReport.DataTypeProjectId=@dataTypeProjectId AND StartWorkReport.UnitIds LIKE @unitId";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@dataTypeProjectId", this.tvDataTypeInit.SelectedNodeID));
            listStr.Add(new SqlParameter("@unitId", "%" + this.tvUnit3.SelectedNodeID + "%"));
            if (!string.IsNullOrEmpty(this.tvDataTypeInit.SelectedNode.ParentNode.Text))
            {
                var result = GetCNId(this.tvDataTypeInit.SelectedNode.ParentNode.Text);
                if (result != "0")
                {
                    strSql += "  AND StartWorkReport.CNProfessionalId=@CNProfessionalId";
                    listStr.Add(new SqlParameter("@CNProfessionalId", result));
                }
            }
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvUnit3.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvUnit3, tb);
            gvUnit3.DataSource = table;
            gvUnit3.DataBind();
        }

        protected void gvUnit3_Sort(object sender, GridSortEventArgs e)
        {
            gvUnit3.SortDirection = e.SortDirection;
            gvUnit3.SortField = e.SortField;
            BindDataUnit3();
        }

        protected void gvUnit3_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvUnit3.PageIndex = e.NewPageIndex;
            BindDataUnit3();
        }

        protected void ddlgvUnit3PageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvUnit3.PageSize = Convert.ToInt32(ddlgvUnit3PageSize.SelectedValue);
            BindDataUnit3();
        }

        protected void btnMenuUnit3Edit_Click(object sender, EventArgs e)
        {
            EditDataUnit3();
        }

        protected void btnMenuUnit3Del_Click(object sender, EventArgs e)
        {
            if (gvUnit3.SelectedRowIndexArray.Length > 0)
            {
                foreach (int rowIndex in gvUnit3.SelectedRowIndexArray)
                {
                    string rowID = gvUnit3.DataKeys[rowIndex][0].ToString();
                    var database = BLL.StartWorkReportService.GetStartWorkReportById(rowID);
                    if (database != null)
                    {
                        BLL.StartWorkReportService.DeleteStartWorkReportById(rowID);
                    }
                }
                BindDataUnit3();
                ShowNotify("删除数据成功!", MessageBoxIcon.Success);
            }
        }
        /// <summary>
        /// 编辑
        /// </summary>
        private void EditDataUnit3()
        {
            if (gvUnit3.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
                return;
            }
            PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("StartWorkEdit.aspx?startWorkReportId={0}", gvUnit3.SelectedRowID, "编辑 - ")));
        }

        protected void gvUnit3_RowDoubleClick(object sender, GridRowClickEventArgs e)
        {
            EditDataUnit3();
        }

        protected void gvUnit3_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvUnit3.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvUnit2
        private void BindUnit2()
        {
            Model.DataBase_DataTypeProject parentDataTypeProject = BLL.DataTypeProjectService.GetDataTypeProjectById(this.tvDataTypeInit.SelectedNode.ParentNode.NodeID);
            if (parentDataTypeProject.DataTypeName.Contains("建筑工程综合册"))
            {
                this.UnitDataBind2("建筑工程");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("设备安装综合册"))
            {
                this.UnitDataBind2("设备");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("管道安装综合册"))
            {
                this.UnitDataBind2("管道");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("电气电信安装综合册"))
            {
                this.UnitDataBind2("电气");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("仪表安装综合册"))
            {
                this.UnitDataBind2("仪表");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("消防工程综合册"))
            {
                this.UnitDataBind2("消防");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("防腐绝热工程综合册"))
            {
                this.UnitDataBind2("防腐");
            }
        }

        /// <summary>
        /// 绑定树节点
        /// </summary>
        private void UnitDataBind2(string cNProfessionalName)
        {
            this.tvUnit2.Nodes.Clear();
            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 == Const.ProjectUnitType_1 || x.UnitType == Const.ProjectUnitType_2)
                         orderby y.UnitCode
                         select y).ToList();
            if (this.tvDataTypeInit.SelectedNode.Text.Contains("施工单位和特种作业人员资质证明文件"))
            {
                units = units.Where(e => !e.UnitName.Contains("公司")).ToList();
            }
            foreach (var q in units)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = q.UnitName;
                newNode.NodeID = q.UnitId + "," + cNProfessionalName;
                newNode.EnableClickEvent = true;
                this.tvUnit2.Nodes.Add(newNode);
            }
        }

        protected void tvUnit2_NodeCommand(object sender, TreeCommandEventArgs e)
        {
            if (this.tvUnit2.SelectedNode.Nodes.Count == 0)
            {
                string[] strs = this.tvUnit2.SelectedNodeID.Split(',');
                string unitId = strs[0];
                string cNProfessionalName = strs[1];
                this.gvUnit2.Hidden = false;
                string fileType = this.tvDataTypeInit.SelectedNode.Text;
                if (this.tvDataTypeInit.SelectedNode.Text.Contains("施工技术方案、施工技术措施(包括冬季施工措施)、施工作业指导书等报批文件"))
                {
                    fileType = "施工技术方案、施工技术措施(包括冬季施工措施)、施工作业指导书等报批文件";
                }
                var q = from x in Funs.DB.View_DataBaseProject where x.UnitId.Contains(unitId) && x.ProjectId == this.CurrUser.LoginProjectId && x.FileType == fileType && x.Major == cNProfessionalName select x;
                this.gvUnit2.DataSource = q;
                this.gvUnit2.PageIndex = 0;
                this.gvUnit2.DataBind();
            }
        }

        protected void gvUnit2_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvUnit2.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvUnit4
        private void BindUnit4()
        {
            Model.DataBase_DataTypeProject parentDataTypeProject = BLL.DataTypeProjectService.GetDataTypeProjectById(this.tvDataTypeInit.SelectedNode.ParentNode.NodeID);
            if (parentDataTypeProject.DataTypeName.Contains("建筑工程综合册"))
            {
                this.UnitDataBind4("建筑工程");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("设备安装综合册"))
            {
                this.UnitDataBind4("设备");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("管道安装综合册"))
            {
                this.UnitDataBind4("管道");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("电气电信安装综合册"))
            {
                this.UnitDataBind4("电气");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("仪表安装综合册"))
            {
                this.UnitDataBind4("仪表");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("消防工程综合册"))
            {
                this.UnitDataBind4("消防");
            }
            else if (parentDataTypeProject.DataTypeName.Contains("防腐绝热工程综合册"))
            {
                this.UnitDataBind4("防腐");
            }
        }

        /// <summary>
        /// 绑定树节点
        /// </summary>
        private void UnitDataBind4(string cNProfessionalName)
        {
            this.tvUnit4.Nodes.Clear();
            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 == Const.ProjectUnitType_1 || x.UnitType == Const.ProjectUnitType_2)
                         orderby y.UnitCode
                         select y).ToList();
            foreach (var q in units)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = q.UnitName;
                newNode.NodeID = q.UnitId;
                newNode.EnableClickEvent = true;
                this.tvUnit4.Nodes.Add(newNode);
            }
        }

        protected void tvUnit4_NodeCommand(object sender, TreeCommandEventArgs e)
        {
            if (this.tvUnit4.SelectedNode.Nodes.Count == 0)
            {
                this.btnNew.Hidden = false;
                BindGridUnit4();
            }
        }

        private void BindGridUnit4()
        {
            string strSql = @"SELECT Files.FileId,
                                     Files.ProjectId,
                                     Files.DataTypeProjectId,
                                     Files.FileCode,
                                     Files.FileName,
                                     Files.Pages,
                                     Files.Remark,
                                     Files.CompileDate,
                                     Files.CompileMan,
                                     Files.AttachUrl,
                                     Files.UnitWorkId,
                                     Files.DivisionProjectId,
                                     Files.UnitId,
                                     Files.FileType,
                                     U.UserName AS CompileManName,
                                     Unit.UnitName,
                                     UnitWork.UnitWorkName "
                               + @" FROM DataBase_File AS Files "
                               + @" LEFT JOIN Sys_User AS U ON U.UserId = Files.CompileMan "
                               + @" LEFT JOIN Base_Unit AS Unit ON Unit.UnitId = Files.UnitId "
                               + @" LEFT JOIN WBS_UnitWork AS UnitWork ON UnitWork.UnitWorkId = Files.UnitWorkId "
                               + @" WHERE Files.ProjectId=@projectId AND Files.DataTypeProjectId=@dataTypeProjectId AND Files.UnitId=@unitId ";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@dataTypeProjectId", this.tvDataTypeInit.SelectedNodeID));
            listStr.Add(new SqlParameter("@unitId", this.tvUnit4.SelectedNodeID));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvUnit4.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvUnit4, tb);
            gvUnit4.DataSource = table;
            gvUnit4.DataBind();
        }

        protected void ddlgvUnit4PageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvUnit4.PageSize = Convert.ToInt32(ddlgvUnit4PageSize.SelectedValue);
            BindGridUnit4();
        }

        protected void gvUnit4_Sort(object sender, GridSortEventArgs e)
        {
            gvUnit4.SortDirection = e.SortDirection;
            gvUnit4.SortField = e.SortField;
            BindGridUnit4();
        }

        protected void gvUnit4_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvUnit4.PageIndex = e.NewPageIndex;
            BindGridUnit4();
        }
        protected void btnMenuEditUnit4_Click(object sender, EventArgs e)
        {
            EditDataUnit4();
        }

        protected void btnMenuDelUnit4_Click(object sender, EventArgs e)
        {
            if (gvUnit4.SelectedRowIndexArray.Length > 0)
            {
                foreach (int rowIndex in gvUnit4.SelectedRowIndexArray)
                {
                    string rowID = gvUnit4.DataKeys[rowIndex][0].ToString();
                    var database = BLL.FileService.GetFileById(rowID);
                    if (database != null)
                    {
                        BLL.FileService.DeleteFileById(rowID);
                    }
                }
                BindGridUnit4();
                ShowNotify("删除数据成功!", MessageBoxIcon.Success);
            }
        }

        protected void gvUnit4_RowDoubleClick(object sender, GridRowClickEventArgs e)
        {
            EditDataUnit4();
        }

        /// <summary>
        /// 编辑
        /// </summary>
        private void EditDataUnit4()
        {
            if (gvUnit4.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
                return;
            }
            PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("FileEdit.aspx?fileId={0}", gvUnit4.SelectedRowID, "编辑 - ")));
        }

        protected void gvUnit4_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvUnit4.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvUnit
        /// <summary>
        /// 绑定树节点
        /// </summary>
        private void UnitDataBind(string cNProfessionalCode)
        {
            this.tvUnit.Nodes.Clear();
            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 == Const.ProjectUnitType_2
                         orderby y.UnitCode
                         select y).ToList();
            foreach (var q in units)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = q.UnitName;
                newNode.NodeID = q.UnitId + "," + cNProfessionalCode;
                newNode.EnableClickEvent = true;
                this.tvUnit.Nodes.Add(newNode);
            }
        }

        protected void tvUnit_NodeCommand(object sender, TreeCommandEventArgs e)
        {
            if (this.tvUnit.SelectedNode.Nodes.Count == 0)
            {
                string[] strs = this.tvUnit.SelectedNodeID.Split(',');
                string unitId = strs[0];
                string cNProfessionalCode = strs[1];

                var q = from x in Funs.DB.View_Comprehensive_InspectionEquipment where x.UnitId == unitId && x.ProjectId == this.CurrUser.LoginProjectId && x.CNProfessionalCode == cNProfessionalCode select x;
                this.gvUnit.DataSource = q;
                this.gvUnit.DataBind();
            }
        }
        protected void gvUnit_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvUnit.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvFile2
        private void WBSDataBind(string cNProfessionalCode)
        {
            this.tvWBS.Nodes.Clear();
            var installations = from x in Funs.DB.WBS_UnitWork where x.ProjectId == this.CurrUser.LoginProjectId orderby x.UnitWorkCode select x;
            foreach (var q in installations)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = q.UnitWorkName;
                newNode.NodeID = q.UnitWorkId;
                newNode.EnableClickEvent = true;
                this.tvWBS.Nodes.Add(newNode);

                var divisionProjects = from x in Funs.DB.WBS_DivisionProject
                                       join y in Funs.DB.Base_CNProfessional
                                       on x.CNProfessionalId equals y.CNProfessionalId
                                       where y.CNProfessionalCode == cNProfessionalCode && x.ProjectId == this.CurrUser.LoginProjectId && x.IsSelected == true && x.UnitWorkId == q.UnitWorkId
                                       orderby x.SortIndex
                                       select x;
                foreach (var d in divisionProjects)
                {
                    TreeNode node = new TreeNode();
                    node.ToolTip = d.DivisionName;
                    node.Text = d.DivisionName;
                    node.NodeID = d.DivisionProjectId;
                    node.EnableClickEvent = true;
                    newNode.Nodes.Add(node);
                }
            }
        }

        protected void tvWBS_NodeCommand(object sender, TreeCommandEventArgs e)
        {            
            this.btnNew.Hidden = false;
            string UnitWorkId = string.Empty;
            string DivisionProjectId = string.Empty;
            Model.DataBase_DataTypeProject dataTypeProject = BLL.DataTypeProjectService.GetDataTypeProjectById(this.tvDataTypeInit.SelectedNodeID);
            if (this.tvDataTypeInit.SelectedNode.Nodes.Count == 0)
            {
                string path = this.tvWBS.SelectedNode.ParentNode.NodeID;
                if (!string.IsNullOrEmpty(path))
                {
                    UnitWorkId = path;//装置
                    DivisionProjectId = this.tvWBS.SelectedNodeID;//分部
                }

                if (dataTypeProject.IsRelatedWBS == true)
                {
                    this.Type = "WBS";    //WBS文件类型
                    var q = from x in Funs.DB.View_ProcessControl_InspectionManagement where x.UnitWorkId == UnitWorkId && x.ParentDivisionProjectId == DivisionProjectId && x.IsYellow == null select x;
                    this.gvFile2.DataSource = q;
                    this.gvFile2.DataBind();
                }
                else
                {
                    this.Type = "WBSYellow";    //WBS文件类型
                    var q = from x in Funs.DB.View_ProcessControl_InspectionManagement where x.UnitWorkId == UnitWorkId && x.ParentDivisionProjectId == DivisionProjectId && x.IsYellow == true select x;
                    this.gvFile2.DataSource = q;
                    this.gvFile2.DataBind();
                }
            }
        }
        protected void gvFile2_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvFile2.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvWBS2
        /// <summary>
        /// 绑定树节点
        /// </summary>
        private void WBSDataBind2(string cNProfessionalCode)
        {
            this.tvWBS2.Nodes.Clear();
            var installations = from x in Funs.DB.WBS_UnitWork where x.ProjectId == this.CurrUser.LoginProjectId orderby x.UnitWorkCode select x;
            foreach (var q in installations)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = q.UnitWorkName;
                newNode.NodeID = q.UnitWorkId;
                newNode.EnableClickEvent = true;
                this.tvWBS2.Nodes.Add(newNode);

                var divisionProjects = from x in Funs.DB.WBS_DivisionProject
                                       join y in Funs.DB.Base_CNProfessional
                                       on x.CNProfessionalId equals y.CNProfessionalId
                                       where y.CNProfessionalCode == cNProfessionalCode && x.ProjectId == this.CurrUser.LoginProjectId && x.IsSelected == true && x.UnitWorkId == q.UnitWorkId
                                       orderby x.SortIndex
                                       select x;
                foreach (var d in divisionProjects)
                {
                    TreeNode node = new TreeNode();
                    node.ToolTip = d.DivisionName;
                    node.Text = d.DivisionName;
                    node.NodeID = d.DivisionProjectId;
                    node.EnableClickEvent = true;
                    newNode.Nodes.Add(node);
                }
            }
        }

        protected void tvWBS2_NodeCommand(object sender, TreeCommandEventArgs e)
        {
            Model.DataBase_DataTypeProject dataTypeProject = BLL.DataTypeProjectService.GetDataTypeProjectById(this.tvDataTypeInit.SelectedNodeID);
            if (this.tvDataTypeInit.SelectedNode.Nodes.Count == 0)
            {
                this.Type = "分项工程质量验收记录";    //分项工程质量验收记录文件类型
                this.btnNew.Hidden = false;
                BindDataWBS2();
            }
        }

        private void BindDataWBS2()
        {
            string strSql = @"SELECT Files.FileId,
                                     Files.ProjectId,
                                     Files.DataTypeProjectId,
                                     Files.FileCode,
                                     Files.FileName,
                                     Files.Pages,
                                     Files.Remark,
                                     Files.CompileDate,
                                     Files.CompileMan,
                                     Files.AttachUrl,
                                     Files.UnitWorkId,
                                     Files.DivisionProjectId,
                                     Files.UnitId,
                                     Files.FileType,
                                     U.UserName AS CompileManName,
                                     Unit.UnitName,
                                     UnitWork.UnitWorkName "
                               + @" FROM DataBase_File AS Files "
                               + @" LEFT JOIN Sys_User AS U ON U.UserId = Files.CompileMan "
                               + @" LEFT JOIN Base_Unit AS Unit ON Unit.UnitId = Files.UnitId "
                               + @" LEFT JOIN WBS_UnitWork AS UnitWork ON UnitWork.UnitWorkId = Files.UnitWorkId "
                               + @" WHERE Files.ProjectId=@projectId AND Files.DataTypeProjectId=@dataTypeProjectId AND  Files.DivisionProjectId=@divisionProjectId";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@dataTypeProjectId", this.tvDataTypeInit.SelectedNodeID));
            listStr.Add(new SqlParameter("@divisionProjectId", this.tvWBS2.SelectedNodeID));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvWBS2.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvWBS2, tb);
            gvWBS2.DataSource = table;
            gvWBS2.DataBind();
        }

        protected void ddlgvWBS2PageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvWBS2.PageSize = Convert.ToInt32(ddlgvWBS2PageSize.SelectedValue);
            BindDataWBS2();
        }

        protected void gvWBS2_Sort(object sender, GridSortEventArgs e)
        {
            gvWBS2.SortDirection = e.SortDirection;
            gvWBS2.SortField = e.SortField;
            BindDataWBS2();
        }

        protected void gvWBS2_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvWBS2.PageIndex = e.NewPageIndex;
            BindDataWBS2();
        }

        /// <summary>
        /// 编辑
        /// </summary>
        private void EditDataWBS2()
        {
            if (gvWBS2.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
                return;
            }
            PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("FileEdit.aspx?fileId={0}", gvFile.SelectedRowID, "编辑 - ")));
        }

        protected void gvWBS2_RowDoubleClick(object sender, GridRowClickEventArgs e)
        {
            EditDataWBS2();
        }

        protected void gvWBS2_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvWBS2.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }

        protected void btnMenuWBS2Edit_Click(object sender, EventArgs e)
        {
            EditDataWBS2();
        }

        protected void btnMenuWBS2Del_Click(object sender, EventArgs e)
        {
            if (gvWBS2.SelectedRowIndexArray.Length > 0)
            {
                foreach (int rowIndex in gvWBS2.SelectedRowIndexArray)
                {
                    string rowID = gvWBS2.DataKeys[rowIndex][0].ToString();
                    var database = BLL.FileService.GetFileById(rowID);
                    if (database != null)
                    {
                        BLL.FileService.DeleteFileById(rowID);
                    }
                }
                BindDataWBS2();
                ShowNotify("删除数据成功!", MessageBoxIcon.Success);
            }
        }
        #endregion

        #region gvCN
        /// <summary>
        /// 绑定树节点
        /// </summary>
        private void CNDataBind()
        {
            this.tvCN.Nodes.Clear();
            var cns = (from x in Funs.DB.Base_CNProfessional
                       orderby x.SortIndex
                       select x).ToList();
            foreach (var q in cns)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = q.ProfessionalName;
                newNode.NodeID = q.CNProfessionalId;
                newNode.EnableClickEvent = true;
                this.tvCN.Nodes.Add(newNode);
            }
        }

        protected void tvCN_NodeCommand(object sender, TreeCommandEventArgs e)
        {
            if (this.tvCN.SelectedNode.Nodes.Count == 0)
            {
                string cNProfessionalId = this.tvCN.SelectedNodeID;
                string fileType = "设备报审文件 (报审表 SH/T 3903-A9)";
                var q = from x in Funs.DB.View_DataBaseProject where x.ProjectId == this.CurrUser.LoginProjectId && x.FileType == fileType && x.CNProfessionalId == cNProfessionalId select x;
                this.gvCN.DataSource = q;
                this.gvCN.DataBind();
            }
        }

        protected void gvCN_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvCN.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvPhoto
        private void BindDataPhoto()
        {
            string strSql = @"SELECT Photo.PhotoId, 
                                     Photo.ProjectId, 
                                     Photo.PhotoType, 
                                     Photo.Date, 
                                     Photo.Place, 
                                     Photo.Person, 
                                     Photo.Subject, 
                                     Photo.Background, 
                                     Photo.Photographer, 
                                     Photo.AttachUrl "
                               + @" FROM DataBase_Photo AS Photo "
                               + @" WHERE Photo.ProjectId=@projectId AND Photo.PhotoType=@photoType";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@photoType", this.tvDataTypeInit.SelectedNodeID));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvPhoto.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvPhoto, tb);
            gvPhoto.DataSource = table;
            gvPhoto.DataBind();
        }

        protected void ddlgvPhotoPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvPhoto.PageSize = Convert.ToInt32(ddlgvPhotoPageSize.SelectedValue);
            BindDataPhoto();
        }

        protected void gvPhoto_Sort(object sender, GridSortEventArgs e)
        {
            gvPhoto.SortDirection = e.SortDirection;
            gvPhoto.SortField = e.SortField;
            BindDataPhoto();
        }

        protected void gvPhoto_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvPhoto.PageIndex = e.NewPageIndex;
            BindDataPhoto();
        }

        protected void gvPhoto_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvPhoto.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        /// <summary>
        /// 编辑
        /// </summary>
        private void EditDataPhoto()
        {
            if (gvPhoto.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
                return;
            }
            PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("PhotoEdit.aspx?photoId={0}", gvPhoto.SelectedRowID, "编辑 - ")));
        }

        protected void gvPhoto_RowDoubleClick(object sender, GridRowClickEventArgs e)
        {
            EditDataPhoto();
        }

        protected void btnMenuPhotoEdit_Click(object sender, EventArgs e)
        {
            EditDataPhoto();
        }

        protected void btnMenuPhotoDel_Click(object sender, EventArgs e)
        {
            if (gvPhoto.SelectedRowIndexArray.Length > 0)
            {
                foreach (int rowIndex in gvPhoto.SelectedRowIndexArray)
                {
                    string rowID = gvPhoto.DataKeys[rowIndex][0].ToString();
                    var database = BLL.PhotoService.GetPhotoById(rowID);
                    if (database != null)
                    {
                        BLL.PhotoService.DeletePhotoById(rowID);
                    }
                }
                BindDataPhoto();
                ShowNotify("删除数据成功!", MessageBoxIcon.Success);
            }
        }
        #endregion

        #region gvInspectionPerson
        private void BindDataInspectionPerson()
        {
            string strSql = @"SELECT Insp.InspectionPersonId,
                                     Insp.ProjectId,
                                     Insp.UnitId,
                                     Insp.InspectionPersonCode,
                                     Insp.PersonName,
                                     Insp.PostId,
                                     Insp.CertificateNumber,
                                     Insp.QualifiedProjectCode,
                                     Insp.ValidityDate,
                                     Insp.ApprovalTime,
                                     Insp.DepartureTime,
                                     Insp.Remark,
                                     Insp.CNProfessionalId,
                                     Insp.CompileMan,
                                     Insp.CompileDate,
                                     Insp.IsOnSite,
                                     Insp.UnitWorkId,
                                     Unit.UnitName,
                                     Post.PostName,
                                     CNProfessional.ProfessionalName "
                               + @" FROM Comprehensive_InspectionPerson AS Insp "
                               + @" LEFT JOIN Base_Unit AS Unit ON Unit.UnitId = Insp.UnitId"
                               + @" LEFT JOIN Base_Post AS Post ON Post.PostId = Insp.PostId"
                               + @" LEFT JOIN Base_CNProfessional AS CNProfessional ON CNProfessional.CNProfessionalId = Insp.CNProfessionalId"
                               + @" WHERE Insp.ProjectId=@projectId ";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            if(!string.IsNullOrEmpty(this.hdPostId.Text.Trim()))
            {
                strSql += "  AND Insp.PostId=@PostId";
                listStr.Add(new SqlParameter("@PostId",this.hdPostId.Text.Trim()));
            }
            else
            {
                strSql += "  AND Insp.PostId!=@PostId";
                listStr.Add(new SqlParameter("@PostId", Const.PostMangerId));
            }
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvInspectionPerson.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvInspectionPerson, tb);
            gvInspectionPerson.DataSource = table;
            gvInspectionPerson.DataBind();
        }

        protected void ddlgvInspectionPersonPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvInspectionPerson.PageSize = Convert.ToInt32(ddlgvInspectionPersonPageSize.SelectedValue);
            BindDataInspectionPerson();
        }

        protected void gvInspectionPerson_Sort(object sender, GridSortEventArgs e)
        {
            gvInspectionPerson.SortDirection = e.SortDirection;
            gvInspectionPerson.SortField = e.SortField;
            BindDataInspectionPerson();
        }

        protected void gvInspectionPerson_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvInspectionPerson.PageIndex = e.NewPageIndex;
            BindDataInspectionPerson();
        }

        protected void gvInspectionPerson_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvInspectionPerson.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvNCRManagement
        private void BindDataNCRManagement()
        {
            string strSql = @"SELECT NCR.NCRManagementId,
                                     NCR.ProjectId,
                                     NCR.CNProfessionalId,
                                     NCR.NCRCode,
                                     NCR.Contents,
                                     NCR.IssuedDate,
                                     NCR.ClosedDate,
                                     NCR.CompleteDate,
                                     NCR.ResponsibleMan,
                                     NCR.AttachUrl,
                                     NCR.ImplementationFrontState,
                                     NCR.CompileMan,
                                     NCR.UnitWorkId,
                                     U.UnitName AS SendUnit,
                                     CNP.ProfessionalName,
                                    STUFF(( SELECT ',' + UnitName FROM Base_Unit
                                            where PATINDEX('%,' + RTRIM(Base_Unit.UnitId) + ',%',',' + NCR.ReceiveUnit + ',')>0
                                            ORDER BY PATINDEX('%,' + RTRIM(NCR.ReceiveUnit) + ',%',',' + NCR.ReceiveUnit + ',')
                                    FOR XML PATH('')), 1, 1,'') AS ReceiveUnit "
                               + @" FROM Comprehensive_NCRManagement AS NCR "
                               + @" LEFT JOIN Base_Unit AS U ON U.UnitId = NCR.SendUnit"
                               + @" LEFT JOIN Base_CNProfessional AS CNP ON CNP.CNProfessionalId = NCR.CNProfessionalId"
                               + @" WHERE NCR.ProjectId=@projectId AND NCR.CNProfessionalId=@CNProfessionalId";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@CNProfessionalId", Const.CNProfessionalCVId));
            
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvNCRManagement.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvNCRManagement, tb);
            gvNCRManagement.DataSource = table;
            gvNCRManagement.DataBind();

            OutputSummaryData(tb);//合计行
        }

        /// <summary>
        /// 合计行
        /// </summary>
        /// <param name="tb"></param>
        private void OutputSummaryData(DataTable tb)
        {
            //foreach (DataRow row in tb.Rows)
            //{
                //donateTotal += Convert.ToInt32(row["Donate"]);
                //feeTotal += Convert.ToInt32(row["Fee"]);
            //}
            JObject summary = new JObject();
            summary.Add("tfPageIndex", "总数:");
            summary.Add("SendUnit", tb.Rows.Count);
            summary.Add("ProfessionalName", "完成情况:");
            summary.Add("NCRCode", ConvertComplete());

            gvNCRManagement.SummaryData = summary;
        }

        /// <summary>
        /// 完成情况
        /// </summary>
        /// <returns></returns>
        protected string ConvertComplete()
        {
            decimal totalCount = 0;
            decimal completeCount = 0;
            decimal com = 0;
            IQueryable<Model.Comprehensive_NCRManagement> q = from x in Funs.DB.Comprehensive_NCRManagement where x.ProjectId == this.CurrUser.LoginProjectId select x;
            IQueryable<Model.Comprehensive_NCRManagement> q2 = from x in Funs.DB.Comprehensive_NCRManagement where x.ProjectId == this.CurrUser.LoginProjectId && x.CompleteDate != null select x;
            q = q.Where(e => e.CNProfessionalId == Const.CNProfessionalCVId);
            q2 = q2.Where(e => e.CNProfessionalId == Const.CNProfessionalCVId);
            totalCount = q.Count();
            completeCount = q2.Count();

            com = decimal.Round((decimal.Round((Convert.ToDecimal(completeCount) / totalCount), 4) * 100), 2);

            return com + "%";
        }

        protected void ddlNCRManagementPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvNCRManagement.PageSize = Convert.ToInt32(ddlNCRManagementPageSize.SelectedValue);
            BindDataNCRManagement();
        }

        protected void gvNCRManagement_Sort(object sender, GridSortEventArgs e)
        {
            gvNCRManagement.SortDirection = e.SortDirection;
            gvNCRManagement.SortField = e.SortField;
            BindDataNCRManagement();
        }

        protected void gvNCRManagement_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvNCRManagement.PageIndex = e.NewPageIndex;
            BindDataNCRManagement();
        }

        protected void gvNCRManagement_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvNCRManagement.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region QualityAccident
        private void BindDataQualityAccident()
        {
            string strSql = @"SELECT QA.QualityAccidentId,
                                     QA.ProjectId,
                                     QA.UnitId,
                                     QA.time,
                                     QA.Place,
                                     QA.DirectEconomicLoss,
                                     QA.RemedialMeasures,
                                     QA.ResponsibilityDetermination,
                                     QA.CorrectiveActions,
                                     QA.AttachUrl,
                                     QA.CompileMan,
                                     QA.CompileDate,
                                     QA.UnitWorkId,
                                     U.UnitName "
                               + @" FROM Comprehensive_QualityAccident QA "
                               + @" LEFT JOIN Base_Unit AS U ON U.UnitId = QA.UnitId"
                               + @" LEFT JOIN WBS_UnitWork AS UW ON UW.UnitWorkId = QA.UnitWorkId"
                               + @" WHERE QA.ProjectId=@projectId ";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));

            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvQualityAccident.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvQualityAccident, tb);
            gvQualityAccident.DataSource = table;
            gvQualityAccident.DataBind();
        }

        protected void ddlQualityAccidentPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvQualityAccident.PageSize = Convert.ToInt32(ddlQualityAccidentPageSize.SelectedValue);
            BindDataQualityAccident();
        }

        protected void gvQualityAccident_Sort(object sender, GridSortEventArgs e)
        {
            gvQualityAccident.SortDirection = e.SortDirection;
            gvQualityAccident.SortField = e.SortField;
            BindDataQualityAccident();
        }

        protected void gvQualityAccident_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvQualityAccident.PageIndex = e.NewPageIndex;
            BindDataQualityAccident();
        }

        protected void gvQualityAccident_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvQualityAccident.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvGeneralPlanApproval
        private void BindDataGeneralPlanApproval()
        {
            string strSql = @"SELECT GPA.GeneralPlanApprovalId,
                                     GPA.ProjectId,
                                     GPA.UnitId,
                                     GPA.CNProfessionalId,
                                     GPA.PlanCode,
                                     GPA.PlanName,
                                     GPA.ApprovalDate,
                                     GPA.AuditMan,
                                     GPA.ApprovalMan,
                                     GPA.ImplementationDeviation,
                                     GPA.AttachUrl,
                                     GPA.CompileMan,
                                     GPA.CompileDate,
                                     GPA.UnitWorkId,
                                     U.UnitName,
                                     C.ProfessionalName,
                                     STUFF(( SELECT ',' + UnitWorkName FROM WBS_UnitWork
                                             where PATINDEX('%,' + RTRIM(WBS_UnitWork.UnitWorkId) + ',%',',' + GPA.UnitWorkId + ',')>0
                                             ORDER BY PATINDEX('%,' + RTRIM(GPA.UnitWorkId) + ',%',',' + GPA.UnitWorkId + ',')
                                     FOR XML PATH('')), 1, 1,'') AS UnitWorkName "
                               + @" FROM Comprehensive_GeneralPlanApproval AS GPA "
                               + @" LEFT JOIN Base_Unit AS U ON U.UnitId = GPA.UnitId"
                               + @" LEFT JOIN Base_CNProfessional AS C ON C.CNProfessionalId = GPA.CNProfessionalId"
                               + @" WHERE GPA.ProjectId=@projectId AND GPA.CNProfessionalId=@CNProfessionalId AND GPA.UnitWorkId LIKE @unitWorkId";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@CNProfessionalId", Const.CNProfessionalCVId));
            listStr.Add(new SqlParameter("@unitWorkId", "%" + this.hdUnitWorkId.Text.Trim() + "%"));

            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvGeneralPlanApproval.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvGeneralPlanApproval, tb);
            gvGeneralPlanApproval.DataSource = table;
            gvGeneralPlanApproval.DataBind();
        }

        protected void ddlGeneralPlanApprovalPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvGeneralPlanApproval.PageSize = Convert.ToInt32(ddlGeneralPlanApprovalPageSize.SelectedValue);
            BindDataGeneralPlanApproval();
        }

        protected void gvGeneralPlanApproval_Sort(object sender, GridSortEventArgs e)
        {
            gvGeneralPlanApproval.SortDirection = e.SortDirection;
            gvGeneralPlanApproval.SortField = e.SortField;
            BindDataGeneralPlanApproval();
        }

        protected void gvGeneralPlanApproval_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvGeneralPlanApproval.PageIndex = e.NewPageIndex;
            BindDataGeneralPlanApproval();
        }

        protected void gvGeneralPlanApproval_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvGeneralPlanApproval.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvDesignDetails
        private void BindDataDesignDetails()
        {
            string strSql = @"SELECT design.DesignDetailsId, 
                                     design.ProjectId, 
                                     design.CNProfessionalId, 
                                     design.DesignDetailsCode, 
                                     design.DetailsMan, 
                                     design.DetailsDate, 
                                     design.UnitWorkId, 
                                     design.UnitName, 
                                     design.AttachUrl, 
                                     design.CompileMan, 
                                     design.CompileDate,
                                     cnp.ProfessionalName,
                                     unitWork.UnitWorkName,
                                     STUFF(( SELECT ',' + UnitName FROM Base_Unit
                                            where PATINDEX('%,' + RTRIM(Base_Unit.UnitId) + ',%',',' + design.UnitName + ',')>0
                                            ORDER BY PATINDEX('%,' + RTRIM(design.UnitName) + ',%',',' + design.UnitName + ',')
                                    FOR XML PATH('')), 1, 1,'') AS UnitNames "
                               + @" FROM Comprehensive_DesignDetails AS design "
                               + @" LEFT JOIN Base_CNProfessional AS cnp ON cnp.CNProfessionalId = design.CNProfessionalId"
                               + @" LEFT JOIN WBS_UnitWork AS unitWork ON unitWork.UnitWorkId = design.UnitWorkId"
                               + @" WHERE design.ProjectId=@projectId AND design.CNProfessionalId=@CNProfessionalId AND design.UnitWorkId LIKE @unitWorkId";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@CNProfessionalId", Const.CNProfessionalCVId));
            listStr.Add(new SqlParameter("@unitWorkId", "%" + this.hdUnitWorkId.Text.Trim() + "%"));

            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvDesignDetails.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvDesignDetails, tb);
            gvDesignDetails.DataSource = table;
            gvDesignDetails.DataBind();
        }

        protected void ddlDesignDetailsPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvDesignDetails.PageSize = Convert.ToInt32(ddlDesignDetailsPageSize.SelectedValue);
            BindDataDesignDetails();
        }

        protected void gvDesignDetails_Sort(object sender, GridSortEventArgs e)
        {
            gvDesignDetails.SortDirection = e.SortDirection;
            gvDesignDetails.SortField = e.SortField;
            BindDataDesignDetails();
        }

        protected void gvDesignDetails_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvDesignDetails.PageIndex = e.NewPageIndex;
            BindDataDesignDetails();
        }

        protected void gvDesignDetails_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvDesignDetails.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvDesignChangeOrder
        private void BindDataDesignChangeOrder()
        {
            string strSql = @"SELECT DesignChangeOrder.DesignChangeOrderId,
                                     DesignChangeOrder.ProjectId,
                                     DesignChangeOrder.CNProfessionalId,
                                     DesignChangeOrder.UnitWorkId,
                                     DesignChangeOrder.ChangeOrderCode,
                                     DesignChangeOrder.ChangeReason,
                                     DesignChangeOrder.Contents,
                                     DesignChangeOrder.IssuedDate,
                                     DesignChangeOrder.ApprovalDate,
                                     DesignChangeOrder.UnitId,
                                     DesignChangeOrder.HandleState,
                                     DesignChangeOrder.AttachUrl,
                                     DesignChangeOrder.ImplementationFrontState,
                                     DesignChangeOrder.CompileMan,
                                     DesignChangeOrder.CompileDate,
                                     DesignChangeOrder.CompleteDate,
                                     CNP.ProfessionalName,
                                     STUFF(( SELECT ',' + UnitWorkName FROM WBS_UnitWork
                                            where PATINDEX('%,' + RTRIM(WBS_UnitWork.UnitWorkId) + ',%',',' + DesignChangeOrder.UnitWorkId + ',')>0
                                            ORDER BY PATINDEX('%,' + RTRIM(DesignChangeOrder.UnitWorkId) + ',%',',' + DesignChangeOrder.UnitWorkId + ',')
                                    FOR XML PATH('')), 1, 1,'') AS UnitWorkName,
                                    STUFF(( SELECT ',' + UnitName FROM Base_Unit
                                            where PATINDEX('%,' + RTRIM(Base_Unit.UnitId) + ',%',',' + DesignChangeOrder.UnitId + ',')>0
                                            ORDER BY PATINDEX('%,' + RTRIM(DesignChangeOrder.UnitId) + ',%',',' + DesignChangeOrder.UnitId + ',')
                                    FOR XML PATH('')), 1, 1,'') AS UnitName "
                               + @" FROM Comprehensive_DesignChangeOrder AS DesignChangeOrder "
                               + @" LEFT JOIN Base_CNProfessional AS CNP ON CNP.CNProfessionalId = DesignChangeOrder.CNProfessionalId"
                               + @" WHERE DesignChangeOrder.ProjectId=@projectId AND DesignChangeOrder.CNProfessionalId=@CNProfessionalId AND DesignChangeOrder.UnitWorkId LIKE @unitWorkId";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@CNProfessionalId", Const.CNProfessionalCVId));
            listStr.Add(new SqlParameter("@unitWorkId", "%" + this.hdUnitWorkId.Text.Trim() + "%"));

            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvDesignChangeOrder.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvDesignChangeOrder, tb);
            gvDesignChangeOrder.DataSource = table;
            gvDesignChangeOrder.DataBind();
        }

        protected void ddlDesignChangeOrderPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvDesignChangeOrder.PageSize = Convert.ToInt32(ddlDesignChangeOrderPageSize.SelectedValue);
            BindDataDesignChangeOrder();
        }

        protected void gvDesignChangeOrder_Sort(object sender, GridSortEventArgs e)
        {
            gvDesignChangeOrder.SortDirection = e.SortDirection;
            gvDesignChangeOrder.SortField = e.SortField;
            BindDataDesignChangeOrder();
        }

        protected void gvDesignChangeOrder_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvDesignChangeOrder.PageIndex = e.NewPageIndex;
            BindDataDesignChangeOrder();
        }

        protected void gvDesignChangeOrder_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvDesignChangeOrder.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvMajorPlanApproval
        private void BindDataMajorPlanApproval()
        {
            string strSql = @"SELECT MajorPlan.MajorPlanApprovalId,
                                     MajorPlan.ProjectId,
                                     MajorPlan.UnitId,
                                     MajorPlan.CNProfessionalId,
                                     MajorPlan.PlanCode,
                                     MajorPlan.PlanName,
                                     MajorPlan.ReviewMan,
                                     MajorPlan.ApprovalDate,
                                     MajorPlan.AuditMan,
                                     MajorPlan.ApprovalMan,
                                     MajorPlan.ImplementationDeviation,
                                     MajorPlan.AttachUrl,
                                     MajorPlan.CompileMan,
                                     MajorPlan.CompileDate,
                                     MajorPlan.UnitWorkId,
                                     Unit.UnitName,
                                     CNP.ProfessionalName,
                                     STUFF(( SELECT ',' + UnitWorkName FROM WBS_UnitWork
                                            where PATINDEX('%,' + RTRIM(WBS_UnitWork.UnitWorkId) + ',%',',' + MajorPlan.UnitWorkId + ',')>0
                                            ORDER BY PATINDEX('%,' + RTRIM(MajorPlan.UnitWorkId) + ',%',',' + MajorPlan.UnitWorkId + ',')
                                     FOR XML PATH('')), 1, 1,'') AS UnitWorkName "
                               + @" FROM Comprehensive_MajorPlanApproval AS MajorPlan "
                               + @" LEFT JOIN Base_Unit AS Unit ON Unit.UnitId = MajorPlan.UnitId "
                               + @" LEFT JOIN Base_CNProfessional AS CNP ON CNP.CNProfessionalId = MajorPlan.CNProfessionalId "
                               + @" WHERE MajorPlan.ProjectId=@projectId AND MajorPlan.CNProfessionalId=@CNProfessionalId AND MajorPlan.UnitWorkId LIKE @unitWorkId";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@CNProfessionalId", Const.CNProfessionalCVId));
            listStr.Add(new SqlParameter("@unitWorkId", "%" + this.hdUnitWorkId.Text.Trim() + "%"));

            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvMajorPlanApproval.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvMajorPlanApproval, tb);
            gvMajorPlanApproval.DataSource = table;
            gvMajorPlanApproval.DataBind();
        }

        protected void ddlMajorPlanApprovalPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvMajorPlanApproval.PageSize = Convert.ToInt32(ddlMajorPlanApprovalPageSize.SelectedValue);
            BindDataMajorPlanApproval();
        }

        protected void gvMajorPlanApproval_Sort(object sender, GridSortEventArgs e)
        {
            gvMajorPlanApproval.SortDirection = e.SortDirection;
            gvMajorPlanApproval.SortField = e.SortField;
            BindDataMajorPlanApproval();
        }

        protected void gvMajorPlanApproval_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvMajorPlanApproval.PageIndex = e.NewPageIndex;
            BindDataMajorPlanApproval();
        }
        protected void gvMajorPlanApproval_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvMajorPlanApproval.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvInspectionManagement
        private void BindGridInspectionManagement()
        {
            string strSql = @"SELECT distinct Ins.InspectionId,
                                     Ins.ProjectId,
                                     Ins.UnitId,
                                     Ins.CNProfessionalId,
                                     Ins.InspectionCode,
                                     Ins.UnitWorkId,
                                     Ins.ControlPointType,
                                     Ins.AcceptanceSite,
                                     (CASE WHEN Ins.IsOnceQualified=1 THEN '是' ELSE '否' END) AS IsOnceQualified,
                                     Ins.InspectionDate,
                                     Ins.AttachUrl,
                                     Ins.CheckDate,
                                     Ins.CheckMan,
                                     Ins.UnqualifiedReason,
                                     Ins.NoticeCode,
                                     Ins.AcceptanceCheckMan,
                                     Ins.ParentDivisionProjectId,
                                     Ins.CompileMan,
                                     Ins.CompileDate,
                                     Ins.FileType,
                                     Ins.AttachUrl2,
                                     CNP.ProfessionalName,
                                     Unit.UnitName "
                               + @" FROM ProcessControl_InspectionManagementDetail AS d "
                               + @" LEFT JOIN ProcessControl_InspectionManagement AS Ins on d.InspectionId=Ins.InspectionId "
                               + @" LEFT JOIN Base_Unit AS Unit ON Unit.UnitId = Ins.UnitId "
                               + @" LEFT JOIN Base_CNProfessional AS CNP ON CNP.CNProfessionalId = Ins.CNProfessionalId"
                               + @" WHERE Ins.ProjectId=@projectId AND Ins.CNProfessionalId=@CNProfessionalId ";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@CNProfessionalId", Const.CNProfessionalCVId));
            if (!string.IsNullOrEmpty(this.hdUnitWorkId.Text.Trim()))
            {
                strSql += "  AND d.UnitWorkId=@unitWorkId";
                listStr.Add(new SqlParameter("@unitWorkId", this.hdUnitWorkId.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(hdControlPointType.Text.Trim()))
            {
                strSql += "  AND @ControlPointType LIKE '%'+d.ControlPointType+'%'";
                listStr.Add(new SqlParameter("@ControlPointType", hdControlPointType.Text.Trim()));
            }

            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvInspectionManagement.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvInspectionManagement, tb);
            gvInspectionManagement.DataSource = table;
            gvInspectionManagement.DataBind();
        }

        protected void ddlInspectionManagementPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvInspectionManagement.PageSize = Convert.ToInt32(ddlInspectionManagementPageSize.SelectedValue);
            BindGridInspectionManagement();
        }

        protected void gvInspectionManagement_Sort(object sender, GridSortEventArgs e)
        {
            gvInspectionManagement.SortDirection = e.SortDirection;
            gvInspectionManagement.SortField = e.SortField;
            BindGridInspectionManagement();
        }

        protected void gvInspectionManagement_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvInspectionManagement.PageIndex = e.NewPageIndex;
            BindGridInspectionManagement();
        }

        protected void gvInspectionManagement_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvInspectionManagement.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion

        #region gvInspectionEquipment
        private void BindDataInspectionEquipment()
        {
            string strSql = @"SELECT Ins.InspectionEquipmentId,
                                     Ins.ProjectId,
                                     Ins.UnitId,
                                     Ins.InspectionCode,
                                     Ins.CNProfessionalId,
                                     Ins.InspectionName,
                                     Ins.Specifications,
                                     Ins.Supplier,
                                     Ins.Counts,
                                     Ins.SamplingCount,
                                     (CASE WHEN Ins.SamplingResult='1' THEN '合格' ELSE '不合格' END) AS SamplingResult,
                                     Ins.InspectionDate,
                                     Ins.AttachUrl,
                                     Ins.CompileMan,
                                     Ins.CompileDate,
                                     Ins.EquipmentNO,
                                     Ins.RemarkCode,
                                     Ins.UsedPlace,
                                     Ins.Attribute,
                                     Unit.UnitName,
                                     cnp.ProfessionalName "
                               + @" FROM Comprehensive_InspectionEquipment AS Ins "
                               + @" LEFT JOIN Base_Unit AS Unit ON Unit.UnitId=Ins.UnitId "
                               + @" LEFT JOIN Base_CNProfessional AS cnp on cnp.CNProfessionalId=Ins.CNProfessionalId"
                               + @" WHERE Ins.ProjectId=@projectId AND Ins.Attribute=@attribute";
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
            listStr.Add(new SqlParameter("@attribute",this.hdAttribute.Text.Trim()));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            gvInspectionEquipment.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(gvInspectionEquipment, tb);
            gvInspectionEquipment.DataSource = table;
            gvInspectionEquipment.DataBind();
        }

        protected void ddlInspectionEquipmentPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvInspectionEquipment.PageSize = Convert.ToInt32(ddlInspectionEquipmentPageSize.SelectedValue);
            BindDataInspectionEquipment();
        }

        protected void gvInspectionEquipment_Sort(object sender, GridSortEventArgs e)
        {
            gvInspectionEquipment.SortDirection = e.SortDirection;
            gvInspectionEquipment.SortField = e.SortField;
            BindDataInspectionEquipment();
        }

        protected void gvInspectionEquipment_PageIndexChange(object sender, GridPageEventArgs e)
        {
            gvInspectionEquipment.PageIndex = e.NewPageIndex;
            BindDataInspectionEquipment();
        }

        protected void gvInspectionEquipment_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = gvInspectionEquipment.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "AttachUrl")
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CommonUpLoadFile&menuId={1}", id, BLL.Const.DataBaseProjectMenuId)));
            }
        }
        #endregion
    }
}