using BLL;
using BLL.CQMS.ProcessControl;
using System;
using System.Collections.Generic;
using System.Linq;
namespace FineUIPro.Web.CQMS.ProcessControl
{
    public partial class InspectionManagementEdit : PageBase
    {
        
        #region 加载
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetButtonPower();
                 BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(drpUnit, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true);//施工分包商
                 
                this.drpUnit.SelectedValue = CurrUser.UnitId;
                this.drpUnit.Enabled = false;
                BLL.CNProfessionalService.InitCNProfessionalDownList(this.drpCNProfessionalId, true);//专业
                var db = Funs.DB;
                var userList = from x in db.Sys_User
                               join y in db.Project_ProjectUnit
                               on x.UnitId equals y.UnitId
                               join p in db.Project_ProjectUser
                               on x.UserId equals p.UserId
                               where p.RoleId.Contains(Const.ZBCNEngineer)
                               where y.UnitId == Const.UnitId_TCC && p.ProjectId == CurrUser.LoginProjectId && y.ProjectId == CurrUser.LoginProjectId
                               select new { UserId = x.UserId, UserName = x.UserName };
                drpAudit.DataValueField = "UserId";
                drpAudit.DataTextField = "UserName";
                this.drpAudit.DataSource = userList.ToList();
                this.drpAudit.DataBind();
                this.hdInspectionNoticeId.Text = Request.Params["inspectionId"];
                this.agree.Hidden = true;
                this.options.Hidden = true;
                this.Panel1.Hidden = true;
                this.btnSave.Hidden = true;
                this.btnSubmit.Hidden = true;
                if (!string.IsNullOrEmpty(this.hdInspectionNoticeId.Text))
                {
                    Model.ProcessControl_InspectionManagement inspectionManagement = BLL.InspectionManagementService.GetInspectionManagementById(this.hdInspectionNoticeId.Text.Trim());
                    if (inspectionManagement != null)
                    {
                        this.Status.Text = inspectionManagement.Status;
                        this.AuditMan.Text = inspectionManagement.AuditMan;
                        this.drpAudit.SelectedValue = inspectionManagement.AuditMan;
                        if (!string.IsNullOrEmpty(inspectionManagement.UnitId))
                        {
                            this.drpUnit.SelectedValue = inspectionManagement.UnitId;
                        }
                        if (!string.IsNullOrEmpty(inspectionManagement.CNProfessionalId))
                        {
                            this.drpCNProfessionalId.SelectedValue = inspectionManagement.CNProfessionalId;
                        }
                        this.txtAcceptanceSite.Text = inspectionManagement.AcceptanceSite;
                        this.txtAcceptanceCheckMan.Text = inspectionManagement.AcceptanceCheckMan;
                        this.txtNoticeCode.Text = inspectionManagement.NoticeCode;
                        this.hdParentDivisionProjectId.Text = inspectionManagement.ParentDivisionProjectId;
                        if (inspectionManagement.IsOnceQualified.HasValue)
                        {
                            if (inspectionManagement.IsOnceQualified.Value)
                            {
                                this.rblIsOnceQualified.SelectedValue = "True";
                            }
                            else
                            {
                                this.rblIsOnceQualified.SelectedValue = "False";
                            }
                            if (this.rblIsOnceQualified.SelectedValue == "False")
                            {
                                this.txtUnqualifiedReason.Hidden = false;
                                this.txtUnqualifiedReason.Text = inspectionManagement.UnqualifiedReason;
                            }
                        }
                        this.Grid1.DataSource = BLL.InspectionManagementDetailService.GetInspectionDetails(this.hdInspectionNoticeId.Text.Trim());
                        this.Grid1.DataBind();
                        this.txtInspectionCode.Text = inspectionManagement.InspectionCode;
                       
                        this.txtInspectionDate.Text = inspectionManagement.InspectionDate.HasValue ? string.Format("{0:yyyy-MM-dd}", inspectionManagement.InspectionDate) : "";
                      
                        this.rblIsOnceQualified.Hidden = true;
                        this.txtInspectionDate.Hidden = true;
                        var res = InspectionManagementApproveService.GetCurrentApprove(hdInspectionNoticeId.Text.ToString());
                        var approveList = InspectionManagementApproveService.getListData(hdInspectionNoticeId.Text.ToString());
                        if (res != null)
                        {
                            if (res.ApproveMan == CurrUser.UserId && res.ApproveType!=Const.InspectionManagement_Complete && inspectionManagement.Status == Const.InspectionManagement_Complete)
                            {
                                this.btnSave.Hidden = false;
                                this.btnSubmit.Hidden = false;
                            }
                            if (res.ApproveType == BLL.Const.InspectionManagement_Audit && inspectionManagement.Status == Const.InspectionManagement_Complete)
                            {
                                this.drpUnit.Enabled = false;
                                this.drpCNProfessionalId.Enabled = false;
                                this.txtInspectionCode.Enabled = false;
                                this.txtNoticeCode.Enabled = false;
                                this.txtAcceptanceSite.Enabled = false;
                                this.txtAcceptanceCheckMan.Enabled = false;
                             
                                //this.rblIsOnceQualified.Enabled = false;
                               // this.txtInspectionDate.Enabled = false;
                                //this.txtUnqualifiedReason.Enabled = false;
                               
                                this.rblIsOnceQualified.Hidden = false;
                                this.txtInspectionDate.Hidden = false;
                                if (res.ApproveMan == CurrUser.UserId )
                                {
                                    //this.agree.Hidden = false;
                                    this.Panel1.Hidden = false;
                                    this.options.Hidden = false;
                                    this.drpAudit.Hidden = true;
                                }
                                
                            }
                        }
                        else if (approveList.Count > 0)
                        {
                            this.rblIsOnceQualified.Hidden = false;
                            this.txtInspectionDate.Hidden = false;
                            this.btnSave.Hidden = true;
                            this.btnSubmit.Hidden = true;
                        }//第一次进来  显示保存 审核按钮
                        else if( inspectionManagement.Status == Const.InspectionManagement_Complete)
                        {
                            
                            this.btnSave.Hidden = false;
                            this.btnSubmit.Hidden = false;
                        }
                    }
                }
            }
        }
        #endregion
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.drpUnit.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请先选择施工分包商!", MessageBoxIcon.Warning);
                return;
            }
            if (this.drpCNProfessionalId.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请先选择专业!", MessageBoxIcon.Warning);
                return;
            }
            
            Model.ProcessControl_InspectionManagement inspectionManagement = new Model.ProcessControl_InspectionManagement();
            inspectionManagement.ProjectId = this.CurrUser.LoginProjectId;
            if (this.drpUnit.SelectedValue != BLL.Const._Null)
            {
                inspectionManagement.UnitId = this.drpUnit.SelectedValue;
            }
            if (this.drpCNProfessionalId.SelectedValue != BLL.Const._Null)
            {
                inspectionManagement.CNProfessionalId = this.drpCNProfessionalId.SelectedValue;
            }
            inspectionManagement.NoticeCode = this.txtNoticeCode.Text.Trim();
            if (!string.IsNullOrEmpty(this.hdUnitWorkId.Text.Trim()))
            {
                inspectionManagement.UnitWorkId = this.hdUnitWorkId.Text.Trim();
            }
            if (!string.IsNullOrEmpty(this.hdBranch.Text.Trim()))
            {
                inspectionManagement.Branch = this.hdBranch.Text.Trim();
            }
            if (!string.IsNullOrEmpty(this.hdControlPointType.Text.Trim()))
            {
                inspectionManagement.ControlPointType = this.hdControlPointType.Text.Trim();
            }
            inspectionManagement.AcceptanceSite = this.txtAcceptanceSite.Text.Trim();
            inspectionManagement.AcceptanceCheckMan = this.txtAcceptanceCheckMan.Text.Trim();
            if (!string.IsNullOrEmpty(this.rblIsOnceQualified.SelectedValue))
            {
                if (this.rblIsOnceQualified.SelectedValue == "True")
                {
                    inspectionManagement.IsOnceQualified = true;
                }
                else
                {
                    inspectionManagement.IsOnceQualified = false;
                    inspectionManagement.UnqualifiedReason = this.txtUnqualifiedReason.Text.Trim();
                }
            }
            inspectionManagement.InspectionCode = this.txtInspectionCode.Text.Trim();
            inspectionManagement.InspectionDate = Funs.GetNewDateTime(this.txtInspectionDate.Text.Trim());
            inspectionManagement.Status = this.Status.Text;
            inspectionManagement.AuditMan = this.AuditMan.Text;
            inspectionManagement.UnqualifiedOption = txtOptions.Text.Trim();
            if (string.IsNullOrEmpty(this.hdInspectionNoticeId.Text.Trim()))
            {
                inspectionManagement.CompileDate = DateTime.Now;
                if (!string.IsNullOrEmpty(this.hdInspectionNoticeId.Text.Trim()))
                {
                    inspectionManagement.InspectionId = this.hdInspectionNoticeId.Text.Trim();
                }
                else
                {
                    inspectionManagement.InspectionId = SQLHelper.GetNewID(typeof(Model.ProcessControl_InspectionManagement));
                    this.hdInspectionNoticeId.Text = inspectionManagement.InspectionId;
                }
                BLL.InspectionManagementService.AddInspectionManagement(inspectionManagement);
            }
            else
            {
                Model.ProcessControl_InspectionManagement oldInspectionManagement = BLL.InspectionManagementService.GetInspectionManagementById(this.hdInspectionNoticeId.Text.Trim());
                inspectionManagement.AttachUrl2 = oldInspectionManagement.AttachUrl2;
                inspectionManagement.CompileMan = oldInspectionManagement.CompileMan;
                inspectionManagement.PlanComplateDate = oldInspectionManagement.PlanComplateDate;
                inspectionManagement.RePlanComplateDate = oldInspectionManagement.RePlanComplateDate;
               // inspectionManagement.InspectionCode =  oldInspectionManagement.InspectionCode;
                inspectionManagement.UnitWorkId = oldInspectionManagement.UnitWorkId;
                inspectionManagement.CCUnitIds = oldInspectionManagement.CCUnitIds;
                if (string.IsNullOrEmpty(oldInspectionManagement.CompileMan2))
                {
                    inspectionManagement.CompileMan2 = this.CurrUser.UserId;
                }
                else
                {
                    inspectionManagement.CompileMan2 = oldInspectionManagement.CompileMan2;
                }
                //inspectionManagement.IsOnceQualified = inspectionManagement.IsOnceQualified;
                inspectionManagement.InspectionId = this.hdInspectionNoticeId.Text.Trim();
               
                BLL.InspectionManagementService.UpdateInspectionManagement(inspectionManagement);
            }
            ///保存当前编制人记录,或者,更新当前编制人记录的编制时间
            Model.ProcessControl_InspectionManagementApprove approve = InspectionManagementApproveService.GetApproveByApproveMan(inspectionManagement.InspectionId, CurrUser.UserId);
            if (approve == null)
            {
                approve = new Model.ProcessControl_InspectionManagementApprove();
                approve.InspectionId = inspectionManagement.InspectionId;
                approve.ApproveMan = this.CurrUser.UserId;
                approve.ApproveType = Const.InspectionManagement_Compile;
            }           
                approve.ApproveDate = DateTime.Now;
                approve.IsAgree = Convert.ToBoolean(rblIsAgree.SelectedValue);
            
            approve.ApproveIdea = txtOptions.Text.Trim();
            if (string.IsNullOrEmpty(approve.InspectionManagementApproveId))
            {
                InspectionManagementApproveService.AddApprove(approve);
            }
            else
            {
                InspectionManagementApproveService.UpdateApprove(approve);
            }
            
            //保存下一步审核人
            if (approve.ApproveType == Const.InspectionManagement_Audit)//==会签状态升级版本
            {
                if (Convert.ToBoolean(rblIsAgree.SelectedValue))
                {
                    Model.ProcessControl_InspectionManagementApprove reApprove = new Model.ProcessControl_InspectionManagementApprove();
                    reApprove.InspectionId = approve.InspectionId;
                    reApprove.ApproveDate = DateTime.Now.AddSeconds(10);
                    reApprove.ApproveMan = approve.ApproveMan;
                    reApprove.ApproveType = Const.InspectionManagement_Complete;                    
                    InspectionManagementApproveService.AddApprove(reApprove);
                    if (!inspectionManagement.InspectionDate.HasValue)
                    {
                        inspectionManagement.InspectionDate = DateTime.Now;
                        BLL.InspectionManagementService.UpdateInspectionManagement(inspectionManagement);
                    }
                }
                else
                {
                    Model.ProcessControl_InspectionManagementApprove reApprove = new Model.ProcessControl_InspectionManagementApprove();
                    reApprove.InspectionId = approve.InspectionId;
                    reApprove.ApproveMan = inspectionManagement.CompileMan2;
                    reApprove.ApproveType = Const.InspectionManagement_ReCompile;
                    var im = BLL.InspectionManagementService.GetInspectionManagementById(inspectionManagement.InspectionId);
                    im.Status = "0";//打回重新编制 
                    APICommonService.SendSubscribeMessage(inspectionManagement.CompileMan2, "控制点检查检测不通过", this.CurrUser.UserName, string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
                    BLL.InspectionManagementService.UpdateInspectionManagement(im);
                    InspectionManagementApproveService.AddApprove(reApprove);
                }
            }
            else
            {
                Model.ProcessControl_InspectionManagementApprove newApprove = new Model.ProcessControl_InspectionManagementApprove();
                newApprove.InspectionId = inspectionManagement.InspectionId;
                newApprove.ApproveMan = this.drpAudit.SelectedValue;
                newApprove.ApproveType = Const.InspectionManagement_Audit;
                newApprove.ApproveIdea = txtOptions.Text.Trim();
                APICommonService.SendSubscribeMessage(inspectionManagement.CompileMan2, "控制点检查检测待办理", this.CurrUser.UserName, string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
                InspectionManagementApproveService.AddApprove(newApprove);
            }
            
            ShowNotify("提交成功!", MessageBoxIcon.Success);
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #region 保存
        /// 
        /// 保存按钮
        /// 
        /// 
        /// 
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (this.drpUnit.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请先选择施工分包商!", MessageBoxIcon.Warning);
                return;
            }
            if (this.drpCNProfessionalId.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请先选择专业!", MessageBoxIcon.Warning);
                return;
            }
            
            Model.ProcessControl_InspectionManagement inspectionManagement = new Model.ProcessControl_InspectionManagement();
            inspectionManagement.ProjectId = this.CurrUser.LoginProjectId;
            if (this.drpUnit.SelectedValue != BLL.Const._Null)
            {
                inspectionManagement.UnitId = this.drpUnit.SelectedValue;
            }
            if (this.drpCNProfessionalId.SelectedValue != BLL.Const._Null)
            {
                inspectionManagement.CNProfessionalId = this.drpCNProfessionalId.SelectedValue;
            }
            inspectionManagement.NoticeCode = this.txtNoticeCode.Text.Trim();
            if (!string.IsNullOrEmpty(this.hdUnitWorkId.Text.Trim()))
            {
                inspectionManagement.UnitWorkId = this.hdUnitWorkId.Text.Trim();
            }
            if (!string.IsNullOrEmpty(this.hdBranch.Text.Trim()))
            {
                inspectionManagement.Branch = this.hdBranch.Text.Trim();
            }
            if (!string.IsNullOrEmpty(this.hdControlPointType.Text.Trim()))
            {
                inspectionManagement.ControlPointType = this.hdControlPointType.Text.Trim();
            }
            inspectionManagement.AcceptanceSite = this.txtAcceptanceSite.Text.Trim();
            inspectionManagement.AcceptanceCheckMan = this.txtAcceptanceCheckMan.Text.Trim();
            if (!string.IsNullOrEmpty(this.rblIsOnceQualified.SelectedValue))
            {
                if (this.rblIsOnceQualified.SelectedValue == "True")
                {
                    inspectionManagement.IsOnceQualified = true;
                }
                else
                {
                    inspectionManagement.IsOnceQualified = false;
                    inspectionManagement.UnqualifiedReason = this.txtUnqualifiedReason.Text.Trim();
                }
            }
            inspectionManagement.InspectionCode = this.txtInspectionCode.Text.Trim();
            inspectionManagement.InspectionDate = Funs.GetNewDateTime(this.txtInspectionDate.Text.Trim());
            inspectionManagement.Status = this.Status.Text;
            inspectionManagement.AuditMan = this.AuditMan.Text;
            if (string.IsNullOrEmpty(this.hdInspectionNoticeId.Text.Trim()))
            {
                 inspectionManagement.CompileDate = DateTime.Now;
                if (!string.IsNullOrEmpty(this.hdInspectionNoticeId.Text.Trim()))
                {
                    inspectionManagement.InspectionId = this.hdInspectionNoticeId.Text.Trim();
                }
                else
                {
                    inspectionManagement.InspectionId = SQLHelper.GetNewID(typeof(Model.ProcessControl_InspectionManagement));
                    this.hdInspectionNoticeId.Text = inspectionManagement.InspectionId;
                }
                BLL.InspectionManagementService.AddInspectionManagement(inspectionManagement);
            }
            else
            {
                Model.ProcessControl_InspectionManagement oldInspectionManagement = BLL.InspectionManagementService.GetInspectionManagementById(this.hdInspectionNoticeId.Text.Trim());
                inspectionManagement.AttachUrl2 = oldInspectionManagement.AttachUrl2;
                inspectionManagement.InspectionId = this.hdInspectionNoticeId.Text.Trim();
                if (string.IsNullOrEmpty(oldInspectionManagement.CompileMan2))
                {
                    inspectionManagement.CompileMan2 = this.CurrUser.UserId;
                }
                else
                {
                    inspectionManagement.CompileMan2 = oldInspectionManagement.CompileMan2;
                }
                BLL.InspectionManagementService.UpdateInspectionManagement(inspectionManagement);
            }
            Model.ProcessControl_InspectionManagementApprove approve = InspectionManagementApproveService.GetApproveByApproveMan(inspectionManagement.InspectionId, CurrUser.UserId);
            if (approve == null)
            {
                approve = new Model.ProcessControl_InspectionManagementApprove();
                approve.InspectionId = inspectionManagement.InspectionId;
                approve.ApproveMan = this.CurrUser.UserId;
                approve.ApproveType = Const.InspectionManagement_Compile;
            }
            approve.IsAgree = Convert.ToBoolean(rblIsAgree.SelectedValue);
            approve.ApproveIdea = txtOptions.Text.Trim();
            if (string.IsNullOrEmpty(approve.InspectionManagementApproveId))
            {
                InspectionManagementApproveService.AddApprove(approve);
            }
            else
            {
                InspectionManagementApproveService.UpdateApprove(approve);
            }
            ShowNotify("保存成功!", MessageBoxIcon.Success);
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion
        #region 附件上传
        /// 
        /// 附件上传
        /// 
        /// 
        /// 
        protected void btnAttach_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdInspectionNoticeId.Text))   //新增记录
            {
                this.hdInspectionNoticeId.Text = SQLHelper.GetNewID(typeof(Model.ProcessControl_InspectionManagement));
            }
            var res = InspectionManagementApproveService.GetState(this.hdInspectionNoticeId.Text);
            if (res != null)
            {
                if (res.ApproveType == BLL.Const.InspectionManagement_ReCompile)
                {
                    PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/InspectionManagement&menuId={1}", this.hdInspectionNoticeId.Text, BLL.Const.InspectionNoticeMenuId)));
                }
                else if (res.ApproveType == BLL.Const.InspectionManagement_Compile)
                {
                    PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/InspectionManagement&menuId={1}", this.hdInspectionNoticeId.Text, BLL.Const.InspectionNoticeMenuId)));
                }
                else
                {
                    PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/InspectionManagement&menuId={1}", this.hdInspectionNoticeId.Text, BLL.Const.InspectionNoticeMenuId)));
                }
            }
            else
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/InspectionManagement&menuId={1}", this.hdInspectionNoticeId.Text, BLL.Const.InspectionNoticeMenuId)));
            }
        }
        protected void btnAttach_Click1(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdInspectionNoticeId.Text))   //新增记录
            {
                this.hdInspectionNoticeId.Text = SQLHelper.GetNewID(typeof(Model.ProcessControl_InspectionManagement));
            }
            var res = InspectionManagementApproveService.GetState(this.hdInspectionNoticeId.Text);
            if (res != null)
            {
                if (res.ApproveType == BLL.Const.InspectionManagement_ReCompile)
                {
                    PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/InspectionManagement&menuId={1}", this.hdInspectionNoticeId.Text+"Option", BLL.Const.InspectionNoticeMenuId)));
                }
                else if (res.ApproveType == BLL.Const.InspectionManagement_Compile)
                {
                    PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/InspectionManagement&menuId={1}", this.hdInspectionNoticeId.Text + "Option", BLL.Const.InspectionNoticeMenuId)));
                }
                else
                {
                    PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/InspectionManagement&menuId={1}", this.hdInspectionNoticeId.Text + "Option", BLL.Const.InspectionNoticeMenuId)));
                }
            }
            else
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/InspectionManagement&menuId={1}", this.hdInspectionNoticeId.Text + "Option", BLL.Const.InspectionNoticeMenuId)));
            }
        }
        #endregion
        #region 搜索
        /// 
        /// 搜索
        /// 
        /// 
        /// 
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (this.drpCNProfessionalId.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请先选择专业!", MessageBoxIcon.Warning);
                return;
            }
            string window = String.Format("ShowUnitWork.aspx?CNPrefessionalId={0}", this.drpCNProfessionalId.SelectedValue, "查找 - ");
            PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window));
        }
        #endregion
        #region 关闭弹出窗口
        /// 
        /// 关闭弹出窗口
        /// 
        /// 
        /// 
        protected void Window1_Close(object sender, WindowCloseEventArgs e)
        {
            this.hdUnitWorkId.Text = string.Empty;
            this.hdBranch.Text = string.Empty;
            this.hdControlPointType.Text = string.Empty;
            List lists = Funs.GetStrListByStr(hdItemsString.Text, '|');
            string divisionProjectId = lists[0];
            string breakdownProjectId = lists[1];
            var divisionProject = BLL.DivisionProjectService.GetDivisionProjectById(divisionProjectId);
            if (divisionProject != null)
            {
                this.hdBranch.Text = divisionProject.DivisionProjectId;
                if (!string.IsNullOrEmpty(divisionProject.UnitWorkId))
                {
                    var unitWork = BLL.UnitWorkService.getUnitWorkByUnitWorkId(divisionProject.UnitWorkId);
                    if (unitWork != null)
                    {
                        this.hdUnitWorkId.Text = unitWork.UnitWorkId;
                    }
                }
            }
            var breakdownProject = BLL.BreakdownProjectService.GetBreakdownProjectById(breakdownProjectId);
            if (breakdownProject != null)
            {
                this.hdControlPointType.Text = breakdownProject.BreakdownProjectId;
            }
        }
        #endregion
        #region 获取按钮权限
        /// 
        /// 获取按钮权限
        /// 
        /// 
        /// 
        private void GetButtonPower()
        {
            if (Request.Params["value"] == BLL.Const._Null)
            {
                return;
            }
            var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.InspectionManagementMenuId);
            if (buttonList.Count > 0)
            {
                if (buttonList.Contains(BLL.Const.BtnSave))
                {
                    this.btnSave.Hidden = false;
                }
            }
        }
        #endregion
        #region 是否一次合格选择事件
        /// 
        /// 是否一次合格选择事件
        /// 
        /// 
        /// 
        protected void rblIsOnceQualified_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.rblIsOnceQualified.SelectedValue == "True")
            {
                this.txtUnqualifiedReason.Hidden = true;
                this.txtInspectionDate.Hidden = false;
                this.rblIsAgree.SelectedValue = "true";
            }
            else
            {
                this.txtUnqualifiedReason.Hidden = false; 
                this.txtInspectionDate.Hidden = true;
                this.rblIsAgree.SelectedValue = "false";
            }
        }
        #endregion
        #region 转换字符串
        /// 
        /// 获取单位工程
        /// 
        /// 
        /// 
        protected string ConvertUnitWork(object UnitWorkId)
        {
            string name = string.Empty;
            if (UnitWorkId != null)
            {
                Model.WBS_UnitWork unitWork = BLL.UnitWorkService.GetUnitWorkByUnitWorkId(UnitWorkId.ToString());
                if (unitWork != null)
                {
                    name = unitWork.UnitWorkName;
                }
            }
            return name;
        }
        /// 
        /// 获取分部
        /// 
        /// 
        /// 
        protected string ConvertBranch(object Branch)
        {
            string name = string.Empty;
            if (Branch != null)
            {
                var branch = BLL.DivisionProjectService.GetDivisionProjectById(Branch.ToString());
                if (branch != null)
                {
                    name = branch.DivisionName;
                }
            }
            return name;
        }
        /// 
        /// 获取控制点内容
        /// 
        /// 
        /// 
        protected string ConvertControlPointType(object ControlPointType)
        {
            string name = string.Empty;
            if (ControlPointType != null)
            {
                var controlPointType = BLL.BreakdownProjectService.GetBreakdownProjectById(ControlPointType.ToString());
                if (controlPointType != null)
                {
                    name = controlPointType.BreakdownName;
                }
            }
            return name;
        }
        /// 
        /// 获取控制点等级
        /// 
        /// 
        /// 
        protected string ConvertClass(object ControlPointType)
        {
            string name = string.Empty;
            if (ControlPointType != null)
            {
                var controlPointType = BLL.BreakdownProjectService.GetBreakdownProjectById(ControlPointType.ToString());
                if (controlPointType != null)
                {
                    name = controlPointType.Class;
                }
            }
            return name;
        }
        #endregion
    }
}