2022-03-15 17:36:38 +08:00
using BLL ;
2023-09-22 17:36:00 +08:00
using Microsoft.Office.Interop.Excel ;
2022-03-15 17:36:38 +08:00
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.HSSE.SitePerson
{
public partial class PersonInfo : PageBase
{
#region 加 载 页 面
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
////权限按钮方法
this . GetButtonPower ( ) ;
btnNew . OnClientClick = Window1 . GetShowReference ( "PersonInfoEdit.aspx" ) + "return false;" ;
this . btnMenuDelete . OnClientClick = Grid1 . GetNoSelectionAlertReference ( "请至少选择一项!" ) ;
this . btnMenuDelete . ConfirmText = String . Format ( "你确定要删除选中的 <b><script>{0}</script></b> 行数据吗?" , Grid1 . GetSelectedCountReference ( ) ) ;
Funs . DropDownPageSize ( this . ddlPageSize ) ;
UnitService . InitUnitDropDownList ( this . drpUnit , this . CurrUser . LoginProjectId , true ) ;
if ( ProjectUnitService . GetProjectUnitTypeByProjectIdUnitId ( this . CurrUser . LoginProjectId , this . CurrUser . UnitId ) )
{
this . drpUnit . SelectedValue = this . CurrUser . UnitId ;
this . drpUnit . Enabled = false ;
}
2023-09-22 17:36:00 +08:00
this . txtStartDate . Text = string . Format ( "{0:yyyy-MM-dd 00:00}" , DateTime . Now ) ;
this . txtEndDate . Text = string . Format ( "{0:yyyy-MM-dd 23:59}" , DateTime . Now ) ;
2022-03-15 17:36:38 +08:00
// 绑定表格
BindGrid ( ) ;
}
}
#endregion
#region 绑 定 数 据
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
2023-09-22 17:36:00 +08:00
string sql = @ "select NEWID() PersonInOutId, PersonId,UnitName,PersonName,IdentityCard,case when IsIn =1 then '进门' else '出门' end IsInName,InOutWay,case when IsIn =1 then MinTime else MaxTime end ChangeTime from (
select PersonId , UnitName , PersonName , IdentityCard , IsIn , InOutWay , MAX ( ChangeTime ) MaxTime , MIN ( ChangeTime ) MinTime from SitePerson_PersonInOut where ProjectId = ' " + this.CurrUser.LoginProjectId + " ' ";
if ( ! string . IsNullOrEmpty ( this . drpUnit . SelectedValue ) & & this . drpUnit . SelectedValue ! = Const . _Null )
{
sql + = " and UnitId ='" + this . drpUnit . SelectedValue + "' " ;
}
if ( ! string . IsNullOrEmpty ( this . txtPersonName . Text . Trim ( ) ) )
{
sql + = " and PersonName like '%" + this . txtPersonName . Text . Trim ( ) + "%' " ;
}
if ( this . rbInOutWay . SelectedValue ! = "0" )
{
sql + = " and InOutWay = '" + this . rbInOutWay . SelectedValue + "' " ;
}
if ( ! string . IsNullOrEmpty ( this . txtStartDate . Text ) )
{
sql + = " and ChangeTime >= '" + this . txtStartDate . Text + "' " ;
}
if ( ! string . IsNullOrEmpty ( this . txtEndDate . Text ) )
{
sql + = " and ChangeTime <= '" + this . txtEndDate . Text + "' " ;
}
sql + = "group by PersonId,UnitName,PersonName,IdentityCard,year(ChangeTime),month(ChangeTime),day(ChangeTime),IsIn,InOutWay ) a order by ChangeTime desc" ;
System . Data . DataTable tb = SQLHelper . GetDataTableRunText ( sql , null ) ;
Grid1 . RecordCount = tb . Rows . Count ;
tb = GetFilteredTable ( Grid1 . FilteredData , tb ) ;
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
2022-03-15 17:36:38 +08:00
}
#endregion
#region 页 索 引 改 变 事 件
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 排 序
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort ( object sender , GridSortEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 分 页 选 择 下 拉 改 变 事 件
/// <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 ( ) ;
}
#endregion
#region 关 闭 弹 出 窗 事 件
/// <summary>
/// 关闭弹出框事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close ( object sender , WindowCloseEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 编 辑
/// <summary>
/// Grid行双击事件
/// </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 PersonInOutId = Grid1 . SelectedRowID ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "PersonInfoEdit.aspx?PersonInOutId={0}&type=view" , PersonInOutId , "查看 - " ) ) ) ;
}
#endregion
#region 删 除
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click ( object sender , EventArgs e )
{
this . DeleteData ( ) ;
}
/// <summary>
/// 删除方法
/// </summary>
private void DeleteData ( )
{
if ( Grid1 . SelectedRowIndexArray . Length > 0 )
{
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
BLL . PersonInOutService . DeletePersonInOutById ( Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ) ;
BindGrid ( ) ;
}
ShowNotify ( "删除数据成功!(表格数据已重新绑定)" , MessageBoxIcon . Success ) ;
}
}
2023-09-22 17:36:00 +08:00
#endregion
#region 转 换 字 符 串
protected string ConvertInTestRecord ( object TestManId )
{
string inTestRecord = "<span style='color:red'>0</span>" ;
if ( TestManId ! = null & & ! string . IsNullOrEmpty ( TestManId . ToString ( ) ) )
{
string strSql = @ "select max(TestScores) from dbo.Training_TestRecord AS TestRecord
LEFT JOIN dbo . Training_TestPlan AS TestPlan ON TestPlan . TestPlanId = TestRecord . TestPlanId
LEFT JOIN dbo . Training_TestTraining AS Training ON Training . TrainingId = TestRecord . TestType
2023-11-20 20:24:38 +08:00
where ( TestPlan . PlanName LIKE ' % 入 场 % ' OR Training . TrainingName LIKE ' % 入 场 % ' ) and TestRecord . ProjectId = ' " + CurrUser.LoginProjectId + " ' and TestManId = ' " + TestManId + " ' ";
2022-03-15 17:36:38 +08:00
2023-09-22 17:36:00 +08:00
System . Data . DataTable tb = SQLHelper . GetDataTableRunText ( strSql , null ) ;
if ( tb ! = null & & tb . Rows . Count > 0 & & ! string . IsNullOrEmpty ( tb . Rows [ 0 ] [ 0 ] . ToString ( ) ) )
{
var sysTestRule = Funs . DB . Sys_TestRule . FirstOrDefault ( ) ;
if ( sysTestRule ! = null )
{
if ( sysTestRule . PassingScore > 0 )
{
if ( decimal . Parse ( tb . Rows [ 0 ] [ 0 ] . ToString ( ) ) < sysTestRule . PassingScore )
{
inTestRecord = "<span style='color:red'>" + tb . Rows [ 0 ] [ 0 ] . ToString ( ) + "</span>" ;
}
else
{
inTestRecord = tb . Rows [ 0 ] [ 0 ] . ToString ( ) ;
}
}
else
{
if ( decimal . Parse ( tb . Rows [ 0 ] [ 0 ] . ToString ( ) ) < 80 )
{
inTestRecord = "<span style='color:red'>" + tb . Rows [ 0 ] [ 0 ] . ToString ( ) + "</span>" ;
}
else
{
inTestRecord = tb . Rows [ 0 ] [ 0 ] . ToString ( ) ;
}
}
}
else
{
if ( decimal . Parse ( tb . Rows [ 0 ] [ 0 ] . ToString ( ) ) < 80 )
{
inTestRecord = "<span style='color:red'>" + tb . Rows [ 0 ] [ 0 ] . ToString ( ) + "</span>" ;
}
else
{
inTestRecord = tb . Rows [ 0 ] [ 0 ] . ToString ( ) ;
}
}
}
}
return inTestRecord ;
}
protected string ConvertInOutWayName ( object InOutWay )
2022-03-15 17:36:38 +08:00
{
string name = string . Empty ;
if ( InOutWay ! = null )
{
if ( InOutWay . ToString ( ) = = Const . InOutWay_1 )
{
name = "门禁" ;
}
else if ( InOutWay . ToString ( ) = = Const . InOutWay_2 )
{
name = "手动" ;
}
else if ( InOutWay . ToString ( ) = = Const . InOutWay_3 )
{
name = "移动端" ;
}
else
{
name = "其他" ;
}
}
return name ;
}
#endregion
#region 判 断 按 钮 权 限
/// <summary>
/// 判断按钮权限
/// </summary>
private void GetButtonPower ( )
{
if ( Request . Params [ "value" ] = = "0" )
{
return ;
}
var buttonList = BLL . CommonService . GetAllButtonList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . PersonInfoMenuId ) ;
if ( buttonList . Count ( ) > 0 )
{
if ( buttonList . Contains ( BLL . Const . BtnAdd ) )
{
this . btnNew . Hidden = false ;
this . btnImport . Hidden = false ;
this . btnPersonOut . Hidden = false ;
this . btnClock . 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 = this . Grid1 . RecordCount ;
BindGrid ( ) ;
Response . Write ( GetGridTableHtml1 ( Grid1 ) ) ;
Response . End ( ) ;
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml1 ( 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 ( "labNumber" ) as AspNet . Label ) . Text ;
}
if ( column . ColumnID = = "tfIdentityCard" )
{
html = ( row . FindControl ( "lblIdentityCard" ) as AspNet . Label ) . Text ;
}
if ( column . ColumnID = = "tfWorkAreaName" )
{
html = ( row . FindControl ( "lblWorkAreaName" ) as AspNet . Label ) . Text ;
}
if ( column . ColumnID = = "tfIntoOut" )
{
html = ( row . FindControl ( "lblIntoOut" ) as AspNet . Label ) . Text ;
}
if ( column . ColumnID = = "tfAddress" )
{
html = ( row . FindControl ( "lblAddress" ) as AspNet . Label ) . Text ;
}
//sb.AppendFormat("<td>{0}</td>", html);
sb . AppendFormat ( "<td style='vnd.ms-excel.numberformat:@;width:140px;'>{0}</td>" , html ) ;
}
sb . Append ( "</tr>" ) ;
}
sb . Append ( "</table>" ) ;
return sb . ToString ( ) ;
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btSearch_Click ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
/// <summary>
/// 导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "PersonInfoIn.aspx" , "导入 - " ) ) ) ;
}
protected void btnPersonOut_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "PersonUnitList.aspx" , "导出 - " ) ) ) ;
}
protected void btnClock_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "PersonInfoClock.aspx" , "一键考勤 - " ) , "一键考勤" , 700 , 450 ) ) ;
}
}
}