2024-11-19 09:45:27 +08:00
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.Personal
{
public partial class RunLog : PageBase
{
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
Funs . DropDownPageSize ( this . ddlPageSize ) ;
if ( this . CurrUser ! = null & & this . CurrUser . PageSize . HasValue )
{
Grid1 . PageSize = this . CurrUser . PageSize . Value ;
}
ProjectService . InitAllUnEndProjectNameDropDownList ( this . drpProject , true ) ;
Funs . FineUIPleaseSelect ( this . drpUnit ) ;
this . drpRole . DataValueField = "RoleId" ;
this . drpRole . DataTextField = "RoleName" ;
this . drpRole . DataSource = from x in Funs . DB . Sys_Role
where x . IsOffice = = false | | x . IsOffice = = null
orderby x . RoleCode
select x ;
this . drpRole . DataBind ( ) ;
Funs . FineUIPleaseSelect ( this . drpRole ) ;
this . txtStartTime . Text = string . Format ( "{0:yyyy-MM-dd}" , DateTime . Now . AddMonths ( - 1 ) ) ;
this . txtEndTime . Text = string . Format ( "{0:yyyy-MM-dd}" , DateTime . Now ) ;
this . ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
this . BindGrid ( ) ;
//if (this.CurrUser.UserId != BLL.Const.sysglyId)
//{
// this.txtUser.Hidden = true;
//}
}
}
#region BindGrid
/// <summary>
/// gv 绑定数据
/// </summary>
private void BindGrid ( )
{
string strSql = @"SELECT sysLog.LogId,sysLog.UserId,sysLog.OperationTime,sysLog.Ip,sysLog.HostName,sysLog.OperationLog,users.UserName,units.UnitName,Project.ProjectId,Project.ProjectName,RoleName= STUFF(( SELECT ',' + RoleName FROM dbo.Sys_Role where PATINDEX('%,' + RTRIM(RoleId) + ',%',',' +ProjectUser.RoleId + ',')>0 FOR XML PATH('')), 1, 1,'')"
+ @" FROM dbo.Sys_Log as sysLog"
+ @" LEFT JOIN Sys_User as users ON users.UserId=sysLog.UserId "
+ @" LEFT JOIN Base_Unit as units on users.UnitId=units.UnitId"
+ @" LEFT JOIN Project_ProjectUser as ProjectUser on ProjectUser.UserId=sysLog.UserId and ProjectUser.ProjectId=sysLog.ProjectId"
+ @" LEFT JOIN Base_Project as Project on sysLog.ProjectId=Project.ProjectId"
2026-06-15 19:05:39 +08:00
+ @" WHERE sysLog.UserId != '" + Const . hfnbdId + "'" ;
2024-11-19 09:45:27 +08:00
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
//if (this.CurrUser.UserId != BLL.Const.sysglyId)
//{
// strSql += " AND sysLog.UserId = @UserId";
// listStr.Add(new SqlParameter("@UserId", this.CurrUser.UserId));
//}
if ( this . drpProject . SelectedValue ! = BLL . Const . _Null )
{
strSql + = " AND sysLog.ProjectId = @ProjectId" ;
listStr . Add ( new SqlParameter ( "@ProjectId" , this . drpProject . SelectedValue ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtUser . Text . Trim ( ) ) )
{
strSql + = " AND users.UserName LIKE @UserName" ;
listStr . Add ( new SqlParameter ( "@UserName" , "%" + this . txtUser . Text . Trim ( ) + "%" ) ) ;
}
if ( this . drpUnit . SelectedValue ! = BLL . Const . _Null )
{
strSql + = " AND users.UnitId = @UnitId" ;
listStr . Add ( new SqlParameter ( "@UnitId" , this . drpUnit . SelectedValue ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtStartTime . Text . Trim ( ) ) )
{
strSql + = " AND sysLog.OperationTime >= @StartTime" ;
listStr . Add ( new SqlParameter ( "@StartTime" , this . txtStartTime . Text . Trim ( ) ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtEndTime . Text . Trim ( ) ) )
{
strSql + = " AND sysLog.OperationTime <= @EndTime" ;
listStr . Add ( new SqlParameter ( "@EndTime" , this . txtEndTime . Text . Trim ( ) ) ) ;
}
if ( this . drpRole . SelectedValue ! = BLL . Const . _Null )
{
strSql + = " AND (select count(*) from Project_ProjectUser pu where pu.UserId=sysLog.UserId and pu.ProjectId=sysLog.ProjectId and pu.RoleId like @RoleId)>0" ;
listStr . Add ( new SqlParameter ( "@RoleId" , "%" + this . drpRole . SelectedValue + "%" ) ) ;
}
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 ddlPageSize_SelectedIndexChanged ( object sender , EventArgs e )
{
this . Grid1 . PageSize = Funs . GetNewIntOrZero ( this . ddlPageSize . SelectedValue ) ;
this . BindGrid ( ) ;
}
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
BindGrid ( ) ;
}
protected void Grid1_Sort ( object sender , FineUIPro . GridSortEventArgs e )
{
BindGrid ( ) ;
}
#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 )
{
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 = = "tfPageIndex" )
{
html = ( row . FindControl ( "lblPageIndex" ) as AspNet . Label ) . Text ;
}
sb . AppendFormat ( "<td>{0}</td>" , html ) ;
}
sb . Append ( "</tr>" ) ;
}
sb . Append ( "</table>" ) ;
return sb . ToString ( ) ;
}
#endregion
protected void drpProject_SelectedIndexChanged ( object sender , EventArgs e )
{
BindGrid ( ) ;
BLL . UnitService . InitUnitDropDownList ( this . drpUnit , this . drpProject . SelectedValue , true ) ;
this . drpUnit . SelectedValue = BLL . Const . _Null ;
}
}
}