using BLL;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.CQMS.ConstructionLog
{
    public partial class ConstructionLogEdit : PageBase
    {
        /// 
        /// 主键
        /// 
        public string ConstructionLogId
        {
            get
            {
                return (string)ViewState["ConstructionLogId"];
            }
            set
            {
                ViewState["ConstructionLogId"] = value;
            }
        }
        /// 
        /// 办理类型
        /// 
        public string State
        {
            get
            {
                return (string)ViewState["State"];
            }
            set
            {
                ViewState["State"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
                ConstructionLogId = Request.Params["ConstructionLogId"];
                this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
                plApprove1.Hidden = true;
                plApprove2.Hidden = true;
                rblIsAgree.Hidden = true;
                rblIsAgree.SelectedValue = "true";
                if (project != null)
                {
                    this.txtProjectName.Text = project.ProjectName;
                    this.txtProjectCode.Text = project.ProjectCode;
                }
                UnitService.InitUnitByProjectIdUnitTypeDropDownList2(drpUnit, this.CurrUser.LoginProjectId, true);
                if (!string.IsNullOrEmpty(ConstructionLogId))
                {
                    this.hdConstructionLogId.Text = ConstructionLogId;
                    plApprove1.Hidden = false;
                    plApprove2.Hidden = false;
                    var dt = CQMSConstructionLogApproveService.getListData(ConstructionLogId);
                    gvApprove.DataSource = dt;
                    gvApprove.DataBind();
                    hdConstructionLogId.Text = ConstructionLogId;
                    Model.CQMS_ConstructionLog constructionLog = BLL.CQMSConstructionLogService.GetConstructionLogById(ConstructionLogId);
                    if (constructionLog.LogDate != null)
                    {
                        this.txtLogDate.Text = string.Format("{0:yyyy-MM-dd}", constructionLog.LogDate);
                    }
                    this.txtWeather.Text = constructionLog.Weather;
                    this.txtDayTemperature.Text = constructionLog.DayTemperature;
                    this.txtNightTemperature.Text = constructionLog.NightTemperature;
                    this.txtWeatherRemark.Text = constructionLog.WeatherRemark;
                    var item = (from x in Funs.DB.CQMS_ConstructionLogItem where x.ConstructionLogId == ConstructionLogId select x).FirstOrDefault();
                    if (item != null)
                    {
                        if (!string.IsNullOrEmpty(item.UnitId))
                        {
                            this.drpUnit.SelectedValue = item.UnitId;
                            this.hdUnitId.Text = item.UnitId;
                        }
                        this.txtConstructionManager.Text = item.ConstructionManager;
                        this.txtSafetyGuardian.Text = item.SafetyGuardian;
                        this.txtConstructionWorker.Text = item.ConstructionWorker;
                        if (item.MechanicNum != null)
                        {
                            this.txtMechanicNum.Text = item.MechanicNum.ToString();
                        }
                        if (item.MechanicNum1 != null)
                        {
                            this.txtMechanicNum1.Text = item.MechanicNum1.ToString();
                        }
                        if (item.MechanicNum2 != null)
                        {
                            this.txtMechanicNum2.Text = item.MechanicNum2.ToString();
                        }
                        if (item.MechanicNum3 != null)
                        {
                            this.txtMechanicNum3.Text = item.MechanicNum3.ToString();
                        }
                        if (item.MechanicNum4 != null)
                        {
                            this.txtMechanicNum4.Text = item.MechanicNum4.ToString();
                        }
                        if (item.MechanicNum5 != null)
                        {
                            this.txtMechanicNum5.Text = item.MechanicNum5.ToString();
                        }
                        if (item.MechanicNum6 != null)
                        {
                            this.txtMechanicNum6.Text = item.MechanicNum6.ToString();
                        }
                        if (item.MechanicNum7 != null)
                        {
                            this.txtMechanicNum7.Text = item.MechanicNum7.ToString();
                        }
                        if (item.MechanicNum8 != null)
                        {
                            this.txtMechanicNum8.Text = item.MechanicNum8.ToString();
                        }
                        if (item.MechanicNum9 != null)
                        {
                            this.txtMechanicNum9.Text = item.MechanicNum9.ToString();
                        }
                        if (item.MechanicNum10 != null)
                        {
                            this.txtMechanicNum10.Text = item.MechanicNum10.ToString();
                        }
                        if (item.MechanicNum11 != null)
                        {
                            this.txtMechanicNum11.Text = item.MechanicNum11.ToString();
                        }
                        if (item.MechanicNum12 != null)
                        {
                            this.txtMechanicNum12.Text = item.MechanicNum12.ToString();
                        }
                        if (item.MechanicNum13 != null)
                        {
                            this.txtMechanicNum13.Text = item.MechanicNum13.ToString();
                        }
                        if (item.MechanicNum14 != null)
                        {
                            this.txtMechanicNum14.Text = item.MechanicNum14.ToString();
                        }
                        if (item.MechanicNum15 != null)
                        {
                            this.txtMechanicNum15.Text = item.MechanicNum15.ToString();
                        }
                        if (item.MechanicNum16 != null)
                        {
                            this.txtMechanicNum16.Text = item.MechanicNum16.ToString();
                        }
                        if (item.MechanicNum17 != null)
                        {
                            this.txtMechanicNum17.Text = item.MechanicNum17.ToString();
                        }
                        if (item.LabourNum != null)
                        {
                            this.txtLabourNum.Text = item.LabourNum.ToString();
                        }
                        this.txtMainConstructionMachine.Text = item.MainConstructionMachine;
                        this.txtConstructionContent.Text = item.ConstructionContent;
                        this.txtConstructionEnvironment.Text = item.ConstructionEnvironment;
                        this.txtSafetyWorkSituation.Text = item.SafetyWorkSituation;
                        if (!string.IsNullOrEmpty(item.SafetyAndQualityMeasures))
                        {
                            string[] strs = item.SafetyAndQualityMeasures.Split(',');
                            this.cblSafetyAndQualityMeasures.SelectedValueArray = strs;
                        }
                        if (!string.IsNullOrEmpty(item.HabituaViolations))
                        {
                            string[] strs = item.HabituaViolations.Split(',');
                            this.cblHabituaViolations.SelectedValueArray = strs;
                        }
                        if (!string.IsNullOrEmpty(item.SafetyStandardization))
                        {
                            string[] strs = item.SafetyStandardization.Split(',');
                            this.cblSafetyStandardization.SelectedValueArray = strs;
                        }
                        this.txtCivilizedConstruction.Text = item.CivilizedConstruction;
                        this.txtEquipment1.Text = item.Equipment1;
                        this.txtEquipment2.Text = item.Equipment2;
                        this.txtEquipment3.Text = item.Equipment3;
                        this.txtEquipment4.Text = item.Equipment4;
                        this.txtEquipment5.Text = item.Equipment5;
                        this.txtEquipment6.Text = item.Equipment6;
                        this.txtEquipment7.Text = item.Equipment7;
                        this.txtProcessHandover.Text = item.ProcessHandover;
                        this.txtWorkArrangement.Text = item.WorkArrangement;
                        this.txtMeetingSituation.Text = item.MeetingSituation;
                        this.txtVisaRecords.Text = item.VisaRecords;
                        this.txtUnresolvedIssues.Text = item.UnresolvedIssues;
                        this.txtFileProcessing.Text = item.FileProcessing;
                        this.txtRectificationOfIssues.Text = item.RectificationOfIssues;
                        this.txtImportantEvents.Text = item.ImportantEvents;
                        this.txtProblemAndCauseAnalysis.Text = item.ProblemAndCauseAnalysis;
                        var list = BLL.CQMSConstructionLogImageProgressService.GetConstructionLogImageProgressByConstructionLogIdAndUnitId(ConstructionLogId, item.UnitId);
                        if (list.Count > 0)
                        {
                            this.Grid5.DataSource = list;
                            this.Grid5.DataBind();
                        }
                    }
                    if (!string.IsNullOrEmpty(constructionLog.State))
                    {
                        State = constructionLog.State;
                    }
                    else
                    {
                        State = BLL.Const.ConstructionLog_Compile;
                        this.rblIsAgree.Hidden = true;
                    }
                    if (State != BLL.Const.ConstructionLog_Complete)
                    {
                        CQMSConstructionLogService.Init(drpHandleType, State, false);
                    }
                    if (State == BLL.Const.ConstructionLog_Compile || State == BLL.Const.ConstructionLog_ReCompile)
                    {
                        this.rblIsAgree.Hidden = true;
                        UserService.Init2(drpHandleMan, CurrUser.LoginProjectId, false);
                        if (State == BLL.Const.ConstructionLog_ReCompile)
                        {
                            plApprove1.Hidden = true;
                        }
                    }
                    else
                    {
                        this.drpHandleMan.Enabled = false;
                        this.rblIsAgree.Hidden = false;
                    }
                }
                else
                {
                    this.hdConstructionLogId.Text = SQLHelper.GetNewID();
                    this.txtLogDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
                    State = Const.ConstructionLog_Compile;
                    CQMSConstructionLogService.Init(drpHandleType, State, false);
                    UserService.Init2(drpHandleMan, CurrUser.LoginProjectId, false);
                    if (project != null && project.City != null)
                    {
                        var weather = (from x in Funs.DB.CQMS_ConstructionLogWeather where x.ProjectId == this.CurrUser.LoginProjectId && x.City == project.City && x.Date == Funs.GetNewDateTime(this.txtLogDate.Text.Trim()) orderby x.UpdateTime descending select x).FirstOrDefault();
                        if (weather != null)
                        {
                            string WeaDay = weather.WeaDay;
                            string WeaNight = weather.WeaNight;
                            if (WeaDay == WeaNight)
                            {
                                this.txtWeather.Text = WeaDay;
                            }
                            else
                            {
                                this.txtWeather.Text = WeaDay + "转" + WeaNight;
                            }
                            this.txtDayTemperature.Text = weather.Tem1.Value.ToString("0.#");
                            this.txtNightTemperature.Text = weather.Tem2.Value.ToString("0.#");
                        }
                        //string api_key = "c6de966ba27f600ecab87f43a9c32ca2";
                        //string result = Funs.RequestGet2("https://restapi.amap.com/v3/config/district?keywords=" + project.City + "&subdistrict=0&key=" + api_key, "");
                        //var j1 = JsonConvert.DeserializeObject(result);
                        //if (j1.infocode == "10000")
                        //{
                        //    string cityid = j1.districts[0].adcode;
                        //    string result2 = Funs.RequestGet2("https://restapi.amap.com/v3/weather/weatherInfo?city=" + cityid + "&extensions=all&key=" + api_key, "");
                        //    var j2 = JsonConvert.DeserializeObject(result2);
                        //    if (j2.infocode == "10000")
                        //    {
                        //        this.txtWeather.Text = j2.forecasts[0].casts[0].dayweather;
                        //        this.txtDayTemperature.Text = j2.forecasts[0].casts[0].daytemp;
                        //        this.txtNightTemperature.Text = j2.forecasts[0].casts[0].nighttemp;
                        //    }
                        //}
                    }
                }
                DateTime date = Convert.ToDateTime(this.txtLogDate.Text.Trim());
                this.txtWeek.Text = Funs.GetWeekDay(date.DayOfWeek.ToString());
                BindGrid1();
                BindGrid2();
            }
        }
        private void BindGrid1()
        {
            string strSql = @"SELECT chec.CheckControlCode,chec.CheckSite,chec.ProjectId,chec.unitId,cNProfessional.ProfessionalName,"
                          + @" QualityQuestionType.QualityQuestionType as QuestionType,"
                          + @" chec.checkman,chec.CheckDate,chec.DocCode,chec.submitman,chec.state,chec.CNProfessionalCode,"
                          + @" unit.UnitName,unitWork.UnitWorkName,u.userName "
                          + @" FROM Check_CheckControl chec"
                          + @" left join Base_Unit unit on unit.unitId=chec.unitId"
                          + @" left join Base_CNProfessional cNProfessional on cNProfessional.CNProfessionalId=chec.CNProfessionalCode"
                          + @" left join WBS_UnitWork unitWork on unitWork.UnitWorkId = chec.UnitWorkId"
                          + @" left join Base_QualityQuestionType QualityQuestionType on QualityQuestionType.QualityQuestionTypeId = chec.QuestionType"
                          + @" left join sys_User u on u.userId = chec.CheckMan"
                          + @" where chec.ProjectId=@ProjectId";
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            strSql += " AND chec.CheckDate=@checkTime ";
            listStr.Add(new SqlParameter("@checkTime", txtLogDate.Text.Trim()));
            if (drpUnit.SelectedValue != BLL.Const._Null)
            {
                strSql += " AND chec.unitId=@unitId";
                listStr.Add(new SqlParameter("@unitId", drpUnit.SelectedValue));
            }
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid1.RecordCount = tb.Rows.Count;
            tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = GetPagedDataTable(Grid1, tb);
            Grid1.DataSource = table;
            Grid1.DataBind();
            Grid3.DataSource = table;
            Grid3.DataBind();
        }
        private void BindGrid2()
        {
            DateTime date = Funs.GetNewDateTimeOrNow(txtLogDate.Text.Trim());
            var inspectionManagement = (from x in Funs.DB.ProcessControl_InspectionManagement
                                        where x.InspectionDate.Value.Date == date && x.UnitId == this.drpUnit.SelectedValue
                                        select x).FirstOrDefault();
            if (inspectionManagement != null)
            {
                this.Grid2.DataSource = BLL.InspectionManagementDetailService.GetInspectionDetails(inspectionManagement.InspectionId);
                this.Grid2.DataBind();
                this.Grid4.DataSource = BLL.InspectionManagementDetailService.GetInspectionDetails(inspectionManagement.InspectionId);
                this.Grid4.DataBind();
            }
            else
            {
                this.Grid2.DataSource = null;
                this.Grid2.DataBind();
                this.Grid4.DataSource = null;
                this.Grid4.DataBind();
            }
        }
        private void BindGrid5()
        {
            DateTime date = Funs.GetNewDateTimeOrNow(txtLogDate.Text.Trim());
            var list = BLL.CQMSConstructionLogImageProgressService.GetConstructionLogImageProgressByConstructionLogIdAndUnitId(this.hdConstructionLogId.Text, this.drpUnit.SelectedValue);
            if (list.Count > 0)
            {
                this.Grid5.DataSource = list;
                this.Grid5.DataBind();
            }
            else
            {
                this.Grid5.DataSource = null;
                this.Grid5.DataBind();
            }
        }
        protected void txtLogDate_TextChanged(object sender, EventArgs e)
        {
            DateTime today = DateTime.Now.Date;
            if (!string.IsNullOrEmpty(this.txtLogDate.Text.Trim()))
            {
                today = Convert.ToDateTime(this.txtLogDate.Text.Trim()).Date;
            }
            this.txtWeek.Text = Funs.GetWeekDay(today.DayOfWeek.ToString());
            BindGrid1();
            BindGrid2();
        }
        protected void imgBtnFile_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdConstructionLogId.Text))   //新增记录
            {
                this.hdConstructionLogId.Text = SQLHelper.GetNewID(typeof(Model.CQMS_ConstructionLog));
            }
            PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/ConstructionLog&menuId={1}", this.hdConstructionLogId.Text, BLL.Const.CQMSConstructionLogMenuId)));
        }
        protected void WindowAtt_Close(object sender, WindowCloseEventArgs e)
        {
            List view = getViewTestPlanTrainingList();
            //将gd数据保存在list中
            Grid5.DataSource = view;
            Grid5.DataBind();
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.drpUnit.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请选择施工单位!", MessageBoxIcon.Warning);
                return;
            }
            SaveData("submit");
            ShowNotify("提交成功!", MessageBoxIcon.Success);
            if (string.IsNullOrEmpty(Request.Params["Main"]))
            {
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else
            {
                PageContext.RegisterStartupScript(String.Format("window.close();"));
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (this.drpUnit.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请选择施工单位!", MessageBoxIcon.Warning);
                return;
            }
            SaveData("save");
            ShowNotify("保存成功!", MessageBoxIcon.Success);
            if (string.IsNullOrEmpty(Request.Params["Main"]))
            {
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else
            {
                PageContext.RegisterStartupScript(String.Format("window.close();"));
            }
        }
        protected void SaveData(string saveType)
        {
            if (this.drpUnit.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请选择施工单位!", MessageBoxIcon.Warning);
                return;
            }
            SaveItem(false);
            Model.CQMS_ConstructionLog constructionLog = new Model.CQMS_ConstructionLog();
            constructionLog.ProjectId = CurrUser.LoginProjectId;
            constructionLog.LogDate = Funs.GetNewDateTime(this.txtLogDate.Text.Trim());
            constructionLog.Weather = this.txtWeather.Text.Trim();
            constructionLog.DayTemperature = this.txtDayTemperature.Text.Trim();
            constructionLog.NightTemperature = this.txtNightTemperature.Text.Trim();
            constructionLog.WeatherRemark = this.txtWeatherRemark.Text.Trim();
            //if (this.drpUnit.SelectedValue != BLL.Const._Null)
            //{
            //    constructionLog.UnitId = this.drpUnit.SelectedValue;
            //}
            //constructionLog.ProgressAndWorkSituation = this.txtProgressAndWorkSituation.Text.Trim();
            //constructionLog.ConstructionManager = this.txtConstructionManager.Text.Trim();
            //constructionLog.SafetyGuardian = this.txtSafetyGuardian.Text.Trim();
            //constructionLog.ConstructionWorker = this.txtConstructionWorker.Text.Trim();
            //constructionLog.MechanicNum = Funs.GetNewInt(this.txtMechanicNum.Text.Trim());
            //constructionLog.LabourNum = Funs.GetNewInt(this.txtLabourNum.Text.Trim());
            //constructionLog.MainConstructionMachine = this.txtMainConstructionMachine.Text.Trim();
            //constructionLog.ConstructionContent = this.txtConstructionContent.Text.Trim();
            //constructionLog.ConstructionEnvironment = this.txtConstructionEnvironment.Text.Trim();
            //constructionLog.SafetyWorkSituation = this.txtSafetyWorkSituation.Text.Trim();
            //string safetyAndQualityMeasures = string.Empty;
            //foreach (var item in this.cblSafetyAndQualityMeasures.SelectedValueArray)
            //{
            //    safetyAndQualityMeasures += item + ",";
            //}
            //if (!string.IsNullOrEmpty(safetyAndQualityMeasures))
            //{
            //    safetyAndQualityMeasures = safetyAndQualityMeasures.Substring(0, safetyAndQualityMeasures.Length - 1);
            //}
            //constructionLog.SafetyAndQualityMeasures = safetyAndQualityMeasures;
            //string habituaViolations = string.Empty;
            //foreach (var item in this.cblHabituaViolations.SelectedValueArray)
            //{
            //    habituaViolations += item + ",";
            //}
            //if (!string.IsNullOrEmpty(habituaViolations))
            //{
            //    habituaViolations = habituaViolations.Substring(0, habituaViolations.Length - 1);
            //}
            //constructionLog.HabituaViolations = habituaViolations;
            //string safetyStandardization = string.Empty;
            //foreach (var item in this.cblSafetyStandardization.SelectedValueArray)
            //{
            //    safetyStandardization += item + ",";
            //}
            //if (!string.IsNullOrEmpty(safetyStandardization))
            //{
            //    safetyStandardization = safetyStandardization.Substring(0, safetyStandardization.Length - 1);
            //}
            //constructionLog.SafetyStandardization = safetyStandardization;
            //constructionLog.CivilizedConstruction = this.txtCivilizedConstruction.Text.Trim();
            //constructionLog.Equipment1 = this.txtEquipment1.Text.Trim();
            //constructionLog.Equipment2 = this.txtEquipment2.Text.Trim();
            //constructionLog.Equipment3 = this.txtEquipment3.Text.Trim();
            //constructionLog.Equipment4 = this.txtEquipment4.Text.Trim();
            //constructionLog.Equipment5 = this.txtEquipment5.Text.Trim();
            //constructionLog.Equipment6 = this.txtEquipment6.Text.Trim();
            //constructionLog.Equipment7 = this.txtEquipment7.Text.Trim();
            //constructionLog.Equipment8 = this.txtEquipment8.Text.Trim();
            //constructionLog.Equipment9 = this.txtEquipment9.Text.Trim();
            //constructionLog.Equipment10 = this.txtEquipment10.Text.Trim();
            //constructionLog.ProcessHandover = this.txtProcessHandover.Text.Trim();
            //constructionLog.WorkArrangement = this.txtWorkArrangement.Text.Trim();
            //constructionLog.MeetingSituation = this.txtMeetingSituation.Text.Trim();
            //constructionLog.VisaRecords = this.txtVisaRecords.Text.Trim();
            //constructionLog.UnresolvedIssues = this.txtUnresolvedIssues.Text.Trim();
            //constructionLog.FileProcessing = this.txtFileProcessing.Text.Trim();
            //constructionLog.RectificationOfIssues = this.txtRectificationOfIssues.Text.Trim();
            //constructionLog.ImportantEvents = this.txtImportantEvents.Text.Trim();
            //constructionLog.ProblemAndCauseAnalysis = this.txtProblemAndCauseAnalysis.Text.Trim();
            constructionLog.CompileMan = this.CurrUser.UserId;
            constructionLog.CompileDate = DateTime.Now;
            if (saveType == "submit")
            {
                constructionLog.State = drpHandleType.SelectedValue.Trim();
            }
            else
            {
                Model.CQMS_ConstructionLog constructionLog1 = BLL.CQMSConstructionLogService.GetConstructionLogById(ConstructionLogId);
                if (constructionLog1 != null)
                {
                    if (string.IsNullOrEmpty(constructionLog1.State))
                    {
                        constructionLog.State = BLL.Const.CheckControl_Compile;
                    }
                    else
                    {
                        constructionLog.State = constructionLog1.State;
                    }
                }
                else
                {
                    constructionLog.State = BLL.Const.ConstructionLog_Compile;
                }
            }
            if (!string.IsNullOrEmpty(ConstructionLogId) && CQMSConstructionLogService.GetConstructionLogById(Request.Params["ConstructionLogId"]) != null)
            {
                Model.CQMS_ConstructionLogApprove approve1 = BLL.CQMSConstructionLogApproveService.GetConstructionLogApproveByConstructionLogId(ConstructionLogId);
                if (approve1 != null && saveType == "submit")
                {
                    approve1.ApproveDate = DateTime.Now;
                    approve1.ApproveIdea = txtOpinions.Text.Trim();
                    approve1.IsAgree = Convert.ToBoolean(this.rblIsAgree.SelectedValue);
                    BLL.CQMSConstructionLogApproveService.UpdateConstructionLogApprove(approve1);
                }
                if (saveType == "submit")
                {
                    Model.CQMS_ConstructionLogApprove approve = new Model.CQMS_ConstructionLogApprove();
                    approve.ConstructionLogId = ConstructionLogId;
                    if (this.drpHandleMan.SelectedValue != BLL.Const._Null)
                    {
                        approve.ApproveMan = this.drpHandleMan.SelectedValue;
                    }
                    approve.ApproveType = this.drpHandleType.SelectedValue;
                    if (this.drpHandleType.SelectedValue != BLL.Const.ConstructionLog_Complete)
                    {
                        approve.ApproveDate = DateTime.Now.AddMinutes(1);
                    }
                    BLL.CQMSConstructionLogApproveService.AddConstructionLogApprove(approve);
                    //APICommonService.SendSubscribeMessage(approve.ApproveMan, "施工日志待办理", this.CurrUser.UserName, string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
                }
                constructionLog.ConstructionLogId = ConstructionLogId;
                CQMSConstructionLogService.UpdateConstructionLog(constructionLog);
            }
            else
            {
                if (!string.IsNullOrEmpty(hdConstructionLogId.Text))
                {
                    constructionLog.ConstructionLogId = hdConstructionLogId.Text;
                }
                else
                {
                    constructionLog.ConstructionLogId = SQLHelper.GetNewID(typeof(Model.ZHGL_ConstructionLog));
                }
                constructionLog.CompileMan = CurrUser.UserId;
                CQMSConstructionLogService.AddConstructionLog(constructionLog);
                if (saveType == "submit")
                {
                    Model.CQMS_ConstructionLogApprove approve1 = new Model.CQMS_ConstructionLogApprove();
                    approve1.ConstructionLogId = constructionLog.ConstructionLogId;
                    approve1.ApproveDate = DateTime.Now;
                    approve1.ApproveMan = this.CurrUser.UserId;
                    approve1.ApproveType = BLL.Const.ConstructionLog_Compile;
                    BLL.CQMSConstructionLogApproveService.AddConstructionLogApprove(approve1);
                    Model.CQMS_ConstructionLogApprove approve = new Model.CQMS_ConstructionLogApprove();
                    approve.ConstructionLogId = constructionLog.ConstructionLogId;
                    if (this.drpHandleMan.SelectedValue != "0")
                    {
                        approve.ApproveMan = this.drpHandleMan.SelectedValue;
                    }
                    approve.ApproveType = this.drpHandleType.SelectedValue;
                    BLL.CQMSConstructionLogApproveService.AddConstructionLogApprove(approve);
                    //APICommonService.SendSubscribeMessage(approve.ApproveMan, "质量巡检问题待办理", this.CurrUser.UserName, string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
                }
                else
                {
                    Model.CQMS_ConstructionLogApprove approve1 = new Model.CQMS_ConstructionLogApprove();
                    approve1.ConstructionLogId = constructionLog.ConstructionLogId;
                    approve1.ApproveMan = this.CurrUser.UserId;
                    approve1.ApproveType = BLL.Const.ConstructionLog_Compile;
                    BLL.CQMSConstructionLogApproveService.AddConstructionLogApprove(approve1);
                }
            }
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            LogService.AddSys_Log(CurrUser, string.Format("{0:yyyy-MM-dd}", constructionLog.CompileDate), ConstructionLogId, Const.ConstructionLogMenuId, "保存施工日志");
        }
        protected string ConvertImageUrlByImage(object registrationId)
        {
            string url = string.Empty;
            if (registrationId != null)
            {
                IList sourlist = AttachFileService.GetBeforeFileList(registrationId.ToString(), BLL.Const.CheckListMenuId);
                if (sourlist != null && sourlist.Count > 0)
                {
                    string AttachUrl = "";
                    foreach (var item in sourlist)
                    {
                        if (!string.IsNullOrEmpty(item.AttachUrl) && item.AttachUrl.ToLower().EndsWith(".jpg") || item.AttachUrl.ToLower().EndsWith(".jpeg") || item.AttachUrl.ToLower().EndsWith(".png"))
                            AttachUrl += item.AttachUrl.TrimEnd(',') + ",";
                    }
                    url = BLL.UploadAttachmentService.ShowImage(ConfigurationManager.AppSettings["CEMS_IMG_URL"], AttachUrl.TrimEnd(','));
                }
            }
            return url;
        }
        protected string ConvertImgUrlByImage(object registrationId)
        {
            string url = string.Empty;
            if (registrationId != null)
            {
                IList sourlist = AttachFileService.Getfilelist(registrationId.ToString() + "r", BLL.Const.CheckListMenuId);
                if (sourlist != null && sourlist.Count > 0)
                {
                    string AttachUrl = "";
                    foreach (var item in sourlist)
                    {
                        if (!string.IsNullOrEmpty(item.AttachUrl) && item.AttachUrl.ToLower().EndsWith(".jpg") || item.AttachUrl.ToLower().EndsWith(".jpeg") || item.AttachUrl.ToLower().EndsWith(".png"))
                            AttachUrl += item.AttachUrl.TrimEnd(',') + ",";
                    }
                    url = BLL.UploadAttachmentService.ShowImage(ConfigurationManager.AppSettings["CEMS_IMG_URL"], AttachUrl.TrimEnd(','));
                }
            }
            return url;
        }
        public string Convertstatus(Object code)
        {
            Model.Check_CheckControl checkControl = BLL.CheckControlService.GetCheckControl(code.ToString());
            if (checkControl.State.Equals("5") || checkControl.State.Equals("6"))
            {
                return "未确认";
            }
            else if (checkControl.State == Const.CheckControl_Complete)
            { //闭环
                return "已闭环";
            }
            //else if( checkControl.LimitDate> )
            else if (Convert.ToDateTime(checkControl.LimitDate).AddDays(1) < DateTime.Now)  //延期未整改
            {
                return "超期未整改";
            }
            else  //期内未整改
            {
                return "未整改";
            }
        }
        /// 
        /// 把状态转换代号为文字形式
        /// 
        /// 
        /// 
        protected string ConvertState(object state)
        {
            if (state != null)
            {
                if (state.ToString() == BLL.Const.CheckControl_ReCompile)
                {
                    return "重新编制";
                }
                else if (state.ToString() == BLL.Const.CheckControl_Compile)
                {
                    return "编制";
                }
                else if (state.ToString() == BLL.Const.CheckControl_Audit1)
                {
                    return "总包负责人审批";
                }
                else if (state.ToString() == BLL.Const.CheckControl_Audit2)
                {
                    return "分包专业工程师回复";
                }
                else if (state.ToString() == BLL.Const.CheckControl_Audit3)
                {
                    return "分包负责人审批";
                }
                else if (state.ToString() == BLL.Const.CheckControl_Audit4)
                {
                    return "总包专业工程师确认";
                }
                else if (state.ToString() == BLL.Const.CheckControl_Audit5)
                {
                    return "总包负责人确认";
                }
                else if (state.ToString() == BLL.Const.CheckControl_Complete)
                {
                    return "审批完成";
                }
                else if (state.ToString() == BLL.Const.CheckControl_ReCompile2)
                {
                    return "分包专业工程师重新回复";
                }
                else
                {
                    return "";
                }
            }
            return "";
        }
        //
        //获取办理人姓名
        //
        //
        //
        protected string ConvertMan(object CheckControlCode)
        {
            if (CheckControlCode != null)
            {
                Model.Check_CheckControlApprove a = BLL.CheckControlApproveService.GetCheckControlApproveByCheckControlId(CheckControlCode.ToString());
                if (a != null)
                {
                    if (a.ApproveMan != null)
                    {
                        return BLL.UserService.GetUserByUserId(a.ApproveMan).UserName;
                    }
                }
                else
                {
                    return "";
                }
            }
            return "";
        }
        protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e)
        {
            SaveItem(true);
            this.hdUnitId.Text = this.drpUnit.SelectedValue;
            BindGrid1();
            BindGrid2();
            BindGrid5();
        }
        private void SaveItem(bool b)
        {
            if (this.hdUnitId.Text != BLL.Const._Null && !string.IsNullOrEmpty(this.hdUnitId.Text))
            {
                //保存之前选择单位记录
                Model.CQMS_ConstructionLogItem newItem = new Model.CQMS_ConstructionLogItem();
                newItem.ConstructionLogItemId = SQLHelper.GetNewID();
                newItem.ConstructionLogId = this.hdConstructionLogId.Text;
                newItem.UnitId = this.hdUnitId.Text;
                newItem.ConstructionManager = this.txtConstructionManager.Text.Trim();
                newItem.SafetyGuardian = this.txtSafetyGuardian.Text.Trim();
                newItem.ConstructionWorker = this.txtConstructionWorker.Text.Trim();
                newItem.MechanicNum = Funs.GetNewInt(this.txtMechanicNum.Text.Trim());
                newItem.MechanicNum1 = Funs.GetNewInt(this.txtMechanicNum1.Text.Trim());
                newItem.MechanicNum2 = Funs.GetNewInt(this.txtMechanicNum2.Text.Trim());
                newItem.MechanicNum3 = Funs.GetNewInt(this.txtMechanicNum3.Text.Trim());
                newItem.MechanicNum4 = Funs.GetNewInt(this.txtMechanicNum4.Text.Trim());
                newItem.MechanicNum5 = Funs.GetNewInt(this.txtMechanicNum5.Text.Trim());
                newItem.MechanicNum6 = Funs.GetNewInt(this.txtMechanicNum6.Text.Trim());
                newItem.MechanicNum7 = Funs.GetNewInt(this.txtMechanicNum7.Text.Trim());
                newItem.MechanicNum8 = Funs.GetNewInt(this.txtMechanicNum8.Text.Trim());
                newItem.MechanicNum9 = Funs.GetNewInt(this.txtMechanicNum9.Text.Trim());
                newItem.MechanicNum10 = Funs.GetNewInt(this.txtMechanicNum10.Text.Trim());
                newItem.MechanicNum11 = Funs.GetNewInt(this.txtMechanicNum11.Text.Trim());
                newItem.MechanicNum12 = Funs.GetNewInt(this.txtMechanicNum12.Text.Trim());
                newItem.MechanicNum13 = Funs.GetNewInt(this.txtMechanicNum13.Text.Trim());
                newItem.MechanicNum14 = Funs.GetNewInt(this.txtMechanicNum14.Text.Trim());
                newItem.MechanicNum15 = Funs.GetNewInt(this.txtMechanicNum15.Text.Trim());
                newItem.MechanicNum16 = Funs.GetNewInt(this.txtMechanicNum16.Text.Trim());
                newItem.MechanicNum17 = Funs.GetNewInt(this.txtMechanicNum17.Text.Trim());
                newItem.LabourNum = Funs.GetNewInt(this.txtLabourNum.Text.Trim());
                newItem.MainConstructionMachine = this.txtMainConstructionMachine.Text.Trim();
                newItem.ConstructionContent = this.txtConstructionContent.Text.Trim();
                newItem.ConstructionEnvironment = this.txtConstructionEnvironment.Text.Trim();
                newItem.SafetyWorkSituation = this.txtSafetyWorkSituation.Text.Trim();
                string safetyAndQualityMeasures = string.Empty;
                foreach (var item in this.cblSafetyAndQualityMeasures.SelectedValueArray)
                {
                    safetyAndQualityMeasures += item + ",";
                }
                if (!string.IsNullOrEmpty(safetyAndQualityMeasures))
                {
                    safetyAndQualityMeasures = safetyAndQualityMeasures.Substring(0, safetyAndQualityMeasures.Length - 1);
                }
                newItem.SafetyAndQualityMeasures = safetyAndQualityMeasures;
                string habituaViolations = string.Empty;
                foreach (var item in this.cblHabituaViolations.SelectedValueArray)
                {
                    habituaViolations += item + ",";
                }
                if (!string.IsNullOrEmpty(habituaViolations))
                {
                    habituaViolations = habituaViolations.Substring(0, habituaViolations.Length - 1);
                }
                newItem.HabituaViolations = habituaViolations;
                string safetyStandardization = string.Empty;
                foreach (var item in this.cblSafetyStandardization.SelectedValueArray)
                {
                    safetyStandardization += item + ",";
                }
                if (!string.IsNullOrEmpty(safetyStandardization))
                {
                    safetyStandardization = safetyStandardization.Substring(0, safetyStandardization.Length - 1);
                }
                newItem.SafetyStandardization = safetyStandardization;
                newItem.CivilizedConstruction = this.txtCivilizedConstruction.Text.Trim();
                newItem.Equipment1 = this.txtEquipment1.Text.Trim();
                newItem.Equipment2 = this.txtEquipment2.Text.Trim();
                newItem.Equipment3 = this.txtEquipment3.Text.Trim();
                newItem.Equipment4 = this.txtEquipment4.Text.Trim();
                newItem.Equipment5 = this.txtEquipment5.Text.Trim();
                newItem.Equipment6 = this.txtEquipment6.Text.Trim();
                newItem.Equipment7 = this.txtEquipment7.Text.Trim();
                newItem.ProcessHandover = this.txtProcessHandover.Text.Trim();
                newItem.WorkArrangement = this.txtWorkArrangement.Text.Trim();
                newItem.MeetingSituation = this.txtMeetingSituation.Text.Trim();
                newItem.VisaRecords = this.txtVisaRecords.Text.Trim();
                newItem.UnresolvedIssues = this.txtUnresolvedIssues.Text.Trim();
                newItem.FileProcessing = this.txtFileProcessing.Text.Trim();
                newItem.RectificationOfIssues = this.txtRectificationOfIssues.Text.Trim();
                newItem.ImportantEvents = this.txtImportantEvents.Text.Trim();
                newItem.ProblemAndCauseAnalysis = this.txtProblemAndCauseAnalysis.Text.Trim();
                var oldItem = (from x in Funs.DB.CQMS_ConstructionLogItem where x.ConstructionLogId == this.hdConstructionLogId.Text && x.UnitId == this.hdUnitId.Text select x).FirstOrDefault();
                if (oldItem != null)
                {
                    BLL.CQMSConstructionLogItemService.DeleteConstructionLogItemById(oldItem.ConstructionLogItemId);
                }
                BLL.CQMSConstructionLogItemService.AddConstructionLogItem(newItem);
                BLL.CQMSConstructionLogImageProgressService.DeleteConstructionLogImageProgressByIdAndUnitId(this.hdConstructionLogId.Text, this.hdUnitId.Text);
                var data = Grid5.GetMergedData();
                if (data != null)
                {
                    foreach (JObject mergedRow in Grid5.GetMergedData())
                    {
                        JObject values = mergedRow.Value("values");
                        int rowIndex = mergedRow.Value("index");
                        string ImageProgressDef = values.Value("ImageProgressDef");
                        string ConstructionLogImageProgressId = values.Value("ConstructionLogImageProgressId");
                        var item = new Model.CQMS_ConstructionLogImageProgress
                        {
                            ConstructionLogImageProgressId = ConstructionLogImageProgressId,
                            ConstructionLogId = this.hdConstructionLogId.Text,
                            UnitId = this.hdUnitId.Text,
                            ImageProgressDef = ImageProgressDef,
                            SortIndex = rowIndex
                        };
                        BLL.CQMSConstructionLogImageProgressService.AddConstructionLogImageProgress(item);
                    }
                }
            }
            if (b)
            {
                this.txtConstructionManager.Text = string.Empty;
                this.txtSafetyGuardian.Text = string.Empty;
                this.txtConstructionWorker.Text = string.Empty;
                this.txtMechanicNum.Text = string.Empty;
                this.txtMechanicNum1.Text = string.Empty;
                this.txtMechanicNum2.Text = string.Empty;
                this.txtMechanicNum3.Text = string.Empty;
                this.txtMechanicNum4.Text = string.Empty;
                this.txtMechanicNum5.Text = string.Empty;
                this.txtMechanicNum6.Text = string.Empty;
                this.txtMechanicNum7.Text = string.Empty;
                this.txtMechanicNum8.Text = string.Empty;
                this.txtMechanicNum9.Text = string.Empty;
                this.txtMechanicNum10.Text = string.Empty;
                this.txtMechanicNum11.Text = string.Empty;
                this.txtMechanicNum12.Text = string.Empty;
                this.txtMechanicNum13.Text = string.Empty;
                this.txtMechanicNum14.Text = string.Empty;
                this.txtMechanicNum15.Text = string.Empty;
                this.txtMechanicNum16.Text = string.Empty;
                this.txtMechanicNum17.Text = string.Empty;
                this.txtLabourNum.Text = string.Empty;
                this.txtMainConstructionMachine.Text = string.Empty;
                this.txtConstructionContent.Text = string.Empty;
                this.txtConstructionEnvironment.Text = string.Empty;
                this.txtSafetyWorkSituation.Text = string.Empty;
                this.cblSafetyAndQualityMeasures.SelectedValueArray = null;
                this.cblHabituaViolations.SelectedValueArray = null;
                this.cblSafetyStandardization.SelectedValueArray = null;
                this.txtCivilizedConstruction.Text = string.Empty;
                this.txtEquipment1.Text = string.Empty;
                this.txtEquipment2.Text = string.Empty;
                this.txtEquipment3.Text = string.Empty;
                this.txtEquipment4.Text = string.Empty;
                this.txtEquipment5.Text = string.Empty;
                this.txtEquipment6.Text = string.Empty;
                this.txtEquipment7.Text = string.Empty;
                this.txtEquipment8.Text = string.Empty;
                this.txtEquipment9.Text = string.Empty;
                this.txtEquipment10.Text = string.Empty;
                this.txtProcessHandover.Text = string.Empty;
                this.txtWorkArrangement.Text = string.Empty;
                this.txtMeetingSituation.Text = string.Empty;
                this.txtVisaRecords.Text = string.Empty;
                this.txtUnresolvedIssues.Text = string.Empty;
                this.txtFileProcessing.Text = string.Empty;
                this.txtRectificationOfIssues.Text = string.Empty;
                this.txtImportantEvents.Text = string.Empty;
                this.txtProblemAndCauseAnalysis.Text = string.Empty;
                this.Grid1.DataSource = null;
                this.Grid1.DataBind();
                this.Grid2.DataSource = null;
                this.Grid2.DataBind();
                this.Grid5.DataSource = null;
                this.Grid5.DataBind();
                if (this.drpUnit.SelectedValue != BLL.Const._Null)
                {
                    Model.CQMS_ConstructionLogItem unitItem = BLL.CQMSConstructionLogItemService.GetConstructionLogItemByConstructionLogIdAndUnitId(this.hdConstructionLogId.Text, this.drpUnit.SelectedValue);
                    if (unitItem != null)
                    {
                        this.txtConstructionManager.Text = unitItem.ConstructionManager;
                        this.txtSafetyGuardian.Text = unitItem.SafetyGuardian;
                        this.txtConstructionWorker.Text = unitItem.ConstructionWorker;
                        if (unitItem.MechanicNum != null)
                        {
                            this.txtMechanicNum.Text = unitItem.MechanicNum.ToString();
                        }
                        if (unitItem.MechanicNum1 != null)
                        {
                            this.txtMechanicNum1.Text = unitItem.MechanicNum1.ToString();
                        }
                        if (unitItem.MechanicNum2 != null)
                        {
                            this.txtMechanicNum2.Text = unitItem.MechanicNum2.ToString();
                        }
                        if (unitItem.MechanicNum3 != null)
                        {
                            this.txtMechanicNum3.Text = unitItem.MechanicNum3.ToString();
                        }
                        if (unitItem.MechanicNum4 != null)
                        {
                            this.txtMechanicNum4.Text = unitItem.MechanicNum4.ToString();
                        }
                        if (unitItem.MechanicNum5 != null)
                        {
                            this.txtMechanicNum5.Text = unitItem.MechanicNum5.ToString();
                        }
                        if (unitItem.MechanicNum6 != null)
                        {
                            this.txtMechanicNum6.Text = unitItem.MechanicNum6.ToString();
                        }
                        if (unitItem.MechanicNum7 != null)
                        {
                            this.txtMechanicNum7.Text = unitItem.MechanicNum7.ToString();
                        }
                        if (unitItem.MechanicNum8 != null)
                        {
                            this.txtMechanicNum8.Text = unitItem.MechanicNum8.ToString();
                        }
                        if (unitItem.MechanicNum9 != null)
                        {
                            this.txtMechanicNum9.Text = unitItem.MechanicNum9.ToString();
                        }
                        if (unitItem.MechanicNum10 != null)
                        {
                            this.txtMechanicNum10.Text = unitItem.MechanicNum10.ToString();
                        }
                        if (unitItem.MechanicNum11 != null)
                        {
                            this.txtMechanicNum11.Text = unitItem.MechanicNum11.ToString();
                        }
                        if (unitItem.MechanicNum12 != null)
                        {
                            this.txtMechanicNum12.Text = unitItem.MechanicNum12.ToString();
                        }
                        if (unitItem.MechanicNum13 != null)
                        {
                            this.txtMechanicNum13.Text = unitItem.MechanicNum13.ToString();
                        }
                        if (unitItem.MechanicNum14 != null)
                        {
                            this.txtMechanicNum14.Text = unitItem.MechanicNum14.ToString();
                        }
                        if (unitItem.MechanicNum15 != null)
                        {
                            this.txtMechanicNum15.Text = unitItem.MechanicNum15.ToString();
                        }
                        if (unitItem.MechanicNum16 != null)
                        {
                            this.txtMechanicNum16.Text = unitItem.MechanicNum16.ToString();
                        }
                        if (unitItem.MechanicNum17 != null)
                        {
                            this.txtMechanicNum17.Text = unitItem.MechanicNum17.ToString();
                        }
                        if (unitItem.LabourNum != null)
                        {
                            this.txtLabourNum.Text = unitItem.LabourNum.ToString();
                        }
                        this.txtMainConstructionMachine.Text = unitItem.MainConstructionMachine;
                        this.txtConstructionContent.Text = unitItem.ConstructionContent;
                        this.txtConstructionEnvironment.Text = unitItem.ConstructionEnvironment;
                        this.txtSafetyWorkSituation.Text = unitItem.SafetyWorkSituation;
                        if (!string.IsNullOrEmpty(unitItem.SafetyAndQualityMeasures))
                        {
                            string[] strs = unitItem.SafetyAndQualityMeasures.Split(',');
                            this.cblSafetyAndQualityMeasures.SelectedValueArray = strs;
                        }
                        if (!string.IsNullOrEmpty(unitItem.HabituaViolations))
                        {
                            string[] strs = unitItem.HabituaViolations.Split(',');
                            this.cblHabituaViolations.SelectedValueArray = strs;
                        }
                        if (!string.IsNullOrEmpty(unitItem.SafetyStandardization))
                        {
                            string[] strs = unitItem.SafetyStandardization.Split(',');
                            this.cblSafetyStandardization.SelectedValueArray = strs;
                        }
                        this.txtCivilizedConstruction.Text = unitItem.CivilizedConstruction;
                        this.txtEquipment1.Text = unitItem.Equipment1;
                        this.txtEquipment2.Text = unitItem.Equipment2;
                        this.txtEquipment3.Text = unitItem.Equipment3;
                        this.txtEquipment4.Text = unitItem.Equipment4;
                        this.txtEquipment5.Text = unitItem.Equipment5;
                        this.txtEquipment6.Text = unitItem.Equipment6;
                        this.txtEquipment7.Text = unitItem.Equipment7;
                        this.txtProcessHandover.Text = unitItem.ProcessHandover;
                        this.txtWorkArrangement.Text = unitItem.WorkArrangement;
                        this.txtMeetingSituation.Text = unitItem.MeetingSituation;
                        this.txtVisaRecords.Text = unitItem.VisaRecords;
                        this.txtUnresolvedIssues.Text = unitItem.UnresolvedIssues;
                        this.txtFileProcessing.Text = unitItem.FileProcessing;
                        this.txtRectificationOfIssues.Text = unitItem.RectificationOfIssues;
                        this.txtImportantEvents.Text = unitItem.ImportantEvents;
                        this.txtProblemAndCauseAnalysis.Text = unitItem.ProblemAndCauseAnalysis;
                    }
                }
            }
        }
        /// 
        /// 把状态转换代号为文字形式
        /// 
        /// 
        /// 
        protected string ConvertState2(object state)
        {
            if (state != null)
            {
                if (state.ToString() == BLL.Const.ConstructionLog_ReCompile)
                {
                    return "重新编制";
                }
                else if (state.ToString() == BLL.Const.ConstructionLog_Compile)
                {
                    return "编制";
                }
                else if (state.ToString() == BLL.Const.ConstructionLog_Audit)
                {
                    return "审核";
                }
                else if (state.ToString() == BLL.Const.ConstructionLog_Complete)
                {
                    return "审批完成";
                }
                else
                {
                    return "";
                }
            }
            return "";
        }
        protected void rblIsAgree_SelectedIndexChanged(object sender, EventArgs e)
        {
            HandleType();
            this.drpHandleMan.Items.Clear();
            if (this.rblIsAgree.SelectedValue == "true")
            {
                this.drpHandleMan.Enabled = false;
            }
            else
            {
                this.drpHandleMan.Enabled = true;
                var approve = BLL.CQMSConstructionLogApproveService.GetComplie(ConstructionLogId);
                if (approve != null)
                {
                    ListItem[] list = new ListItem[1];
                    string name = BLL.UserService.GetUserNameByUserId(approve.ApproveMan);
                    list[0] = new ListItem(name, approve.ApproveMan);
                    drpHandleMan.DataValueField = "Value";
                    drpHandleMan.DataTextField = "Text";
                    drpHandleMan.DataSource = list;
                    drpHandleMan.DataBind();
                    this.drpHandleMan.SelectedValue = approve.ApproveMan;
                }
            }
        }
        /// 
        /// 待办事项的下拉框的处理
        /// 
        public void HandleType()
        {
            drpHandleType.Items.Clear();
            CQMSConstructionLogService.Init(drpHandleType, State, false);
            string res = null;
            List list = new List();
            list.Add(Const.ConstructionLog_ReCompile);
            var count = drpHandleType.Items.Count;
            List listitem = new List();
            if (rblIsAgree.SelectedValue.Equals("true"))
            {
                for (int i = 0; i < count; i++)
                {
                    res = drpHandleType.Items[i].Value;
                    if (list.Contains(res))
                    {
                        var item = (drpHandleType.Items[i]);
                        listitem.Add(item);
                    }
                }
                if (listitem.Count > 0)
                {
                    for (int i = 0; i < listitem.Count; i++)
                    {
                        drpHandleType.Items.Remove(listitem[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    res = drpHandleType.Items[i].Value;
                    if (!list.Contains(res))
                    {
                        var item = drpHandleType.Items[i];
                        listitem.Add(item);
                    }
                }
                if (listitem.Count > 0)
                {
                    for (int i = 0; i < listitem.Count; i++)
                    {
                        drpHandleType.Items.Remove(listitem[i]);
                    }
                }
            }
            if (count > 0)
            {
                drpHandleType.SelectedIndex = 0;
                //HandleMan();
            }
        }
        protected void drpHandleType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //HandleMan();
        }
        #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;
        }
        /// 
        /// 获取是否合格
        /// 
        /// 
        /// 
        protected string ConvertOK(object InspectionId)
        {
            string name = string.Empty;
            if (InspectionId != null)
            {
                var inspection = BLL.InspectionManagementService.GetInspectionManagementById(InspectionId.ToString());
                if (inspection != null)
                {
                    if (inspection.IsOnceQualified == true)
                    {
                        name = "是";
                    }
                    else
                    {
                        name = "否";
                    }
                }
            }
            return name;
        }
        #endregion
        protected void btnWeather_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtLogDate.Text.Trim()))
            {
                PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("Weather.aspx?Date={0}", txtLogDate.Text.Trim(), "编辑 - ")));
            }
            else
            {
                Alert.ShowInTop("请选择日期!", MessageBoxIcon.Warning);
                return;
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.drpUnit.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请选择施工单位!", MessageBoxIcon.Warning);
                return;
            }
            List view = getViewTestPlanTrainingList();
            Model.CQMS_ConstructionLogImageProgress notice = new Model.CQMS_ConstructionLogImageProgress
            {
                ConstructionLogImageProgressId = SQLHelper.GetNewID()
            };
            view.Add(notice);
            //将gd数据保存在list中
            Grid5.DataSource = view;
            Grid5.DataBind();
        }
        #region 收集页面明细信息
        /// 
        /// 收集页面信息
        /// 
        /// 
        private List getViewTestPlanTrainingList()
        {
            List view = new List();
            var data = Grid5.GetMergedData();
            if (data != null)
            {
                foreach (JObject mergedRow in Grid5.GetMergedData())
                {
                    JObject values = mergedRow.Value("values");
                    int rowIndex = mergedRow.Value("index");
                    string ImageProgressDef = values.Value("ImageProgressDef");
                    string ConstructionLogImageProgressId = values.Value("ConstructionLogImageProgressId");
                    var item = new Model.CQMS_ConstructionLogImageProgress
                    {
                        ConstructionLogImageProgressId = ConstructionLogImageProgressId,
                        ImageProgressDef = ImageProgressDef,
                        SortIndex = rowIndex
                    };
                    view.Add(item);
                }
            }
            return view;
        }
        #endregion
        #region grid 操作
        /// 
        /// 
        /// 
        /// 
        /// 
        protected void Grid5_RowCommand(object sender, GridCommandEventArgs e)
        {
            string itemId = Grid5.DataKeys[e.RowIndex][0].ToString();
            if (e.CommandName == "delete")
            {
                var getView = getViewTestPlanTrainingList();
                var getfi = getView.FirstOrDefault(x => x.ConstructionLogImageProgressId == itemId);
                if (getfi != null)
                {
                    getView.Remove(getfi);
                }
                Grid5.DataSource = getView;
                Grid5.DataBind();
            }
        }
        protected string ConvertImage(object ConstructionLogImageProgressId)
        {
            string url = string.Empty;
            if (ConstructionLogImageProgressId != null)
            {
                IList sourlist = AttachFileService.Getfilelist(ConstructionLogImageProgressId.ToString(), BLL.Const.CQMSConstructionLogMenuId);
                if (sourlist != null && sourlist.Count > 0)
                {
                    string AttachUrl = "";
                    foreach (var item in sourlist)
                    {
                        if (!string.IsNullOrEmpty(item.AttachUrl) && item.AttachUrl.ToLower().EndsWith(".jpg") || item.AttachUrl.ToLower().EndsWith(".jpeg") || item.AttachUrl.ToLower().EndsWith(".png"))
                            AttachUrl += item.AttachUrl.TrimEnd(',') + ",";
                    }
                    url = BLL.UploadAttachmentService.ShowImage(ConfigurationManager.AppSettings["CEMS_IMG_URL"], AttachUrl.TrimEnd(','));
                }
            }
            return url;
        }
        #endregion
    }
}