using BLL;
using System;
using System.Linq;
namespace FineUIPro.Web.HSSE.Hazard
{
    public partial class RoutingInspectionView : PageBase
    {
        #region 定义项
        /// 
        /// 主键
        /// 
        private string PatrolPlanId
        {
            get
            {
                return (string)ViewState["PatrolPlanId"];
            }
            set
            {
                ViewState["PatrolPlanId"] = value;
            }
        }
        private string HazardSelectedItemId
        {
            get
            {
                return (string)ViewState["HazardSelectedItemId"];
            }
            set
            {
                ViewState["HazardSelectedItemId"] = value;
            }
        }
        private string RoutingInspectionId
        {
            get
            {
                return (string)ViewState["RoutingInspectionId"];
            }
            set
            {
                ViewState["RoutingInspectionId"] = 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)
        {
            using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
            {
                if (!IsPostBack)
                {
                    this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
                    UserService.InitUsersDropDownList(this.drpPatrolMan, this.CurrUser.LoginProjectId, true, string.Empty);
                    UserService.InitUsersDropDownList(this.drpRiskMan, this.CurrUser.LoginProjectId, true, string.Empty);
                    this.RoutingInspectionId = Request.Params["RoutingInspectionId"];
                    this.hdCheckManId.Text = this.CurrUser.UserId;
                    if (!string.IsNullOrEmpty(this.RoutingInspectionId))
                    {
                        Model.Hazard_RoutingInspection routingInspection = BLL.Hazard_RoutingInspectionService.GetRoutingInspectionByRoutingInspectionId(this.RoutingInspectionId);
                        Model.Hazard_PatrolPlan plan = BLL.Hazard_PatrolPlanService.GetPatrolPlanByPatrolPlanId(routingInspection.PatrolPlanId);
                        HazardSelectedItemId = plan.HazardSelectedItemId;
                        Model.Hazard_HazardSelectedItem item = BLL.Hazard_HazardSelectedItemService.GetHazardSelectedItemByHazardSelectedItemId(plan.HazardSelectedItemId);
                        if (item != null)
                        {
                            var q = BLL.HazardListService.GetHazardListById(item.HazardId);
                            if (q != null)
                            {
                                this.txtHazardCode.Text = q.HazardCode;
                                this.txtHazardItems.Text = item.HazardItems;
                                this.txtDefectsType.Text = item.DefectsType;
                                this.txtMayLeadAccidents.Text = item.MayLeadAccidents;
                            }
                        }
                        if (routingInspection != null)
                        {
                            if (!string.IsNullOrEmpty(routingInspection.PatrolManId))
                            {
                                this.drpPatrolMan.SelectedValue = routingInspection.PatrolManId;
                            }
                            if (routingInspection.PatrolTime != null)
                            {
                                this.txtPatrolTime.Text = string.Format("{0:yyyy-MM-dd}", routingInspection.PatrolTime);
                            }
                            if (routingInspection.PatrolResult != null)
                            {
                                this.rblPatrolResult.SelectedValue = routingInspection.PatrolResult.ToString();
                            }
                            this.txtControlMeasures.Text = routingInspection.ControlMeasures;
                            this.txtDealReason.Text = routingInspection.DealReason;
                            if (!string.IsNullOrEmpty(routingInspection.RiskManId))
                            {
                                this.drpRiskMan.SelectedValue = routingInspection.RiskManId;
                            }
                        }
                        else
                        {
                            this.drpPatrolMan.SelectedValue = this.CurrUser.UserId;
                            this.txtPatrolTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
                            this.drpRiskMan.SelectedValue = this.CurrUser.UserId;
                        }
                    }
                }
            }
        }
        #endregion
        #region 附件上传
        /// 
        /// 上传附件资源
        /// 
        /// 
        /// 
        protected void btnAttachUrl_Click(object sender, EventArgs e)
        {
            string edit = "-1";
            DateTime date = Funs.GetNewDateTimeOrNow(this.txtPatrolTime.Text.Trim());
            string dateStr = date.Year.ToString() + date.Month.ToString();
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/RoutingInspection/" + dateStr + "&menuId={1}&type={2}", this.RoutingInspectionId, Const.ProjectRiskControlMenuId, edit)));
        }
        #endregion
    }
}