CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/CQMS/Check/RewardAndPunish.aspx.cs

465 lines
15 KiB
C#
Raw Normal View History

2026-03-16 20:12:55 +08:00
using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
namespace FineUIPro.Web.CQMS.Check
{
public partial class RewardAndPunish : PageBase
{
/// <summary>
/// 项目id
/// </summary>
public string ProjectId
{
get { return (string)ViewState["ProjectId"]; }
set { ViewState["ProjectId"] = value; }
}
/// <summary>
/// 主键
/// </summary>
public string RewardAndPunishID
{
get { return (string)ViewState["RewardAndPunishID"]; }
set { ViewState["RewardAndPunishID"] = value; }
}
public string SysTemType
{
get { return (string)ViewState["SysTemType"]; }
set { ViewState["SysTemType"] = value; }
}
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.ucTree.UnitId = this.CurrUser.UnitId;
this.ucTree.ProjectId = this.ProjectId;
if (!string.IsNullOrEmpty(this.ProjectId))
{
this.panelLeftRegion.Hidden = true;
////权限按钮方法
this.GetButtonPower();
}
UnitService.InitUnitByProjectIdUnitTypeDropDownList(drpResponseUnit, this.CurrUser.LoginProjectId, "", true);
this.SysTemType = Request.Params["type"] ?? "1";
btnNew.OnClientClick = Window1.GetShowReference(String.Format("RewardAndPunishEdit.aspx?sysTemType={0}",SysTemType, "编辑 - ")) + "return false;";
// 绑定表格
BindGrid();
}
}
/// <summary>
/// 公司级树加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void changeTree(object sender, EventArgs e)
{
this.ProjectId = this.ucTree.ProjectId;
this.GetButtonPower();
if (string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
btnNew.Hidden = true;
}
this.BindGrid();
}
/// <summary>
/// 绑定数据
/// </summary>
public void BindGrid()
{
if (string.IsNullOrEmpty(this.ProjectId))
{
return;
}
DataTable tb = ChecklistData();
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
protected DataTable ChecklistData()
{
string strSql = @" SELECT RewardAndPunishID
,Type
,ResponseUnit
,NoticeUnit
,Description
,Money
,Date
,CreateMan
,ProjectId,RewardAndPunishCode,Remark,DataSource,RewardAndPunishType,RewardAndPunishMan,TeamGroupId
FROM dbo.Check_RewardAndPunish
where ProjectId=@ProjectId and SysTemType = @SysTemType ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.ProjectId));
listStr.Add(new SqlParameter("@SysTemType", this.SysTemType));
if (drpType.SelectedValue != Const._Null)
{
strSql += " AND Type = @Type";
listStr.Add(new SqlParameter("@Type", drpType.SelectedValue));
}
if (drpRewardAndPunishType.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpRewardAndPunishType.SelectedValue))
{
strSql += " AND RewardAndPunishType = @RewardAndPunishType";
listStr.Add(new SqlParameter("@RewardAndPunishType", drpRewardAndPunishType.SelectedValue));
}
if (this.drpDataSource.SelectedValue != BLL.Const._Null)
{
if (this.drpDataSource.SelectedValue == "0")
{
strSql += " AND (DataSource is null or DataSource = @DataSource) ";
listStr.Add(new SqlParameter("@DataSource", drpDataSource.SelectedValue));
}
else
{
strSql += " AND DataSource = @DataSource";
listStr.Add(new SqlParameter("@DataSource", drpDataSource.SelectedValue));
}
}
if (drpResponseUnit.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpRewardAndPunishType.SelectedValue))
{
strSql += " AND ResponseUnit = @ResponseUnit";
listStr.Add(new SqlParameter("@ResponseUnit", drpResponseUnit.SelectedValue));
}
strSql += " ORDER BY Date DESC";
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
return tb;
}
#region
/// <summary>
/// 过滤表头
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_FilterChange(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
//Grid1.SortDirection = e.SortDirection;
//Grid1.SortField = e.SortField;
BindGrid();
}
/// <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
//<summary>
//获取办理人姓名
//</summary>
//<param name="state"></param>
//<returns></returns>
protected string ConvertMan(object userid)
{
if (userid != null && !string.IsNullOrEmpty(userid.ToString()))
{
return BLL.UserService.GetUserByUserId(userid.ToString()).UserName;
}
return "";
}
protected string ConvertRewardAndPunishType(object Type,object RewardAndPunishType)
{
Model.Sys_Const model;
if (Type != null && Type.ToString() == "1")
{
model = Funs.DB.Sys_Const.FirstOrDefault(x => x.GroupId == "RewardType" && x.ConstValue == RewardAndPunishType.ToString());
}
else
{
model = Funs.DB.Sys_Const.FirstOrDefault(x => x.GroupId == "PunishType" && x.ConstValue == RewardAndPunishType.ToString());
}
if (model == null)
{
return "";
}
return model.ConstText;
}
protected string ConvertUnitName(object uintid)
{
if (uintid != null && !string.IsNullOrEmpty(uintid.ToString()))
{
return BLL.UnitService.GetUnitByUnitId(uintid.ToString()).UnitName;
}
return "";
}
protected string ConvertPersionName(object persionid)
{
if (persionid != null && !string.IsNullOrEmpty(persionid.ToString()))
{
return BLL.PersonService.GetPersonById(persionid.ToString()).PersonName;
}
return "";
}
protected string ConvertTeamGroupName(object teamGroupid)
{
if (teamGroupid != null && !string.IsNullOrEmpty(teamGroupid.ToString()))
{
return BLL.TeamGroupService.getTeamGroupNameById(teamGroupid.ToString());
}
return "";
}
protected string ConvertDataSource(object dataSource)
{
string data = "常规";
if (dataSource != null)
{
if (dataSource.ToString() == "1")
{
data = "巡检";
}
}
return data;
}
protected string ConvertType(object type)
{
if (type != null)
{
if (type.ToString() == "1")
return "奖励";
else
return "处罚";
}
return "";
}
#region Grid双击事件
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
btnMenuModify_Click(null, null);
}
/// <summary>
/// 编辑按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuModify_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string codes = Grid1.SelectedRowID.Split(',')[0];
var checks = BLL.RewardAndPunishService.GetRewardAndPunishById(codes);
if (checks != null)
{
if (checks.CreateMan != this.CurrUser.UserId)
{
Alert.ShowInTop("您不是当前办理人,无法编辑,请右键查看!", MessageBoxIcon.Warning);
return;
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(
String.Format("RewardAndPunishEdit.aspx?RewardAndPunishID={0}", codes, "编辑 - ")));
return;
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#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.ProjectId, this.CurrUser.UserId,
BLL.Const.RewardAndPunishMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDel.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuModify.Hidden = false;
}
}
}
#endregion
protected void drpType_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 批量删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDel_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string codes = Grid1.DataKeys[rowIndex][0].ToString();
BLL.RewardAndPunishService.DeleteRewardAndPunishById(codes);
//删除对应的附件
BLL.UploadFileService.DeleteFile(Funs.RootPath, AttachFileService.getFileUrl(codes));
BLL.LogService.AddSys_Log(this.CurrUser, "", codes, BLL.Const.CheckListMenuId, "删除奖罚通知单(定稿)");
}
Grid1.DataBind();
BindGrid();
Alert.ShowInTop("删除数据成功!", MessageBoxIcon.Success);
}
/// <summary>
/// 关闭弹出窗
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
protected void drpType_OnSelectedIndexChanged(object sender, EventArgs e)
{
if (this.drpType.SelectedText == "奖励")
{
ConstValue.InitConstValueDropDownList(this.drpRewardAndPunishType, "RewardType", true);
}
else
{
ConstValue.InitConstValueDropDownList(this.drpRewardAndPunishType, "PunishType", true);
}
BindGrid();
}
protected string ConvertAttachFile(object rewardAndPunishID)
{
string fileUrl = "";
var model = BLL.RewardAndPunishService.GetRewardAndPunishById(rewardAndPunishID.ToString());
if (model != null)
{
if (model.DataSource == "1")
{
fileUrl = BLL.AttachFileService.GetBtnFileUrl(model.HazardRegisterId);
}
else
{
fileUrl = BLL.AttachFileService.GetBtnFileUrl(model.RewardAndPunishID);
}
}
return fileUrl;
}
}
}