using Aspose.Words;
using BLL;
using FineUIPro.Web.BaseInfo;
using Model;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
namespace FineUIPro.Web.DataShow
{
    public partial class SecurityRiskItem : PageBase
    {
        #region 加载页面
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string projectId = Request.Params["projectId"];
                this.txtProject.Text=ProjectService.GetProjectNameByProjectId(projectId);
                Funs.DropDownPageSize(this.ddlPageSize);
                btnClose.OnClientClick = ActiveWindow.GetHideReference();
                ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
                // 绑定表格
                BindGrid();
                this.Panel1.Title = "安全风险数据(" + BLL.UnitService.GetUnitNameByUnitId(BLL.Const.UnitId_CWCEC) + ")";
            }
        }
        /// 
        /// 绑定数据
        /// 
        private void BindGrid()
        {
            string strSql = @"select Item.HazardSelectedItemId,Item.HazardListId,List.IdentificationDate,List.WorkAreaName,Item.WorkStage,Item.HazardListTypeId
                    , Item.HazardListTypeId,Item.HazardId,Item.HazardItems,Item.DefectsType,Item.MayLeadAccidents
                    ,Item.HelperMethod,Item.HazardJudge_L,Item.HazardJudge_E,Item.HazardJudge_C,HazardJudge_D,Item.HazardJudge_E
                    ,level.RiskLevelName,Item.ControlMeasures
                    from Hazard_HazardSelectedItem AS Item
                    LEFT JOIN Hazard_HazardList AS List on List.HazardListId = Item.HazardListId
                    LEFT JOIN Base_RiskLevel as level on level.RiskLevelId = Item.HazardLevel
                WHERE List.States = " + BLL.Const.State_2;
            List listStr = new List();
            strSql += " AND List.ProjectId = @ProjectId";
            listStr.Add(new SqlParameter("@ProjectId", Request.Params["projectId"]));
            if (!string.IsNullOrEmpty(txtStartTime.Text.Trim()))
            {
                strSql += " AND List.IdentificationDate >= @StartTime";
                listStr.Add(new SqlParameter("@StartTime", this.txtStartTime.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(this.txtEndTime.Text.Trim()))
            {
                strSql += " AND List.IdentificationDate <= @EndTime";
                listStr.Add(new SqlParameter("@EndTime", this.txtEndTime.Text.Trim()));
            }
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid1.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(Grid1, tb);
            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        #endregion
        #region 查询
        /// 
        /// 查询
        /// 
        /// 
        /// 
        protected void TextBox_TextChanged(object sender, EventArgs e)
        {
            this.BindGrid();
        }
        #endregion
        #region 表排序、分页、关闭窗口
        /// 
        /// 分页
        /// 
        /// 
        /// 
        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            BindGrid();
        }
        /// 
        /// 排序
        /// 
        /// 
        /// 
        protected void Grid1_Sort(object sender, GridSortEventArgs e)
        {
            BindGrid();
        }
        /// 
        /// 分页显示条数下拉框
        /// 
        /// 
        /// 
        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
            BindGrid();
        }
        #endregion
        #region 转换字符串
        /// 
        /// 转换工作阶段
        /// 
        /// 
        /// 
        protected string ConvertWorkStage(object workStage)
        {
            if (workStage != null)
            {
                string workStages = string.Empty;
                string[] strList = workStage.ToString().Split(',');
                foreach (string str in strList)
                {
                    Model.Base_WorkStage c = BLL.WorkStageService.GetWorkStageById(str);
                    if (c != null)
                    {
                        workStages += c.WorkStageName + ",";
                    }
                }
                if (!string.IsNullOrEmpty(workStages))
                {
                    workStages = workStages.Substring(0, workStages.LastIndexOf(","));
                }
                return workStages;
            }
            return "";
        }
        /// 
        /// 获取危险源编号
        /// 
        /// 
        /// 
        protected string ConvertHazardCode(object HazardId)
        {
            string hazardCode = string.Empty;
            if (HazardId != null)
            {
                Model.Technique_HazardList hazardList = BLL.HazardListService.GetHazardListById(HazardId.ToString());
                if (hazardList != null)
                {
                    hazardCode = hazardList.HazardCode;
                }
            }
            return hazardCode;
        }
        /// 
        /// 获取危险源类别
        /// 
        /// 
        /// 
        protected string ConvertSupHazardListTypeId(object hazardListTypeId)
        {
            if (hazardListTypeId != null)
            {
                Model.Technique_HazardListType hazardListType = BLL.HazardListTypeService.GetHazardListTypeById(hazardListTypeId.ToString());
                if (hazardListType != null)
                {
                    var hazard = BLL.HazardListTypeService.GetHazardListTypeById(hazardListType.SupHazardListTypeId);
                    if (hazard != null)
                    {
                        return hazard.HazardListTypeName;
                    }
                }
            }
            return null;
        }
        /// 
        /// 获取危险源项
        /// 
        /// 
        /// 
        protected string ConvertHazardListTypeId(object hazardListTypeId)
        {
            if (hazardListTypeId != null)
            {
                Model.Technique_HazardListType hazardListType = BLL.HazardListTypeService.GetHazardListTypeById(hazardListTypeId.ToString());
                if (hazardListType != null)
                {
                    return hazardListType.HazardListTypeName;
                }
            }
            return null;
        }
        #endregion
    }
}