namespace FineUIPro.Web.HSSE.License
{
    using BLL;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Linq;
    public partial class ApplyView : PageBase
    {
        #region 定义项
        /// 
        /// 主键
        /// 
        private string LicenseApplyId
        {
            get
            {
                return (string)ViewState["LicenseApplyId"];
            }
            set
            {
                ViewState["LicenseApplyId"] = value;
            }
        }
        #endregion
        #region 加载
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.SimpleForm1.Title = UnitService.GetUnitNameByUnitId(Const.UnitId_TCC) + this.Title;
                this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
                this.LicenseApplyId = Request.Params["LicenseApplyId"];
                if (!string.IsNullOrEmpty(this.LicenseApplyId))
                {
                    var getApply = LicensePublicService.GetApplyById(this.LicenseApplyId);
                    if (getApply != null)
                    {
                        this.txtApplyUnit.Text = UnitService.GetUnitNameByUnitId(getApply.ApplyUnitId);
                        this.txtApplyManName.Text = UserService.GetUserNameByUserId(getApply.ApplyManId);
                        if (!string.IsNullOrEmpty(getApply.LicenseTypeId))
                        {
                            this.txtType.Text = LicenseTypeService.GetLicenseTypeById(getApply.LicenseTypeId).LicenseTypeName;
                        }
                        if (getApply.ApplyStartTime.HasValue)
                        {
                            this.txtApplyDate.Text = getApply.ApplyStartTime.Value.ToString("yyyy-MM-dd HH:mm");
                        }
                    }
                }
                this.BindGrid();
            }
        }
        #endregion
        #region 流程列表绑定数据
        /// 
        /// 流程列表绑定数据
        /// 
        private void BindGrid()
        {
            DataTable getDataTable = new DataTable();
            if (!string.IsNullOrEmpty(this.LicenseApplyId))
            {
                string strSql = @"SELECT FlowOperateId,MenuId,DataId,SortIndex,AuditFlowName,OperaterId,Users.UserName AS OperaterName,OperaterTime,Opinion,IsClosed "
                    + @" FROM dbo.Sys_FlowOperate LEFT JOIN Sys_User AS Users ON OperaterId = Users.UserId"
                    + @" WHERE IsClosed = 1 AND DataId=@DataId ORDER BY SortIndex DESC";
                List listStr = new List();
                listStr.Add(new SqlParameter("@DataId", this.LicenseApplyId));
                SqlParameter[] parameter = listStr.ToArray();
                getDataTable = SQLHelper.GetDataTableRunText(strSql, parameter);
            }
            Grid1.DataSource = getDataTable;
            Grid1.DataBind();
        }
        #endregion
    }
}