513 lines
20 KiB
C#
513 lines
20 KiB
C#
using BLL;
|
|
using BLL.Common;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using AspNet = System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.HSSE.Hazard
|
|
{
|
|
public partial class HazardList : PageBase
|
|
{
|
|
#region 定义项
|
|
/// <summary>
|
|
/// 清单主键
|
|
/// </summary>
|
|
public string HazardListId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["HazardListId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["HazardListId"] = 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();
|
|
// 绑定表格
|
|
BindGrid();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string strSql = "select HazardList.HazardListId,HazardList.VersionNo,HazardList.WorkStage,Users.UserName,HazardList.CompileDate,CodeRecords.Code AS HazardListCode,HazardList.WorkAreaName,HazardList.IdentificationDate,ControllingPersonUsers.UserName AS ControllingPersonName "
|
|
+ @" ,(CASE WHEN HazardList.States = " + BLL.Const.State_0 + " OR HazardList.States IS NULL THEN '待['+OperateUser.UserName+']提交' WHEN HazardList.States = " + BLL.Const.State_2 + " THEN '审核/审批完成' ELSE '待['+OperateUser.UserName+']办理' END) AS FlowOperateName"
|
|
+ @" from Hazard_HazardList AS HazardList "
|
|
+ @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON HazardList.HazardListId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1"
|
|
+ @" LEFT JOIN Sys_User AS OperateUser ON FlowOperate.OperaterId=OperateUser.UserId "
|
|
+ @" LEFT JOIN Sys_User AS Users ON HazardList.CompileMan=Users.UserId "
|
|
+ @" LEFT JOIN Sys_User AS ControllingPersonUsers ON HazardList.ControllingPerson=ControllingPersonUsers.UserId "
|
|
+ @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON HazardList.HazardListId=CodeRecords.DataId WHERE 1=1 ";
|
|
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.txtHazardListCode.Text.Trim()))
|
|
{
|
|
strSql += " AND HazardListCode LIKE @HazardListCode";
|
|
listStr.Add(new SqlParameter("@HazardListCode", "%" + this.txtHazardListCode.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 查询
|
|
/// <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 删除
|
|
/// <summary>
|
|
/// 右键删除事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuDel_Click(object sender, EventArgs e)
|
|
{
|
|
this.DeleteData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除方法
|
|
/// </summary>
|
|
private void DeleteData()
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length > 0)
|
|
{
|
|
bool isShow = false;
|
|
if (Grid1.SelectedRowIndexArray.Length == 1)
|
|
{
|
|
isShow = true;
|
|
}
|
|
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
|
{
|
|
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
|
if (this.judgementDelete(rowID, isShow))
|
|
{
|
|
var getV = BLL.Hazard_HazardListService.GetHazardList(rowID);
|
|
if (getV != null)
|
|
{
|
|
BLL.LogService.AddSys_Log(this.CurrUser, getV.HazardListCode, getV.HazardListId, BLL.Const.ProjectHazardListMenuId, BLL.Const.BtnDelete);
|
|
BLL.Hazard_HazardSelectedItemService.DeleteHazardSelectedItemByHazardListId(rowID);
|
|
BLL.Hazard_HazardListService.DeleteHazardListByHazardListId(rowID);
|
|
}
|
|
}
|
|
}
|
|
|
|
BindGrid();
|
|
ShowNotify("删除数据成功!(表格数据已重新绑定)", MessageBoxIcon.Success);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断是否可删除
|
|
/// </summary>
|
|
/// <param name="rowID"></param>
|
|
/// <param name="isShow"></param>
|
|
/// <returns></returns>
|
|
private bool judgementDelete(string rowID, bool isShow)
|
|
{
|
|
string content = string.Empty;
|
|
if (string.IsNullOrEmpty(content))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (isShow)
|
|
{
|
|
Alert.ShowInTop(content);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
#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 HazardListId = Grid1.SelectedRowID;
|
|
var hazardList = BLL.Hazard_HazardListService.GetHazardList(HazardListId);
|
|
if (hazardList != null)
|
|
{
|
|
if (this.btnMenuModify.Hidden || hazardList.States == BLL.Const.State_2) ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HazardListView.aspx?HazardListId={0}", HazardListId, "查看 - ")));
|
|
}
|
|
else
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HazardListEdit.aspx?HazardListId={0}", HazardListId, "编辑 - ")));
|
|
}
|
|
}
|
|
}
|
|
#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.ProjectHazardListMenuId);
|
|
if (buttonList.Count() > 0)
|
|
{
|
|
if (buttonList.Contains(BLL.Const.BtnAdd))
|
|
{
|
|
this.btnNew.Hidden = false;
|
|
}
|
|
if (buttonList.Contains(BLL.Const.BtnModify))
|
|
{
|
|
this.btnMenuModify.Hidden = false;
|
|
}
|
|
if (buttonList.Contains(BLL.Const.BtnDelete))
|
|
{
|
|
this.btnMenuDel.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 导出按钮
|
|
/// 导出按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnOut_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
string strSql = @"select CodeRecords.Code 清单编号, HazardList.VersionNo 版本号, WorkStage .WorkStageName 工作阶段, HazardList.WorkAreaName 单位工程, HazardList.IdentificationDate 评估时间,
|
|
ControllingPersonUsers.UserName AS 风险责任人 , Users.UserName 编制人 , HazardList.CompileDate 编制日期,
|
|
(CASE WHEN HazardList.States = 0 OR HazardList.States IS NULL THEN '待['+OperateUser.UserName+']提交' WHEN HazardList.States = 2 THEN '审核/审批完成' ELSE '待['+OperateUser.UserName+']办理' END) AS 状态,
|
|
SupHazardListType.HazardListTypeName 危险源类别, HazardListType.HazardListTypeName 危险源项, HazardItems 危险因素明细,DefectsType 缺陷类型, MayLeadAccidents 可能导致的事故,
|
|
HelperMethod 辅助方法, HazardJudge_L L,HazardJudge_E E,HazardJudge_C C, HazardJudge_D D, HazardLevel 危险级别, ControlMeasures 控制措施
|
|
from Hazard_HazardList AS HazardList
|
|
LEFT JOIN Sys_FlowOperate AS FlowOperate ON HazardList.HazardListId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1
|
|
LEFT JOIN Sys_User AS OperateUser ON FlowOperate.OperaterId=OperateUser.UserId
|
|
LEFT JOIN Sys_User AS Users ON HazardList.CompileMan=Users.UserId
|
|
LEFT JOIN Sys_User AS ControllingPersonUsers ON HazardList.ControllingPerson=ControllingPersonUsers.UserId
|
|
LEFT JOIN Sys_CodeRecords AS CodeRecords ON HazardList.HazardListId=CodeRecords.DataId
|
|
LEFT JOIN Hazard_HazardSelectedItem AS Item ON Item.HazardListId = HazardList.HazardListId
|
|
LEFT JOIN Technique_HazardListType AS HazardListType ON HazardListType.HazardListTypeId=Item.HazardListTypeId
|
|
LEFT JOIN Technique_HazardListType AS SupHazardListType ON HazardListType.HazardListTypeId=SupHazardListType.HazardListTypeId
|
|
LEFT JOIN Base_WorkStage AS WorkStage on WorkStage.WorkStageId = Item.WorkStage
|
|
WHERE 1=1 ";
|
|
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.txtHazardListCode.Text.Trim()))
|
|
{
|
|
strSql += " AND HazardListCode LIKE @HazardListCode";
|
|
listStr.Add(new SqlParameter("@HazardListCode", "%" + this.txtHazardListCode.Text.Trim() + "%"));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
tb.TableName = "风险评估";
|
|
Response.ClearContent();
|
|
string filename = Funs.GetNewFileName();
|
|
|
|
string uploadfilepath = Server.MapPath("~/") + filename;
|
|
NPOIHelper.DataSetToExcel(tb, uploadfilepath);
|
|
|
|
string fileName = Path.GetFileName(filename);
|
|
FileInfo info = new FileInfo(uploadfilepath);
|
|
if (info.Exists)
|
|
{
|
|
long fileSize = info.Length;
|
|
Response.Clear();
|
|
Response.ContentType = "application/x-zip-compressed";
|
|
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("风险评估" + filename, System.Text.Encoding.UTF8) + ".xls");
|
|
Response.AddHeader("Content-Length", fileSize.ToString());
|
|
Response.TransmitFile(uploadfilepath, 0, fileSize);
|
|
Response.Flush();
|
|
Response.Close();
|
|
}
|
|
else
|
|
{
|
|
ShowNotify("文件不存在!", MessageBoxIcon.Warning);
|
|
}
|
|
Response.Write(GetGridTableHtml(Grid1));
|
|
|
|
|
|
Response.End();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出方法
|
|
/// </summary>
|
|
/// <param name="grid"></param>
|
|
/// <returns></returns>
|
|
private string GetGridTableHtml(Grid grid)
|
|
{
|
|
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
|
|
|
|
#region 打印
|
|
/// <summary>
|
|
/// 打印全部危险源
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuAllPrint_Click(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(Grid1.SelectedRowID))
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/ReportPrint/ExReportPrint.aspx?reportId={0}&&replaceParameter={1}&&varValue={2}", Const.HazardListReportId, Grid1.SelectedRowID, "", "打印 - ")));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打印重要危险源
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuImportantPrint_Click(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(Grid1.SelectedRowID))
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/ReportPrint/ExReportPrint.aspx?reportId={0}&&replaceParameter={1}&&varValue={2}", Const.HazardListImportantReportId, Grid1.SelectedRowID, "", "打印 - ")));
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |