404 lines
14 KiB
C#
404 lines
14 KiB
C#
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 TaskNotice : PageBase
|
|
{
|
|
|
|
|
|
#region 加载页面
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
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);
|
|
|
|
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|
// 绑定表格
|
|
BindGrid();
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string projectId = this.CurrUser.LoginProjectId;
|
|
|
|
string strSql = @"SELECT task.TaskNoticeId,
|
|
task.TrainTitle,
|
|
task.TrainType,
|
|
traintype.TrainTypeName,
|
|
task.TeachHour,
|
|
task.Units,
|
|
task.TeachAddress,
|
|
task.TeachMan,
|
|
task.TrainStartDate,
|
|
task.Cycle,
|
|
task.CycleStartDate,
|
|
task.CycleEndDate,
|
|
task.TrainContent,
|
|
users.UserName AS CreatMan,
|
|
task.CreatDate,task.DayOfWeek,task.WeekOfMonth,task.State,
|
|
task.ProjectId
|
|
FROM dbo.EduTrain_TaskNotice AS task
|
|
LEFT JOIN dbo.Base_TrainType AS traintype ON traintype.TrainTypeId = task.TrainType
|
|
LEFT JOIN dbo.Sys_User AS users ON users.UserId = task.CreatMan where 1=1 ";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
strSql += " AND task.ProjectId = @ProjectId";
|
|
listStr.Add(new SqlParameter("@ProjectId", projectId));
|
|
if (drpTrainType.SelectedValue!=Const._Null)
|
|
{
|
|
strSql += " AND task.TrainType = @TrainType";
|
|
listStr.Add(new SqlParameter("@TrainType", drpTrainType.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();
|
|
// 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
|
|
|
|
#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)
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TaskNoticeEdit.aspx", "编辑 - ")));
|
|
}
|
|
#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;
|
|
}
|
|
var TaskNoticeId = Grid1.SelectedRowID;
|
|
var model = EduTrain_TaskNoticeService.GetEduTrain_TaskNoticeById(TaskNoticeId);
|
|
if (model != null)
|
|
{
|
|
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TaskNoticeEdit.aspx?TaskNoticeId={0}", TaskNoticeId, "编辑 - ")));
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
protected void btnMenuAddNew_Click(object sender, EventArgs e)
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
{
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
var TaskNoticeId = Grid1.SelectedRowID;
|
|
var model = EduTrain_TaskNoticeService.GetEduTrain_TaskNoticeById(TaskNoticeId);
|
|
if (model != null)
|
|
{
|
|
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TaskNoticeEdit.aspx?TaskNoticeId={0}&Type=new", TaskNoticeId, "编辑 - ")));
|
|
|
|
}
|
|
}
|
|
#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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <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()
|
|
{
|
|
if (Request.Params["value"] == "0")
|
|
{
|
|
return;
|
|
}
|
|
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ProjectTrainRecordMenuId);
|
|
if (buttonList.Count() > 0)
|
|
{
|
|
if (buttonList.Contains(BLL.Const.BtnAdd))
|
|
{
|
|
this.btnNew.Hidden = false;
|
|
this.btnMenuAddNew.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="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;
|
|
}
|
|
|
|
protected string ConvertState(object state)
|
|
{
|
|
if (state != null)
|
|
{
|
|
switch (state.ToString())
|
|
{
|
|
case "0": return "编制";
|
|
case "1": return "已提交";
|
|
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
protected string ConvertUserName(object users)
|
|
{
|
|
string userName = string.Empty;
|
|
if (users != null)
|
|
{
|
|
List<string> infos = users.ToString().Split(',').ToList();
|
|
if (infos.Count() > 0)
|
|
{
|
|
foreach (var item in infos)
|
|
{
|
|
Model.Sys_User unit = BLL.UserService.GetUserByUserId(item);
|
|
if (unit != null)
|
|
{
|
|
userName += unit.UserName + ",";
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(userName))
|
|
{
|
|
userName = userName.Substring(0, userName.LastIndexOf(","));
|
|
}
|
|
}
|
|
}
|
|
return userName;
|
|
}
|
|
#endregion
|
|
|
|
#region 查询事件
|
|
/// <summary>
|
|
/// 查询事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Text_TextChanged(object sender, EventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
} |