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
350 lines
12 KiB
C#
350 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
|
|
namespace FineUIPro.Web.HSSE.HazardousMG
|
|
{
|
|
/// <summary>
|
|
/// 安全巡检页面
|
|
/// </summary>
|
|
public partial class SafetyPatrol : PageBase
|
|
{
|
|
#region 关联危大工程主键
|
|
/// <summary>
|
|
/// 关联的危大、超危工程主键(从危大清单右键进入时按此过滤)
|
|
/// </summary>
|
|
private string HazardProjectId
|
|
{
|
|
get { return (string)ViewState["HazardProjectId"]; }
|
|
set { ViewState["HazardProjectId"] = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region 加载
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
this.HazardProjectId = Request.Params["HazardProjectId"];
|
|
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|
this.BindGrid();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出Word:每条记录生成独立文档(文档名使用监督巡视部位)。
|
|
/// 单条直接下载 .docx;多条打包为 .zip,压缩包内每个 .docx 以监督巡视部位命名。
|
|
/// </summary>
|
|
protected void btnOut_Click(object sender, EventArgs e)
|
|
{
|
|
string[] ids = Grid1.SelectedRowIDArray;
|
|
if (ids == null || ids.Length == 0)
|
|
{
|
|
Alert.ShowInTop("请先勾选要导出的巡检记录!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
|
|
List<KeyValuePair<string, byte[]>> files = new List<KeyValuePair<string, byte[]>>();
|
|
int dupIndex = 0;
|
|
foreach (string id in ids)
|
|
{
|
|
if (string.IsNullOrEmpty(id))
|
|
{
|
|
continue;
|
|
}
|
|
Model.HSSE_SafetyPatrol info = BLL.SafetyPatrolService.GetById(id);
|
|
if (info == null)
|
|
{
|
|
continue;
|
|
}
|
|
byte[] bytes = BLL.SafetyPatrolWordService.Generate(id);
|
|
if (bytes == null)
|
|
{
|
|
continue;
|
|
}
|
|
////文件名 = 监督巡视部位 + 编号(编码唯一,规避同名覆盖)
|
|
string baseName = SanitizeFileName(info.HazardProjectName);
|
|
string codeSuffix = string.IsNullOrEmpty(info.Code) ? string.Empty : "_" + info.Code;
|
|
string fileName = baseName + codeSuffix + ".docx";
|
|
// 同名记录去重,避免覆盖
|
|
while (files.Any(f => f.Key == fileName))
|
|
{
|
|
dupIndex++;
|
|
fileName = baseName + "(" + dupIndex + ").docx";
|
|
}
|
|
files.Add(new KeyValuePair<string, byte[]>(fileName, bytes));
|
|
}
|
|
|
|
if (files.Count == 0)
|
|
{
|
|
Alert.ShowInTop("未找到有效巡检记录!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
|
|
Response.Clear();
|
|
if (files.Count == 1)
|
|
{
|
|
// 单条:直接下发 .docx
|
|
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(files[0].Key, System.Text.Encoding.UTF8));
|
|
Response.BinaryWrite(files[0].Value);
|
|
}
|
|
else
|
|
{
|
|
// 多条:打包为 .zip
|
|
Response.ContentType = "application/zip";
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("安全巡检记录_" + BLL.Funs.GetNewFileName() + ".zip", System.Text.Encoding.UTF8));
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
using (ZipArchive zip = new ZipArchive(ms, ZipArchiveMode.Create, true))
|
|
{
|
|
foreach (KeyValuePair<string, byte[]> f in files)
|
|
{
|
|
ZipArchiveEntry entry = zip.CreateEntry(f.Key, CompressionLevel.Optimal);
|
|
using (Stream es = entry.Open())
|
|
{
|
|
es.Write(f.Value, 0, f.Value.Length);
|
|
}
|
|
}
|
|
}
|
|
Response.BinaryWrite(ms.ToArray());
|
|
}
|
|
}
|
|
Response.Flush();
|
|
Response.End();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清洗文件名(去非法字符),保证文件名合法可下载。
|
|
/// </summary>
|
|
/// <param name="name">监督巡视部位名称</param>
|
|
/// <returns>合法文件名(不含扩展名)</returns>
|
|
private static string SanitizeFileName(string name)
|
|
{
|
|
if (string.IsNullOrEmpty(name))
|
|
{
|
|
return "监督记录表";
|
|
}
|
|
string fileName = name;
|
|
foreach (char c in Path.GetInvalidFileNameChars())
|
|
{
|
|
fileName = fileName.Replace(c, '_');
|
|
}
|
|
fileName = fileName.Trim();
|
|
if (fileName.Length == 0)
|
|
{
|
|
return "监督记录表";
|
|
}
|
|
if (fileName.Length > 80)
|
|
{
|
|
fileName = fileName.Substring(0, 80);
|
|
}
|
|
return fileName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 扫码巡检按钮事件
|
|
/// </summary>
|
|
protected void btnNew_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.CurrUser == null || string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
|
|
{
|
|
Alert.ShowInTop("请先选择项目!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference("SafetyPatrolEdit.aspx"));
|
|
}
|
|
#endregion
|
|
|
|
#region 模板绑定辅助方法
|
|
/// <summary>
|
|
/// 巡检状态颜色(待整改标红、整改待复查标橙、正常标绿)
|
|
/// </summary>
|
|
public Color GetPatrolStatusColor(object value)
|
|
{
|
|
string state = value == null ? "" : value.ToString();
|
|
switch (state)
|
|
{
|
|
case "待整改":
|
|
return Color.Red;
|
|
case "整改待复查":
|
|
return Color.Orange;
|
|
default:
|
|
return Color.Green;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 数据绑定
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
if (this.CurrUser == null || string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
|
|
{
|
|
Alert.ShowInTop("请先登录或选择项目!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
List<Model.HSSE_SafetyPatrol> list = BLL.SafetyPatrolService.GetList(this.CurrUser.LoginProjectId);
|
|
////按关联危大工程过滤(从危大清单右键进入)
|
|
if (!string.IsNullOrEmpty(this.HazardProjectId))
|
|
{
|
|
list = list.Where(x => x.HazardProjectId == this.HazardProjectId).ToList();
|
|
}
|
|
////查询条件过滤
|
|
string projectName = this.txtProjectName.Text.Trim();
|
|
if (!string.IsNullOrEmpty(projectName))
|
|
{
|
|
list = list.Where(x => x.HazardProjectName != null && x.HazardProjectName.Contains(projectName)).ToList();
|
|
}
|
|
////巡检日期时间段过滤
|
|
DateTime startDate;
|
|
if (DateTime.TryParse(this.txtStartTime.Text, out startDate))
|
|
{
|
|
list = list.Where(x => x.PatrolDate.HasValue && x.PatrolDate.Value.Date >= startDate.Date).ToList();
|
|
}
|
|
DateTime endDate;
|
|
if (DateTime.TryParse(this.txtEndTime.Text, out endDate))
|
|
{
|
|
list = list.Where(x => x.PatrolDate.HasValue && x.PatrolDate.Value.Date <= endDate.Date).ToList();
|
|
}
|
|
Grid1.RecordCount = list.Count;
|
|
var table = this.GetPagedDataTable(Grid1, list);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页事件
|
|
/// </summary>
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 每页记录数下拉事件
|
|
/// </summary>
|
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue);
|
|
this.BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 排序事件
|
|
/// </summary>
|
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 查询
|
|
/// <summary>
|
|
/// 查询
|
|
/// </summary>
|
|
protected void TextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置查询条件
|
|
/// </summary>
|
|
protected void btnRset_Click(object sender, EventArgs e)
|
|
{
|
|
this.txtProjectName.Text = "";
|
|
this.txtStartTime.Text = "";
|
|
this.txtEndTime.Text = "";
|
|
this.BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 编辑
|
|
/// <summary>
|
|
/// 双击行编辑事件
|
|
/// </summary>
|
|
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|
{
|
|
this.EditData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 右键菜单编辑事件
|
|
/// </summary>
|
|
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;
|
|
}
|
|
string id = Grid1.SelectedRowID;
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SafetyPatrolEdit.aspx?PatrolId={0}", id)));
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 右键菜单删除事件
|
|
/// </summary>
|
|
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();
|
|
BLL.SafetyPatrolService.Delete(rowID);
|
|
}
|
|
this.BindGrid();
|
|
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑窗口关闭事件
|
|
/// </summary>
|
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 附件查看
|
|
/// <summary>
|
|
/// 附件查看(弹出附件列表窗口)
|
|
/// </summary>
|
|
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
|
|
{
|
|
if (e.CommandName == "attchUrl")
|
|
{
|
|
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type={0}&toKeyId={1}&path=FileUpload/SafetyPatrol&menuId={2}",
|
|
-1, e.RowID, BLL.Const.SafetyPatrolMenuId)));
|
|
}
|
|
else if (e.CommandName == "attchUrlRectify")
|
|
{
|
|
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type={0}&toKeyId={1}&path=FileUpload/SafetyPatrolCorrect&menuId={2}",
|
|
-1, e.RowID, BLL.Const.SafetyPatrolRectifyMenuId)));
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|