using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace FineUIPro.Web.ZHGL.DataSync
{
    public partial class SYHSEData_SYHSEEdit: PageBase
    {
        #region  
        /// 
        /// 主键
        /// 
        public string Id
        {
            get
            {
                return (string)ViewState["Id"];
            }
            set
            {
                ViewState["Id"] = value;
            }
        }
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
                ////权限按钮方法
                this.GetButtonPower();
                this.Id = Request.Params["Id"];
                if (!string.IsNullOrEmpty(this.Id))
                {
                    Model.SYHSEData_SYHSE model = BLL.SYHSEData_SYHSEService.GetSYHSEData_SYHSEById(this.Id);
                    if (model != null)
                    {
                        //this.txtUnitId.Text = model.UnitId;
                        this.txtCollCropCode.Text = model.CollCropCode;
                        this.txtUnitName.Text = model.UnitName;
                        if (model.ReportDate != null)
                        {
                            this.txtReportDate.SelectedDate = model.ReportDate;
                        }
                        if (model.GeneralRiskNum.HasValue)
                        {
                            this.txtGeneralRiskNum.Text = model.GeneralRiskNum.Value.ToString();
                        }
                        if (model.LowRiskNum.HasValue)
                        {
                            this.txtLowRiskNum.Text = model.LowRiskNum.Value.ToString();
                        }
                        if (model.MediumRiskNum.HasValue)
                        {
                            this.txtMediumRiskNum.Text = model.MediumRiskNum.Value.ToString();
                        }
                        if (model.HighRiskNum.HasValue)
                        {
                            this.txtHighRiskNum.Text = model.HighRiskNum.Value.ToString();
                        }
                        if (model.GradedResponsiblePersonNum.HasValue)
                        {
                            this.txtGradedResponsiblePersonNum.Text = model.GradedResponsiblePersonNum.Value.ToString();
                        }
                        if (model.ChargeInsurancePersonNum.HasValue)
                        {
                            this.txtChargeInsurancePersonNum.Text = model.ChargeInsurancePersonNum.Value.ToString();
                        }
                        if (model.DesignQuantity.HasValue)
                        {
                            this.txtDesignQuantity.Text = model.DesignQuantity.Value.ToString();
                        }
                        if (model.RunningCapacity.HasValue)
                        {
                            this.txtRunningCapacity.Text = model.RunningCapacity.Value.ToString();
                        }
                        if (model.InterlockSettingValue.HasValue)
                        {
                            this.txtInterlockSettingValue.Text = model.InterlockSettingValue.Value.ToString();
                        }
                        if (model.VideoSurveillanceNum.HasValue)
                        {
                            this.txtVideoSurveillanceNum.Text = model.VideoSurveillanceNum.Value.ToString();
                        }
                        if (model.TotalWorkinghours.HasValue)
                        {
                            this.txtTotalWorkinghours.Text = model.TotalWorkinghours.Value.ToString();
                        }
                        if (model.SafeWorkinghours.HasValue)
                        {
                            this.txtSafeWorkinghours.Text = model.SafeWorkinghours.Value.ToString();
                        }
                        if (model.LostWorkinghours.HasValue)
                        {
                            this.txtLostWorkinghours.Text = model.LostWorkinghours.Value.ToString();
                        }
                        if (model.TotalEnergyConsumption.HasValue)
                        {
                            this.txtTotalEnergyConsumption.Text = model.TotalEnergyConsumption.Value.ToString();
                        }
                        if (model.IncomeComprehensiveEnergyConsumption.HasValue)
                        {
                            this.txtIncomeComprehensiveEnergyConsumption.Text = model.IncomeComprehensiveEnergyConsumption.Value.ToString();
                        }
                        if (model.NewWaterConsumption.HasValue)
                        {
                            this.txtNewWaterConsumption.Text = model.NewWaterConsumption.Value.ToString();
                        }
                        if (model.GeneralClosedNum.HasValue)
                        {
                            this.txtGeneralClosedNum.Text = model.GeneralClosedNum.Value.ToString();
                        }
                        if (model.GeneralNotClosedNum.HasValue)
                        {
                            this.txtGeneralNotClosedNum.Text = model.GeneralNotClosedNum.Value.ToString();
                        }
                        if (model.MajorClosedNum.HasValue)
                        {
                            this.txtMajorClosedNum.Text = model.MajorClosedNum.Value.ToString();
                        }
                        if (model.MajorNotClosedNum.HasValue)
                        {
                            this.txtMajorNotClosedNum.Text = model.MajorNotClosedNum.Value.ToString();
                        }
                        if (model.HotWorkPermitNum.HasValue)
                        {
                            this.txtHotWorkPermitNum.Text = model.HotWorkPermitNum.Value.ToString();
                        }
                        if (model.HotWorkClosedNum.HasValue)
                        {
                            this.txtHotWorkClosedNum.Text = model.HotWorkClosedNum.Value.ToString();
                        }
                        if (model.HighPermitNum.HasValue)
                        {
                            this.txtHighPermitNum.Text = model.HighPermitNum.Value.ToString();
                        }
                        if (model.HighClosedNum.HasValue)
                        {
                            this.txtHighClosedNum.Text = model.HighClosedNum.Value.ToString();
                        }
                        if (model.TemporaryElectricityPermitNum.HasValue)
                        {
                            this.txtTemporaryElectricityPermitNum.Text = model.TemporaryElectricityPermitNum.Value.ToString();
                        }
                        if (model.TemporaryElectricityClosedNum.HasValue)
                        {
                            this.txtTemporaryElectricityClosedNum.Text = model.TemporaryElectricityClosedNum.Value.ToString();
                        }
                        if (model.BlindPlatePermitNum.HasValue)
                        {
                            this.txtBlindPlatePermitNum.Text = model.BlindPlatePermitNum.Value.ToString();
                        }
                        if (model.BlindPlateClosedNum.HasValue)
                        {
                            this.txtBlindPlateClosedNum.Text = model.BlindPlateClosedNum.Value.ToString();
                        }
                        if (model.GroundbreakingPermitNum.HasValue)
                        {
                            this.txtGroundbreakingPermitNum.Text = model.GroundbreakingPermitNum.Value.ToString();
                        }
                        if (model.GroundbreakingClosedNum.HasValue)
                        {
                            this.txtGroundbreakingClosedNum.Text = model.GroundbreakingClosedNum.Value.ToString();
                        }
                        if (model.OpenCircuitPermitNum.HasValue)
                        {
                            this.txtOpenCircuitPermitNum.Text = model.OpenCircuitPermitNum.Value.ToString();
                        }
                        if (model.OpenCircuitClosedNum.HasValue)
                        {
                            this.txtOpenCircuitClosedNum.Text = model.OpenCircuitClosedNum.Value.ToString();
                        }
                        if (model.HoistingPermitNum.HasValue)
                        {
                            this.txtHoistingPermitNum.Text = model.HoistingPermitNum.Value.ToString();
                        }
                        if (model.HoistingClosedNum.HasValue)
                        {
                            this.txtHoistingClosedNum.Text = model.HoistingClosedNum.Value.ToString();
                        }
                    }
                }
                else
                {
                    var base_Unit = BLL.UnitService.GetUnitByUnitId(BLL.Const.UnitId_CWCEC);
                    txtUnitName.Text = base_Unit.UnitName;
                    txtCollCropCode.Text = base_Unit.CollCropCode;
                    txtReportDate.SelectedDate = DateTime.Now;
                }
            }
        }
        /// 
        /// 保存按钮
        /// 
        /// 
        /// 
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (txtReportDate.SelectedDate == null)
            {
                ShowNotify("请选择上报日期!");
                return;
            }
            Model.SYHSEData_SYHSE table = new Model.SYHSEData_SYHSE();
            table.UnitId = BLL.Const.UnitId_CWCEC;
            table.CollCropCode = this.txtCollCropCode.Text;
            table.UnitName = this.txtUnitName.Text;
            table.ReportDate = this.txtReportDate.SelectedDate;
            table.GeneralRiskNum = Funs.GetNewInt(this.txtGeneralRiskNum.Text);
            table.LowRiskNum = Funs.GetNewInt(this.txtLowRiskNum.Text);
            table.MediumRiskNum = Funs.GetNewInt(this.txtMediumRiskNum.Text);
            table.HighRiskNum = Funs.GetNewInt(this.txtHighRiskNum.Text);
            table.GradedResponsiblePersonNum = Funs.GetNewInt(this.txtGradedResponsiblePersonNum.Text);
            table.ChargeInsurancePersonNum = Funs.GetNewInt(this.txtChargeInsurancePersonNum.Text);
            table.DesignQuantity = Funs.GetNewInt(this.txtDesignQuantity.Text);
            table.RunningCapacity = Funs.GetNewInt(this.txtRunningCapacity.Text);
            table.InterlockSettingValue = Funs.GetNewInt(this.txtInterlockSettingValue.Text);
            table.VideoSurveillanceNum = Funs.GetNewInt(this.txtVideoSurveillanceNum.Text);
            table.TotalWorkinghours = Funs.GetNewInt(this.txtTotalWorkinghours.Text);
            table.SafeWorkinghours = Funs.GetNewInt(this.txtSafeWorkinghours.Text);
            table.LostWorkinghours = Funs.GetNewInt(this.txtLostWorkinghours.Text);
            table.TotalEnergyConsumption = Funs.GetNewInt(this.txtTotalEnergyConsumption.Text);
            table.IncomeComprehensiveEnergyConsumption = Funs.GetNewInt(this.txtIncomeComprehensiveEnergyConsumption.Text);
            table.NewWaterConsumption = Funs.GetNewInt(this.txtNewWaterConsumption.Text);
            table.GeneralClosedNum = Funs.GetNewInt(this.txtGeneralClosedNum.Text);
            table.GeneralNotClosedNum = Funs.GetNewInt(this.txtGeneralNotClosedNum.Text);
            table.MajorClosedNum = Funs.GetNewInt(this.txtMajorClosedNum.Text);
            table.MajorNotClosedNum = Funs.GetNewInt(this.txtMajorNotClosedNum.Text);
            table.HotWorkPermitNum = Funs.GetNewInt(this.txtHotWorkPermitNum.Text);
            table.HotWorkClosedNum = Funs.GetNewInt(this.txtHotWorkClosedNum.Text);
            table.HighPermitNum = Funs.GetNewInt(this.txtHighPermitNum.Text);
            table.HighClosedNum = Funs.GetNewInt(this.txtHighClosedNum.Text);
            table.TemporaryElectricityPermitNum = Funs.GetNewInt(this.txtTemporaryElectricityPermitNum.Text);
            table.TemporaryElectricityClosedNum = Funs.GetNewInt(this.txtTemporaryElectricityClosedNum.Text);
            table.BlindPlatePermitNum = Funs.GetNewInt(this.txtBlindPlatePermitNum.Text);
            table.BlindPlateClosedNum = Funs.GetNewInt(this.txtBlindPlateClosedNum.Text);
            table.GroundbreakingPermitNum = Funs.GetNewInt(this.txtGroundbreakingPermitNum.Text);
            table.GroundbreakingClosedNum = Funs.GetNewInt(this.txtGroundbreakingClosedNum.Text);
            table.OpenCircuitPermitNum = Funs.GetNewInt(this.txtOpenCircuitPermitNum.Text);
            table.OpenCircuitClosedNum = Funs.GetNewInt(this.txtOpenCircuitClosedNum.Text);
            table.HoistingPermitNum = Funs.GetNewInt(this.txtHoistingPermitNum.Text);
            table.HoistingClosedNum = Funs.GetNewInt(this.txtHoistingClosedNum.Text);
            if (string.IsNullOrEmpty(this.Id))
            {
                table.Id = SQLHelper.GetNewID(typeof(Model.SYHSEData_SYHSE));
                BLL.SYHSEData_SYHSEService.AddSYHSEData_SYHSE(table);
            }
            else
            {
                table.Id = this.Id;
                BLL.SYHSEData_SYHSEService.UpdateSYHSEData_SYHSE(table);
            }
            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
        }
        protected void txtReportDate_DateSelect(object sender, EventArgs e)
        {
            if (txtReportDate.SelectedDate != null)
            {
                DateTime dt = (DateTime)txtReportDate.SelectedDate;
                if (BLL.SYHSEData_SYHSEService.IsReportByDate(dt))
                {
                    txtReportDate.SelectedDate = null;
                    ShowNotify("该日期已上报!");
                }
            }
        }
        protected void btnSyn_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.Id))
            {
                var responedata = SYHSEData_SYHSEService.PushCNCEC(Id);
                if (responedata.code == 1)
                {
                    ShowNotify("上报成功!");
                    PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
                }
                else
                {
                    ShowNotify(responedata.message);
                    // PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
                }
            }
        }
        #region 获取按钮权限
        /// 
        /// 获取按钮权限
        /// 
        /// 
        /// 
        private void GetButtonPower()
        {
            var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SYHSEData_SYHSEMenuId);
            if (buttonList.Count() > 0)
            {
                if (buttonList.Contains(BLL.Const.BtnSave))
                {
                    this.btnSave.Hidden = false;
                }
            }
        }
        #endregion        
    }
}