459 lines
16 KiB
C#
459 lines
16 KiB
C#
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.PostTraining
|
|
{
|
|
public partial class Record : PageBase
|
|
{
|
|
#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)
|
|
{
|
|
this.ProjectId = this.CurrUser.LoginProjectId;
|
|
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId)
|
|
{
|
|
this.ProjectId = Request.Params["projectId"];
|
|
}
|
|
this.InitDropDownList();
|
|
|
|
////权限按钮方法
|
|
this.GetButtonPower();
|
|
this.btnNew.OnClientClick = Window1.GetShowReference("RecordEdit.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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下拉框加载
|
|
/// </summary>
|
|
private void InitDropDownList()
|
|
{
|
|
//单位
|
|
BLL.UnitService.InitUnitDropDownList(this.drpUnitId, this.CurrUser.LoginProjectId, true);
|
|
////获取适用岗位下拉框
|
|
//PostTrainingRoleService.InitPostTrainingRoleDropDownList(this.drpRole, true);
|
|
//获取培训类别下拉框
|
|
PostTrainingCategoryService.InitPostTrainingCategoryDropDownList(this.drpCategory, true);
|
|
//获取培训方式下拉框
|
|
PostTrainingMethodService.InitPostTrainingMethodDropDownList(this.drpMethod, null, true);
|
|
////获取培训师资下拉框
|
|
//PostTrainingTeachersService.InitPostTrainingTeachersDropDownList(this.drpTeachers, null, true);
|
|
////获取培训效果下拉框
|
|
//PostTrainingRecordService.InitPostTrainingOutcomeDropDownList(this.drpOutcome, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 培训类别下拉加载
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void drpCategory_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
//培训课程
|
|
PostTrainingCourseService.InitPostTrainingCourseDropDownList(this.drpCourse, this.drpCategory.SelectedValue, true);
|
|
this.BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string strSql = @"SELECT Record.* ,SUser.UserName AS CompileManName
|
|
FROM PostTraining_Record AS Record
|
|
LEFT JOIN Sys_User AS SUser ON SUser.UserId=Record.CompileMan
|
|
WHERE 1=1 ";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
if (!string.IsNullOrEmpty(this.txtCode.Text.Trim()))
|
|
{
|
|
strSql += " AND Record.Code LIKE @Code";
|
|
listStr.Add(new SqlParameter("@Code", "%" + this.txtCode.Text.Trim() + "%"));
|
|
}
|
|
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
|
|
{
|
|
strSql += " AND Record.Name LIKE @Name";
|
|
listStr.Add(new SqlParameter("@Name", "%" + this.txtName.Text.Trim() + "%"));
|
|
}
|
|
//if (this.drpRole.SelectedValue != BLL.Const._Null)
|
|
//{
|
|
// strSql += " AND Record.RoleId = @RoleId";
|
|
// listStr.Add(new SqlParameter("@RoleId", this.drpRole.SelectedValue));
|
|
//}
|
|
if (this.drpCategory.SelectedValue != BLL.Const._Null)
|
|
{
|
|
strSql += " AND Record.CategoryId = @CategoryId";
|
|
listStr.Add(new SqlParameter("@CategoryId", this.drpCategory.SelectedValue));
|
|
}
|
|
if (this.drpCourse.SelectedValue != null && this.drpCourse.SelectedValue != BLL.Const._Null)
|
|
{
|
|
strSql += " AND Record.CourseId = @CourseId";
|
|
listStr.Add(new SqlParameter("@CourseId", this.drpCourse.SelectedValue));
|
|
}
|
|
if (this.drpMethod.SelectedValue != BLL.Const._Null)
|
|
{
|
|
strSql += " AND Record.Method = @Method";
|
|
listStr.Add(new SqlParameter("@Method", this.drpMethod.SelectedValue));
|
|
}
|
|
//if (this.drpTeachers.SelectedValue != BLL.Const._Null)
|
|
//{
|
|
// strSql += " AND Record.Teachers = @Teachers";
|
|
// listStr.Add(new SqlParameter("@Teachers", this.drpTeachers.SelectedValue));
|
|
//}
|
|
//if (this.drpOutcome.SelectedValue != BLL.Const._Null)
|
|
//{
|
|
// strSql += " AND Record.Outcome = @Outcome";
|
|
// listStr.Add(new SqlParameter("@Outcome", this.drpOutcome.SelectedValue));
|
|
//}
|
|
|
|
strSql += " ORDER BY Record.Code ASC ";
|
|
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();
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
#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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取适用岗位名称
|
|
/// </summary>
|
|
/// <param name="roleIds"></param>
|
|
/// <returns></returns>
|
|
protected string ConvertRoleName(object roleIds)
|
|
{
|
|
string roleName = string.Empty;
|
|
if (roleIds != null)
|
|
{
|
|
List<string> infos = roleIds.ToString().Split(',').ToList();
|
|
if (infos.Count() > 0)
|
|
{
|
|
foreach (var item in infos)
|
|
{
|
|
Model.PostTraining_Role role = BLL.PostTrainingRoleService.GetRoleById(item);
|
|
if (role != null)
|
|
{
|
|
roleName += role.Name + ",";
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(roleName))
|
|
{
|
|
roleName = roleName.Substring(0, roleName.LastIndexOf(","));
|
|
}
|
|
}
|
|
}
|
|
return roleName;
|
|
}
|
|
|
|
#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 (this.btnMenuEdit.Hidden)
|
|
{
|
|
Alert.ShowInTop("抱歉!您没有编辑权限!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
{
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
string id = Grid1.SelectedRowID;
|
|
var model = BLL.PostTrainingRecordService.GetRecordById(id);
|
|
if (model != null)
|
|
{
|
|
if (this.btnMenuEdit.Hidden) ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
|
|
{
|
|
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RecordView.aspx?Id={0}", id, "查看 - ")));
|
|
}
|
|
else
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RecordEdit.aspx?Id={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 newModel = BLL.PostTrainingRecordService.GetRecordById(rowID);
|
|
if (newModel != null)
|
|
{
|
|
BLL.LogService.AddSys_Log(this.CurrUser, newModel.Code, newModel.Id, BLL.Const.PostTrainingRecordMenuId, BLL.Const.BtnDelete);
|
|
BLL.PostTrainingRecordService.DeleteRecordById(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;
|
|
}
|
|
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.PostTrainingRecordMenuId);
|
|
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>
|
|
/// 关闭弹出窗
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void WindowAtt_Close(object sender, WindowCloseEventArgs 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 = 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
|
|
|
|
#region 导入
|
|
|
|
/// <summary>
|
|
/// 导入
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnImport_Click(object sender, EventArgs e)
|
|
{
|
|
//PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("RecordDataIn.aspx?", "导入 - ")));
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |