2024-05-16 09:15:08 +08:00
using BLL ;
using Model ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Web ;
using System.Web.UI ;
using System.Web.UI.WebControls ;
using System.Data ;
using System.Data.SqlClient ;
using System.Linq ;
namespace FineUIPro.Web.HSSE.Hazard
{
public partial class ConstructionRisk : PageBase
{
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
GetButtonPower ( ) ; //权限设置
this . InitTreeMenu ( ) ; //加载树
}
}
#region 加 载 树 施 工 单 位
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu ( )
{
this . tvControlItem . Nodes . Clear ( ) ;
List < Base_Unit > units = null ;
var user = Person_PersonsService . GetPerson_PersonsById ( this . CurrUser . PersonId ) ;
if ( ! string . IsNullOrEmpty ( user . UnitId ) )
{
var projectUnit = BLL . ProjectUnitService . GetProjectUnitByUnitIdProjectId ( this . CurrUser . LoginProjectId , user . UnitId ) ;
if ( projectUnit ! = null )
{
if ( projectUnit . UnitType = = BLL . Const . ProjectUnitType_1 | | projectUnit . UnitType = = BLL . Const . ProjectUnitType_3 | | projectUnit . UnitType = = BLL . Const . ProjectUnitType_4 )
{
var ids = Funs . DB . HSSE_ConstructionRisk . Select ( x = > x . UnitId ) . Distinct ( ) . ToList ( ) ;
units = ( from x in Funs . DB . Base_Unit
where ids . Contains ( x . UnitId )
select x ) . OrderBy ( x = > x . UnitCode ) . ToList ( ) ;
}
else
{
units = ( from x in Funs . DB . Base_Unit
where x . UnitId = = this . CurrUser . UnitId select x ) . ToList ( ) ;
}
}
}
else if ( user . UnitId = = Const . UnitId_SEDIN | | user . PersonId = = Const . hfnbdId )
{
var ids = Funs . DB . HSSE_ConstructionRisk . Select ( x = > x . UnitId ) . Distinct ( ) . ToList ( ) ;
units = ( from x in Funs . DB . Base_Unit
where ids . Contains ( x . UnitId )
select x ) . OrderBy ( x = > x . UnitCode ) . ToList ( ) ;
}
if ( units ! = null & & units . Count > 0 )
{
foreach ( var unit in units )
{
TreeNode rootNode = new TreeNode ( ) ;
rootNode . Text = unit . UnitName ;
rootNode . NodeID = unit . UnitId ;
rootNode . ToolTip = "单位" ;
rootNode . Expanded = false ;
this . tvControlItem . Nodes . Add ( rootNode ) ;
this . BindNodes ( rootNode ) ;
}
}
}
#endregion
#region 关 闭 弹 出 窗 口 及 刷 新 页 面
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close ( object sender , WindowCloseEventArgs e )
{
this . InitTreeMenu ( ) ;
this . BindGrid ( ) ;
}
protected void Window2_Close ( object sender , WindowCloseEventArgs e )
{
if ( hdState . Text = = "A" )
{
var ids = Grid1 . SelectedRowID . Split ( '|' ) ;
if ( ids . Length > 1 )
{
hdState . Text = "" ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "../Check/RectifyNoticesAdd.aspx?ControlId={0}" , ids [ 1 ] , "编辑 - " ) ) ) ;
}
}
else if ( hdState . Text = = "B" )
{
var ids = Grid1 . SelectedRowID . Split ( '|' ) ;
if ( ids . Length > 1 )
{
hdState . Text = "" ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "../HiddenInspection/HiddenRectificationAdd.aspx?ControlId={0}" , ids [ 1 ] , "编辑 - " ) ) ) ;
}
}
this . InitTreeMenu ( ) ;
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>
/// <summary>
/// 右键删除明细
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
var ids = rowID . Split ( '|' ) ;
if ( ids . Length > = 1 )
{
var list = Funs . DB . HSSE_ConstructionRiskControl . Where ( x = > x . ConstructionRiskId = = ids [ 0 ] ) . ToList ( ) ;
Funs . DB . HSSE_ConstructionRiskControl . DeleteAllOnSubmit ( list ) ;
var constructionRisk = Funs . DB . HSSE_ConstructionRisk . Where ( x = > x . ConstructionRiskId = = ids [ 0 ] ) . FirstOrDefault ( ) ;
Funs . DB . HSSE_ConstructionRisk . DeleteOnSubmit ( constructionRisk ) ;
Funs . DB . SubmitChanges ( ) ;
}
}
ShowNotify ( "删除成功!" , MessageBoxIcon . Success ) ;
this . InitTreeMenu ( ) ;
this . BindGrid ( ) ;
}
#endregion
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid ( )
{
if ( this . tvControlItem . SelectedNode ! = null & & this . tvControlItem . SelectedNode . NodeID . Contains ( "|" ) )
{
2024-05-27 16:34:45 +08:00
var ids = this . tvControlItem . SelectedNode . NodeID . Split ( '|' ) ;
2024-05-16 09:15:08 +08:00
string strSql = @"select c.UnitWorkName, '' Id,*
2024-05-27 16:34:45 +08:00
,b.CheckResult,(CASE WHEN a.States = " + BLL . Const . State_3 + " THEN '审核/审批完成' when a.States = " + BLL . Const . State_0 + " OR a.States IS NULL THEN '待提交' WHEN a.States = " + BLL . Const . State_2 + " THEN '待总包安全经理审核' ELSE '待['+OperateUser.PersonName+']办理' END) AS FlowOperateName"
2024-05-16 09:15:08 +08:00
+ @" from [dbo].[HSSE_ConstructionRisk] a left join [dbo].[HSSE_ConstructionRiskControl] b
on a.ConstructionRiskId =b.ConstructionRiskId left join WBS_UnitWork c on a.WorkAreaId = c.UnitWorkId
LEFT JOIN Sys_FlowOperate AS FlowOperate ON a.ConstructionRiskId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1
LEFT JOIN Person_Persons AS OperateUser ON FlowOperate.OperaterId=OperateUser.PersonId
where a.UnitId=@UnitId and a.DateWeek=@DateWeek order by a.[ConstructionContent],b.[ShowIndex]" ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@UnitId" , ids [ 0 ] ) ) ;
2024-05-27 16:34:45 +08:00
listStr . Add ( new SqlParameter ( "@DateWeek" , ids [ 1 ] ) ) ;
2024-05-16 09:15:08 +08:00
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
2024-05-27 16:34:45 +08:00
foreach ( DataRow row in tb . Rows )
2024-05-16 09:15:08 +08:00
{
2024-05-27 16:34:45 +08:00
row [ "Id" ] = row [ "ConstructionRiskId" ] + "|" + row [ "ControlId" ] ;
2024-05-16 09:15:08 +08:00
}
2024-05-27 16:34:45 +08:00
2024-05-16 09:15:08 +08:00
Grid1 . DataSource = tb ;
Grid1 . DataBind ( ) ;
}
2024-05-27 16:34:45 +08:00
else
{
Grid1 . DataSource = null ;
Grid1 . DataBind ( ) ;
}
2024-05-16 09:15:08 +08:00
}
#region 绑 定 树 节 点
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes ( TreeNode node )
{
var DateWeek = ( from x in Funs . DB . HSSE_ConstructionRisk
where x . ProjectId = = this . CurrUser . LoginProjectId
& & x . UnitId = = node . NodeID
select x . DateWeek ) . OrderByDescending ( x = > x ) . ToList ( ) ;
foreach ( var d in DateWeek )
{
TreeNode newNode = new TreeNode ( ) ;
newNode . Text = d ; //string.Format("{0:yyyy-MM-dd}", d.AssessmentDate);
newNode . NodeID = node . NodeID + "|" + d ;
newNode . EnableClickEvent = true ;
newNode . ToolTip = "标签" ;
node . Nodes . Add ( newNode ) ;
}
}
#endregion
#region 获 取 按 钮 权 限
private void GetButtonPower ( )
{
if ( Request . Params [ "value" ] = = "0" )
{
return ;
}
var buttonList = BLL . CommonService . GetAllButtonList ( this . CurrUser . LoginProjectId , this . CurrUser . PersonId , BLL . Const . ConstructionRiskMenuId ) ;
if ( buttonList . Count ( ) > 0 )
{
if ( buttonList . Contains ( BLL . Const . BtnIn ) )
{
this . btnImport . Hidden = false ;
this . btnNew . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnDelete ) )
{
this . btnMenuDelete . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnAuditing ) )
{
this . btnMenuDelete . Hidden = false ;
}
}
}
#endregion
#region 导 入
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ConstructionRiskDataIn.aspx" , "导入 - " ) ) ) ;
}
#endregion
#region 导 入
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ConstructionRiskEdit.aspx" , "添加 - " ) ) ) ;
}
#endregion
protected void btnAudit_Click ( object sender , EventArgs e )
{
2024-05-27 16:34:45 +08:00
//if (Grid1.SelectedRowIndexArray.Length == 0)
//{
// Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
// return;
//}
//foreach (int rowIndex in Grid1.SelectedRowIndexArray)
//{
// string rowID = Grid1.DataKeys[rowIndex][0].ToString();
// var ids = rowID.Split('|');
// if (ids.Length >= 1)
// {
// var r = Funs.DB.HSSE_ConstructionRisk.FirstOrDefault(x => x.ConstructionRiskId == ids[0]);
// if (r != null && r.States == "2")
// {
// r.States = "3";
// }
// }
//}
var r = Funs . DB . HSSE_ConstructionRisk . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = "2" ) ;
foreach ( var item in r )
2024-05-16 09:15:08 +08:00
{
2024-05-27 16:34:45 +08:00
item . States = "3" ;
2024-05-16 09:15:08 +08:00
}
Funs . DB . SubmitChanges ( ) ;
2024-05-27 16:34:45 +08:00
BindGrid ( ) ;
2024-05-16 09:15:08 +08:00
}
#region 点 击 TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand111 ( object sender , TreeCommandEventArgs e )
{
BindGrid ( ) ;
}
#endregion
protected void btnMenuCheck_Click ( object sender , EventArgs e )
{
var ids = Grid1 . SelectedRowID . Split ( '|' ) ;
if ( ids . Length > 1 )
{
hdState . Text = "" ;
PageContext . RegisterStartupScript ( Window2 . GetSaveStateReference ( hdState . ClientID )
+ Window2 . GetShowReference ( String . Format ( "ConstructionRiskControlCheck.aspx?ControlId={0}" , ids [ 1 ] , "编辑 - " ) ) ) ;
}
}
protected void Grid1_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
var ids = Grid1 . SelectedRowID . Split ( '|' ) ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ConstructionRiskEdit.aspx?ConstructionRiskId={0}" , ids [ 0 ] , "编辑 - " ) ) ) ;
}
}
}