CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/ZHGL/Supervise/UnitHazardRegister.aspx.cs

167 lines
5.8 KiB
C#
Raw Normal View History

2026-03-06 12:58:28 +08:00
using BLL;
using System;
using System.Linq;
using Model;
namespace FineUIPro.Web.ZHGL.Supervise
{
public partial class UnitHazardRegister : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetButtonPower();
btnNew.OnClientClick = Window1.GetShowReference("UnitHazardRegisterEdit.aspx?type=" + Request["type"]) + "return false;";
// 获取 Type 参数
string type = Request["type"] ?? "0";
drpCheckMainType.SelectedValue = type;
BLL.SuperviseCheckTypeService.InitCheckTypeDropDownListByMainType(
this.drpCheckType, type, true);
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
BindGrid();
}
}
/// <summary>
/// 绑定Grid数据
/// </summary>
private void BindGrid()
{
// 构建查询条件
var input = new UnitHazardRegisterInput
{
CheckMainType = drpCheckMainType.SelectedValue,
SearchText = this.txtSearch.Text.Trim(),
CheckType = this.drpCheckType.SelectedValue,
ProjectId = this.CurrUser.LoginProjectId
};
int totalCount;
// 使用新方法获取数据
var list = BLL.UnitHazardRegisterService.GetUnitHazardRegisters(
input,
Grid1.PageIndex,
Grid1.PageSize,
false,
out totalCount);
Grid1.RecordCount = totalCount;
Grid1.DataSource = list;
Grid1.DataBind();
}
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
btnEdit_Click(null, null);
}
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
protected void txtSearch_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
protected void drpCheckMainType_SelectedIndexChanged(object sender, EventArgs e)
{
// 重新加载检查类别下拉框
string type = drpCheckMainType.SelectedValue;
BLL.SuperviseCheckTypeService.InitCheckTypeDropDownListByMainType(this.drpCheckType, type, true);
BindGrid();
}
protected void btnEdit_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string registerId = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(Window1.GetShowReference(
String.Format("UnitHazardRegisterEdit.aspx?UnitHazardRegisterId={0}&type={1}",
registerId, Request["type"])));
}
protected void btnDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (UnitHazardRegisterService.CanDeleteRegister(rowID) || (this.CurrUser.UserId ==Const.hfnbdId || this.CurrUser.UserId == Const.sysglyId))
{
BLL.UnitHazardRegisterItemService.DeleteItemsByRegisterId(rowID);
BLL.UnitHazardRegisterService.DeleteUnitHazardRegisterById(rowID);
}
else
{
ShowNotify("该检查已进入整改流程不允许删除!", MessageBoxIcon.Warning);
return;
}
}
BindGrid();
ShowNotify("删除成功!", MessageBoxIcon.Success);
}
}
protected void btnOut_Click(object sender, EventArgs e)
{
string type = Request["type"] ?? "0";
string typeText = type == "0" ? "安全" : "质量";
Response.ClearContent();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("企业" + typeText + "检查.xls", System.Text.Encoding.UTF8));
Response.Charset = "UTF-8";
Grid1.PageSize = 100000;
BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
private void GetButtonPower()
{
string menuId = Request["type"] == "0" ?
BLL.Const.UnitHazardRegisterMenu_Safety :
BLL.Const.UnitHazardRegisterMenu_Quality;
var buttonList = BLL.CommonService.GetAllButtonList(
this.CurrUser.LoginProjectId, this.CurrUser.UserId, menuId);
if (buttonList.Count > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd)) btnNew.Hidden = false;
if (buttonList.Contains(BLL.Const.BtnModify)) btnEdit.Hidden = false;
if (buttonList.Contains(BLL.Const.BtnDelete)) btnDelete.Hidden = false;
}
}
}
}