2025-02-12 09:27:47 +08:00
using BLL ;
using System ;
using System.Collections.Generic ;
2025-04-06 23:26:22 +08:00
using System.Configuration ;
2025-02-12 09:27:47 +08:00
using System.Data ;
using System.Data.SqlClient ;
using System.Linq ;
using System.Text ;
using AspNet = System . Web . UI . WebControls ;
namespace FineUIPro.Web.HSSE.Check
{
public partial class CheckSpecialRecord : PageBase
{
#region 定 义 项
/// <summary>
/// GV被选择项列表
/// </summary>
public List < string > ItemSelectedList
{
get
{
return ( List < string > ) ViewState [ "ItemSelectedList" ] ;
}
set
{
ViewState [ "ItemSelectedList" ] = 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 ) ;
GetButtonPower ( ) ;
this . ItemSelectedList = new List < string > ( ) ;
ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
2025-04-06 23:26:22 +08:00
SetProblemTypes ( ) ;
SetUnitProject ( ) ;
SetResponsibleUnit ( ) ;
this . txtStartTime . Text = DateTime . Today . ToString ( "yyyy-MM-dd" ) ;
this . txtEndTime . Text = DateTime . Today . ToString ( "yyyy-MM-dd" ) ;
2025-02-12 09:27:47 +08:00
// 绑定表格
BindGrid ( ) ;
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
2025-04-06 23:26:22 +08:00
string strSql = "SELECT a.InspectionId,a.InspectionCode,a.ProjectId,(SELECT ProjectName FROM Base_Project as p WHERE p.ProjectId = a.ProjectId) as ProjectName, a.PersonResponsible,(SELECT UserName FROM Sys_User as u WHERE u.UserID = a.PersonResponsible) as PersonResponsibleName, (CASE WHEN a.States = '1' THEN '待检查' WHEN a.States = '2' THEN '待审核/整改' WHEN a.States = '3' THEN '已闭环' END ) as Status, a.CheckMan, a.CreateTime, a.ProblemTypeName,b.CompileTime as CheckTime, " +
"b.InspectionItemId,b.BeforelUrl,b.AfterUrl, (CASE WHEN b.States = '1'and a.States = '1' THEN '待提交' WHEN a.States = '2' and b.States = '1' THEN '待审核' WHEN a.States = '2' and b.States = '2' THEN '待整改' WHEN a.States = '2' and b.States = '3' THEN '已闭环' WHEN a.States = '3' THEN '已闭环' END) as itemStates," +
"a.Place FROM Inspect_InspectionItem as b LEFT JOIN Inspect_Inspection as a on b.InspectionId = a.InspectionId WHERE a.InspectType = '1'" ;
2025-02-12 09:27:47 +08:00
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
if ( ! string . IsNullOrEmpty ( this . CurrUser . LoginProjectId ) )
{
2025-04-06 23:26:22 +08:00
strSql + = "and a.ProjectId = @ProjectId" ;
2025-02-12 09:27:47 +08:00
listStr . Add ( new SqlParameter ( "@ProjectId" , this . CurrUser . LoginProjectId ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtCheckMan . Text . Trim ( ) ) )
{
2025-04-06 23:26:22 +08:00
strSql + = " AND a.CheckMan LIKE @CheckMan" ;
2025-02-12 09:27:47 +08:00
listStr . Add ( new SqlParameter ( "@CheckMan" , "%" + this . txtCheckMan . Text . Trim ( ) + "%" ) ) ;
}
2025-04-06 23:26:22 +08:00
if ( this . txtType . SelectedText . Trim ( ) ! = "请选择" & & ! string . IsNullOrEmpty ( this . txtType . SelectedText . Trim ( ) ) )
2025-02-12 09:27:47 +08:00
{
2025-04-06 23:26:22 +08:00
strSql + = " AND a.ProblemTypeName = @Type" ;
listStr . Add ( new SqlParameter ( "@Type" , this . txtType . SelectedText . Trim ( ) ) ) ;
2025-02-12 09:27:47 +08:00
}
2025-04-06 23:26:22 +08:00
if ( ! string . IsNullOrEmpty ( this . txtWorkAreaName . SelectedText ) & & this . txtWorkAreaName . SelectedText . Trim ( ) ! = "请选择" )
2025-02-12 09:27:47 +08:00
{
2025-04-06 23:26:22 +08:00
strSql + = " AND a.Place = @Place" ;
listStr . Add ( new SqlParameter ( "@Place" , this . txtWorkAreaName . SelectedText . Trim ( ) ) ) ;
2025-02-12 09:27:47 +08:00
}
2025-04-06 23:26:22 +08:00
if ( ! string . IsNullOrEmpty ( this . txtWorkAreaName . Text . Trim ( ) ) )
2025-02-12 09:27:47 +08:00
{
2025-04-06 23:26:22 +08:00
strSql + = " AND a.Place LIKE @Place" ;
listStr . Add ( new SqlParameter ( "@Place" , "%" + this . txtWorkAreaName . Text . Trim ( ) + "%" ) ) ;
2025-02-12 09:27:47 +08:00
}
if ( ! string . IsNullOrEmpty ( txtStartTime . Text . Trim ( ) ) )
{
2025-04-06 23:26:22 +08:00
strSql + = " AND b.CompileTime >= @StartTime" ;
listStr . Add ( new SqlParameter ( "@StartTime" , string . Format ( "{0} {1}" , this . txtStartTime . Text . Trim ( ) , "00:00:00" ) ) ) ;
2025-02-12 09:27:47 +08:00
}
if ( ! string . IsNullOrEmpty ( this . txtEndTime . Text . Trim ( ) ) )
{
2025-04-06 23:26:22 +08:00
strSql + = " AND b.CompileTime <= @EndTime" ;
listStr . Add ( new SqlParameter ( "@EndTime" , string . Format ( "{0} {1}" , this . txtEndTime . Text . Trim ( ) , "23:59:59" ) ) ) ;
2025-02-12 09:27:47 +08:00
}
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
2025-04-06 23:26:22 +08:00
#region 问 题 类 型 下 拉 框 赋 值
public void SetProblemTypes ( )
{
txtType . DataValueField = "RectifyId" ;
txtType . DataTextField = "RectifyName" ;
List < Model . Technique_Rectify > list = ( from x in Funs . DB . Technique_Rectify select x ) . ToList ( ) ;
list . Insert ( 0 , new Model . Technique_Rectify ( )
{
RectifyId = "-1" ,
RectifyName = "请选择"
} ) ;
txtType . DataSource = list ;
txtType . DataBind ( ) ;
}
#endregion
#region 单 位 工 程 下 拉 框 赋 值
public void SetUnitProject ( )
{
List < Model . WBS_UnitWork > list = new List < Model . WBS_UnitWork > ( ) {
new Model . WBS_UnitWork ( )
{
UnitWorkId = "-1" ,
UnitWorkName = "请选择"
}
} ;
if ( ! string . IsNullOrEmpty ( this . CurrUser . LoginProjectId ) )
{
list . AddRange ( ( from x in Funs . DB . WBS_UnitWork where x . ProjectId = = this . CurrUser . LoginProjectId select x ) . ToList ( ) ) ;
}
txtWorkAreaName . DataValueField = "UnitWorkId" ;
txtWorkAreaName . DataTextField = "UnitWorkName" ;
txtWorkAreaName . DataSource = list ;
txtWorkAreaName . DataBind ( ) ;
}
#endregion
#region 责 任 单 位 下 拉 框 赋 值
public void SetResponsibleUnit ( )
{
List < Model . UnitItem > list = new List < Model . UnitItem > ( ) {
new Model . UnitItem ( )
{
UnitId = "-1" ,
UnitName = "请选择"
}
} ;
if ( ! string . IsNullOrEmpty ( this . CurrUser . LoginProjectId ) )
{
list . AddRange ( ( from x in Funs . DB . Project_ProjectUnit
join y in Funs . DB . Base_Unit on x . UnitId equals y . UnitId
where x . ProjectId = = this . CurrUser . LoginProjectId
select new Model . UnitItem ( )
{
UnitId = y . UnitId ,
UnitName = y . UnitName
} ) . ToList ( ) ) ;
}
txtResponsibilityUnitName . DataValueField = "UnitId" ;
txtResponsibilityUnitName . DataTextField = "UnitName" ;
txtResponsibilityUnitName . DataSource = list ;
txtResponsibilityUnitName . DataBind ( ) ;
}
#endregion
2025-02-12 09:27:47 +08:00
#region 表 排 序 、 分 页 、 关 闭 窗 口
/// <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 )
{
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 )
{
btnMenuSee_Click ( null , null ) ;
}
#endregion
#region 查 看
/// <summary>
/// 查看按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuSee_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
string RegistrationId = Grid1 . SelectedRowID ;
2025-04-06 23:26:22 +08:00
if ( RegistrationId ! = null )
2025-02-12 09:27:47 +08:00
{
2025-04-06 23:26:22 +08:00
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "CheckSpecialView.aspx?InspectionItemId={0}" , RegistrationId , "查看 - " ) ) ) ;
2025-02-12 09:27:47 +08:00
}
}
#endregion
2025-04-15 20:48:53 +08:00
#region 删 除
protected void btnMenuDel_Click ( object sender , EventArgs e )
2025-02-12 09:27:47 +08:00
{
2025-04-15 20:48:53 +08:00
if ( Grid1 . SelectedRowIndexArray . Length > 0 )
2025-02-12 09:27:47 +08:00
{
2025-04-15 20:48:53 +08:00
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
2025-02-12 09:27:47 +08:00
{
2025-04-15 20:48:53 +08:00
Model . SGGLDB db = Funs . DB ;
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
Model . Inspect_InspectionItem item = db . Inspect_InspectionItem . FirstOrDefault ( x = > x . InspectionItemId = = rowID ) ;
if ( item ! = null )
2025-02-12 09:27:47 +08:00
{
2025-04-15 20:48:53 +08:00
db . Inspect_InspectionItem . DeleteOnSubmit ( item ) ;
db . SubmitChanges ( ) ;
int count = db . Inspect_Inspection . Count ( x = > x . InspectionId = = item . InspectionId ) ;
if ( count = = 0 )
{
db . Inspect_Inspection . DeleteOnSubmit ( db . Inspect_Inspection . FirstOrDefault ( x = > x . InspectionId = = item . InspectionId ) ) ;
db . SubmitChanges ( ) ;
}
2025-02-12 09:27:47 +08:00
}
}
2025-04-15 20:48:53 +08:00
BindGrid ( ) ;
ShowNotify ( "删除数据成功!" ) ;
2025-02-12 09:27:47 +08:00
}
}
#endregion
#region Grid行点击事件
/// <summary>
/// Grid行点击事件
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowCommand ( object sender , GridCommandEventArgs e )
{
string RegistrationId = Grid1 . DataKeys [ e . RowIndex ] [ 0 ] . ToString ( ) ;
Model . HSSE_Hazard_HazardRegister hazardRegister = BLL . HSSE_Hazard_HazardRegisterService . GetHazardRegisterByCheckItemDetailId ( RegistrationId ) ;
if ( e . CommandName = = "IsSelected" )
{
CheckBoxField checkField = ( CheckBoxField ) Grid1 . FindColumn ( "ckbIsSelected" ) ;
if ( checkField . GetCheckedState ( e . RowIndex ) )
{
if ( ! ItemSelectedList . Contains ( RegistrationId ) )
{
ItemSelectedList . Add ( RegistrationId ) ;
}
}
else
{
if ( ItemSelectedList . Contains ( RegistrationId ) )
{
ItemSelectedList . Remove ( RegistrationId ) ;
}
}
}
2025-04-06 23:26:22 +08:00
2025-02-12 09:27:47 +08:00
if ( e . CommandName = = "del" )
{
if ( BLL . CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . HSSE_HiddenRectificationListMenuId , BLL . Const . BtnDelete ) )
{
if ( hazardRegister . States ! = Const . State_3 | | this . CurrUser . UserId = = BLL . Const . hfnbdId ) //待整改
{
var getD = BLL . HSSE_Hazard_HazardRegisterService . GetHazardRegisterByHazardRegisterId ( RegistrationId ) ;
if ( getD ! = null )
{
BLL . LogService . AddSys_Log ( this . CurrUser , getD . HazardCode , getD . HazardRegisterId , BLL . Const . HSSE_HiddenRectificationListMenuId , BLL . Const . BtnDelete ) ;
BLL . HSSE_Hazard_HazardRegisterService . DeleteHazardRegisterByHazardRegisterId ( RegistrationId ) ;
BindGrid ( ) ;
ShowNotify ( "删除成功!" , MessageBoxIcon . Success ) ;
}
}
else
{
Alert . ShowInTop ( "已闭环,无法删除!" , MessageBoxIcon . Warning ) ;
return ;
}
}
else
{
Alert . ShowInTop ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
return ;
}
}
}
#endregion
2025-04-06 23:26:22 +08:00
2025-02-12 09:27:47 +08:00
2025-04-06 23:26:22 +08:00
#region 整 改 后 图 片
2025-02-12 09:27:47 +08:00
protected string ConvertImgUrl ( object registrationId )
{
string url = string . Empty ;
if ( registrationId ! = null )
{
2025-04-06 23:26:22 +08:00
var imgUrl = Funs . DB . Inspect_InspectionItem . FirstOrDefault ( x = > x . InspectionItemId = = registrationId . ToString ( ) ) . AfterUrl ;
if ( imgUrl ! = null )
2025-02-12 09:27:47 +08:00
{
2025-04-06 23:26:22 +08:00
url = BLL . UploadAttachmentService . ShowImage ( ConfigurationManager . AppSettings [ "CEMS_IMG_URL" ] , imgUrl ) ;
2025-02-12 09:27:47 +08:00
}
}
return url ;
}
2025-04-06 23:26:22 +08:00
#endregion
2025-02-12 09:27:47 +08:00
2025-04-06 23:26:22 +08:00
#region 整 改 前 图 片
2025-02-12 09:27:47 +08:00
protected string ConvertImgUrlByImage ( object registrationId )
{
string url = string . Empty ;
if ( registrationId ! = null )
{
2025-04-06 23:26:22 +08:00
var imgUrl = Funs . DB . Inspect_InspectionItem . FirstOrDefault ( x = > x . InspectionItemId = = registrationId . ToString ( ) ) . BeforelUrl ;
if ( imgUrl ! = null )
2025-02-12 09:27:47 +08:00
{
2025-04-06 23:26:22 +08:00
url = BLL . UploadAttachmentService . ShowImage ( ConfigurationManager . AppSettings [ "CEMS_IMG_URL" ] , imgUrl ) ;
2025-02-12 09:27:47 +08:00
}
}
return url ;
}
#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 = 100000 ;
this . BindGrid ( ) ;
Response . Write ( GetGridTableHtml ( Grid1 ) ) ;
Response . End ( ) ;
}
#pragma warning disable CS0108 // “HiddenRectificationList.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml ( Grid grid )
#pragma warning restore CS0108 // “HiddenRectificationList.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 )
{
if ( column . ColumnID ! = "ckbIsSelected" & & column . ColumnID ! = "tfImageUrl1" & & column . ColumnID ! = "tfImageUrl2" & & column . ColumnID ! = "Punish" & & column . ColumnID ! = "Del" )
{
sb . AppendFormat ( "<td style=\"vnd.ms-excel.numberformat:@\" >{0}</td>" , column . HeaderText ) ;
}
}
sb . Append ( "</tr>" ) ;
foreach ( GridRow row in grid . Rows )
{
sb . Append ( "<tr>" ) ;
foreach ( GridColumn column in grid . Columns )
{
if ( column . ColumnID ! = "ckbIsSelected" & & column . ColumnID ! = "tfImageUrl1" & & column . ColumnID ! = "tfImageUrl2" & & column . ColumnID ! = "Punish" & & column . ColumnID ! = "Del" )
{
string html = row . Values [ column . ColumnIndex ] . ToString ( ) ;
if ( column . ColumnID = = "tfPageIndex" )
{
html = ( row . FindControl ( "lblPageIndex" ) as AspNet . Label ) . Text ;
}
if ( column . ColumnID = = "tfImageUrl" )
{
html = ( row . FindControl ( "lbtnImageUrl" ) as AspNet . LinkButton ) . Text ;
}
if ( column . ColumnID = = "tfRectificationImageUrl" )
{
html = ( row . FindControl ( "lbtnRectificationImageUrl" ) as AspNet . LinkButton ) . Text ;
}
//if (column.ColumnID == "tfCutPayment")
//{
// html = (row.FindControl("lbtnCutPayment") as AspNet.LinkButton).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 TextBox_TextChanged ( object sender , EventArgs e )
{
this . BindGrid ( ) ;
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window3_Close ( object sender , WindowCloseEventArgs e )
{
//if (!string.IsNullOrEmpty(this.hdRemark.Text))
//{
string hazardRegisterIds = string . Empty ;
foreach ( var item in ItemSelectedList )
{
hazardRegisterIds + = item + "," ;
}
if ( ! string . IsNullOrEmpty ( hazardRegisterIds ) )
{
hazardRegisterIds = hazardRegisterIds . Substring ( 0 , hazardRegisterIds . LastIndexOf ( "," ) ) ;
}
}
#region 获 取 按 钮 权 限
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower ( )
{
if ( Request . Params [ "value" ] = = "0" )
{
return ;
}
2025-04-15 20:48:53 +08:00
var buttonList = CommonService . GetAllButtonList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , "C7481FEE-EA92-44B8-99F6-C5CA6BBDCFF5" ) ;
if ( buttonList . Count ( ) > 0 )
{
if ( buttonList . Contains ( BLL . Const . BtnSee ) )
{
this . btnMenuSee . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnDelete ) )
{
this . btnMenuDel . Hidden = false ;
}
}
2025-02-12 09:27:47 +08:00
}
#endregion
protected string ConvertState ( object state )
{
if ( state ! = null )
{
var registration = BLL . HSSE_Hazard_HazardRegisterService . GetHazardRegisterByCheckItemDetailId ( state . ToString ( ) ) ;
if ( registration ! = null )
{
if ( registration . States = = "1" ) //待整改
{
return "待整改" ;
}
else if ( registration . States = = "2" ) //待整改
{
return "已整改-待复查验收" ;
}
else if ( registration . States = = "3" ) //待整改
{
return "已闭环" ;
}
{
return "编制" ;
}
}
}
return "" ;
}
}
}