using System;
using System.Linq;
namespace FineUIPro.Web.HSSE.Administrative
{
    public partial class DriverManagerView : PageBase
    {
        #region 定义项
        /// 
        /// 主键
        /// 
        private string DriverManagerId
        {
            get
            {
                return (string)ViewState["DriverManagerId"];
            }
            set
            {
                ViewState["DriverManagerId"] = value;
            }
        }
        #endregion
        #region 加载
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnClose.OnClientClick = ActiveWindow.GetHideReference();
                this.DriverManagerId = Request.Params["DriverManagerId"];
                if (!string.IsNullOrEmpty(this.DriverManagerId))
                {
                    var DriverManager = BLL.DriverManagerService.GetDriverManagerById(this.DriverManagerId);
                    if (DriverManager != null)
                    {
                        this.txtDriverManagerCode.Text = BLL.CodeRecordsService.ReturnCodeByDataId(this.DriverManagerId);
                        this.txtDriverName.Text = DriverManager.DriverName;
                        this.txtDriverCode.Text = DriverManager.DriverCode;
                        this.txtDrivingDate.Text = string.Format("{0:yyyy-MM-dd}", DriverManager.DrivingDate);
                        this.txtCheckDate.Text = string.Format("{0:yyyy-MM-dd}", DriverManager.CheckDate);
                        this.txtDriverCarModel.Text = DriverManager.DriverCarModel;
                        this.txtRemark.Text = DriverManager.Remark;
                    }
                }
                ///初始化审核菜单
                this.ctlAuditFlow.MenuId = BLL.Const.DriverManagerMenuId;
                this.ctlAuditFlow.DataId = this.DriverManagerId;
            }
        }
        #endregion
        #region 年检有效期
        /// 
        /// 年检有效期
        /// 
        /// 
        /// 
        protected void TextBox_TextChanged(object sender, EventArgs e)
        {
            var driverManager = BLL.DriverManagerService.GetDriverManagerById(this.DriverManagerId);
            if (driverManager != null)
            {
                var buttonList = BLL.CommonService.GetAllButtonList(driverManager.ProjectId, this.CurrUser.UserId, BLL.Const.DriverManagerMenuId);
                if (buttonList.Count() > 0 && buttonList.Contains(BLL.Const.BtnModify))
                {
                    driverManager.CheckDate = BLL.Funs.GetNewDateTime(this.txtCheckDate.Text);
                    BLL.DriverManagerService.UpdateDriverManager(driverManager);
                    PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
                }
            }
        }
        #endregion
        #region 附件上传
        /// 
        /// 上传附件
        /// 
        /// 
        /// 
        protected void btnAttachUrl_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.DriverManagerId))
            {
                PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/DriverManagerAttachUrl&menuId={1}", DriverManagerId, BLL.Const.DriverManagerMenuId)));
            }
        }
        #endregion
    }
}