隐患整改导出

This commit is contained in:
geh 2025-04-21 09:33:45 +08:00
parent 226efdacc2
commit df2f29c5c4
18 changed files with 1242 additions and 67 deletions

View File

@ -32,6 +32,14 @@ namespace BLL
wordDoc = new Document(path);
}
public Document Document
{
get
{
return wordDoc;
}
}
/// <summary>
/// 添加图片
/// </summary>

View File

@ -0,0 +1,31 @@
安全质量环保检查记录
编号20250105
|项目名称|«projectName» |
|项 | «remark» |
|目 | |
|概 | |
|况 | |
|工程名称|«projectName» |
|检 |为深入贯彻《关于做好今冬明春重大事故隐患排杏整治的通知》、《关 |
|查 |于开展建筑施工安全生产“自查自纠”活动的通知》、《关于开展我市建|
|发 |筑施工安全“强执法 |
|现 |补短板”专项行动的通知》等文件要求,加强项目危大工程安全管控,|
|的 |2025年1月5日由项目经理带队项目领导班子副职以及项目安质部|
|问 |、工程部、物设部、工经部、办公室等部门、分包单位相关人员参加|
|题 |,对本项目在建工程进行了专项检查暨安全质量环保周常检查记录 |
| |,现将具体检查问题记录如下: |
| |现场问题: |
| | |
| | |
|被检查单| |
|位负责人|年 月 日 |
|检查单位|中化学建设投资集团安徽工程有限公司«projectName» |
|检查人员| |
| |年 月 日 |
本表一式2份整改单位、检查单位各1份验证存档。

View File

@ -67,7 +67,7 @@
</f:FormRow>
<f:FormRow>
<Items>
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" AllowCellEditing="true" Title="安全隐患及整改要求"
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" AllowCellEditing="true" Title="安全隐患及整改要求" EnableCollapse="true"
runat="server" BoxFlex="1" DataKeyNames="RectifyNoticesItemId" DataIDField="RectifyNoticesItemId" EnableColumnLines="true"
AllowSorting="true" SortField="RectifyNoticesItemId" SortDirection="ASC" EnableTextSelection="True" MinHeight="240px"
EnableRowDoubleClickEvent="true" OnRowCommand="Grid1_RowCommand" PageSize="500" >
@ -116,6 +116,9 @@
<f:LinkButtonField ID="del" ColumnID="del" HeaderText="删除" Width="60px" HeaderTextAlign="Center"
CommandName="delete" Icon="Delete" />
</Columns>
<Listeners>
<f:Listener Event="beforerowcontextmenu" Handler="onRowContextMenu"/>
</Listeners>
</f:Grid>
</Items>
</f:FormRow>
@ -165,6 +168,22 @@
Target="Parent" EnableResize="false" runat="server" IsModal="true" Width="700px"
Height="500px">
</f:Window>
<f:Menu ID="Menu1" runat="server">
<Items>
<f:MenuButton ID="btnPrinter" EnablePostBack="true" runat="server"
Text="导出" Icon="Printer" OnClick="btnPrinter_Click" EnableAjax="false" DisableControlBeforePostBack="false">
</f:MenuButton>
</Items>
</f:Menu>
</form>
<script type="text/javascript">
var menuID = '<%= Menu1.ClientID %>';
// 返回false来阻止浏览器右键菜单
function onRowContextMenu(event, rowId) {
F(menuID).show(); //showAt(event.pageX, event.pageY);
return false;
}
</script>
</body>
</html>

View File

@ -5,7 +5,11 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Tables;
namespace FineUIPro.Web.HSSE.Check
{
@ -417,5 +421,188 @@ namespace FineUIPro.Web.HSSE.Check
//}
/// <summary>
/// 导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrinter_Click(object sender, EventArgs e)
{
//获取所有列表导出
if (!string.IsNullOrEmpty(this.RectifyNoticesId))
{
var rectifyNotices = RectifyNoticesService.GetRectifyNoticesById(RectifyNoticesId);
string CheckManIds = rectifyNotices.CheckManIds;
string CheckManNames = string.Empty;
if (CheckManIds != null)
{
string[] Ids = CheckManIds.ToString().Split(',');
foreach (string t in Ids)
{
var Name = BLL.UserService.GetUserNameByUserId(t);
if (Name != null)
{
CheckManNames += Name + ",";
}
}
}
string DutyPersonId = rectifyNotices.DutyPersonId;
string DutyPersonName = UserService.GetUserNameByUserId(DutyPersonId);
var dataList = (from item in Funs.DB.Check_RectifyNoticesItem
join rectify in Funs.DB.Technique_Rectify
on item.RectifyId equals rectify.RectifyId into rectifyGroup
from rectify in rectifyGroup.DefaultIfEmpty()
where item.RectifyNoticesId == RectifyNoticesId
select new
{
RectifyNoticesItemId = item.RectifyNoticesItemId,
RectifyId = rectify.RectifyName,
RectifyNoticesId = item.RectifyNoticesId,
WrongContent = item.WrongContent,
Requirement = item.Requirement,
LimitTime = item.LimitTime,
RectifyResults = item.RectifyResults,
IsRectify = item.IsRectify
}).ToList();
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
initTemplatePath = "File\\Word\\HSSE\\安全质量环保检查记录(模板)建投隐患整改通知单.doc";
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".doc", RectifyNoticesId + ".doc");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
AsposeWordHelper helper = new AsposeWordHelper();
helper.OpenTempelte(newUrl); //打开模板文件
var project =
(from x in Funs.DB.Base_Project where x.ProjectId == this.CurrUser.LoginProjectId select x)
.FirstOrDefault();
string projectName = project.ProjectName;
string remark = project.Remark;
string[] fieldNames =
{
"projectName", "remark"
};
object[] fieldValues =
{
projectName, remark
};
helper.Executefield(fieldNames, fieldValues); //域赋值
if (dataList.Count > 0)
{
Document doc = helper.Document;
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = (Table)doc.GetChild(NodeType.Table, 1, true); // 定位第一个表格
int number = 1;
foreach (var item in dataList)
{
string WrongContent = item.WrongContent;
string Requirement = item.Requirement;
string LimitTime = item.LimitTime.HasValue
? $" {item.LimitTime.Value.Year} 年 {item.LimitTime.Value.Month:D2} 月 {item.LimitTime.Value.Day:D2} 日"
: "";
List<string> Paths = new List<string>();
var res = AttachFileService.getFileUrl(item.RectifyNoticesItemId + "#1");
if (!string.IsNullOrEmpty(res))
{
string[] arr = res.Split(',');
for (int i = 0; i < arr.Length; i++)
{
Paths.Add(rootPath + arr[i]);
}
}
// 克隆模板占位行
Row newRow = (Row)table.LastRow.Clone(true);
table.AppendChild(newRow);
// 定位到单元格
Cell cell = newRow.FirstCell;
// 清空单元格所有段落
cell.RemoveAllChildren();
Paragraph para = new Paragraph(doc); // 显式创建段落
cell.AppendChild(para);
builder.MoveTo(para); // 定位到段落
// 插入文本
builder.Write(" 存在问题" + number.ToString() + "" + WrongContent);
builder.Writeln(); // 换行
builder.Write(" 整改要求:" + Requirement);
builder.Writeln(); // 换行
builder.Write(" 整改时间:" + LimitTime + " 整改责任人:" + DutyPersonName + " 监督人:" +
CheckManNames);
builder.Writeln(); // 换行
// 插入多张图片(横向排列)
if (Paths.Count > 0)
{
foreach (string imgPath in Paths)
{
// 计算每张图片宽度(总宽度按单元格宽度平分)
double cellWidth = cell.CellFormat.Width;
double imgWidth = (cellWidth - 10 * (Paths.Count - 1)) / Paths.Count - 10;
// 插入图片并调整尺寸
Shape image = builder.InsertImage(imgPath);
image.Width = Paths.Count == 1 ? imgWidth / 2 : imgWidth;
// image.Height = image.ImageData.ImageSize.HeightPixels * (imgWidth / image.ImageData.ImageSize.WidthPixels);
image.Height = 120;
// 图片间留间距(横向排列)
if (imgPath != Paths.Last())
{
builder.MoveTo(cell.LastParagraph.AppendChild(new Run(doc)));
builder.Write(" "); // 插入空格分隔
}
}
}
number++;
}
// 删除模板中的原始占位行
table.Rows.RemoveAt(0);
}
helper.SaveDoc(newUrl); //文件保存保存为doc
// 验证文件是否存在
if (!File.Exists(newUrl))
{
throw new Exception("文件不存在: " + newUrl);
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition",
"attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
}
}
}

View File

@ -7,10 +7,12 @@
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.HSSE.Check {
namespace FineUIPro.Web.HSSE.Check
{
public partial class RectifyNoticesAdd {
public partial class RectifyNoticesAdd
{
/// <summary>
/// form1 控件。
@ -254,5 +256,23 @@ namespace FineUIPro.Web.HSSE.Check {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window WindowAtt;
/// <summary>
/// Menu1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Menu Menu1;
/// <summary>
/// btnPrinter 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnPrinter;
}
}

View File

@ -57,7 +57,7 @@
</f:FormRow>
<f:FormRow>
<Items>
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" Title="安全隐患及整改要求" runat="server"
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" Title="安全隐患及整改要求" runat="server" EnableCollapse="true"
DataKeyNames="RectifyNoticesItemId" DataIDField="RectifyNoticesItemId" EnableColumnLines="true" PageSize="500"
AllowSorting="true" SortField="RectifyNoticesItemId" SortDirection="ASC" EnableTextSelection="True" MinHeight="240px">
<Columns>
@ -92,6 +92,9 @@
HeaderText="合格" HeaderTextAlign="Center" TextAlign="Center">
</f:RenderField>
</Columns>
<Listeners>
<f:Listener Event="beforerowcontextmenu" Handler="onRowContextMenu"/>
</Listeners>
</f:Grid>
</Items>
</f:FormRow>
@ -167,6 +170,22 @@
Target="Parent" EnableResize="false" runat="server" IsModal="true" Width="700px"
Height="500px">
</f:Window>
</form>
<f:Menu ID="Menu1" runat="server">
<Items>
<f:MenuButton ID="btnPrinter" EnablePostBack="true" runat="server"
Text="导出" Icon="Printer" OnClick="btnPrinter_Click" EnableAjax="false" DisableControlBeforePostBack="false">
</f:MenuButton>
</Items>
</f:Menu>
</form>
<script type="text/javascript">
var menuID = '<%= Menu1.ClientID %>';
// 返回false来阻止浏览器右键菜单
function onRowContextMenu(event, rowId) {
F(menuID).show(); //showAt(event.pageX, event.pageY);
return false;
}
</script>
</body>
</html>

View File

@ -6,6 +6,10 @@ using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.IO;
using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Tables;
namespace FineUIPro.Web.HSSE.Check
{
@ -315,5 +319,189 @@ namespace FineUIPro.Web.HSSE.Check
}
}
}
/// <summary>
/// 导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrinter_Click(object sender, EventArgs e)
{
//获取所有列表导出
if (!string.IsNullOrEmpty(this.RectifyNoticesId))
{
var rectifyNotices = RectifyNoticesService.GetRectifyNoticesById(RectifyNoticesId);
string CheckManIds = rectifyNotices.CheckManIds;
string CheckManNames = string.Empty;
if (CheckManIds != null)
{
string[] Ids = CheckManIds.ToString().Split(',');
foreach (string t in Ids)
{
var Name = BLL.UserService.GetUserNameByUserId(t);
if (Name != null)
{
CheckManNames += Name + ",";
}
}
}
string DutyPersonId = rectifyNotices.DutyPersonId;
string DutyPersonName = UserService.GetUserNameByUserId(DutyPersonId);
var dataList = (from item in Funs.DB.Check_RectifyNoticesItem
join rectify in Funs.DB.Technique_Rectify
on item.RectifyId equals rectify.RectifyId into rectifyGroup
from rectify in rectifyGroup.DefaultIfEmpty()
where item.RectifyNoticesId == RectifyNoticesId
select new
{
RectifyNoticesItemId = item.RectifyNoticesItemId,
RectifyId = rectify.RectifyName,
RectifyNoticesId = item.RectifyNoticesId,
WrongContent = item.WrongContent,
Requirement = item.Requirement,
LimitTime = item.LimitTime,
RectifyResults = item.RectifyResults,
IsRectify = item.IsRectify
}).ToList();
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
initTemplatePath = "File\\Word\\HSSE\\安全质量环保检查记录(模板)建投隐患整改通知单.doc";
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".doc", RectifyNoticesId + ".doc");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
AsposeWordHelper helper = new AsposeWordHelper();
helper.OpenTempelte(newUrl); //打开模板文件
var project =
(from x in Funs.DB.Base_Project where x.ProjectId == this.CurrUser.LoginProjectId select x)
.FirstOrDefault();
string projectName = project.ProjectName;
string remark = project.Remark;
string[] fieldNames =
{
"projectName", "remark"
};
object[] fieldValues =
{
projectName, remark
};
helper.Executefield(fieldNames, fieldValues); //域赋值
if (dataList.Count > 0)
{
Document doc = helper.Document;
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = (Table)doc.GetChild(NodeType.Table, 1, true); // 定位第一个表格
int number = 1;
foreach (var item in dataList)
{
string WrongContent = item.WrongContent;
string Requirement = item.Requirement;
string LimitTime = item.LimitTime.HasValue
? $" {item.LimitTime.Value.Year} 年 {item.LimitTime.Value.Month:D2} 月 {item.LimitTime.Value.Day:D2} 日"
: "";
List<string> Paths = new List<string>();
var res = AttachFileService.getFileUrl(item.RectifyNoticesItemId + "#1");
if (!string.IsNullOrEmpty(res))
{
string[] arr = res.Split(',');
for (int i = 0; i < arr.Length; i++)
{
Paths.Add(rootPath + arr[i]);
}
}
// 克隆模板占位行
Row newRow = (Row)table.LastRow.Clone(true);
table.AppendChild(newRow);
// 定位到单元格
Cell cell = newRow.FirstCell;
// 清空单元格所有段落
cell.RemoveAllChildren();
Paragraph para = new Paragraph(doc); // 显式创建段落
cell.AppendChild(para);
builder.MoveTo(para); // 定位到段落
// 插入文本
builder.Write(" 存在问题" + number.ToString() + "" + WrongContent);
builder.Writeln(); // 换行
builder.Write(" 整改要求:" + Requirement);
builder.Writeln(); // 换行
builder.Write(" 整改时间:" + LimitTime + " 整改责任人:" + DutyPersonName + " 监督人:" +
CheckManNames);
builder.Writeln(); // 换行
// 插入多张图片(横向排列)
if (Paths.Count > 0)
{
foreach (string imgPath in Paths)
{
// 计算每张图片宽度(总宽度按单元格宽度平分)
double cellWidth = cell.CellFormat.Width;
double imgWidth = (cellWidth - 10 * (Paths.Count - 1)) / Paths.Count - 10;
// 插入图片并调整尺寸
Shape image = builder.InsertImage(imgPath);
image.Width = Paths.Count == 1 ? imgWidth / 2 : imgWidth;
// image.Height = image.ImageData.ImageSize.HeightPixels * (imgWidth / image.ImageData.ImageSize.WidthPixels);
image.Height = 120;
// 图片间留间距(横向排列)
if (imgPath != Paths.Last())
{
builder.MoveTo(cell.LastParagraph.AppendChild(new Run(doc)));
builder.Write(" "); // 插入空格分隔
}
}
}
number++;
}
// 删除模板中的原始占位行
table.Rows.RemoveAt(0);
}
helper.SaveDoc(newUrl); //文件保存保存为doc
// 验证文件是否存在
if (!File.Exists(newUrl))
{
throw new Exception("文件不存在: " + newUrl);
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition",
"attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
}
}
}

View File

@ -265,5 +265,23 @@ namespace FineUIPro.Web.HSSE.Check
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window WindowAtt;
/// <summary>
/// Menu1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Menu Menu1;
/// <summary>
/// btnPrinter 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnPrinter;
}
}

View File

@ -58,7 +58,7 @@
<f:FormRow>
<Items>
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" Title="安全隐患及整改要求" runat="server" AllowCellEditing="true"
DataKeyNames="RectifyNoticesItemId" DataIDField="RectifyNoticesItemId" EnableColumnLines="true"
DataKeyNames="RectifyNoticesItemId" DataIDField="RectifyNoticesItemId" EnableColumnLines="true" EnableCollapse="true"
AllowSorting="true" SortField="RectifyNoticesItemId" SortDirection="ASC" EnableTextSelection="True"
MinHeight="240px" PageSize="500">
<Columns>
@ -176,6 +176,13 @@
</Items>
</f:Panel>
</form>
<f:Menu ID="Menu1" runat="server">
<Items>
<f:MenuButton ID="btnPrinter" EnablePostBack="true" runat="server"
Text="导出" Icon="Printer" OnClick="btnPrinter_Click" EnableAjax="false" DisableControlBeforePostBack="false">
</f:MenuButton>
</Items>
</f:Menu>
<script type="text/javascript">
var rdbIsAgreeID = '<%= rdbIsAgree.ClientID %>';
var grid1ClientID = '<%= Grid1.ClientID %>';
@ -198,6 +205,15 @@
// 回发到后台更新
__doPostBack('', 'UPDATE_SUMMARY');
var menuID = '<%= Menu1.ClientID %>';
// 返回false来阻止浏览器右键菜单
function onRowContextMenu(event, rowId) {
F(menuID).show(); //showAt(event.pageX, event.pageY);
return false;
}
}
</script>
</body>

View File

@ -6,7 +6,11 @@ using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.IO;
using System.Linq;
using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Tables;
namespace FineUIPro.Web.HSSE.Check
{
public partial class RectifyNoticesRecheck : PageBase
@ -334,5 +338,189 @@ namespace FineUIPro.Web.HSSE.Check
}
this.lbCom.Hidden = !this.lbDutyPerson.Hidden;
}
/// <summary>
/// 导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrinter_Click(object sender, EventArgs e)
{
//获取所有列表导出
if (!string.IsNullOrEmpty(this.RectifyNoticesId))
{
var rectifyNotices = RectifyNoticesService.GetRectifyNoticesById(RectifyNoticesId);
string CheckManIds = rectifyNotices.CheckManIds;
string CheckManNames = string.Empty;
if (CheckManIds != null)
{
string[] Ids = CheckManIds.ToString().Split(',');
foreach (string t in Ids)
{
var Name = BLL.UserService.GetUserNameByUserId(t);
if (Name != null)
{
CheckManNames += Name + ",";
}
}
}
string DutyPersonId = rectifyNotices.DutyPersonId;
string DutyPersonName = UserService.GetUserNameByUserId(DutyPersonId);
var dataList = (from item in Funs.DB.Check_RectifyNoticesItem
join rectify in Funs.DB.Technique_Rectify
on item.RectifyId equals rectify.RectifyId into rectifyGroup
from rectify in rectifyGroup.DefaultIfEmpty()
where item.RectifyNoticesId == RectifyNoticesId
select new
{
RectifyNoticesItemId = item.RectifyNoticesItemId,
RectifyId = rectify.RectifyName,
RectifyNoticesId = item.RectifyNoticesId,
WrongContent = item.WrongContent,
Requirement = item.Requirement,
LimitTime = item.LimitTime,
RectifyResults = item.RectifyResults,
IsRectify = item.IsRectify
}).ToList();
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
initTemplatePath = "File\\Word\\HSSE\\安全质量环保检查记录(模板)建投隐患整改通知单.doc";
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".doc", RectifyNoticesId + ".doc");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
AsposeWordHelper helper = new AsposeWordHelper();
helper.OpenTempelte(newUrl); //打开模板文件
var project =
(from x in Funs.DB.Base_Project where x.ProjectId == this.CurrUser.LoginProjectId select x)
.FirstOrDefault();
string projectName = project.ProjectName;
string remark = project.Remark;
string[] fieldNames =
{
"projectName", "remark"
};
object[] fieldValues =
{
projectName, remark
};
helper.Executefield(fieldNames, fieldValues); //域赋值
if (dataList.Count > 0)
{
Document doc = helper.Document;
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = (Table)doc.GetChild(NodeType.Table, 1, true); // 定位第一个表格
int number = 1;
foreach (var item in dataList)
{
string WrongContent = item.WrongContent;
string Requirement = item.Requirement;
string LimitTime = item.LimitTime.HasValue
? $" {item.LimitTime.Value.Year} 年 {item.LimitTime.Value.Month:D2} 月 {item.LimitTime.Value.Day:D2} 日"
: "";
List<string> Paths = new List<string>();
var res = AttachFileService.getFileUrl(item.RectifyNoticesItemId + "#1");
if (!string.IsNullOrEmpty(res))
{
string[] arr = res.Split(',');
for (int i = 0; i < arr.Length; i++)
{
Paths.Add(rootPath + arr[i]);
}
}
// 克隆模板占位行
Row newRow = (Row)table.LastRow.Clone(true);
table.AppendChild(newRow);
// 定位到单元格
Cell cell = newRow.FirstCell;
// 清空单元格所有段落
cell.RemoveAllChildren();
Paragraph para = new Paragraph(doc); // 显式创建段落
cell.AppendChild(para);
builder.MoveTo(para); // 定位到段落
// 插入文本
builder.Write(" 存在问题" + number.ToString() + "" + WrongContent);
builder.Writeln(); // 换行
builder.Write(" 整改要求:" + Requirement);
builder.Writeln(); // 换行
builder.Write(" 整改时间:" + LimitTime + " 整改责任人:" + DutyPersonName + " 监督人:" +
CheckManNames);
builder.Writeln(); // 换行
// 插入多张图片(横向排列)
if (Paths.Count > 0)
{
foreach (string imgPath in Paths)
{
// 计算每张图片宽度(总宽度按单元格宽度平分)
double cellWidth = cell.CellFormat.Width;
double imgWidth = (cellWidth - 10 * (Paths.Count - 1)) / Paths.Count - 10;
// 插入图片并调整尺寸
Shape image = builder.InsertImage(imgPath);
image.Width = Paths.Count == 1 ? imgWidth / 2 : imgWidth;
// image.Height = image.ImageData.ImageSize.HeightPixels * (imgWidth / image.ImageData.ImageSize.WidthPixels);
image.Height = 120;
// 图片间留间距(横向排列)
if (imgPath != Paths.Last())
{
builder.MoveTo(cell.LastParagraph.AppendChild(new Run(doc)));
builder.Write(" "); // 插入空格分隔
}
}
}
number++;
}
// 删除模板中的原始占位行
table.Rows.RemoveAt(0);
}
helper.SaveDoc(newUrl); //文件保存保存为doc
// 验证文件是否存在
if (!File.Exists(newUrl))
{
throw new Exception("文件不存在: " + newUrl);
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition",
"attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
}
}
}

View File

@ -283,5 +283,23 @@ namespace FineUIPro.Web.HSSE.Check
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.WebControls.Label lblPageIndex;
/// <summary>
/// Menu1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Menu Menu1;
/// <summary>
/// btnPrinter 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnPrinter;
}
}

View File

@ -59,7 +59,7 @@
<f:FormRow>
<Items>
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" Title="安全隐患及整改要求" runat="server" AllowCellEditing="true"
DataKeyNames="RectifyNoticesItemId" DataIDField="RectifyNoticesItemId" EnableColumnLines="true"
DataKeyNames="RectifyNoticesItemId" DataIDField="RectifyNoticesItemId" EnableColumnLines="true" EnableCollapse="true"
AllowSorting="true" SortField="RectifyNoticesItemId" SortDirection="ASC" EnableTextSelection="True"
OnRowCommand="Grid1_RowCommand" MinHeight="240px" PageSize="500">
<Columns>
@ -100,6 +100,9 @@
<f:LinkButtonField HeaderText="整改*" ConfirmTarget="Top" Width="80" CommandName="AttachUrl"
HeaderTextAlign="Center" TextAlign="Center" ToolTip="整改照片" Text="照片" />
</Columns>
<Listeners>
<f:Listener Event="beforerowcontextmenu" Handler="onRowContextMenu"/>
</Listeners>
</f:Grid>
</Items>
</f:FormRow>
@ -149,6 +152,22 @@
Target="Parent" EnableResize="false" runat="server" IsModal="true" Width="700px"
Height="500px">
</f:Window>
</form>
<f:Menu ID="Menu1" runat="server">
<Items>
<f:MenuButton ID="btnPrinter" EnablePostBack="true" runat="server"
Text="导出" Icon="Printer" OnClick="btnPrinter_Click" EnableAjax="false" DisableControlBeforePostBack="false">
</f:MenuButton>
</Items>
</f:Menu>
</form>
<script type="text/javascript">
var menuID = '<%= Menu1.ClientID %>';
// 返回false来阻止浏览器右键菜单
function onRowContextMenu(event, rowId) {
F(menuID).show(); //showAt(event.pageX, event.pageY);
return false;
}
</script>
</body>
</html>

View File

@ -6,7 +6,11 @@ using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.IO;
using System.Linq;
using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Tables;
namespace FineUIPro.Web.HSSE.Check
{
public partial class RectifyNoticesRectify : PageBase
@ -273,5 +277,188 @@ namespace FineUIPro.Web.HSSE.Check
}
}
#endregion
/// <summary>
/// 导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrinter_Click(object sender, EventArgs e)
{
//获取所有列表导出
if (!string.IsNullOrEmpty(this.RectifyNoticesId))
{
var rectifyNotices = RectifyNoticesService.GetRectifyNoticesById(RectifyNoticesId);
string CheckManIds = rectifyNotices.CheckManIds;
string CheckManNames = string.Empty;
if (CheckManIds != null)
{
string[] Ids = CheckManIds.ToString().Split(',');
foreach (string t in Ids)
{
var Name = BLL.UserService.GetUserNameByUserId(t);
if (Name != null)
{
CheckManNames += Name + ",";
}
}
}
string DutyPersonId = rectifyNotices.DutyPersonId;
string DutyPersonName = UserService.GetUserNameByUserId(DutyPersonId);
var dataList = (from item in Funs.DB.Check_RectifyNoticesItem
join rectify in Funs.DB.Technique_Rectify
on item.RectifyId equals rectify.RectifyId into rectifyGroup
from rectify in rectifyGroup.DefaultIfEmpty()
where item.RectifyNoticesId == RectifyNoticesId
select new
{
RectifyNoticesItemId = item.RectifyNoticesItemId,
RectifyId = rectify.RectifyName,
RectifyNoticesId = item.RectifyNoticesId,
WrongContent = item.WrongContent,
Requirement = item.Requirement,
LimitTime = item.LimitTime,
RectifyResults = item.RectifyResults,
IsRectify = item.IsRectify
}).ToList();
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
initTemplatePath = "File\\Word\\HSSE\\安全质量环保检查记录(模板)建投隐患整改通知单.doc";
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".doc", RectifyNoticesId + ".doc");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
AsposeWordHelper helper = new AsposeWordHelper();
helper.OpenTempelte(newUrl); //打开模板文件
var project =
(from x in Funs.DB.Base_Project where x.ProjectId == this.CurrUser.LoginProjectId select x)
.FirstOrDefault();
string projectName = project.ProjectName;
string remark = project.Remark;
string[] fieldNames =
{
"projectName", "remark"
};
object[] fieldValues =
{
projectName, remark
};
helper.Executefield(fieldNames, fieldValues); //域赋值
if (dataList.Count > 0)
{
Document doc = helper.Document;
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = (Table)doc.GetChild(NodeType.Table, 1, true); // 定位第一个表格
int number = 1;
foreach (var item in dataList)
{
string WrongContent = item.WrongContent;
string Requirement = item.Requirement;
string LimitTime = item.LimitTime.HasValue
? $" {item.LimitTime.Value.Year} 年 {item.LimitTime.Value.Month:D2} 月 {item.LimitTime.Value.Day:D2} 日"
: "";
List<string> Paths = new List<string>();
var res = AttachFileService.getFileUrl(item.RectifyNoticesItemId + "#1");
if (!string.IsNullOrEmpty(res))
{
string[] arr = res.Split(',');
for (int i = 0; i < arr.Length; i++)
{
Paths.Add(rootPath + arr[i]);
}
}
// 克隆模板占位行
Row newRow = (Row)table.LastRow.Clone(true);
table.AppendChild(newRow);
// 定位到单元格
Cell cell = newRow.FirstCell;
// 清空单元格所有段落
cell.RemoveAllChildren();
Paragraph para = new Paragraph(doc); // 显式创建段落
cell.AppendChild(para);
builder.MoveTo(para); // 定位到段落
// 插入文本
builder.Write(" 存在问题" + number.ToString() + "" + WrongContent);
builder.Writeln(); // 换行
builder.Write(" 整改要求:" + Requirement);
builder.Writeln(); // 换行
builder.Write(" 整改时间:" + LimitTime + " 整改责任人:" + DutyPersonName + " 监督人:" +
CheckManNames);
builder.Writeln(); // 换行
// 插入多张图片(横向排列)
if (Paths.Count > 0)
{
foreach (string imgPath in Paths)
{
// 计算每张图片宽度(总宽度按单元格宽度平分)
double cellWidth = cell.CellFormat.Width;
double imgWidth = (cellWidth - 10 * (Paths.Count - 1)) / Paths.Count - 10;
// 插入图片并调整尺寸
Shape image = builder.InsertImage(imgPath);
image.Width = Paths.Count == 1 ? imgWidth / 2 : imgWidth;
// image.Height = image.ImageData.ImageSize.HeightPixels * (imgWidth / image.ImageData.ImageSize.WidthPixels);
image.Height = 120;
// 图片间留间距(横向排列)
if (imgPath != Paths.Last())
{
builder.MoveTo(cell.LastParagraph.AppendChild(new Run(doc)));
builder.Write(" "); // 插入空格分隔
}
}
}
number++;
}
// 删除模板中的原始占位行
table.Rows.RemoveAt(0);
}
helper.SaveDoc(newUrl); //文件保存保存为doc
// 验证文件是否存在
if (!File.Exists(newUrl))
{
throw new Exception("文件不存在: " + newUrl);
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition",
"attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
}
}
}

View File

@ -211,5 +211,23 @@ namespace FineUIPro.Web.HSSE.Check
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window WindowAtt;
/// <summary>
/// Menu1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Menu Menu1;
/// <summary>
/// btnPrinter 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnPrinter;
}
}

View File

@ -94,6 +94,9 @@
HeaderText="合格" HeaderTextAlign="Center" TextAlign="Center">
</f:RenderField>
</Columns>
<Listeners>
<f:Listener Event="beforerowcontextmenu" Handler="onRowContextMenu"/>
</Listeners>
</f:Grid>
</Items>
</f:FormRow>
@ -135,6 +138,22 @@
Target="Parent" EnableResize="false" runat="server" IsModal="true" Width="700px"
Height="500px">
</f:Window>
<f:Menu ID="Menu1" runat="server">
<Items>
<f:MenuButton ID="btnPrinter" EnablePostBack="true" runat="server"
Text="导出" Icon="Printer" OnClick="btnPrinter_Click" EnableAjax="false" DisableControlBeforePostBack="false">
</f:MenuButton>
</Items>
</f:Menu>
</form>
<script type="text/javascript">
var menuID = '<%= Menu1.ClientID %>';
// 返回false来阻止浏览器右键菜单
function onRowContextMenu(event, rowId) {
F(menuID).show(); //showAt(event.pageX, event.pageY);
return false;
}
</script>
</body>
</html>

View File

@ -3,7 +3,11 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Tables;
namespace FineUIPro.Web.HSSE.Check
{
public partial class RectifyNoticesView1 : PageBase
@ -120,5 +124,189 @@ namespace FineUIPro.Web.HSSE.Check
}
return url;
}
/// <summary>
/// 导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrinter_Click(object sender, EventArgs e)
{
//获取所有列表导出
if (!string.IsNullOrEmpty(this.RectifyNoticesId))
{
var rectifyNotices = RectifyNoticesService.GetRectifyNoticesById(RectifyNoticesId);
string CheckManIds = rectifyNotices.CheckManIds;
string CheckManNames = string.Empty;
if (CheckManIds != null)
{
string[] Ids = CheckManIds.ToString().Split(',');
foreach (string t in Ids)
{
var Name = BLL.UserService.GetUserNameByUserId(t);
if (Name != null)
{
CheckManNames += Name + ",";
}
}
}
string DutyPersonId = rectifyNotices.DutyPersonId;
string DutyPersonName = UserService.GetUserNameByUserId(DutyPersonId);
var dataList = (from item in Funs.DB.Check_RectifyNoticesItem
join rectify in Funs.DB.Technique_Rectify
on item.RectifyId equals rectify.RectifyId into rectifyGroup
from rectify in rectifyGroup.DefaultIfEmpty()
where item.RectifyNoticesId == RectifyNoticesId
select new
{
RectifyNoticesItemId = item.RectifyNoticesItemId,
RectifyId = rectify.RectifyName,
RectifyNoticesId = item.RectifyNoticesId,
WrongContent = item.WrongContent,
Requirement = item.Requirement,
LimitTime = item.LimitTime,
RectifyResults = item.RectifyResults,
IsRectify = item.IsRectify
}).ToList();
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
initTemplatePath = "File\\Word\\HSSE\\安全质量环保检查记录(模板)建投隐患整改通知单.doc";
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".doc", RectifyNoticesId + ".doc");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
AsposeWordHelper helper = new AsposeWordHelper();
helper.OpenTempelte(newUrl); //打开模板文件
var project =
(from x in Funs.DB.Base_Project where x.ProjectId == this.CurrUser.LoginProjectId select x)
.FirstOrDefault();
string projectName = project.ProjectName;
string remark = project.Remark;
string[] fieldNames =
{
"projectName", "remark"
};
object[] fieldValues =
{
projectName, remark
};
helper.Executefield(fieldNames, fieldValues); //域赋值
if (dataList.Count > 0)
{
Document doc = helper.Document;
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = (Table)doc.GetChild(NodeType.Table, 1, true); // 定位第一个表格
int number = 1;
foreach (var item in dataList)
{
string WrongContent = item.WrongContent;
string Requirement = item.Requirement;
string LimitTime = item.LimitTime.HasValue
? $" {item.LimitTime.Value.Year} 年 {item.LimitTime.Value.Month:D2} 月 {item.LimitTime.Value.Day:D2} 日"
: "";
List<string> Paths = new List<string>();
var res = AttachFileService.getFileUrl(item.RectifyNoticesItemId + "#1");
if (!string.IsNullOrEmpty(res))
{
string[] arr = res.Split(',');
for (int i = 0; i < arr.Length; i++)
{
Paths.Add(rootPath + arr[i]);
}
}
// 克隆模板占位行
Row newRow = (Row)table.LastRow.Clone(true);
table.AppendChild(newRow);
// 定位到单元格
Cell cell = newRow.FirstCell;
// 清空单元格所有段落
cell.RemoveAllChildren();
Paragraph para = new Paragraph(doc); // 显式创建段落
cell.AppendChild(para);
builder.MoveTo(para); // 定位到段落
// 插入文本
builder.Write(" 存在问题" + number.ToString() + "" + WrongContent);
builder.Writeln(); // 换行
builder.Write(" 整改要求:" + Requirement);
builder.Writeln(); // 换行
builder.Write(" 整改时间:" + LimitTime + " 整改责任人:" + DutyPersonName + " 监督人:" +
CheckManNames);
builder.Writeln(); // 换行
// 插入多张图片(横向排列)
if (Paths.Count > 0)
{
foreach (string imgPath in Paths)
{
// 计算每张图片宽度(总宽度按单元格宽度平分)
double cellWidth = cell.CellFormat.Width;
double imgWidth = (cellWidth - 10 * (Paths.Count - 1)) / Paths.Count - 10;
// 插入图片并调整尺寸
Shape image = builder.InsertImage(imgPath);
image.Width = Paths.Count == 1 ? imgWidth / 2 : imgWidth;
// image.Height = image.ImageData.ImageSize.HeightPixels * (imgWidth / image.ImageData.ImageSize.WidthPixels);
image.Height = 120;
// 图片间留间距(横向排列)
if (imgPath != Paths.Last())
{
builder.MoveTo(cell.LastParagraph.AppendChild(new Run(doc)));
builder.Write(" "); // 插入空格分隔
}
}
}
number++;
}
// 删除模板中的原始占位行
table.Rows.RemoveAt(0);
}
helper.SaveDoc(newUrl); //文件保存保存为doc
// 验证文件是否存在
if (!File.Exists(newUrl))
{
throw new Exception("文件不存在: " + newUrl);
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition",
"attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
}
}
}

View File

@ -7,10 +7,12 @@
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.HSSE.Check {
namespace FineUIPro.Web.HSSE.Check
{
public partial class RectifyNoticesView1 {
public partial class RectifyNoticesView1
{
/// <summary>
/// form1 控件。
@ -182,5 +184,23 @@ namespace FineUIPro.Web.HSSE.Check {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window WindowAtt;
/// <summary>
/// Menu1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Menu Menu1;
/// <summary>
/// btnPrinter 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnPrinter;
}
}

View File

@ -71,7 +71,7 @@ namespace WebAPI.Controllers.HSSE
/// <param name="PersonId"></param>
/// <returns></returns>
[HttpPost]
public Model.ResponeData updateSignTime(string PersonId, DateTime? newSignTime = null)
public Model.ResponeData updateSignTime([FromBody] Item item)
{
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
{
@ -79,11 +79,44 @@ namespace WebAPI.Controllers.HSSE
try
{
// 查找要修改的记录
var person = db.SitePerson_Person.FirstOrDefault(x => x.PersonId == PersonId);
var person = db.SitePerson_Person.FirstOrDefault(x => x.PersonId == item.PersonId);
if (person != null)
{
person.SignTime = newSignTime.HasValue ? newSignTime.Value : DateTime.Now; // 更新签字时间
person.SignTime = item.newSignTime.HasValue ? item.newSignTime.Value : DateTime.Now; // 更新签字时间
db.SubmitChanges();
Model.ToDoItem toDoItem = new Model.ToDoItem
{
MenuId = Const.PersonListMenuId,
DataId = item.PersonId + "_1",
UrlStr = item.AttachUrl1,
};
if (!string.IsNullOrEmpty(item.AttachUrl1))
{
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
toDoItem.DataId = item.PersonId + "_2";
toDoItem.UrlStr = item.AttachUrl2;
if (!string.IsNullOrEmpty(item.AttachUrl2))
{
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
toDoItem.DataId = item.PersonId + "_3";
toDoItem.UrlStr = item.AttachUrl3;
if (!string.IsNullOrEmpty(item.AttachUrl3))
{
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
toDoItem.DataId = item.PersonId + "_4";
toDoItem.UrlStr = item.AttachUrl4;
if (!string.IsNullOrEmpty(item.AttachUrl4))
{
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
responeData.code = 1;
responeData.message = "保存成功。";
}
@ -100,4 +133,14 @@ namespace WebAPI.Controllers.HSSE
#endregion
}
public class Item
{
public string PersonId { get; set; }
public string AttachUrl1 { get; set; }
public string AttachUrl2 { get; set; }
public string AttachUrl3 { get; set; }
public string AttachUrl4 { get; set; }
public DateTime? newSignTime { get; set; }
}
}