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.HiddenInspection
{
    public partial class HiddenRectificationRectify : PageBase
    {
        #region 定义项
        /// 
        /// 主键
        /// 
        private string HazardRegisterId
        {
            get
            {
                return (string)ViewState["HazardRegisterId"];
            }
            set
            {
                ViewState["HazardRegisterId"] = value;
            }
        }
        /// 
        /// 图片路径
        /// 
        public string ImageUrl
        {
            get
            {
                return (string)ViewState["ImageUrl"];
            }
            set
            {
                ViewState["ImageUrl"] = value;
            }
        }
        /// 
        /// 整改后附件路径
        /// 
        public string RectificationImageUrl
        {
            get
            {
                return (string)ViewState["RectificationImageUrl"];
            }
            set
            {
                ViewState["RectificationImageUrl"] = value;
            }
        }
        #endregion
        #region 加载
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
                this.HazardRegisterId = Request.Params["HazardRegisterId"];
                //新增初始化
                if (!string.IsNullOrEmpty(this.HazardRegisterId))
                {
                    Model.View_Hazard_HazardRegister registration = (from x in Funs.DB.View_Hazard_HazardRegister where x.HazardRegisterId == HazardRegisterId select x).FirstOrDefault();
                    if (registration != null)
                    {
                        this.txtUnitName.Text = registration.ResponsibilityUnitName;
                        this.txtWorkAreaName.Text = registration.WorkAreaName;
                        this.txtRegisterTypesName.Text = registration.RegisterTypesName;
                        this.txtRequirements.Text = registration.Requirements;
                        if (registration.CheckCycle == "D")
                        {
                            this.txtType.Text = "日检";
                        }
                        else if (registration.CheckCycle == "W")
                        {
                            this.txtType.Text = "周检";
                        }
                        else if (registration.CheckCycle == "M")
                        {
                            this.txtType.Text = "月检";
                        }
                        this.txtResponsibleManName.Text = registration.ResponsibilityManName;
                        if (registration.RectificationPeriod != null)
                        {
                            this.txtRectificationPeriod.Text = string.Format("{0:yyyy-MM-dd HH:mm:ss}", registration.RectificationPeriod);
                        }
                        this.txtRegisterDef.Text = registration.RegisterDef;
                        this.txtCutPayment.Text = registration.CutPayment.ToString();
                        this.txtCheckManName.Text = registration.CheckManName;
                        if (registration.CheckTime != null)
                        {
                            this.txtCheckTime.Text = string.Format("{0:yyyy-MM-dd HH:mm:ss}", registration.CheckTime);
                        }
                        this.txtRectification.Text = registration.Rectification;
                        if (!string.IsNullOrEmpty(registration.HandleIdea))
                        {
                            this.txtHandleIdea.Hidden = false;
                            this.txtHandleIdea.Text = registration.HandleIdea;
                        }
                        txtRiskLevel.Text = registration.Risk_Level;
                        txtHiddenType.Text = registration.HiddenType;
                    }
                }
            }
        }
        #endregion
        #region 保存
        /// 
        /// 保存按钮
        /// 
        /// 
        /// 
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HSSE_HiddenRectificationListMenuId, BLL.Const.BtnSave))
            {
                SaveData(true);
            }
            else
            {
                Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
                return;
            }
        }
        /// 
        /// 保存数据
        /// 
        /// 
        private void SaveData(bool isClosed)
        {
            Model.HSSE_Hazard_HazardRegister register = BLL.HSSE_Hazard_HazardRegisterService.GetHazardRegisterByHazardRegisterId(this.HazardRegisterId);
            if (register != null)
            {
                register.States = "2";   //已整改待确认
                register.Rectification = this.txtRectification.Text.Trim();
                register.RectificationTime = DateTime.Now;
                BLL.HSSE_Hazard_HazardRegisterService.UpdateHazardRegister(register);
                BLL.LogService.AddSys_Log(this.CurrUser, register.HazardCode, register.HazardRegisterId, BLL.Const.HSSE_HiddenRectificationListMenuId, BLL.Const.BtnModify);
                if (isClosed)
                {
                    string scripts = String.Format("F.getActiveWindow().window.reloadGrid('{0}');", "");
                    PageContext.RegisterStartupScript(scripts + ActiveWindow.GetHidePostBackReference());
                }
            }
        }
        #endregion
        #region 附件查看
        /// 
        /// 附件查看
        /// 
        /// 
        /// 
        protected void btnAttachUrl_Click(object sender, EventArgs e)
        {
            string edit = "0";
            Model.HSSE_Hazard_HazardRegister register = BLL.HSSE_Hazard_HazardRegisterService.GetHazardRegisterByHazardRegisterId(this.HazardRegisterId);
            DateTime date = Convert.ToDateTime(register.CheckTime);
            string dateStr = date.Year.ToString() + date.Month.ToString();
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Registration/" + dateStr + "&menuId={1}&edit={2}", this.HazardRegisterId, Const.HSSE_HiddenRectificationListMenuId, edit)));
        }
        #endregion
        #region 附件上传
        /// 
        /// 附件上传
        /// 
        /// 
        /// 
        protected void btnAttachUrlR_Click(object sender, EventArgs e)
        {
            string edit = "1";
            Model.HSSE_Hazard_HazardRegister register = BLL.HSSE_Hazard_HazardRegisterService.GetHazardRegisterByHazardRegisterId(this.HazardRegisterId);
            DateTime date = Convert.ToDateTime(register.CheckTime);
            string dateStr = date.Year.ToString() + date.Month.ToString();
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Registration/" + dateStr + "&menuId={1}&edit={2}", this.HazardRegisterId + "-R", Const.HSSE_HiddenRectificationListMenuId, edit)));
        }
        #endregion
    }
}