Files
SGGL_HBAZ/SGGL/FineUIPro.Web/HSSE/HazardousMG/SafetyPatrolEdit.aspx.cs
T
yangjl 192824ea90 安全巡检接入真实数据库:编码字段自动生成、公示牌二维码修复、安全问题统计排除作废
- 安全巡检表新增编码字段(Code,全局唯一 XJ-序号),WebAPI/桌面端新增时自动生成,不可重复
- 修复危大超危工程公示牌二维码不显示:urlName 含非法字符?导致 image.Save 抛异常,改用主键+内容哈希安全文件名
- 安全问题统计(mainProject/main3)排除作废数据(States=4),图表口径与顶部计数一致
- Word 导出文件名改为 监督巡视部位+编号
- Model.cs 由 SqlMetal 重新生成,补齐巡检人ID/签收人ID/发现问题/处理要求等字段;新增 HSSE_SafetyPatrol.Code.cs 补充 Code 列
- 新增安全巡检完整建表脚本(SGGLDB_V2026-08-25-001);删除已过时的接口文档 SafetyPatrol_API.md
2026-08-26 19:13:11 +08:00

317 lines
14 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace FineUIPro.Web.HSSE.HazardousMG
{
/// <summary>
/// 编辑安全巡检记录页面
/// </summary>
public partial class SafetyPatrolEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
private string PatrolId
{
get
{
return (string)ViewState["PatrolId"];
}
set
{
ViewState["PatrolId"] = value;
}
}
/// <summary>
/// 巡检状态(编辑页已不提供选择,加载时保留原值,新增默认正常)
/// </summary>
private string PatrolStatus
{
get
{
return (string)ViewState["PatrolStatus"];
}
set
{
ViewState["PatrolStatus"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
this.InitDropDownList();
this.PatrolId = Request.Params["PatrolId"];
if (!string.IsNullOrEmpty(this.PatrolId))
{
////编辑:回填数据
Model.HSSE_SafetyPatrol info = BLL.SafetyPatrolService.GetById(this.PatrolId);
if (info != null)
{
if (!string.IsNullOrEmpty(info.HazardProjectId))
{
this.ddlHazardProject.SelectedValue = info.HazardProjectId;
}
if (info.PatrolDate.HasValue)
{
this.dpPatrolDate.SelectedDate = info.PatrolDate.Value;
}
this.txtCode.Text = info.Code;
this.PatrolStatus = string.IsNullOrEmpty(info.PatrolStatus) ? "正常" : info.PatrolStatus;
this.InitUserDropDownList(info.PatrolMan, info.PatrolManId, info.Receiver, info.ReceiverId);
this.RenderContent(info.Content);
this.txtProblems.Text = info.Problems;
this.txtHandleRequire.Text = info.HandleRequire;
this.txtRectifyReview.Text = info.RectifyReview;
this.txtRemarks.Text = info.Remarks;
}
}
else
{
////新增(扫码巡检):默认巡检日期为当天、巡检状态为正常;巡检人默认当前登录账号
this.dpPatrolDate.SelectedDate = DateTime.Now;
this.PatrolStatus = "正常";
this.InitUserDropDownList(null, null, null, null);
}
////让父级编辑窗口高度自适应内容,避免固定高度留下大空白;超过 720px 时内部滚动
string fitJs = "setTimeout(function(){try{var w=F.activeWindow;if(w){var el=document.getElementById('patrolContent');var h=el?el.offsetHeight:0;h+=40;if(h>720){h=720;}w.setSize(780,h);}}catch(e){}},200);";
PageContext.RegisterStartupScript(fitJs);
}
}
/// <summary>
/// 初始化危大、超危清单下拉
/// </summary>
private void InitDropDownList()
{
if (this.CurrUser == null || string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
return;
}
List<Model.HSSE_HazardProject> projects = BLL.HazardProjectService.GetList(this.CurrUser.LoginProjectId);
foreach (Model.HSSE_HazardProject p in projects)
{
this.ddlHazardProject.Items.Add(new FineUIPro.ListItem(p.ProjectName + "" + p.ProjectCode + "", p.HazardProjectId));
}
}
/// <summary>
/// 绑定巡检人、签收人下拉(来自项目用户)
/// </summary>
/// <param name="patrolMan">巡检人名称(回显用)</param>
/// <param name="patrolManId">巡检人ID(回显用)</param>
/// <param name="receiver">签收人名称(回显用)</param>
/// <param name="receiverId">签收人ID(回显用)</param>
private void InitUserDropDownList(string patrolMan, string patrolManId, string receiver, string receiverId)
{
if (this.CurrUser == null || string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
return;
}
List<Model.Sys_User> users = BLL.UserService.GetProjectUserListByProjectId(this.CurrUser.LoginProjectId);
////巡检人(默认当前登录账号);签收人允许留空
this.BindPatrolUser(this.ddlPatrolMan, users, patrolMan, patrolManId, this.CurrUser.UserId);
this.BindPatrolUser(this.ddlReceiver, users, receiver, receiverId, null);
}
/// <summary>
/// 绑定单个用户下拉:优先按ID回显,其次按名称回显;均不匹配且名称有值时保留原名称
/// </summary>
/// <param name="ddl">目标下拉</param>
/// <param name="users">项目用户列表</param>
/// <param name="selectName">回显名称</param>
/// <param name="selectId">回显ID</param>
/// <param name="defaultUserId">默认选中用户ID(可空)</param>
private void BindPatrolUser(FineUIPro.DropDownList ddl, List<Model.Sys_User> users, string selectName, string selectId, string defaultUserId)
{
ddl.Items.Clear();
////签收人允许留空(首项为占位)
if (ddl.ID == "ddlReceiver")
{
ddl.Items.Add(new FineUIPro.ListItem("请选择", ""));
}
string selectValue = string.IsNullOrEmpty(selectId) ? string.Empty : selectId;
foreach (Model.Sys_User u in users)
{
////默认选中项(巡检人默认当前登录账号)
if (string.IsNullOrEmpty(selectValue) && !string.IsNullOrEmpty(defaultUserId) && u.UserId == defaultUserId)
{
selectValue = u.UserId;
}
////名称回显(老数据无ID
if (string.IsNullOrEmpty(selectValue) && !string.IsNullOrEmpty(selectName) && u.UserName == selectName)
{
selectValue = u.UserId;
}
ddl.Items.Add(new FineUIPro.ListItem(u.UserName, u.UserId));
}
////名称在项目用户中找不到(如外部人员):追加原名称选项,保留旧数据
if (string.IsNullOrEmpty(selectValue) && !string.IsNullOrEmpty(selectName))
{
ddl.Items.Insert(0, new FineUIPro.ListItem(selectName, ""));
}
if (!string.IsNullOrEmpty(selectValue))
{
ddl.SelectedValue = selectValue;
}
else if (ddl.Items.Count > 0)
{
ddl.SelectedIndex = 0;
}
}
/// <summary>
/// 根据巡视内容渲染"其它"输入框。1-4 项为固定默认值(写死、始终显示),不再从 Content 解析勾选。
/// Content 以后只存「其它」内容:兼容旧格式「…;其它:xxx」,也兼容直接为其它文本的新格式。
/// </summary>
/// <param name="content">Content 字段(以后仅其它内容;旧数据可能形如:1、…;4、…;其它:xxx</param>
private void RenderContent(string content)
{
if (string.IsNullOrEmpty(content))
{
return;
}
string other = null;
foreach (string seg in content.Split(''))
{
string s = seg.Trim();
if (s.Length == 0)
{
continue;
}
if (s.StartsWith("其它") || s.StartsWith("其他"))
{
int idx = s.IndexOf('');
other = idx >= 0 ? s.Substring(idx + 1).Trim() : string.Empty;
break;
}
}
// 新格式:Content 无「其它:」前缀、且不以项号前缀(1、…)开头,则整段即为其它内容
if (other == null)
{
other = Regex.IsMatch(content, @"^\s*\d+、") ? string.Empty : content.Trim();
}
if (other.Length > 0)
{
this.txtContentOther.Text = other;
}
}
/// <summary>
/// 构造 Content 文本。1-4 项固定写死(始终显示,不参与存储),Content 仅存「其它」内容。
/// 「其它」无多选:输入框有内容即表示选中。
/// </summary>
/// <returns>如:其它:基坑围挡损坏;无其它内容返回空串</returns>
private string BuildContent()
{
string other = this.txtContentOther.Text.Trim();
if (other.Length > 0)
{
return "其它:" + other;
}
return string.Empty;
}
#endregion
#region
/// <summary>
/// 保存按钮事件
/// </summary>
protected void btnSave_Click(object sender, EventArgs e)
{
if (this.CurrUser == null || string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
Alert.ShowInTop("请先选择项目!", MessageBoxIcon.Warning);
return;
}
////新增时先生成主键
if (string.IsNullOrEmpty(this.PatrolId))
{
this.PatrolId = Guid.NewGuid().ToString();
}
if (string.IsNullOrEmpty(this.ddlHazardProject.SelectedValue))
{
Alert.ShowInTop("请选择危大工程类别!", MessageBoxIcon.Warning);
return;
}
////根据所选清单回填工程名称
string hazardProjectName = string.Empty;
Model.HSSE_HazardProject project = BLL.HazardProjectService.GetById(this.ddlHazardProject.SelectedValue);
if (project != null)
{
hazardProjectName = project.ProjectName;
}
////巡检人、签收人(下拉选中项:ID + 名称;外部人员无ID时仅保留名称)
string patrolManId = this.ddlPatrolMan.SelectedValue;
string patrolManName = this.ddlPatrolMan.SelectedItem == null ? string.Empty : this.ddlPatrolMan.SelectedItem.Text.Trim();
if (patrolManName == "请选择")
{
patrolManName = string.Empty;
}
string receiverId = this.ddlReceiver.SelectedValue;
string receiverName = this.ddlReceiver.SelectedItem == null ? string.Empty : this.ddlReceiver.SelectedItem.Text.Trim();
if (receiverName == "请选择")
{
receiverName = string.Empty;
}
Model.HSSE_SafetyPatrol info = new Model.HSSE_SafetyPatrol
{
PatrolId = this.PatrolId,
ProjectId = this.CurrUser.LoginProjectId,
HazardProjectId = this.ddlHazardProject.SelectedValue,
HazardProjectName = hazardProjectName,
PatrolDate = this.dpPatrolDate.SelectedDate,
PatrolMan = patrolManName,
PatrolManId = patrolManId,
PatrolStatus = this.PatrolStatus,
Content = this.BuildContent(),
Problems = this.txtProblems.Text.Trim(),
Receiver = receiverName,
ReceiverId = receiverId,
HandleRequire = this.txtHandleRequire.Text.Trim(),
RectifyReview = this.txtRectifyReview.Text.Trim(),
Remarks = this.txtRemarks.Text.Trim()
};
////存在则更新,不存在则新增(服务层已处理)
BLL.SafetyPatrolService.Update(info);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
/// <summary>
/// 上传巡检图片
/// </summary>
protected void btnAttach_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.PatrolId))
{
this.PatrolId = Guid.NewGuid().ToString();
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/SafetyPatrol&menuId={1}", this.PatrolId, BLL.Const.SafetyPatrolMenuId)));
}
/// <summary>
/// 上传整改图片
/// </summary>
protected void btnAttachRectify_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.PatrolId))
{
this.PatrolId = Guid.NewGuid().ToString();
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/SafetyPatrolCorrect&menuId={1}", this.PatrolId, BLL.Const.SafetyPatrolRectifyMenuId)));
}
#endregion
}
}