using Aspose.Words; using Aspose.Words.Tables; using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; namespace FineUIPro.Web.Customization.CNCCG.ZHGL.Problem { public partial class ProblemReplyManager : PageBase { public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } /// /// 页面加载 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); this.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId) { this.ProjectId = Request.Params["projectId"]; } this.ucTree.UnitId = this.CurrUser.UnitId; this.ucTree.ProjectId = this.ProjectId; if (!string.IsNullOrEmpty(this.ProjectId)) { this.panelLeftRegion.Hidden = true; ////权限按钮方法 this.GetButtonPower(); } if (this.CurrUser != null && this.CurrUser.PageSize.HasValue) { Grid1.PageSize = this.CurrUser.PageSize.Value; } this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 this.BindGrid(); } } /// /// 公司级树加载 /// /// /// protected void changeTree(object sender, EventArgs e) { this.ProjectId = this.ucTree.ProjectId; //if (string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) //{ // btnNew.Hidden = true; //} this.GetButtonPower(); this.BindGrid(); } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.ProblemReplyManagerMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { //this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { //this.btnMenuDelete.Hidden = false; } } } #endregion /// /// 搜索 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #region 加载数据 protected void BindGrid() { if (string.IsNullOrEmpty(this.ProjectId)) { return; } int unitType = CommonService.GetUnitTypeByUserId(this.CurrUser.UserId); string strSql = @"SELECT F.ProjectId,ProNoticeId, case when F.ProType='1' then a.ProjectName else d.UnitName end as ProjectName ,ProCode,CheckMans, case when F.ProType='1' then c.UnitName else d.UnitName end as UnitName ,CheckStartTime ,CheckEndTime,b.UserName as CreateUserName,F.CreateDate,CreateUser,State,ProType FROM Problem_Notice F LEFT JOIN Base_Project a on F.ProjectId=a.ProjectId LEFT JOIN Sys_User b on F.CreateUser=b.UserId LEFT JOIN Base_Unit c on F.Unitid=c.UnitId LEFT JOIN Base_unit d on F.ProjectId=d.UnitId Where F.State not in ('0','1') "; List listStr = new List(); if (unitType != 0 && string.IsNullOrEmpty(ProjectId)) //公司/分公司 { strSql += " AND ( F.ProjectId='" + CurrUser.UnitId + "' and proType='2') or ( proType='1' and F.Unitid='" + CurrUser.UnitId + "' ) or a.UnitId='" + CurrUser.UnitId + "'"; } else { if (!string.IsNullOrEmpty(ProjectId)) { strSql += " and proType='1' And F.ProjectId='" + ProjectId + "' "; } } if (!string.IsNullOrEmpty(txtProCode.Text.Trim())) { strSql += " AND F.ProCode like @ProCode "; listStr.Add(new SqlParameter("@ProCode", "%" + this.txtProCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(txtProjectName.Text.Trim())) { strSql += " AND ProjectName like @ProjectName or d.unitname like @ProjectName"; listStr.Add(new SqlParameter("@ProjectName", "%" + this.txtProjectName.Text.Trim() + "%")); } //if (drpProject.SelectedValue != BLL.Const._Null) //{ // strSql += " AND F.ProjectId=@ProjectId "; // listStr.Add(new SqlParameter("@ProjectId", drpProject.SelectedValue)); //} strSql += " order by CreateDate desc"; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 状态 protected string ConvertState(object proType, object state) { if (state != null && proType != null) { //项目级 string proTypes = proType.ToString(); if (state.ToString() == "0") { return "待提交"; } else if (state.ToString() == "1") { // return "被检查单位负责人审批"; return "检查组审批"; } else if (state.ToString() == "2") { return "回复单审批"; } else if (state.ToString() == "3") { return "归档"; } else if (state.ToString() == "-1") { return "定稿"; } } return ""; } #endregion #region 编辑 protected void btnMenuView_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; var ProblemNoticeItem = Funs.DB.Problem_Notice.FirstOrDefault(x => x.ProNoticeId == id); //当前项目下的单位 var unitCount = Funs.DB.Project_ProjectUnit.Where(x => x.ProjectId == ProblemNoticeItem.ProjectId && x.UnitId == CurrUser.UnitId).ToList().Count(); if (unitCount==0) { Alert.ShowInTop("您的单位不属于当前项目下,无法查看!", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProblemReplyManagerEdit.aspx?ProNoticeId={0}&Type=1", id, "查看 - "))); } /// /// 双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑 /// protected void EditData() { if(Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; var ProblemNoticeItem = Funs.DB.Problem_Notice.FirstOrDefault(x => x.ProNoticeId == id); if (ProblemNoticeItem != null) { if ((this.btnMenuEdit.Hidden || Convert.ToInt32(ProblemNoticeItem.State) > 1) && ProblemNoticeItem.CreateUser == CurrUser.UserId) ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面 { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProblemReplyManagerEdit.aspx?ProNoticeId={0}&Type=1", id, "查看 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProblemReplyManagerEdit.aspx?ProNoticeId={0}&Type=0", id, "编辑 - "))); } } } #endregion #region 导出 protected void btnMenuOut_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; var model = Funs.DB.Problem_Notice.FirstOrDefault(x => x.ProNoticeId == id); if (model != null) { if (model.ProType == "1") { var ProjectName = BLL.ProjectService.GetProjectByProjectId(model.ProjectId).ShortName; ; var Cdate = Convert.ToDateTime(model.CreateDate); var NowFileName = Cdate.Month.ToString() + "." + Cdate.Day.ToString() + ProjectName + "安全质量检查回复单"; string rootPath = Server.MapPath("~/"); string initTemplatePath = string.Empty; string uploadfilepath = string.Empty; string newUrl = string.Empty; initTemplatePath = "File\\Word\\安全质量检查回复单.docx"; uploadfilepath = rootPath + initTemplatePath; newUrl = uploadfilepath.Replace("安全质量检查回复单.docx", NowFileName + ".docx"); if (File.Exists(newUrl)) { File.Delete(newUrl); } File.Copy(uploadfilepath, newUrl); Document doc = new Aspose.Words.Document(newUrl); Bookmark Bmark = doc.Range.Bookmarks["ProjectName"]; if (Bmark != null) { Bmark.Text = ProjectName; } //存在问题整改情况 Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); bool isbool = builder.MoveToBookmark("tab1"); if (isbool) { builder.StartTable(); builder.RowFormat.Alignment = Aspose.Words.Tables.RowAlignment.Center; builder.CellFormat.Borders.LineStyle = LineStyle.Single; builder.CellFormat.Borders.Color = System.Drawing.Color.Black; builder.Bold = false; } DataTable dt = new DataTable(); dt.Columns.Add("序号", typeof(string)); dt.Columns.Add("存在问题", typeof(string)); dt.Columns.Add("整改情况", typeof(string)); var detailList = Funs.DB.Problem_Notice_C.Where(x => x.ProNoticeId == id).OrderBy(x => x.SortIndex).ToList(); if (detailList.Count > 0) { foreach (var item in detailList) { dt.Rows.Add(new string[] { (item.SortIndex + 1).ToString(), item.QueDescribe, item.ReSituation }); } } builder.RowFormat.Height = 20; builder.Bold = false; builder.InsertCell(); builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//垂直居中对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐 builder.CellFormat.Width = 40; builder.Write("序号"); builder.InsertCell(); builder.CellFormat.Width = 50; builder.Write("存在问题"); builder.InsertCell(); builder.CellFormat.Width = 60; builder.Write("整改情况"); builder.EndRow(); foreach (DataRow row in dt.Rows) { foreach (DataColumn column in dt.Columns) { builder.InsertCell(); builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//垂直居中对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中对齐 if (column.ColumnName == "序号") { builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐 builder.CellFormat.Width = 40; } else if (column.ColumnName == "存在问题") { builder.CellFormat.Width = 50; } else if (column.ColumnName == "整改情况") { builder.CellFormat.Width = 60; } builder.Write(row[column.ColumnName].ToString()); } builder.EndRow(); } builder.EndTable(); //受检单位负责人签名 Bmark = doc.Range.Bookmarks["TestedUnitManSignature"]; if (Bmark != null) { if (!string.IsNullOrEmpty(model.TestedUnitManSignature)) { string url = rootPath + model.TestedUnitManSignature; DocumentBuilder builders = new DocumentBuilder(doc); builders.MoveToBookmark("TestedUnitManSignature"); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builders.InsertImage(url, 100, 30); } } } } Bmark = doc.Range.Bookmarks["TestedUnitManDatetime"]; if (Bmark != null) { if (model.TestedUnitManDatetime != null) { var TestedUnitManDatetime = Convert.ToDateTime(model.TestedUnitManDatetime); Bmark.Text = TestedUnitManDatetime.Year.ToString() + "年" + TestedUnitManDatetime.Month.ToString() + "月" + TestedUnitManDatetime.Day.ToString() + "日"; } } Bmark = doc.Range.Bookmarks["ReviewOpinions"]; if (Bmark != null) { if (!string.IsNullOrEmpty(model.ReviewOpinions)) { Bmark.Text = model.ReviewOpinions; } } //复查人签字 Bmark = doc.Range.Bookmarks["ReviewSignature"]; if (Bmark != null) { if (!string.IsNullOrEmpty(model.ReviewSignature)) { string url = rootPath + model.ReviewSignature; DocumentBuilder builders = new DocumentBuilder(doc); builders.MoveToBookmark("ReviewSignature"); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builders.InsertImage(url, 100, 30); } } } } Bmark = doc.Range.Bookmarks["ReviewDatetime"]; if (Bmark != null) { if (model.ReviewDatetime != null) { var ReviewDatetime = Convert.ToDateTime(model.ReviewDatetime); Bmark.Text = ReviewDatetime.Year.ToString() + "年" + ReviewDatetime.Month.ToString() + "月" + ReviewDatetime.Day.ToString() + "日"; } } //分管领导 Bmark = doc.Range.Bookmarks["LeaderSignature"]; if (Bmark != null) { if (!string.IsNullOrEmpty(model.LeaderSignature)) { string url = rootPath + model.LeaderSignature; DocumentBuilder builders = new DocumentBuilder(doc); builders.MoveToBookmark("LeaderSignature"); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builders.InsertImage(url, 100, 30); } } } } Bmark = doc.Range.Bookmarks["LeaderDatetime"]; if (Bmark != null) { if (model.LeaderDatetime != null) { var LeaderDatetime = Convert.ToDateTime(model.LeaderDatetime); Bmark.Text = LeaderDatetime.Year.ToString() + "年" + LeaderDatetime.Month.ToString() + "月" + LeaderDatetime.Day.ToString() + "日"; } } //检查组 Bmark = doc.Range.Bookmarks["InspectionUnitSignature"]; if (Bmark != null) { if (!string.IsNullOrEmpty(model.InspectionUnitSignature)) { string url = rootPath + model.InspectionUnitSignature; DocumentBuilder builders = new DocumentBuilder(doc); builders.MoveToBookmark("InspectionUnitSignature"); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builders.InsertImage(url, 100, 30); } } } } Bmark = doc.Range.Bookmarks["InspectionUnitDatetime"]; if (Bmark != null) { if (model.InspectionUnitDatetime != null) { var InspectionUnitDatetime = Convert.ToDateTime(model.InspectionUnitDatetime); Bmark.Text = InspectionUnitDatetime.Year.ToString() + "年" + InspectionUnitDatetime.Month.ToString() + "月" + InspectionUnitDatetime.Day.ToString() + "日"; } } #region 安全质量检查回复单 builder = new Aspose.Words.DocumentBuilder(doc); isbool = builder.MoveToBookmark("tab2"); if (isbool) { builder.StartTable(); builder.RowFormat.Alignment = Aspose.Words.Tables.RowAlignment.Center; builder.CellFormat.Borders.LineStyle = LineStyle.Single; builder.CellFormat.Borders.Color = System.Drawing.Color.Black; builder.Bold = false; } builder.RowFormat.Height = 50; builder.Bold = false; foreach (var item in detailList) { //1.问题描述 builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//垂直居中对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中对齐 builder.CellFormat.Width = 100; builder.InsertCell(); builder.Write("整改前"); builder.InsertCell(); builder.Write("整改后"); //下一行 builder.EndRow(); //整改前照片 builder.InsertCell(); builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Top;//顶端对齐 IList sourlistDetail = AttachFileService.GetBeforeFileList(item.ProNoticeCId, BLL.Const.ProblemNoticeManagerMenuId); if (sourlistDetail != null && sourlistDetail.Count > 0) { string AttachUrl = ""; foreach (var items in sourlistDetail) { if (!string.IsNullOrEmpty(items.AttachUrl) && items.AttachUrl.ToLower().EndsWith(".jpg") || items.AttachUrl.ToLower().EndsWith(".jpeg") || items.AttachUrl.ToLower().EndsWith(".png")) { AttachUrl += items.AttachUrl.TrimEnd(',') + ","; } } AttachUrl = AttachUrl.Remove(AttachUrl.LastIndexOf(","), 1); string[] pics = AttachUrl.Split(','); foreach (string picsitem in pics) { string url = rootPath + picsitem.TrimEnd(','); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builder.InsertImage(url, 200, 180); } } else { builder.Write(""); } } } else { builder.Write(""); } builder.InsertCell(); builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Top;//顶端对齐 //整改后照片 sourlistDetail = AttachFileService.GetBeforeFileList(item.ProNoticeCId + "ZGH", BLL.Const.ProblemNoticeManagerMenuId); if (sourlistDetail != null && sourlistDetail.Count > 0) { string AttachUrl = ""; foreach (var items in sourlistDetail) { if (!string.IsNullOrEmpty(items.AttachUrl) && items.AttachUrl.ToLower().EndsWith(".jpg") || items.AttachUrl.ToLower().EndsWith(".jpeg") || items.AttachUrl.ToLower().EndsWith(".png")) { AttachUrl += items.AttachUrl.TrimEnd(',') + ","; } } AttachUrl = AttachUrl.Remove(AttachUrl.LastIndexOf(","), 1); string[] pics = AttachUrl.Split(','); foreach (string picsitem in pics) { string url = rootPath + picsitem.TrimEnd(','); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builder.InsertImage(url, 200, 180); } } else { builder.Write(""); } } } else { builder.Write(""); } //下一行 builder.EndRow(); builder.InsertCell(); builder.CellFormat.Width = 100; builder.Write("问题:" + item.QueDescribe); //2.整改完成情况 builder.InsertCell(); builder.CellFormat.Width = 100; if (!string.IsNullOrEmpty(item.ReSituation)) { builder.Write("整改完成情况:" + item.ReSituation); } else { builder.Write(""); } builder.EndRow(); } #endregion doc.Save(newUrl); string pdfUrl = newUrl.Replace(".docx", ".pdf"); libreOfficeHelp.ToPdf(newUrl, Path.GetDirectoryName(newUrl)); string fileName = Path.GetFileName(pdfUrl); FileInfo info = new FileInfo(pdfUrl); long fileSize = info.Length; System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed"; System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString()); System.Web.HttpContext.Current.Response.TransmitFile(pdfUrl, 0, fileSize); System.Web.HttpContext.Current.Response.Flush(); System.Web.HttpContext.Current.Response.Close(); File.Delete(newUrl); File.Delete(pdfUrl); } else { var ProjectName = BLL.UnitService.GetUnitByUnitId(model.ProjectId).UnitName; ; var Cdate = Convert.ToDateTime(model.CreateDate); var NowFileName = Cdate.Month.ToString() + "." + Cdate.Day.ToString() + ProjectName + "安全质量检查回复单"; string rootPath = Server.MapPath("~/"); string initTemplatePath = string.Empty; string uploadfilepath = string.Empty; string newUrl = string.Empty; initTemplatePath = "File\\Word\\安全质量检查回复单(公司级).docx"; uploadfilepath = rootPath + initTemplatePath; //newUrl = uploadfilepath.Replace(".doc", string.Format("{0}-{1:D4}", code, Grid1.RecordCount - Grid1.PageIndex * Grid1.PageSize - Grid1.SelectedRowIndex) + ".doc"); newUrl = uploadfilepath.Replace("安全质量检查回复单(公司级).docx", NowFileName + ".docx"); if (File.Exists(newUrl)) { File.Delete(newUrl); } File.Copy(uploadfilepath, newUrl); Document doc = new Aspose.Words.Document(newUrl); Bookmark Bmark = doc.Range.Bookmarks["ProjectName"]; if (Bmark != null) { Bmark.Text = ProjectName; } //存在问题整改情况 Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); bool isbool = builder.MoveToBookmark("tab1"); if (isbool) { builder.StartTable(); builder.RowFormat.Alignment = Aspose.Words.Tables.RowAlignment.Center; builder.CellFormat.Borders.LineStyle = LineStyle.Single; builder.CellFormat.Borders.Color = System.Drawing.Color.Black; builder.Bold = false; } DataTable dt = new DataTable(); dt.Columns.Add("序号", typeof(string)); dt.Columns.Add("存在问题", typeof(string)); dt.Columns.Add("整改情况", typeof(string)); var detailList = Funs.DB.Problem_Notice_C.Where(x => x.ProNoticeId == id).OrderBy(x => x.SortIndex).ToList(); if (detailList.Count > 0) { foreach (var item in detailList) { dt.Rows.Add(new string[] { (item.SortIndex + 1).ToString(), item.QueDescribe, item.ReSituation }); } } builder.RowFormat.Height = 20; builder.Bold = false; builder.InsertCell(); builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//垂直居中对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐 builder.CellFormat.Width = 40; builder.Write("序号"); builder.InsertCell(); builder.CellFormat.Width = 50; builder.Write("存在问题"); builder.InsertCell(); builder.CellFormat.Width = 60; builder.Write("整改情况"); builder.EndRow(); foreach (DataRow row in dt.Rows) { foreach (DataColumn column in dt.Columns) { builder.InsertCell(); builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//垂直居中对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中对齐 if (column.ColumnName == "序号") { builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐 builder.CellFormat.Width = 40; } else if (column.ColumnName == "存在问题") { builder.CellFormat.Width = 50; } else if (column.ColumnName == "整改情况") { builder.CellFormat.Width = 60; } builder.Write(row[column.ColumnName].ToString()); } builder.EndRow(); } builder.EndTable(); //受检单位负责人签名 Bmark = doc.Range.Bookmarks["TestedUnitManSignature"]; if (Bmark != null) { if (!string.IsNullOrEmpty(model.TestedUnitManSignature)) { string url = rootPath + model.TestedUnitManSignature; DocumentBuilder builders = new DocumentBuilder(doc); builders.MoveToBookmark("TestedUnitManSignature"); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builders.InsertImage(url, 150, 50); } } } } Bmark = doc.Range.Bookmarks["TestedUnitManDatetime"]; if (Bmark != null) { if (model.TestedUnitManDatetime != null) { var TestedUnitManDatetime = Convert.ToDateTime(model.TestedUnitManDatetime); Bmark.Text = TestedUnitManDatetime.Year.ToString() + "年" + TestedUnitManDatetime.Month.ToString() + "月" + TestedUnitManDatetime.Day.ToString() + "日"; } } Bmark = doc.Range.Bookmarks["TestedUnitManOpinions"]; if (Bmark != null) { if (model.TestedUnitManOpinions != null) { Bmark.Text =model.TestedUnitManOpinions; } } //分管领导 Bmark = doc.Range.Bookmarks["LeaderSignature"]; if (Bmark != null) { if (!string.IsNullOrEmpty(model.LeaderSignature)) { string url = rootPath + model.LeaderSignature; DocumentBuilder builders = new DocumentBuilder(doc); builders.MoveToBookmark("LeaderSignature"); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builders.InsertImage(url, 150, 50); } } } } Bmark = doc.Range.Bookmarks["LeaderDatetime"]; if (Bmark != null) { if (model.LeaderDatetime != null) { var LeaderDatetime = Convert.ToDateTime(model.LeaderDatetime); Bmark.Text = LeaderDatetime.Year.ToString() + "年" + LeaderDatetime.Month.ToString() + "月" + LeaderDatetime.Day.ToString() + "日"; } } Bmark = doc.Range.Bookmarks["LeaderOpinions"]; if (Bmark != null) { if (model.LeaderOpinions != null) { Bmark.Text = model.LeaderOpinions; } } //检查组 Bmark = doc.Range.Bookmarks["InspectionUnitSignature"]; if (Bmark != null) { if (!string.IsNullOrEmpty(model.InspectionUnitSignature)) { string url = rootPath + model.InspectionUnitSignature; DocumentBuilder builders = new DocumentBuilder(doc); builders.MoveToBookmark("InspectionUnitSignature"); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builders.InsertImage(url, 150, 50); } } } } Bmark = doc.Range.Bookmarks["InspectionUnitDatetime"]; if (Bmark != null) { if (model.InspectionUnitDatetime != null) { var InspectionUnitDatetime = Convert.ToDateTime(model.InspectionUnitDatetime); Bmark.Text = InspectionUnitDatetime.Year.ToString() + "年" + InspectionUnitDatetime.Month.ToString() + "月" + InspectionUnitDatetime.Day.ToString() + "日"; } } Bmark = doc.Range.Bookmarks["InspectionUnitOpinions"]; if (Bmark != null) { if (model.InspectionUnitOpinions != null) { Bmark.Text = model.InspectionUnitOpinions; } } #region 安全质量检查回复单 builder = new Aspose.Words.DocumentBuilder(doc); isbool = builder.MoveToBookmark("tab2"); if (isbool) { builder.StartTable(); builder.RowFormat.Alignment = Aspose.Words.Tables.RowAlignment.Center; builder.CellFormat.Borders.LineStyle = LineStyle.Single; builder.CellFormat.Borders.Color = System.Drawing.Color.Black; builder.Bold = false; } builder.RowFormat.Height = 50; builder.Bold = false; foreach (var item in detailList) { builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//垂直居中对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中对齐 builder.CellFormat.Width = 100; builder.InsertCell(); builder.Write("整改前"); builder.InsertCell(); builder.Write("整改后"); //下一行 builder.EndRow(); //整改前照片 builder.InsertCell(); builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Top;//顶端对齐 IList sourlistDetail = AttachFileService.GetBeforeFileList(item.ProNoticeCId, BLL.Const.ProblemNoticeManagerMenuId); if (sourlistDetail != null && sourlistDetail.Count > 0) { string AttachUrl = ""; foreach (var items in sourlistDetail) { if (!string.IsNullOrEmpty(items.AttachUrl) && items.AttachUrl.ToLower().EndsWith(".jpg") || items.AttachUrl.ToLower().EndsWith(".jpeg") || items.AttachUrl.ToLower().EndsWith(".png")) { AttachUrl += items.AttachUrl.TrimEnd(',') + ","; } } AttachUrl = AttachUrl.Remove(AttachUrl.LastIndexOf(","), 1); string[] pics = AttachUrl.Split(','); foreach (string picsitem in pics) { string url = rootPath + picsitem.TrimEnd(','); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builder.InsertImage(url, 200, 180); } } else { builder.Write(""); } } } else { builder.Write(""); } builder.InsertCell(); builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Top;//顶端对齐 //整改后照片 sourlistDetail = AttachFileService.GetBeforeFileList(item.ProNoticeCId + "ZGH", BLL.Const.ProblemNoticeManagerMenuId); if (sourlistDetail != null && sourlistDetail.Count > 0) { string AttachUrl = ""; foreach (var items in sourlistDetail) { if (!string.IsNullOrEmpty(items.AttachUrl) && items.AttachUrl.ToLower().EndsWith(".jpg") || items.AttachUrl.ToLower().EndsWith(".jpeg") || items.AttachUrl.ToLower().EndsWith(".png")) { AttachUrl += items.AttachUrl.TrimEnd(',') + ","; } } AttachUrl = AttachUrl.Remove(AttachUrl.LastIndexOf(","), 1); string[] pics = AttachUrl.Split(','); foreach (string picsitem in pics) { string url = rootPath + picsitem.TrimEnd(','); if (!string.IsNullOrEmpty(url)) { if (File.Exists(url)) { builder.InsertImage(url, 200, 180); } } else { builder.Write(""); } } } else { builder.Write(""); } //下一行 builder.EndRow(); builder.InsertCell(); builder.CellFormat.Width = 100; builder.Write("问题:"+item.QueDescribe); //2.整改完成情况 builder.InsertCell(); builder.CellFormat.Width = 100; if (!string.IsNullOrEmpty(item.ReSituation)) { builder.Write("整改完成情况:" + item.ReSituation); } else { builder.Write(""); } builder.EndRow(); } #endregion doc.Save(newUrl); string pdfUrl = newUrl.Replace(".docx", ".pdf"); libreOfficeHelp.ToPdf(newUrl, Path.GetDirectoryName(newUrl)); string fileName = Path.GetFileName(pdfUrl); FileInfo info = new FileInfo(pdfUrl); long fileSize = info.Length; System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed"; System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString()); System.Web.HttpContext.Current.Response.TransmitFile(pdfUrl, 0, fileSize); System.Web.HttpContext.Current.Response.Flush(); System.Web.HttpContext.Current.Response.Close(); File.Delete(newUrl); File.Delete(pdfUrl); } } else { ShowNotify("只能导出已回复的数据!", MessageBoxIcon.Warning); return; } } #endregion #region 获取当前节点名称 /// /// 获取当前节点名称 /// /// /// protected string GetThisApprove(object proNoticeId) { string result = ""; if (proNoticeId != null) { var list = ProblemNoticeApprove.GetProblem_NoticeApproveByParentId(proNoticeId.ToString()+"reply"); if (list != null) { string userids = string.Join(",", list.Select(x => x.ApproveMan).ToList()); result = UserService.getUserNamesUserIds(userids); } } return result; } #endregion } }