436 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			436 lines
		
	
	
		
			16 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 HazardInfo : PageBase | |||
|  |     { | |||
|  |         #region 定义项 | |||
|  |         /// <summary> | |||
|  |         /// 清单主键 | |||
|  |         /// </summary> | |||
|  |         public string HazardSelectedItemId | |||
|  |         { | |||
|  |             get | |||
|  |             { | |||
|  |                 return (string)ViewState["HazardSelectedItemId"]; | |||
|  |             } | |||
|  |             set | |||
|  |             { | |||
|  |                 ViewState["HazardSelectedItemId"] = 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); | |||
|  |                 // 绑定表格 | |||
|  |                 BindGrid(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 绑定数据 | |||
|  |         /// </summary> | |||
|  |         private void BindGrid() | |||
|  |         { | |||
|  |             string strSql = "select HazardListItem.*,ControllingPersonUsers.UserName AS ControllingPersonName,Users.UserName,HazardList.WorkAreaName,HazardList.CompileDate,case HazardListItem.State when '1' then '存在' else '已取消' end as StateStr," | |||
|  |                           + @" (select UserName from Sys_User where UserId=(select top 1 Evaluatorld from Hazard_RiskEvaluationRecord where DataId=HazardListItem.HazardSelectedItemId order by EvaluatorDate desc)) as EvaluatorPersonName, " | |||
|  |                           + @" (select top 1 EvaluatorDate from Hazard_RiskEvaluationRecord where DataId=HazardListItem.HazardSelectedItemId order by EvaluatorDate desc) as EvaluatorDate," | |||
|  |                           + @" (select Days from Base_RiskLevel where RiskLevelId=(select top 1 RiskLevel from Hazard_RiskEvaluationRecord where DataId=HazardListItem.HazardSelectedItemId order by EvaluatorDate desc)) as Days, " | |||
|  |                           + @" (select RiskLevelName from Base_RiskLevel where RiskLevelId=HazardListItem.HazardLevel) as RiskLevelName" | |||
|  |                           + @" from Hazard_HazardSelectedItem AS HazardListItem " | |||
|  |                           + @" 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 HazardListItem.HazardLevel = @HazardLevel"; | |||
|  |                 listStr.Add(new SqlParameter("@HazardLevel", this.drpHazardLevel.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(); | |||
|  |         } | |||
|  |         #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 HazardSelectedItemId = Grid1.SelectedRowID; | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HazardInfoEdit.aspx?HazardSelectedItemId={0}", HazardSelectedItemId, "查看 - "))); | |||
|  |         } | |||
|  | 
 | |||
|  |         protected void btnReEvaluator_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length == 0) | |||
|  |             { | |||
|  |                 Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |             string HazardSelectedItemId = Grid1.SelectedRowID; | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HazardReEvaluator.aspx?HazardSelectedItemId={0}", HazardSelectedItemId, "查看 - "))); | |||
|  |         } | |||
|  | 
 | |||
|  |         protected void btnQR_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length == 0) | |||
|  |             { | |||
|  |                 Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |             string HazardSelectedItemId = Grid1.SelectedRowID; | |||
|  |             string strCode = "hazard$" + HazardSelectedItemId; | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/Controls/SeeQRImage.aspx?HazardSelectedItemId={0}&strCode={1}", HazardSelectedItemId, strCode), "二维码查看", 400, 400)); | |||
|  |         } | |||
|  |         #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.ProjectHazardInfoMenuId); | |||
|  |             if (buttonList.Count() > 0) | |||
|  |             { | |||
|  |                 if (buttonList.Contains(BLL.Const.BtnSave)) | |||
|  |                 { | |||
|  |                     this.btnMenuModify.Hidden = false; | |||
|  |                 } | |||
|  |                 if (buttonList.Contains(BLL.Const.BtnAuditing)) | |||
|  |                 { | |||
|  |                     this.btnReEvaluator.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         | |||
|  |     } | |||
|  | } |