SGGL_JT/SUBQHSE/FineUIPro.Web/HSSE/Check/RectifyNoticesRecheck.aspx.cs

526 lines
22 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 BLL;
using Model;
using Newtonsoft.Json.Linq;
using System;
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
{
#region
public string RectifyNoticesId
{
get
{
return (string)ViewState["RectifyNoticesId"];
}
set
{
ViewState["RectifyNoticesId"] = value;
}
}
#endregion
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RectifyNoticesId = Request.Params["RectifyNoticesId"];
var getRectifyNotices = RectifyNoticesService.GetRectifyNoticesById(RectifyNoticesId);
if (getRectifyNotices != null)
{
this.txtUnit.Text = UnitService.GetUnitNameByUnitId(getRectifyNotices.UnitId);
this.txtWorkArea.Text = UnitWorkService.GetUnitWorkName(getRectifyNotices.WorkAreaId);
this.txtCheckMan.Text = UserService.getUserNamesUserIds(getRectifyNotices.CheckManIds);
this.txtCheckPerson.Text = getRectifyNotices.CheckManNames;
this.txtRectifyNoticesCode.Text = getRectifyNotices.RectifyNoticesCode;
this.txtCheckedDate.Text = getRectifyNotices.CheckedDate.ToString();
this.txtReCheckOpinion.Text = getRectifyNotices.ReCheckOpinion;
this.txtHiddenHazardType.Text = "一般";
if (getRectifyNotices.HiddenHazardType == "2")
{
this.txtHiddenHazardType.Text = "较大";
}
else if (getRectifyNotices.HiddenHazardType == "3")
{
this.txtHiddenHazardType.Text = "重大";
}
if (!string.IsNullOrEmpty(getRectifyNotices.ProfessionalEngineerId))
{
this.drpProfessionalEngineer.Text = UserService.GetUserNameByUserId(getRectifyNotices.ProfessionalEngineerId);
}
if (!string.IsNullOrEmpty(getRectifyNotices.ConstructionManagerId))
{
this.drpConstructionManager.Text = UserService.GetUserNameByUserId(getRectifyNotices.ConstructionManagerId);
}
if (!string.IsNullOrEmpty(getRectifyNotices.ProjectManagerId))
{
this.drpProjectManager.Text = UserService.GetUserNameByUserId(getRectifyNotices.ProjectManagerId);
}
this.lbDutyPerson.Text = UserService.GetUserNameByUserId(getRectifyNotices.DutyPersonId);
if (Funs.DB.Check_RectifyNoticesItem.FirstOrDefault(x =>x.RectifyNoticesId == RectifyNoticesId && (!x.IsRectify.HasValue || x.IsRectify == false)) == null)
{
this.rdbIsAgree.SelectedValue = "true";
}
else
{
this.rdbIsAgree.SelectedValue = "false";
}
getControlShow();
}
BindGrid();
BindGrid1();
}
else
{
string arg = GetRequestEventArgument(); // 此函数所在文件PageBase.cs
if (arg == "UPDATE_SUMMARY")
{
getControlShow();
}
}
}
/// <summary>
///
/// </summary>
public void BindGrid()
{
if (!string.IsNullOrEmpty(this.RectifyNoticesId))
{
string strSql = @"select RectifyNoticesItemId, RectifyNoticesId,Rectify.RectifyName as RectifyId, WrongContent, Requirement, LimitTime, RectifyResults
,IsRectify,(CASE WHEN IsRectify=1 THEN '合格' WHEN IsRectify=0 THEN '不合格' ELSE '' END) AS IsRectifyName
from [dbo].[Check_RectifyNoticesItem] item left join Technique_Rectify Rectify on Rectify.RectifyId=item.RectifyId ";
List<SqlParameter> listStr = new List<SqlParameter>();
strSql += "where RectifyNoticesId = @RectifyNoticesId";
listStr.Add(new SqlParameter("@RectifyNoticesId", RectifyNoticesId));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
else
{
Grid1.DataSource = null;
Grid1.DataBind();
}
}
/// <summary>
///
/// </summary>
public void BindGrid1()
{
if (!string.IsNullOrEmpty(this.RectifyNoticesId))
{
string strSql = @"select FlowOperateId, RectifyNoticesId, OperateName, OperateManId, OperateTime, IsAgree, Opinion,S.UserName
,(case when IsAgree=0 then '不同意' else '同意' end) as IsAgreeName
from Check_RectifyNoticesFlowOperate C left join Sys_User S on C.OperateManId=s.UserId ";
List<SqlParameter> listStr = new List<SqlParameter>();
strSql += "where RectifyNoticesId= @RectifyNoticesId";
listStr.Add(new SqlParameter("@RectifyNoticesId", RectifyNoticesId));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
var table = this.GetPagedDataTable(gvFlowOperate, tb);
gvFlowOperate.DataSource = table;
gvFlowOperate.DataBind();
}
else
{
Grid1.DataSource = null;
Grid1.DataBind();
}
}
#region
/// <summary>
/// 获取整改前图片(放于Img中)
/// </summary>
/// <param name="registrationId"></param>
/// <returns></returns>
protected string ConvertImageUrlByImage(object RectifyNoticesItemId)
{
string url = string.Empty;
if (RectifyNoticesItemId != null)
{
var RectifyNoticesItem = BLL.AttachFileService.GetAttachFile(RectifyNoticesItemId.ToString() + "#1", BLL.Const.ProjectRectifyNoticesMenuId);
if (RectifyNoticesItem != null)
{
url = BLL.UploadAttachmentService.ShowImage("../../", RectifyNoticesItem.AttachUrl);
}
}
return url;
}
/// <summary>
/// 获取整改后图片
/// </summary>
/// <param name="registrationId"></param>
/// <returns></returns>
protected string ConvertImgUrlByImage(object RectifyNoticesItemId)
{
string url = string.Empty;
if (RectifyNoticesItemId != null)
{
var RectifyNoticesItem = BLL.AttachFileService.GetAttachFile(RectifyNoticesItemId.ToString() + "#2", BLL.Const.ProjectRectifyNoticesMenuId);
if (RectifyNoticesItem != null)
{
url = BLL.UploadAttachmentService.ShowImage("../../", RectifyNoticesItem.AttachUrl);
}
}
return url;
}
#endregion
#region
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
SaveRectifyNotices(Const.BtnSave);
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSubmit_Click(object sender, EventArgs e)
{
SaveRectifyNotices(Const.BtnSubmit);
}
/// <summary>
/// 保存方法
/// </summary>
/// <param name="saveType"></param>
private void SaveRectifyNotices(string saveType)
{
var getRectifyNotices = RectifyNoticesService.GetRectifyNoticesById(this.RectifyNoticesId);
if (getRectifyNotices != null)
{
var getAllItem = from x in Funs.DB.Check_RectifyNoticesItem
where x.RectifyNoticesId == getRectifyNotices.RectifyNoticesId
select x;
if (getAllItem.Count() > 0)
{
foreach (JObject mergedRow in Grid1.GetModifiedData())
{
JObject values = mergedRow.Value<JObject>("values");
string rectifyNoticesItemId = mergedRow.Value<string>("id");
string isRectify = values.Value<string>("IsRectify");
var getUpdateItem = getAllItem.FirstOrDefault(x => x.RectifyNoticesItemId == rectifyNoticesItemId);
if (getUpdateItem != null)
{
if (isRectify == "合格")
{
getUpdateItem.IsRectify = true;
}
else
{
getUpdateItem.IsRectify = false;
}
Funs.DB.SubmitChanges();
}
}
}
getRectifyNotices.ReCheckOpinion = this.txtReCheckOpinion.Text;
getRectifyNotices.ReCheckDate = DateTime.Now;
if (saveType == Const.BtnSubmit)
{
bool isAgree = false;
if (getAllItem.FirstOrDefault(x => !x.IsRectify.HasValue || x.IsRectify == false) == null)
{
isAgree = true;
}
if (isAgree)
{
getRectifyNotices.States = Const.State_5;
getRectifyNotices.ReCheckDate = DateTime.Now;
//// 回写专项检查明细表
var getcheck = Funs.DB.Check_CheckSpecialDetail.Where(x => x.DataId.Contains(getRectifyNotices.RectifyNoticesId));
if (getcheck.Count() > 0)
{
foreach (var item in getcheck)
{
item.CompleteStatus = true;
item.CompletedDate = DateTime.Now;
Funs.DB.SubmitChanges();
}
//// 根据明细ID判断是否全部整改完成 并更新专项检查状态
Check_CheckSpecialService.UpdateCheckSpecialStates(getcheck.FirstOrDefault().CheckSpecialId);
}
}
else
{
getRectifyNotices.States = Const.State_2;
getRectifyNotices.UnitHeadManDate = null;
getRectifyNotices.CompleteDate = null;
getRectifyNotices.ProfessionalEngineerTime2 = null;
getRectifyNotices.ConstructionManagerTime2 = null;
getRectifyNotices.ProjectManagerTime2 = null;
}
Model.Check_RectifyNoticesFlowOperate newOItem = new Model.Check_RectifyNoticesFlowOperate
{
FlowOperateId = SQLHelper.GetNewID(),
RectifyNoticesId = getRectifyNotices.RectifyNoticesId,
OperateManId = this.CurrUser.UserId,
OperateTime = DateTime.Now,
OperateName = "安全经理/安全工程师复查",
IsAgree = isAgree,
Opinion = this.txtReCheckOpinion.Text.Trim(),
};
Funs.DB.Check_RectifyNoticesFlowOperate.InsertOnSubmit(newOItem);
}
Funs.DB.SubmitChanges();
// Project_HSSEData_HSSEService.StatisticalData(this.CurrUser.LoginProjectId, Project_HSSEData_HSSEService.HSSEDateType.HiddenDangerTroubleshooting);
// Project_HSSEData_HiddenDangerDetailService.StatisticalData(this.CurrUser.LoginProjectId);
ShowNotify(saveType + "成功!", MessageBoxIcon.Success);
if (string.IsNullOrEmpty(Request.Params["Main"]))
{
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
PageContext.RegisterStartupScript(String.Format("window.close();"));
}
}
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rdbIsAgree_SelectedIndexChanged(object sender, EventArgs e)
{
getControlShow();
}
/// <summary>
///
/// </summary>
private void getControlShow()
{
if (this.rdbIsAgree.SelectedValue == "true")
{
this.step1_person2.Hidden = false;
this.lbDutyPerson.Hidden = true;
}
else
{
this.step1_person2.Hidden = true;
this.lbDutyPerson.Hidden = false;
}
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);
}
}
}
}