using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using FineUIPro.Web.SysManage;

namespace FineUIPro.Web.HSSE.Check
{
    public partial class ProjectLeaderCheckView : PageBase
    {
        #region 定义项
        /// <summary>
        /// 主键
        /// </summary>
        public string ProjectLeaderCheckId
        {
            get
            {
                return (string)ViewState["ProjectLeaderCheckId"];
            }
            set
            {
                ViewState["ProjectLeaderCheckId"] = value;
            }
        }
        /// <summary>
        /// 单位  ID
        /// </summary>
        public string UnitId
        {
            get
            {
                return (string)ViewState["UnitId"];
            }
            set
            {
                ViewState["UnitId"] = value;
            }
        }
        /// <summary>
        /// 菜单  ID
        /// </summary>
        public string MenuId
        {
            get
            {
                return (string)ViewState["MenuId"];
            }
            set
            {
                ViewState["MenuId"] = value;
            }
        }
        #endregion

        #region 加载
        /// <summary>
        /// 加载页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.btnClose.OnClientClick = ActiveWindow.GetHideReference();               
                this.ProjectLeaderCheckId = Request.Params["ProjectLeaderCheckId"];
                this.UnitId = Request.Params["UnitId"];
                this.MenuId = Const.ProjectLeaderCheckMenuId;
                if (!string.IsNullOrEmpty(this.ProjectLeaderCheckId))
                {
                    var getProjectLeaderCheck = BLL.Check_ProjectLeaderCheckService.GetProjectLeaderCheckById(this.ProjectLeaderCheckId);
                    if (getProjectLeaderCheck != null)
                    {
                        this.drpUnits.Text = UnitService.getUnitNamesUnitIds(getProjectLeaderCheck.UnitIds);
                        this.drpLeaderIds.Text = UserService.getUserNamesUserIds(getProjectLeaderCheck.LeaderIds);
                        this.txtCheckCode.Text = getProjectLeaderCheck.CheckCode;
                        this.txtCheckDate.Text = string.Format("{0:yyyy-MM-dd}", getProjectLeaderCheck.CheckDate);
                        this.ckIsHoldMeet.Checked = getProjectLeaderCheck.IsHoldMeet.Value;
                        this.txtQuestionDef.Text = getProjectLeaderCheck.QuestionDef;
                        this.txtRequirement.Text = getProjectLeaderCheck.Requirement;
                        this.txtLeaderName.Text = getProjectLeaderCheck.LeaderNames;
                    }
                }
                else
                {
                    ////自动生成编码
                    this.txtCheckCode.Text = BLL.CodeRecordsService.ReturnCodeByMenuIdProjectId(this.MenuId, this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
                    this.txtCheckDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
                }
            }
        }
        #endregion

        #region 附件上传
        /// <summary>
        /// 上传附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAttachUrl_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&type=-1&path=FileUpload/ProjectLeaderCheckAttachUrl&menuId={1}", ProjectLeaderCheckId, this.MenuId)));
        }
        #endregion
    }
}