2025-04-07 17:43:30 +08:00
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
using System.Linq ;
using System.Text ;
using BLL ;
using AspNet = System . Web . UI . WebControls ;
namespace FineUIPro.Web.HSSE.Check
{
2025-04-09 19:14:54 +08:00
public partial class ContactList : PageBase
2025-04-07 17:43:30 +08:00
{
#region 定 义 项
/// <summary>
/// 主键
/// </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 )
{
2025-04-09 19:14:54 +08:00
Funs . DropDownPageSize ( this . ddlPageSize ) ;
2025-04-07 17:43:30 +08:00
this . ProjectId = this . CurrUser . LoginProjectId ;
if ( ! string . IsNullOrEmpty ( Request . Params [ "projectId" ] ) & & Request . Params [ "projectId" ] ! = this . CurrUser . LoginProjectId )
{
this . ProjectId = Request . Params [ "projectId" ] ;
}
2025-04-09 19:14:54 +08:00
this . InitDropDownList ( ) ;
this . ucTree . UnitId = this . CurrUser . UnitId ;
this . ucTree . ProjectId = this . ProjectId ;
if ( ! string . IsNullOrEmpty ( this . ProjectId ) )
{
this . panelLeftRegion . Hidden = true ;
////权限按钮方法
this . GetButtonPower ( ) ;
}
2025-04-07 17:43:30 +08:00
////权限按钮方法
this . GetButtonPower ( ) ;
this . btnNew . OnClientClick = Window1 . GetShowReference ( "ContactListEdit.aspx" ) + "return false;" ;
if ( this . CurrUser ! = null & & this . CurrUser . PageSize . HasValue )
{
Grid1 . PageSize = this . CurrUser . PageSize . Value ;
}
this . ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
// 绑定表格
this . BindGrid ( ) ;
}
}
2025-04-09 19:14:54 +08:00
private void InitDropDownList ( )
{
//发起单位
BLL . UnitService . InitUnitDropDownList ( this . drpSponsorUnit , this . ProjectId , true ) ;
//接收单位
BLL . UnitService . InitUnitDropDownList ( this . drpReceivingUnits , this . ProjectId , true ) ;
}
/// <summary>
/// 公司级树加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void changeTree ( object sender , EventArgs e )
{
this . ProjectId = this . ucTree . ProjectId ;
this . InitDropDownList ( ) ;
this . GetButtonPower ( ) ;
if ( string . IsNullOrEmpty ( this . CurrUser . LoginProjectId ) )
{
btnNew . Hidden = true ;
}
this . BindGrid ( ) ;
}
2025-04-07 17:43:30 +08:00
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
2025-04-09 19:14:54 +08:00
if ( string . IsNullOrEmpty ( this . ProjectId ) )
{
return ;
}
2025-04-07 17:43:30 +08:00
string strSql = @"SELECT T.ContactListId,T.ProjectId,CodeRecords.Code,T.SponsorUnitId,Unit.UnitName AS SponsorUnitName,T.ReceivingUnits,T.ReceivingUnitNames,T.CompileDate,Users.UserName AS CompileManName,T.Remark,T.AttachUrl,T.SeeFile"
+ @" FROM Check_ContactList AS T "
+ @" LEFT JOIN Sys_User AS Users ON T.CompileMan=Users.UserId"
+ @" LEFT JOIN Base_Unit AS Unit ON T.SponsorUnitId=Unit.UnitId"
+ @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON T.ContactListId = CodeRecords.DataId"
+ @" WHERE 1=1 " ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
strSql + = " AND T.ProjectId = @ProjectId" ;
listStr . Add ( new SqlParameter ( "@ProjectId" , this . ProjectId ) ) ;
2025-04-09 19:14:54 +08:00
if ( this . drpSponsorUnit . SelectedValue ! = null & & this . drpSponsorUnit . SelectedValue ! = BLL . Const . _Null )
2025-04-07 17:43:30 +08:00
{
strSql + = " AND T.SponsorUnitId = @SponsorUnitId" ;
listStr . Add ( new SqlParameter ( "@SponsorUnitId" , this . drpSponsorUnit . SelectedValue ) ) ;
}
if ( this . drpReceivingUnits . SelectedValue ! = BLL . Const . _Null )
{
strSql + = " AND T.ReceivingUnits LIKE @ReceivingUnits" ;
listStr . Add ( new SqlParameter ( "@ReceivingUnits" , "%" + this . drpReceivingUnits . SelectedValue + "%" ) ) ;
}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid1 . RecordCount = tb . Rows . Count ;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
}
#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 ddlPageSize_SelectedIndexChanged ( object sender , EventArgs e )
{
this . Grid1 . PageSize = Convert . ToInt32 ( this . ddlPageSize . SelectedValue ) ;
BindGrid ( ) ;
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort ( object sender , FineUIPro . GridSortEventArgs e )
{
this . BindGrid ( ) ;
}
#endregion
#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_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
this . EditData ( ) ;
}
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click ( object sender , EventArgs e )
{
this . EditData ( ) ;
}
/// <summary>
/// 编辑数据方法
/// </summary>
private void EditData ( )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
string id = Grid1 . SelectedRowID ;
var meeting = BLL . ContactListService . GetContactListById ( id ) ;
if ( meeting ! = null )
{
if ( this . btnMenuEdit . Hidden ) ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ContactListView.aspx?ContactListId={0}" , id , "查看 - " ) ) ) ;
}
else
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ContactListEdit.aspx?ContactListId={0}" , id , "编辑 - " ) ) ) ;
}
}
}
#endregion
#region 删 除
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length > 0 )
{
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
var newContactList = BLL . ContactListService . GetContactListById ( rowID ) ;
if ( newContactList ! = null )
{
BLL . LogService . AddSys_Log ( this . CurrUser , newContactList . Code , newContactList . ContactListId , BLL . Const . ProjectContactListMenuId , BLL . Const . BtnDelete ) ;
BLL . ContactListService . DeleteContactListById ( rowID ) ;
}
}
this . BindGrid ( ) ;
ShowNotify ( "删除数据成功!" , MessageBoxIcon . Success ) ;
}
}
#endregion
#region 获 取 按 钮 权 限
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower ( )
{
if ( Request . Params [ "value" ] = = "0" )
{
return ;
}
2025-04-09 19:14:54 +08:00
var buttonList = BLL . CommonService . GetAllButtonList ( this . ProjectId , this . CurrUser . UserId , BLL . Const . ProjectContactListMenuId ) ;
2025-04-07 17:43:30 +08:00
if ( buttonList . Count ( ) > 0 )
{
if ( buttonList . Contains ( BLL . Const . BtnAdd ) )
{
this . btnNew . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnModify ) )
{
this . btnMenuEdit . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnDelete ) )
{
this . btnMenuDelete . 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 = 5000 ;
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 style=\"vnd.ms-excel.numberformat:@\">{0}</td>" , html ) ;
}
sb . Append ( "</tr>" ) ;
}
sb . Append ( "</table>" ) ;
return sb . ToString ( ) ;
}
#endregion
}
}