302 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			302 lines
		
	
	
		
			11 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 OtherHazard : PageBase | |||
|  |     { | |||
|  |         #region 加载页面 | |||
|  |         /// <summary> | |||
|  |         /// 加载页面 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Page_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             // 表头过滤 | |||
|  |             //FilterDataRowItem = FilterDataRowItemImplement; | |||
|  |             if (!IsPostBack) | |||
|  |             { | |||
|  |                 ////权限按钮方法 | |||
|  |                 this.GetButtonPower(); | |||
|  |                 btnNew.OnClientClick = Window1.GetShowReference("OtherHazardEdit.aspx") + "return false;"; | |||
|  | 
 | |||
|  |                 ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); | |||
|  |                 // 绑定表格 | |||
|  |                 BindGrid(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 绑定数据 | |||
|  |         /// </summary> | |||
|  |         private void BindGrid() | |||
|  |         { | |||
|  |             string strSql = @"SELECT OtherHazard.OtherHazardId,OtherHazard.ProjectId,CodeRecords.Code AS OtherHazardCode,OtherHazard.OtherHazardName,Users.UserName,OtherHazard.CompileDate " | |||
|  |                           + @" ,(CASE WHEN OtherHazard.States = " + BLL.Const.State_0 + " OR OtherHazard.States IS NULL THEN '待['+OperateUser.UserName+']提交' WHEN OtherHazard.States =  " + BLL.Const.State_2 + " THEN '审核/审批完成' ELSE '待['+OperateUser.UserName+']办理' END) AS  FlowOperateName" | |||
|  |                           + @" FROM Hazard_OtherHazard AS OtherHazard " | |||
|  |                           + @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON OtherHazard.OtherHazardId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1" | |||
|  |                           + @" LEFT JOIN Sys_User AS OperateUser ON FlowOperate.OperaterId=OperateUser.UserId " | |||
|  |                           + @" LEFT JOIN Sys_User AS Users ON OtherHazard.CompileMan=Users.UserId " | |||
|  |                           + @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON OtherHazard.OtherHazardId=CodeRecords.DataId WHERE 1=1 "; | |||
|  |             List<SqlParameter> listStr = new List<SqlParameter>(); | |||
|  |             strSql += " AND OtherHazard.ProjectId = @ProjectId"; | |||
|  |             if (!string.IsNullOrEmpty(Request.Params["projectId"]))  ///是否文件柜查看页面传项目值 | |||
|  |             { | |||
|  |                 listStr.Add(new SqlParameter("@ProjectId", Request.Params["projectId"])); | |||
|  |                 strSql += " AND OtherHazard.States = @States";  ///状态为已完成 | |||
|  |                 listStr.Add(new SqlParameter("@States", BLL.Const.State_2)); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); | |||
|  |             } | |||
|  |             if (!string.IsNullOrEmpty(this.txtOtherHazardCode.Text.Trim())) | |||
|  |             { | |||
|  |                 strSql += " AND OtherHazardCode LIKE @OtherHazardCode"; | |||
|  |                 listStr.Add(new SqlParameter("@OtherHazardCode", "%" + this.txtOtherHazardCode.Text.Trim() + "%")); | |||
|  |             } | |||
|  |             SqlParameter[] parameter = listStr.ToArray(); | |||
|  |             DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); | |||
|  |             // 2.获取当前分页数据 | |||
|  |             //var table = this.GetPagedDataTable(Grid1, tb1); | |||
|  | 
 | |||
|  |             Grid1.RecordCount = tb.Rows.Count; | |||
|  |             //tb = GetFilteredTable(Grid1.FilteredData, tb); | |||
|  |             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_FilterChange(object sender, EventArgs e) | |||
|  |         { | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 分页 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) | |||
|  |         { | |||
|  |             Grid1.PageIndex = e.NewPageIndex; | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <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(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <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(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 关闭弹出窗 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Window1_Close(object sender, WindowCloseEventArgs e) | |||
|  |         { | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  |         #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 OtherHazardId = Grid1.SelectedRowID; | |||
|  |             var checkWork = BLL.Hazard_OtherHazardService.GetOtherHazardByOtherHazardId(OtherHazardId); | |||
|  |             if (checkWork != null) | |||
|  |             { | |||
|  |                 if (this.btnMenuModify.Hidden || checkWork.States == BLL.Const.State_2)   ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面 | |||
|  |                 { | |||
|  |                     PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("OtherHazardView.aspx?OtherHazardId={0}", OtherHazardId, "查看 - "))); | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("OtherHazardEdit.aspx?OtherHazardId={0}", OtherHazardId, "编辑 - "))); | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 删除 | |||
|  |         /// <summary> | |||
|  |         /// 批量删除 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnMenuDel_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length > 0) | |||
|  |             { | |||
|  |                 foreach (int rowIndex in Grid1.SelectedRowIndexArray) | |||
|  |                 { | |||
|  |                     string rowID = Grid1.DataKeys[rowIndex][0].ToString(); | |||
|  |                     var otherHazard = BLL.Hazard_OtherHazardService.GetOtherHazardByOtherHazardId(rowID); | |||
|  |                     if (otherHazard != null) | |||
|  |                     { | |||
|  |                         BLL.LogService.AddSys_Log(this.CurrUser, otherHazard.OtherHazardCode, otherHazard.OtherHazardId, BLL.Const.OtherHazardMenuId, BLL.Const.BtnDelete); | |||
|  |                         BLL.Hazard_OtherHazardService.DeleteOtherHazard(rowID); | |||
|  |                     } | |||
|  |                 } | |||
|  | 
 | |||
|  |                 BindGrid(); | |||
|  |                 ShowNotify("删除数据成功!(表格数据已重新绑定)"); | |||
|  |             } | |||
|  |         } | |||
|  |         #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.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.OtherHazardMenuId); | |||
|  |             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) | |||
|  |         { | |||
|  |             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 = 500; | |||
|  |             this.BindGrid(); | |||
|  |             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; | |||
|  |                     } | |||
|  |                     sb.AppendFormat("<td>{0}</td>", html); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 sb.Append("</tr>"); | |||
|  |             } | |||
|  | 
 | |||
|  |             sb.Append("</table>"); | |||
|  | 
 | |||
|  |             return sb.ToString(); | |||
|  |         } | |||
|  |         #endregion         | |||
|  |     } | |||
|  | } |