2024-11-19 09:45:27 +08:00
using BLL ;
using Newtonsoft.Json.Linq ;
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.EduTrain
{
public partial class TrainRecord : PageBase
{
2025-02-25 16:41:06 +08:00
private static string trainType ;
2024-11-19 09:45:27 +08:00
#region 定 义 项
/// <summary>
/// 培训记录主键
/// </summary>
public string TrainingId
{
get
{
return ( string ) ViewState [ "TrainingId" ] ;
}
set
{
ViewState [ "TrainingId" ] = value ;
}
}
2025-02-25 16:41:06 +08:00
public string ProjectId
{
get
{
return ( string ) ViewState [ "ProjectId" ] ;
}
set
{
ViewState [ "ProjectId" ] = value ;
}
}
public string UnitId
{
get
{
return ( string ) ViewState [ "UnitId" ] ;
}
set
{
ViewState [ "UnitId" ] = value ;
}
}
2024-11-19 09:45:27 +08:00
#endregion
#region 加 载 页 面
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
2025-02-25 16:41:06 +08:00
Funs . DropDownPageSize ( this . ddlPageSize ) ;
this . ProjectId = this . CurrUser . LoginProjectId ;
if ( ! string . IsNullOrEmpty ( Request . Params [ "projectId" ] ) & & Request . Params [ "projectId" ] ! = this . CurrUser . LoginProjectId )
{
this . ProjectId = Request . Params [ "projectId" ] ;
}
this . ucTree . UnitId = this . CurrUser . UnitId ;
this . ucTree . ProjectId = this . ProjectId ;
2024-11-19 09:45:27 +08:00
Funs . DropDownPageSize ( this . ddlPageSize ) ;
////权限按钮方法
this . GetButtonPower ( ) ;
this . btnMenuDelete . OnClientClick = Grid1 . GetNoSelectionAlertReference ( "请至少选择一项!" ) ;
this . btnMenuDelete . ConfirmText = String . Format ( "你确定要删除选中的 <b><script>{0}</script></b> 行数据吗?" , Grid1 . GetSelectedCountReference ( ) ) ;
//单位
BLL . UnitService . InitUnitDropDownList ( this . drpUnitId , this . CurrUser . LoginProjectId , true ) ;
//培训类型
BLL . TrainTypeService . InitTrainTypeDropDownList ( this . drpTrainType , true ) ;
2025-02-25 16:41:06 +08:00
trainType = Request . Params [ "trainType" ] ;
if ( ! string . IsNullOrEmpty ( trainType ) )
{
this . drpTrainType . Items . FindByText ( trainType ) . Selected = true ;
}
2024-11-19 09:45:27 +08:00
//培训级别;
BLL . TrainLevelService . InitTrainLevelDropDownList ( this . drpTrainLevel , true ) ;
ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
// 绑定表格
BindGrid ( ) ;
if ( this . CurrUser . UserId = = Const . hfnbdId | | this . CurrUser . UserId = = Const . sysglyId )
{
this . btnRefresh . Hidden = false ;
}
2025-02-25 16:41:06 +08:00
if ( ! string . IsNullOrEmpty ( this . CurrUser . LoginProjectId ) )
{
this . panelLeftRegion . Hidden = true ;
// this.Grid1.Columns[0].Hidden = true;
////权限按钮方法
this . GetButtonPower ( ) ;
}
}
}
protected void changeTree ( object sender , EventArgs e )
{
this . ProjectId = this . ucTree . ProjectId ;
//新增UnitId
this . UnitId = this . ucTree . UnitId ;
//判断 当有projectId的时候单位id为空
if ( ! string . IsNullOrEmpty ( this . ProjectId ) )
{
this . UnitId = "" ;
}
this . BindGrid ( ) ;
this . GetButtonPower ( ) ;
if ( string . IsNullOrEmpty ( this . CurrUser . LoginProjectId ) )
{
btnNew . Hidden = true ;
2024-11-19 09:45:27 +08:00
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
2025-02-25 16:41:06 +08:00
if ( string . IsNullOrEmpty ( this . ProjectId ) )
2024-11-19 09:45:27 +08:00
{
2025-02-25 16:41:06 +08:00
return ;
2024-11-19 09:45:27 +08:00
}
2025-02-25 16:41:06 +08:00
if ( ! string . IsNullOrEmpty ( this . ProjectId ) | | ! string . IsNullOrEmpty ( this . UnitId ) ) //项目数据
2024-11-19 09:45:27 +08:00
{
2025-02-25 16:41:06 +08:00
2024-11-19 09:45:27 +08:00
string strSql = "select TrainRecord.TrainingId"
+ @",TrainRecord.TrainTitle"
+ @",TrainType.TrainTypeName,TrainLevel.TrainLevelName"
+ @",TrainRecord.TrainStartDate"
+ @",TrainRecord.TrainEndDate"
+ @",TrainRecord.TeachHour"
+ @",TrainRecord.TeachMan"
+ @",TrainRecord.TrainPersonNum"
+ @",TrainingCode"
// + @",CodeRecords.Code AS TrainingCode"
+ @",(CASE WHEN TrainRecord.States = " + BLL . Const . State_0 + " OR TrainRecord.States IS NULL THEN '待['+OperateUser.UserName+']提交' WHEN TrainRecord.States = " + BLL . Const . State_2 + " THEN '审核/审批完成' ELSE '待['+OperateUser.UserName+']办理' END) AS FlowOperateName"
+ @",TrainRecord.UnitIds"
+ @" from EduTrain_TrainRecord AS TrainRecord "
+ @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON TrainRecord.TrainingId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1"
+ @" LEFT JOIN Sys_User AS OperateUser ON FlowOperate.OperaterId=OperateUser.UserId "
+ @" LEFT JOIN Base_TrainType AS TrainType ON TrainRecord.TrainTypeId=TrainType.TrainTypeId "
+ @" LEFT JOIN Base_TrainLevel AS TrainLevel ON TrainRecord.TrainLevelId=TrainLevel.TrainLevelId "
+ @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON TrainRecord.TrainingId=CodeRecords.DataId WHERE 1=1 " ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
2025-02-25 16:41:06 +08:00
if ( ! string . IsNullOrEmpty ( txtName . Text ) )
{
strSql + = " AND TrainRecord.TrainTitle LIKE @TrainTitle" ;
listStr . Add ( new SqlParameter ( "@TrainTitle" , "%" + this . txtName . Text + "%" ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . ProjectId ) )
{
strSql + = " AND TrainRecord.ProjectId = @ProjectId" ;
listStr . Add ( new SqlParameter ( "@ProjectId" , this . ProjectId ) ) ;
}
if ( ! string . IsNullOrEmpty ( UnitId ) )
{
strSql + = " AND TrainRecord.UnitId = @UnitId" ;
listStr . Add ( new SqlParameter ( "@UnitId" , UnitId ) ) ;
}
2024-11-19 09:45:27 +08:00
if ( ! string . IsNullOrEmpty ( Request . Params [ "projectId" ] ) ) ///是否文件柜查看页面传项目值
{
strSql + = " AND TrainRecord.States = @States" ; ///状态为已完成
listStr . Add ( new SqlParameter ( "@States" , BLL . Const . State_2 ) ) ;
}
if ( this . drpTrainType . SelectedValue ! = BLL . Const . _Null )
{
strSql + = " AND TrainRecord.TrainTypeId = @TrainType" ;
listStr . Add ( new SqlParameter ( "@TrainType" , this . drpTrainType . SelectedValue ) ) ;
}
if ( this . drpTrainLevel . SelectedValue ! = BLL . Const . _Null )
{
strSql + = " AND TrainRecord.TrainLevelId = @TrainLevel" ;
listStr . Add ( new SqlParameter ( "@TrainLevel" , this . drpTrainLevel . SelectedValue ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtStartDate . Text . Trim ( ) ) )
{
strSql + = " AND TrainRecord.TrainStartDate >= @StartDate " ;
listStr . Add ( new SqlParameter ( "@StartDate" , this . txtStartDate . Text . Trim ( ) ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtEndDate . Text . Trim ( ) ) )
{
strSql + = " AND TrainRecord.TrainStartDate <= @EndDate " ;
listStr . Add ( new SqlParameter ( "@EndDate" , this . txtEndDate . Text . Trim ( ) ) ) ;
}
2025-02-25 16:41:06 +08:00
if ( BLL . ProjectUnitService . GetProjectUnitTypeByProjectIdUnitId ( this . ProjectId , this . CurrUser . UnitId ) )
2024-11-19 09:45:27 +08:00
{
strSql + = " AND TrainRecord.UnitIds LIKE @UnitId1" ;
listStr . Add ( new SqlParameter ( "@UnitId1" , "%" + this . CurrUser . UnitId + "%" ) ) ;
}
if ( this . drpUnitId . SelectedValue ! = BLL . Const . _Null )
{
2025-02-25 16:41:06 +08:00
strSql + = " AND TrainRecord.UnitIds LIKE @UnitIds" ;
listStr . Add ( new SqlParameter ( "@UnitIds" , "%" + this . drpUnitId . SelectedValue . Trim ( ) + "%" ) ) ;
2024-11-19 09:45:27 +08:00
}
2025-02-25 16:41:06 +08:00
2024-11-19 09:45:27 +08:00
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 ( ) ;
int totalPersonNum = 0 ;
for ( int i = 0 ; i < tb . Rows . Count ; i + + )
{
totalPersonNum + = Funs . GetNewIntOrZero ( tb . Rows [ i ] [ 8 ] . ToString ( ) ) ;
}
JObject summary = new JObject
2025-02-25 16:41:06 +08:00
{
{ "TeachMan" , "合计:" } ,
{ "TrainPersonNum" , totalPersonNum }
} ;
2024-11-19 09:45:27 +08:00
Grid1 . SummaryData = summary ;
2025-02-25 16:41:06 +08:00
}
#region 2023 - 6 - 27 15 : 03 : 28 修 改 废 弃 代 码
//else //公司级数据
//{
// string strSql = "select TrainRecord.TrainingId"
// + @",TrainRecord.TrainTitle"
// + @",TrainType.TrainTypeName,TrainLevel.TrainLevelName"
// + @",TrainRecord.TrainStartDate"
// + @",TrainRecord.TrainEndDate"
// + @",TrainRecord.TeachHour"
// + @",TrainRecord.TeachMan"
// + @",TrainRecord.TrainPersonNum"
// + @",TrainingCode"
// // + @",CodeRecords.Code AS TrainingCode"
// + @",(CASE WHEN TrainRecord.States = " + BLL.Const.State_0 + " OR TrainRecord.States IS NULL THEN '待['+OperateUser.UserName+']提交' WHEN TrainRecord.States = " + BLL.Const.State_2 + " THEN '审核/审批完成' ELSE '待['+OperateUser.UserName+']办理' END) AS FlowOperateName"
// + @",TrainRecord.UnitIds"
// + @" from EduTrain_TrainRecord AS TrainRecord "
// + @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON TrainRecord.TrainingId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1"
// + @" LEFT JOIN Sys_User AS OperateUser ON FlowOperate.OperaterId=OperateUser.UserId "
// + @" LEFT JOIN Base_TrainType AS TrainType ON TrainRecord.TrainTypeId=TrainType.TrainTypeId "
// + @" LEFT JOIN Base_TrainLevel AS TrainLevel ON TrainRecord.TrainLevelId=TrainLevel.TrainLevelId "
// + @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON TrainRecord.TrainingId=CodeRecords.DataId WHERE 1=1 ";
// List<SqlParameter> listStr = new List<SqlParameter>();
// if (!string.IsNullOrEmpty(ProjectId))
// {
// strSql += " AND (TrainRecord.ProjectId = '' or TrainRecord.ProjectId is null) ";
// //listStr.Add(new SqlParameter("@ProjectId", ProjectId));
// }
// if (this.drpTrainType.SelectedValue != BLL.Const._Null)
// {
// strSql += " AND TrainRecord.TrainTypeId = @TrainType";
// listStr.Add(new SqlParameter("@TrainType", this.drpTrainType.SelectedValue));
// }
// if (this.drpTrainLevel.SelectedValue != BLL.Const._Null)
// {
// strSql += " AND TrainRecord.TrainLevelId = @TrainLevel";
// listStr.Add(new SqlParameter("@TrainLevel", this.drpTrainLevel.SelectedValue));
// }
// if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()))
// {
// strSql += " AND TrainRecord.TrainStartDate >= @StartDate ";
// listStr.Add(new SqlParameter("@StartDate", this.txtStartDate.Text.Trim()));
// }
// if (!string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
// {
// strSql += " AND TrainRecord.TrainStartDate <= @EndDate ";
// listStr.Add(new SqlParameter("@EndDate", this.txtEndDate.Text.Trim()));
// }
// if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId))
// {
// strSql += " AND TrainRecord.UnitIds LIKE @UnitId1";
// listStr.Add(new SqlParameter("@UnitId1", "%" + this.CurrUser.UnitId + "%"));
// }
// strSql += " AND TrainRecord.UnitIds LIKE @UnitId";
// listStr.Add(new SqlParameter("@UnitId", "%" + this.ucTree.UnitId.Trim() + "%"));
// 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();
// int totalPersonNum = 0;
// for (int i = 0; i < tb.Rows.Count; i++)
// {
// totalPersonNum += Funs.GetNewIntOrZero(tb.Rows[i][8].ToString());
// }
// JObject summary = new JObject
// {
// { "TeachMan", "合计:" },
// { "TrainPersonNum", totalPersonNum }
// };
// Grid1.SummaryData = summary;
//}
#endregion
string projectId = this . CurrUser . LoginProjectId ;
if ( ! string . IsNullOrEmpty ( Request . Params [ "projectId" ] ) ) ///是否文件柜查看页面传项目值
{
projectId = Request . Params [ "projectId" ] ;
2024-11-19 09:45:27 +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 )
{
BindGrid ( ) ;
}
#endregion
#region 增 加
/// <summary>
/// 增加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click ( object sender , EventArgs e )
{
2025-02-25 16:41:06 +08:00
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "TrainRecordEdit.aspx?trainType={0}" , trainType , "编辑 - " ) ) ) ;
2024-11-19 09:45:27 +08:00
}
#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 ;
}
this . TrainingId = Grid1 . SelectedRowID ;
var trainRecord = EduTrain_TrainRecordService . GetTrainingByTrainingId ( TrainingId ) ;
if ( trainRecord ! = null )
{
2025-02-25 16:41:06 +08:00
if ( this . btnMenuEdit . Hidden ) ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
2024-11-19 09:45:27 +08:00
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "TrainRecordView.aspx?TrainingId={0}" , TrainingId , "查看 - " ) ) ) ;
}
else
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "TrainRecordEdit.aspx?TrainingId={0}" , TrainingId , "编辑 - " ) ) ) ;
}
}
}
#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 )
{
bool isShow = false ;
if ( Grid1 . SelectedRowIndexArray . Length = = 1 )
{
isShow = true ;
}
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
if ( this . judgementDelete ( rowID , isShow ) )
{
var TrainRecord = EduTrain_TrainRecordService . GetTrainingByTrainingId ( rowID ) ;
if ( TrainRecord ! = null )
{
LogService . AddSys_Log ( this . CurrUser , TrainRecord . TrainingCode , TrainRecord . TrainingId , BLL . Const . ProjectTrainRecordMenuId , BLL . Const . BtnDelete ) ;
EduTrain_TrainRecordService . DeleteTrainingByTrainingId ( rowID ) ;
BindGrid ( ) ;
ShowNotify ( "删除数据成功!(表格数据已重新绑定)" , MessageBoxIcon . Success ) ;
}
}
}
2025-02-25 16:41:06 +08:00
// Project_HSSEData_HSSEService.StatisticalData(this.CurrUser.LoginProjectId, Project_HSSEData_HSSEService.HSSEDateType.EducationAndTraining);
2024-11-19 09:45:27 +08:00
}
}
/// <summary>
/// 判断是否可删除
/// </summary>
/// <param name="rowID"></param>
/// <param name="isShow"></param>
/// <returns></returns>
private bool judgementDelete ( string rowID , bool isShow )
{
string content = string . Empty ;
if ( string . IsNullOrEmpty ( content ) )
{
return true ;
}
else
{
if ( isShow )
{
Alert . ShowInTop ( content ) ;
}
return false ;
}
}
#endregion
#region 关 闭 弹 出 窗
/// <summary>
/// 关闭弹出窗
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close ( object sender , WindowCloseEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 获 取 按 钮 权 限
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower ( )
{
2025-02-25 16:41:06 +08:00
if ( string . IsNullOrEmpty ( this . ProjectId ) )
{
return ;
}
2024-11-19 09:45:27 +08:00
if ( Request . Params [ "value" ] = = "0" )
{
return ;
}
2025-02-25 16:41:06 +08:00
var buttonList = BLL . CommonService . GetAllButtonList ( this . ProjectId , this . CurrUser . UserId , BLL . Const . ProjectTrainRecordMenuId ) ;
2024-11-19 09:45:27 +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 = this . Grid1 . Rows . Count ( ) ;
BindGrid ( ) ;
Response . Write ( GetGridTableHtml ( Grid1 ) ) ;
Response . End ( ) ;
}
#pragma warning disable CS0108 // “TrainRecord.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml ( Grid grid )
#pragma warning restore CS0108 // “TrainRecord.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 = = "tfNumber" )
{
html = ( row . FindControl ( "lblNumber" ) as AspNet . Label ) . Text ;
}
if ( column . ColumnID = = "tfTeachAddress" )
{
html = ( row . FindControl ( "lblTeachAddress" ) as AspNet . Label ) . Text ;
}
if ( column . ColumnID = = "tfUnitIds" )
{
html = ( row . FindControl ( "lblUnitId" ) as AspNet . Label ) . Text ;
}
if ( column . ColumnID = = "tfTrainingCode" )
{
html = ( row . FindControl ( "lblTrainingCode" ) 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
#region 格 式 化 字 符 串
/// <summary>
/// 获取单位名称
/// </summary>
/// <param name="unitIds"></param>
/// <returns></returns>
protected string ConvertUnitName ( object unitIds )
{
string unitName = string . Empty ;
if ( unitIds ! = null )
{
List < string > infos = unitIds . ToString ( ) . Split ( ',' ) . ToList ( ) ;
if ( infos . Count ( ) > 0 )
{
foreach ( var item in infos )
{
Model . Base_Unit unit = BLL . UnitService . GetUnitByUnitId ( item ) ;
if ( unit ! = null )
{
unitName + = unit . UnitName + "," ;
}
}
if ( ! string . IsNullOrEmpty ( unitName ) )
{
unitName = unitName . Substring ( 0 , unitName . LastIndexOf ( "," ) ) ;
}
}
}
return unitName ;
}
#endregion
#region 查 询 事 件
/// <summary>
/// 查询事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Text_TextChanged ( object sender , EventArgs e )
{
this . BindGrid ( ) ;
}
#endregion
#region 打 印
/// <summary>
/// 打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrint_Click ( object sender , EventArgs e )
{
if ( ! string . IsNullOrEmpty ( Grid1 . SelectedRowID ) )
{
PageContext . RegisterStartupScript ( Window2 . GetShowReference ( String . Format ( "~/ReportPrint/ExReportPrint.aspx?reportId={0}&&replaceParameter={1}&&varValue={2}" , Const . TrainRecordReportId , Grid1 . SelectedRowID , "" , "打印 - " ) ) ) ;
}
}
#endregion
protected void btnMenuView_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
this . TrainingId = Grid1 . SelectedRowID ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "TrainRecordView.aspx?TrainingId={0}" , TrainingId , "查看 - " ) ) ) ;
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnRefresh_Click ( object sender , EventArgs e )
{
2025-02-25 16:41:06 +08:00
if ( string . IsNullOrEmpty ( this . ProjectId ) )
{
return ;
}
2024-11-19 09:45:27 +08:00
var getTrainRecords = from x in Funs . DB . EduTrain_TrainRecord
2025-02-25 16:41:06 +08:00
where x . ProjectId = = this . ProjectId & & x . PlanId ! = null
2024-11-19 09:45:27 +08:00
select x ;
if ( getTrainRecords . Count ( ) > 0 )
{
foreach ( var itemRecord in getTrainRecords )
{
var getTrainRecordDetail = Funs . DB . EduTrain_TrainRecordDetail . Where ( x = > x . TrainingId = = itemRecord . TrainingId ) ;
if ( itemRecord . TrainPersonNum > getTrainRecordDetail . Count ( ) )
2025-02-25 16:41:06 +08:00
{
2024-11-19 09:45:27 +08:00
var getTrainingTasks = from x in Funs . DB . Training_Task
where x . PlanId = = itemRecord . PlanId
select x ;
////及格分数
int passScore = 80 ;
var testRule = Funs . DB . Sys_TestRule . FirstOrDefault ( ) ;
if ( testRule ! = null )
{
passScore = testRule . PassingScore ;
}
foreach ( var item in getTrainingTasks )
{
bool isInsert = true ;
var geteu = getTrainRecordDetail . FirstOrDefault ( x = > x . PersonId = = item . UserId ) ;
if ( geteu ! = null )
{
var getperson = Funs . DB . SitePerson_Person . FirstOrDefault ( x = > x . PersonId = = geteu . PersonId ) ;
if ( getperson ! = null & & ! string . IsNullOrEmpty ( getperson . CardNo ) )
{
isInsert = false ;
}
else
{
Funs . DB . EduTrain_TrainRecordDetail . DeleteOnSubmit ( geteu ) ;
Funs . DB . SubmitChanges ( ) ;
}
}
if ( isInsert )
{
decimal gScores = 0 ;
bool result = false ;
var getTestPlan = Funs . DB . Training_TestPlan . FirstOrDefault ( x = > x . PlanId = = itemRecord . PlanId ) ;
if ( getTestPlan ! = null )
{
////获取 考生试卷
var getTestRecord = Funs . DB . Training_TestRecord . Where ( x = > x . TestPlanId = = getTestPlan . TestPlanId & & x . TestManId = = item . UserId ) ;
foreach ( var itemR in getTestRecord )
{
if ( itemR . TestScores > gScores )
{
gScores = itemR . TestScores ? ? 0 ;
}
}
if ( gScores > = passScore )
{
result = true ;
}
Model . EduTrain_TrainRecordDetail newDetail = new Model . EduTrain_TrainRecordDetail
{
TrainDetailId = SQLHelper . GetNewID ( ) ,
TrainingId = itemRecord . TrainingId ,
PersonId = item . UserId ,
CheckScore = gScores ,
CheckResult = result ,
} ;
Funs . DB . EduTrain_TrainRecordDetail . InsertOnSubmit ( newDetail ) ;
Funs . DB . SubmitChanges ( ) ;
///// 培训考试 通过 更新卡号
if ( result )
{
var getPerson = Funs . DB . SitePerson_Person . FirstOrDefault ( x = > x . PersonId = = newDetail . PersonId ) ;
if ( getPerson ! = null & & string . IsNullOrEmpty ( getPerson . CardNo ) )
{
getPerson . CardNo = SQLHelper . RunProcNewId ( "SpGetNewNumber" , "SitePerson_Person" , "CardNo" , getPerson . ProjectId , UnitService . GetUnitCodeByUnitId ( getPerson . UnitId ) ) ;
Funs . DB . SubmitChanges ( ) ;
}
}
}
}
}
}
}
Alert . ShowInTop ( "刷新完成!" , MessageBoxIcon . Success ) ;
}
var getTestPlanStates = from x in Funs . DB . Training_TestPlan
2025-02-25 16:41:06 +08:00
join y in Funs . DB . Training_Plan on x . PlanId equals y . PlanId
where x . States = = Const . State_3 & & y . States = = Const . State_2
select x ;
2024-11-19 09:45:27 +08:00
foreach ( var item in getTestPlanStates )
{
////TODO 讲培训计划 考试记录 写入到培训记录
2025-02-25 16:41:06 +08:00
BLL . APITrainRecordService . InsertTrainRecord ( item ) ;
2024-11-19 09:45:27 +08:00
}
}
}
}