| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  | using BLL; | 
					
						
							|  |  |  |  | using FineUIPro.Web.BaseInfo; | 
					
						
							| 
									
										
										
										
											2024-01-02 16:03:32 +08:00
										 |  |  |  | using Newtonsoft.Json.Linq; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using System.Data; | 
					
						
							|  |  |  |  | using System.Data.SqlClient; | 
					
						
							|  |  |  |  | using System.Linq; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace FineUIPro.Web.DataShow | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     public partial class SecurityRisk : PageBase | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         #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); | 
					
						
							|  |  |  |  |                 ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); | 
					
						
							|  |  |  |  |                 BLL.ProjectService.InitProjectDropDownList(this.drpProject, true); | 
					
						
							|  |  |  |  |                 // 绑定表格t | 
					
						
							|  |  |  |  |                 BindGrid(); | 
					
						
							| 
									
										
										
										
											2024-01-02 16:03:32 +08:00
										 |  |  |  |                 // 合计 | 
					
						
							|  |  |  |  |                 OutputSummaryData(); | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |                 this.Panel1.Title = "安全风险数据(" + BLL.UnitService.GetUnitNameByUnitId(BLL.Const.UnitId_CWCEC) + ")"; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         #endregion | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         #region 加载页面 | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         /// 绑定数据 | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         private void BindGrid() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             string strSql = @"select ProjectId,ProjectCode, ProjectName from Base_Project where ProjectState =1"; | 
					
						
							|  |  |  |  |             List<SqlParameter> listStr = new List<SqlParameter>(); | 
					
						
							|  |  |  |  |             string cpara = string.Empty; | 
					
						
							|  |  |  |  |             if (this.drpProject.SelectedValue != Const._Null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 strSql += " AND projectId = @projectId";  ///状态为已完成 | 
					
						
							|  |  |  |  |                 listStr.Add(new SqlParameter("@projectId", this.drpProject.SelectedValue)); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             //if (!string.IsNullOrEmpty(this.txtStartTime.Text)) | 
					
						
							|  |  |  |  |             //{ | 
					
						
							|  |  |  |  |             //    strSql += " AND h.RegisterDate >=@StartTime"; | 
					
						
							|  |  |  |  |             //    listStr.Add(new SqlParameter("@StartTime", this.txtStartTime.Text)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             //    cpara += " AND c.RegisterDate >=" + this.txtStartTime.Text; | 
					
						
							|  |  |  |  |             //} | 
					
						
							|  |  |  |  |             //if (!string.IsNullOrEmpty(this.txtEndTime.Text)) | 
					
						
							|  |  |  |  |             //{ | 
					
						
							|  |  |  |  |             //    strSql += " AND h.RegisterDate <=@EndTime"; | 
					
						
							|  |  |  |  |             //    listStr.Add(new SqlParameter("@EndTime", this.txtEndTime.Text)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             //    cpara += " AND c.RegisterDate <=" + this.txtEndTime.Text; | 
					
						
							|  |  |  |  |             //} | 
					
						
							|  |  |  |  |              | 
					
						
							|  |  |  |  |             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) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             BindGrid(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         /// 排序 | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         /// <param name="sender"></param> | 
					
						
							|  |  |  |  |         /// <param name="e"></param> | 
					
						
							|  |  |  |  |         protected void Grid1_Sort(object sender, GridSortEventArgs e) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             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) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             EditData(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         ///  | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         private void EditData() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (Grid1.SelectedRowIndexArray.Length == 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); | 
					
						
							|  |  |  |  |                 return; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SecurityRiskItem.aspx?projectId={0}", Grid1.SelectedRowID, "查看 - "))); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         #endregion | 
					
						
							|  |  |  |  |          | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         ///  | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         /// <param name="sender"></param> | 
					
						
							|  |  |  |  |         /// <param name="e"></param> | 
					
						
							|  |  |  |  |         protected void btnView_Click(object sender, EventArgs e) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             EditData(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         /// 总工时数 | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         /// <param name="state"></param> | 
					
						
							|  |  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |  |         protected int Count1(object projectId) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             int cout1 = 0; | 
					
						
							|  |  |  |  |             if (projectId != null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 cout1 = getcount(projectId.ToString(), 1); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return cout1; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         /// 损失工时数 | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         /// <param name="state"></param> | 
					
						
							|  |  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |  |         protected int Count2(object projectId) | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |             int cout2 = 0; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |             if (projectId != null) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |                 cout2 = getcount(projectId.ToString(),2); | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |             return cout2; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         /// 安全工时数 | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         /// <param name="state"></param> | 
					
						
							|  |  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |  |         protected int Count3(object projectId) | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |             int cout3 = 0; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |             if (projectId != null) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |                 cout3= getcount(projectId.ToString(), 3); | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |             return cout3; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         protected int Count4(object projectId) | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |             int cout4 = 0; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |             if (projectId != null) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |                 cout4 = getcount(projectId.ToString(), 4); | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-06-07 18:55:33 +08:00
										 |  |  |  |             return cout4; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-24 16:17:59 +08:00
										 |  |  |  |    | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         ///  | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         /// <param name="projectId"></param> | 
					
						
							|  |  |  |  |         /// <param name="level"></param> | 
					
						
							|  |  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |  |         private int getcount(string projectId, int level) | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2024-01-24 16:17:59 +08:00
										 |  |  |  |             int count = 0; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |             var getlevel = Funs.DB.Base_RiskLevel.FirstOrDefault(x => x.RiskLevel == level); | 
					
						
							|  |  |  |  |             if (getlevel != null) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2024-01-24 16:17:59 +08:00
										 |  |  |  |                 count = (from x in Funs.DB.Hazard_HazardSelectedItem | 
					
						
							|  |  |  |  |                          join y in Funs.DB.Hazard_HazardList on x.HazardListId equals y.HazardListId | 
					
						
							|  |  |  |  |                          where y.ProjectId == projectId && (x.HazardLevel == getlevel.RiskLevelId || x.HazardLevel == level.ToString()) && y.States == Const.State_2 | 
					
						
							|  |  |  |  |                          && y.CompileDate.Value.Year >= 2023 | 
					
						
							|  |  |  |  |                          select x).Count(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 count = (from x in Funs.DB.Hazard_HazardSelectedItem | 
					
						
							|  |  |  |  |                          join y in Funs.DB.Hazard_HazardList on x.HazardListId equals y.HazardListId | 
					
						
							|  |  |  |  |                          where y.ProjectId == projectId && x.HazardLevel == level.ToString() && y.States == Const.State_2 | 
					
						
							|  |  |  |  |                            && y.CompileDate.Value.Year >= 2023 | 
					
						
							|  |  |  |  |                          select x).Count(); | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |             return count; | 
					
						
							| 
									
										
										
										
											2024-01-02 16:03:32 +08:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 16:03:32 +08:00
										 |  |  |  |         #region 合计 | 
					
						
							|  |  |  |  |         private void OutputSummaryData() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             string strSql = @"select ProjectId,ProjectCode, ProjectName ,
 | 
					
						
							|  |  |  |  |                     isnull((select count(*) from Hazard_HazardSelectedItem as a  | 
					
						
							|  |  |  |  | 	                    where (a.IsStart=1 or a.State = '1') and a.ProjectId=p.ProjectId	 | 
					
						
							|  |  |  |  | 	                    and (a.HazardLevel='1' or a.HazardLevel=(select top 1 RiskLevelId from Base_RiskLevel where RiskLevel='1'))),0) as Count1, | 
					
						
							|  |  |  |  |                     isnull((select count(*) from Hazard_HazardSelectedItem as a where (a.IsStart=1 or a.State = '1') and a.ProjectId=p.ProjectId  | 
					
						
							|  |  |  |  | 	                    and (a.HazardLevel='2' or a.HazardLevel=(select top 1 RiskLevelId from Base_RiskLevel where RiskLevel='2'))),0) as Count2, | 
					
						
							|  |  |  |  |                     isnull((select count(*) from Hazard_HazardSelectedItem as a where (a.IsStart=1 or a.State = '1') and a.ProjectId=p.ProjectId  | 
					
						
							|  |  |  |  | 	                    and (a.HazardLevel='3' or a.HazardLevel=(select top 1 RiskLevelId from Base_RiskLevel where RiskLevel='3'))),0) as Count3, | 
					
						
							|  |  |  |  |                     isnull((select count(*) from Hazard_HazardSelectedItem as a where (a.IsStart=1 or a.State = '1') and a.ProjectId=p.ProjectId  | 
					
						
							|  |  |  |  | 	                    and (a.HazardLevel='4' or a.HazardLevel=(select top 1 RiskLevelId from Base_RiskLevel where RiskLevel='4'))),0) as Count4 | 
					
						
							|  |  |  |  |                     from Base_Project as P where ProjectState =1 ";
 | 
					
						
							|  |  |  |  |             List<SqlParameter> listStr = new List<SqlParameter>(); | 
					
						
							|  |  |  |  |             SqlParameter[] parameter = listStr.ToArray(); | 
					
						
							|  |  |  |  |             DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); | 
					
						
							|  |  |  |  |             int Count1 = 0, Count2 = 0, Count3 = 0, Count4 = 0; | 
					
						
							|  |  |  |  |             foreach (DataRow row in tb.Rows) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 Count1 += Convert.ToInt32(row["Count1"]); | 
					
						
							|  |  |  |  |                 Count2 += Convert.ToInt32(row["Count2"]); | 
					
						
							|  |  |  |  |                 Count3 += Convert.ToInt32(row["Count3"]); | 
					
						
							|  |  |  |  |                 Count4 += Convert.ToInt32(row["Count4"]); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             JObject summary = new JObject(); | 
					
						
							|  |  |  |  |             summary.Add("ProjectName", "合计:"); | 
					
						
							|  |  |  |  |             summary.Add("Count1", Count1.ToString()); | 
					
						
							|  |  |  |  |             summary.Add("Count2", Count2.ToString()); | 
					
						
							|  |  |  |  |             summary.Add("Count3", Count3.ToString()); | 
					
						
							|  |  |  |  |             summary.Add("Count4", Count4.ToString()); | 
					
						
							|  |  |  |  |             Grid1.SummaryData = summary; | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-02 16:03:32 +08:00
										 |  |  |  |         #endregion | 
					
						
							| 
									
										
										
										
											2023-03-25 14:46:00 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | } |