466 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			466 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Data;
 | |
| using System.Data.SqlClient;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using AspNet = System.Web.UI.WebControls;
 | |
| 
 | |
| namespace FineUIPro.Web.HSSE.Hazard
 | |
| {
 | |
|     public partial class RiskControl : PageBase
 | |
|     {
 | |
|         #region 定义项
 | |
|         /// <summary>
 | |
|         /// 清单主键
 | |
|         /// </summary>
 | |
|         public string PatrolPlanId
 | |
|         {
 | |
|             get
 | |
|             {
 | |
|                 return (string)ViewState["PatrolPlanId"];
 | |
|             }
 | |
|             set
 | |
|             {
 | |
|                 ViewState["PatrolPlanId"] = value;
 | |
|             }
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 项目id
 | |
|         /// </summary>
 | |
|         public string ProjectId
 | |
|         {
 | |
|             get
 | |
|             {
 | |
|                 return (string)ViewState["ProjectId"];
 | |
|             }
 | |
|             set
 | |
|             {
 | |
|                 ViewState["ProjectId"] = value;
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 加载页面
 | |
|         /// <summary>
 | |
|         /// 加载页面
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Page_Load(object sender, EventArgs e)
 | |
|         {
 | |
|             if (!IsPostBack)
 | |
|             {
 | |
|                 Funs.DropDownPageSize(this.ddlPageSize);
 | |
|                 this.ProjectId = this.CurrUser.LoginProjectId;
 | |
|                 if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.ProjectId)
 | |
|                 {
 | |
|                     this.ProjectId = Request.Params["projectId"];
 | |
|                 }
 | |
|                 ////权限按钮方法
 | |
|                 this.GetButtonPower();
 | |
|                 ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
 | |
|                 BLL.RiskLevelService.InitRiskLevelDropDownList(this.drpHazardLevel, true);
 | |
|                 Funs.FineUIPleaseSelect(this.drpState);
 | |
|                 this.drpState.SelectedValue = "0";
 | |
|                 // 绑定表格
 | |
|                 BindGrid();
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>  
 | |
|         /// 绑定数据
 | |
|         /// </summary>
 | |
|         private void BindGrid()
 | |
|         {
 | |
|             string strSql = "select p.*,HazardListItem.WorkStage,HazardListItem.HazardListTypeId,HazardListItem.HazardId,HazardListItem.HazardItems,ControllingPersonUsers.UserName AS ControllingPersonName,Users.UserName,HazardList.WorkAreaName,HazardList.CompileDate,case p.State when '0' then '未巡检' when '1' then '已巡检' when '2' then '超期巡检' else '超期未巡检' end as StateStr,"
 | |
|                           + @" (select Days from Base_RiskLevel where RiskLevelId=(select top 1 RiskLevel from Hazard_RiskEvaluationRecord where DataId=p.HazardSelectedItemId order by EvaluatorDate desc)) as Days, "
 | |
|                           + @" (select RiskLevelName from Base_RiskLevel where RiskLevelId=(select top 1 RiskLevel from Hazard_RiskEvaluationRecord where DataId=p.HazardSelectedItemId order by EvaluatorDate desc)) as RiskLevelName,"
 | |
|                           + @" (select top 1 CheckDate from Hazard_PatrolPlan where HazardSelectedItemId=p.HazardSelectedItemId and LimitCheckDate<p.LimitCheckDate order by LimitCheckDate desc) as LastCheckDate,"
 | |
|                           + @" dateadd(day,(select days from Base_RiskLevel where RiskLevelId=p.HazardLevel),(select LimitCheckDate from Hazard_PatrolPlan where PatrolPlanId=p.PatrolPlanId)) as NextCheckDate "
 | |
|                           + @" from Hazard_PatrolPlan AS p "
 | |
|                           + @" LEFT JOIN Hazard_HazardSelectedItem AS HazardListItem on HazardListItem.HazardSelectedItemId=p.HazardSelectedItemId"
 | |
|                           + @" LEFT JOIN Hazard_HazardList AS HazardList on HazardList.HazardListId=HazardListItem.HazardListId "
 | |
|                           + @" LEFT JOIN Sys_User AS Users ON HazardListItem.DutyPerson=Users.UserId "
 | |
|                           + @" LEFT JOIN Sys_User AS ControllingPersonUsers ON HazardList.ControllingPerson=ControllingPersonUsers.UserId WHERE HazardList.States = " + BLL.Const.State_2;
 | |
|             List<SqlParameter> listStr = new List<SqlParameter>();
 | |
|             strSql += " AND HazardList.ProjectId = @ProjectId";
 | |
|             if (!string.IsNullOrEmpty(Request.Params["projectId"]))  ///是否文件柜查看页面传项目值
 | |
|             {
 | |
|                 listStr.Add(new SqlParameter("@ProjectId", Request.Params["projectId"]));
 | |
|                 strSql += " AND HazardList.States = @States";  ///状态为已完成
 | |
|                 listStr.Add(new SqlParameter("@States", BLL.Const.State_2));
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 listStr.Add(new SqlParameter("@ProjectId", this.ProjectId));
 | |
|             }
 | |
|             if (!string.IsNullOrEmpty(this.txtWorkAreaName.Text.Trim()))
 | |
|             {
 | |
|                 strSql += " AND HazardList.WorkAreaName LIKE @WorkAreaName";
 | |
|                 listStr.Add(new SqlParameter("@WorkAreaName", "%" + this.txtWorkAreaName.Text.Trim() + "%"));
 | |
|             }
 | |
|             if (this.drpHazardLevel.SelectedValue != BLL.Const._Null)
 | |
|             {
 | |
|                 strSql += " AND p.HazardLevel = @HazardLevel";
 | |
|                 listStr.Add(new SqlParameter("@HazardLevel", this.drpHazardLevel.SelectedValue));
 | |
|             }
 | |
|             if (this.drpState.SelectedValue != BLL.Const._Null)
 | |
|             {
 | |
|                 strSql += " AND p.State = @State";
 | |
|                 listStr.Add(new SqlParameter("@State", this.drpState.SelectedValue));
 | |
|             }
 | |
|             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
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取危险源编号
 | |
|         /// </summary>
 | |
|         /// <param name="WorkStage"></param>
 | |
|         /// <returns></returns>
 | |
|         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;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取危险源类别
 | |
|         /// </summary>
 | |
|         /// <param name="hazardListTypeId"></param>
 | |
|         /// <returns></returns>
 | |
|         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;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取危险源项
 | |
|         /// </summary>
 | |
|         /// <param name="hazardListTypeId"></param>
 | |
|         /// <returns></returns>
 | |
|         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;
 | |
|         }
 | |
| 
 | |
|         #region 查询
 | |
|         /// <summary>
 | |
|         /// 查询
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void TextBox_TextChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             this.BindGrid();
 | |
|         }
 | |
|         #endregion        
 | |
| 
 | |
|         #region 页索引改变事件
 | |
|         /// <summary>
 | |
|         /// 页索引改变事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
 | |
|         {
 | |
|             Grid1.PageIndex = e.NewPageIndex;
 | |
|             BindGrid();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 排序
 | |
|         /// <summary>
 | |
|         /// 排序
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_Sort(object sender, GridSortEventArgs e)
 | |
|         {
 | |
|             Grid1.SortDirection = e.SortDirection;
 | |
|             Grid1.SortField = e.SortField;
 | |
|             BindGrid();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 分页选择下拉改变事件
 | |
|         /// <summary>
 | |
|         /// 分页选择下拉改变事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
 | |
|             BindGrid();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 弹出编辑窗口关闭事件
 | |
|         /// <summary>
 | |
|         /// 弹出编辑窗体关闭事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Window1_Close(object sender, WindowCloseEventArgs e)
 | |
|         {
 | |
|             BindGrid();
 | |
|             string str = this.hdID.Text;
 | |
|             if (!string.IsNullOrEmpty(str))
 | |
|             {
 | |
|                 string[] strs = str.Split('|');
 | |
|                 if (strs.Length >= 2)
 | |
|                 {
 | |
|                     if (strs[0] == "1")  //二次评估
 | |
|                     {
 | |
|                         PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("HazardReEvaluator.aspx?HazardSelectedItemId={0}&LECItemRecordId={1}", strs[1], strs[2], "查看 - ")));
 | |
|                     }
 | |
|                     else if (strs[0] == "2")  //下整改单
 | |
|                     {
 | |
|                         PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("../Check/RectifyNoticesAdd.aspx?HazardSelectedItemId={0}", strs[1], "查看 - ")));
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 弹出编辑窗体关闭事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Window2_Close(object sender, WindowCloseEventArgs e)
 | |
|         {
 | |
|             BindGrid();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 弹出编辑窗体关闭事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Window3_Close(object sender, WindowCloseEventArgs e)
 | |
|         {
 | |
|             BindGrid();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 编制
 | |
|         /// <summary>
 | |
|         /// 编制
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void btnNew_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             int count = BLL.Hazard_HazardListService.GetHazardListCountByVersionNoIsNull(this.ProjectId);
 | |
|             if (count > 0)
 | |
|             {
 | |
|                 Alert.ShowInTop("风险评估版本号还未生成,不能进行操作!", MessageBoxIcon.Warning);
 | |
|                 return;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HazardListEdit.aspx", "编辑 - ")));
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region Grid双击事件
 | |
|         /// <summary>
 | |
|         /// Grid行双击事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
 | |
|         {
 | |
|             btnMenuModify_Click(null, null);
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 编辑
 | |
|         /// <summary>
 | |
|         /// 编辑按钮
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void btnMenuModify_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             if (Grid1.SelectedRowIndexArray.Length == 0)
 | |
|             {
 | |
|                 Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
 | |
|                 return;
 | |
|             }
 | |
|             string PatrolPlanId = Grid1.SelectedRowID;
 | |
|             if (this.btnMenuModify.Hidden == false)
 | |
|             {
 | |
|                 Model.Hazard_PatrolPlan plan = BLL.Hazard_PatrolPlanService.GetPatrolPlanByPatrolPlanId(PatrolPlanId);
 | |
|                 if (plan != null && (plan.DutyPerson == this.CurrUser.UserId || this.CurrUser.UserId == BLL.Const.sysglyId || this.CurrUser.UserId == BLL.Const.hfnbdId))
 | |
|                 {
 | |
|                     string window = String.Format("RoutingInspectionEdit.aspx?PatrolPlanId={0}", PatrolPlanId, "编辑 - ");
 | |
|                     PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdID.ClientID)
 | |
|                       + Window1.GetShowReference(window));
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     Alert.ShowInTop("您不是风险责任人,无法进行巡检!", MessageBoxIcon.Warning);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 转换字符串
 | |
|         /// <summary>
 | |
|         /// 转换工作阶段
 | |
|         /// </summary>
 | |
|         /// <param name="workStage"></param>
 | |
|         /// <returns></returns>
 | |
|         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 "";
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 获取按钮权限
 | |
|         /// <summary>
 | |
|         /// 获取按钮权限
 | |
|         /// </summary>
 | |
|         /// <param name="button"></param>
 | |
|         /// <returns></returns>
 | |
|         private void GetButtonPower()
 | |
|         {
 | |
|             if (Request.Params["value"] == "0")
 | |
|             {
 | |
|                 return;
 | |
|             }
 | |
|             var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.ProjectRiskControlMenuId);
 | |
|             if (buttonList.Count() > 0)
 | |
|             {
 | |
|                 if (buttonList.Contains(BLL.Const.BtnSave))
 | |
|                 {
 | |
|                     this.btnMenuModify.Hidden = false;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 导出按钮
 | |
|         /// 导出按钮
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void btnOut_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             Response.ClearContent();
 | |
|             string filename = Funs.GetNewFileName();
 | |
|             Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("风险分级管控" + filename, System.Text.Encoding.UTF8) + ".xls");
 | |
|             Response.ContentType = "application/excel";
 | |
|             Response.ContentEncoding = System.Text.Encoding.UTF8;
 | |
|             this.Grid1.PageSize = Grid1.RecordCount;
 | |
|             this.BindGrid();
 | |
|             Response.Write(GetGridTableHtml(Grid1));
 | |
|             Response.End();
 | |
|         }
 | |
| 
 | |
| #pragma warning disable CS0108 // “HazardList.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
 | |
|         /// <summary>
 | |
|         /// 导出方法
 | |
|         /// </summary>
 | |
|         /// <param name="grid"></param>
 | |
|         /// <returns></returns>
 | |
|         private string GetGridTableHtml(Grid grid)
 | |
| #pragma warning restore CS0108 // “HazardList.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
 | |
|         {
 | |
|             StringBuilder sb = new StringBuilder();
 | |
|             sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
 | |
|             sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
 | |
|             sb.Append("<tr>");
 | |
|             foreach (GridColumn column in grid.Columns)
 | |
|             {
 | |
|                 sb.AppendFormat("<td>{0}</td>", column.HeaderText);
 | |
|             }
 | |
|             sb.Append("</tr>");
 | |
|             foreach (GridRow row in grid.Rows)
 | |
|             {
 | |
|                 sb.Append("<tr>");
 | |
|                 foreach (GridColumn column in grid.Columns)
 | |
|                 {
 | |
|                     string html = row.Values[column.ColumnIndex].ToString();
 | |
|                     if (column.ColumnID == "tfNumber")
 | |
|                     {
 | |
|                         html = (row.FindControl("lblNumber") as AspNet.Label).Text;
 | |
|                     }
 | |
|                     if (column.ColumnID == "tfVersionNo")
 | |
|                     {
 | |
|                         html = (row.FindControl("lblVersionNo") as AspNet.Label).Text;
 | |
|                     }
 | |
|                     if (column.ColumnID == "tfWorkStage")
 | |
|                     {
 | |
|                         html = (row.FindControl("lblWorkStage") as AspNet.Label).Text;
 | |
|                     }
 | |
|                     sb.AppendFormat("<td>{0}</td>", html);
 | |
|                 }
 | |
| 
 | |
|                 sb.Append("</tr>");
 | |
|             }
 | |
| 
 | |
|             sb.Append("</table>");
 | |
| 
 | |
|             return sb.ToString();
 | |
|         }
 | |
|         #endregion    
 | |
|     }
 | |
| } |