using Aspose.Words; using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; namespace FineUIPro.Web.HSSE.ActionPlan { public partial class ActionPlanList : PageBase { #region 项目主键 /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); ////权限按钮方法 this.GetButtonPower(); this.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId) { this.ProjectId = Request.Params["projectId"]; } this.btnNew.OnClientClick = Window1.GetShowReference("ActionPlanListEdit.aspx") + "return false;"; // 绑定表格 this.BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { if (!string.IsNullOrEmpty(this.ProjectId)) { string strSql = "SELECT ActionPlanList.ActionPlanListId,ActionPlanList.ProjectId,ActionPlanListCode,ActionPlanList.ActionPlanListName,ActionPlanList.VersionNo,(CASE ActionPlanList.ProjectType WHEN '1' THEN 'EPC' WHEN '2' THEN 'EPCM' WHEN '3' THEN 'C' WHEN '4' THEN '其他' END ) AS ProjectType,ActionPlanList.ActionPlanListContents,ActionPlanList.CompileMan,Users.PersonName AS CompileManName, ActionPlanList.CompileDate,ActionPlanList.States" + @" FROM ActionPlan_ActionPlanList AS ActionPlanList " + @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON ActionPlanList.ActionPlanListId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1" + @" LEFT JOIN Person_Persons AS OperateUser ON FlowOperate.OperaterId=OperateUser.PersonId " + @" LEFT JOIN Person_Persons AS Users ON Users.PersonId = ActionPlanList.CompileMan " + @" WHERE 1=1 "; List listStr = new List(); strSql += " AND ActionPlanList.ProjectId = @ProjectId"; listStr.Add(new SqlParameter("@ProjectId", this.ProjectId)); if (!string.IsNullOrEmpty(Request.Params["projectId"])) ///是否文件柜查看页面传项目值 { strSql += " AND ActionPlanList.States = @States"; ///状态为已完成 listStr.Add(new SqlParameter("@States", BLL.Const.State_2)); } if (!string.IsNullOrEmpty(this.txtActionPlanListCode.Text.Trim())) { strSql += " AND ActionPlanListCode LIKE @ActionPlanListCode"; listStr.Add(new SqlParameter("@ActionPlanListCode", "%" + this.txtActionPlanListCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtActionPlanListName.Text.Trim())) { strSql += " AND ActionPlanListName LIKE @ActionPlanListName"; listStr.Add(new SqlParameter("@ActionPlanListName", "%" + this.txtActionPlanListName.Text.Trim() + "%")); } 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 void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { BindGrid(); } /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, EventArgs e) { BindGrid(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); BLL.LogService.AddSys_Log(this.CurrUser, string.Empty, string.Empty, BLL.Const.ProjectActionPlanListMenuId, Const.BtnQuery); } #endregion #region 编辑 /// /// 双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID.Split(',')[0]; Model.ActionPlan_ActionPlanList actionPlanList = ActionPlanListService.GetActionPlanListById(id); if (actionPlanList.States == Const.ActionPlanList_Complete) { Alert.ShowInTop("该文件已经审批完成,无法操作,请右键查看!", MessageBoxIcon.Warning); return; } else if (actionPlanList.States == Const.ActionPlanList_Compile) { if (actionPlanList.CompileMan == CurrUser.PersonId || CurrUser.PersonId == Const.sysglyId) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ActionPlanListEdit.aspx?actionPlanListId={0}", id))); } else { Alert.ShowInTop("您不是编制人,无法操作!请右键查看", MessageBoxIcon.Warning); return; } } else if (actionPlanList.States == Const.ActionPlanList_Audit || actionPlanList.States == Const.ActionPlanList_ReCompile || actionPlanList.States == Const.ActionPlanList_Review) { Model.ActionPlan_ActionPlanListApprove approve = ActionPlanListApproveService.GetActionPlanListApproveByApproveMan(id, CurrUser.PersonId); if (approve != null || CurrUser.PersonId == Const.sysglyId) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ActionPlanListEdit.aspx?actionPlanListId={0}", id))); return; //Response.Redirect("ActionPlanListAudit.aspx?actionPlanListId=" + id); //PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckListView.aspx?CheckControlCode={0}", id, "查看 - "))); } else { if (actionPlanList.CompileMan.Equals(CurrUser.PersonId)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ActionPlanListEdit.aspx?actionPlanListId={0}", id))); } else { Alert.ShowInTop("您不是办理用户,无法操作!请右键查看", MessageBoxIcon.Warning); return; } } } } #endregion protected void btnMenuView_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID.Split(',')[0]; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ActionPlanListView.aspx?ActionPlanListId={0}", id))); } #region 删除 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { bool isShow = false; if (Grid1.SelectedRowIndexArray.Length == 1) { isShow = true; } foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); if (this.judgementDelete(rowID, isShow)) { var getV = BLL.ActionPlanListService.GetActionPlanListById(rowID); if (getV != null) { BLL.LogService.AddSys_Log(this.CurrUser, getV.ActionPlanListCode, getV.ActionPlanListId, BLL.Const.ProjectActionPlanListMenuId, Const.BtnDelete); BLL.ActionPlanListService.DeleteActionPlanListById(rowID); } } } BindGrid(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content); } return false; } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.ProjectActionPlanListMenuId); 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 #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("安全实施计划" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; this.Grid1.PageSize = 5000; this.BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } #endregion /// /// 把办理人转换代号为文字形式 /// /// /// /// public static string ConvertApproveMan(object ActionPlanListId) { string name = string.Empty; if (ActionPlanListId != null) { var approves = BLL.ActionPlanListApproveService.GetActionPlanListApprovesNotHandleList(ActionPlanListId.ToString()); foreach (var item in approves) { name += BLL.Person_PersonsService.GetPersonsNameById(item.ApproveMan) + ","; } if (!string.IsNullOrEmpty(name)) { name = name.Substring(0, name.Length - 1); } } return name; } #region 导出详细 /// /// /// /// btnPrinter_Click /// protected void btnPrinter_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string Id = Grid1.SelectedRowID; Model.ActionPlan_ActionPlanList actionPlanList = BLL.ActionPlanListService.GetActionPlanListById(Id); if (actionPlanList.States != BLL.Const.ActionPlanList_Complete && this.CurrUser.PersonId != BLL.Const.sysglyId && this.CurrUser.PersonId != BLL.Const.hfnbdId) { Alert.ShowInTop("状态必须为审批完成的才能导出!", MessageBoxIcon.Warning); return; } if (actionPlanList != null) { try { string rootPath = Server.MapPath("~/"); string initTemplatePath = string.Empty; string uploadfilepath = string.Empty; string newUrl = string.Empty; string filePath = string.Empty; initTemplatePath = "File\\Word\\ZHGL\\项目安全生产策划书评审表.doc"; uploadfilepath = rootPath + initTemplatePath; string projectName = BLL.ProjectService.GetProjectNameByProjectId(actionPlanList.ProjectId); if (!string.IsNullOrEmpty(projectName)) { projectName = "(" + projectName + ")"; } else { projectName = "(无项目)"; } projectName = projectName.Replace("/", "_"); newUrl = uploadfilepath.Replace(".doc", projectName + ".doc"); filePath = uploadfilepath.Replace(".doc", projectName + ".pdf"); if (File.Exists(newUrl)) { File.Delete(newUrl); } File.Copy(uploadfilepath, newUrl); ///更新书签 Document doc = new Aspose.Words.Document(newUrl); //写入第一行 Bookmark bookmarkProjectName = doc.Range.Bookmarks["ProjectName"]; using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var project = ProjectService.GetProjectByProjectId(actionPlanList.ProjectId); var ActionPlan_ActionPlanListApproveList = db.ActionPlan_ActionPlanListApprove.Where(x => x.ActionPlanListId == Id && x.ApproveType == "2").ToList(); if (bookmarkProjectName != null) { if (project != null) { if (project.ProjectName.Length > 20 && ActionPlan_ActionPlanListApproveList.Count != 0) { bookmarkProjectName.Text = project.ProjectName.Substring(0, 20) + "\n" + project.ProjectName.Substring(20); } else { bookmarkProjectName.Text = project.ProjectName; } } } Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); builder.MoveToBookmark("tab"); builder.StartTable(); builder.CellFormat.Borders.LineStyle = LineStyle.Single; builder.CellFormat.Borders.Color = System.Drawing.Color.Black; builder.Bold = false; builder.RowFormat.Height = 20; builder.Font.Size = 9; #region 工程名称和项目部编制人员 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 = 100; builder.Font.Bold = true; builder.Write("项目部编制人员"); 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 = 300; builder.Font.Bold = false; var getCompileMan = Person_PersonsService.GetPerson_PersonsById(actionPlanList.CompileMan); if (!string.IsNullOrEmpty(getCompileMan.SignatureUrl) && File.Exists(rootPath + getCompileMan.SignatureUrl)) { var file = rootPath + getCompileMan.SignatureUrl; builder.InsertImage(file, 80, 20); } else { builder.Write(getCompileMan.PersonName); } builder.EndRow(); #endregion if (ActionPlan_ActionPlanListApproveList.Count > 0) { #region 项目部审核人 for (int i = 0; i < ActionPlan_ActionPlanListApproveList.Count; i++) { //一行两个 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 = 100; builder.Font.Bold = true; builder.Write("项目部审核人"); 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;//水平居中对齐 var getApproveMan = Person_PersonsService.GetPerson_PersonsById(ActionPlan_ActionPlanListApproveList[i].ApproveMan); //判断是不是最后一个 if (ActionPlan_ActionPlanListApproveList.Count == i + 1) { builder.CellFormat.Width = 150; builder.Font.Bold = false; if (!string.IsNullOrEmpty(getApproveMan.SignatureUrl) && File.Exists(rootPath + getApproveMan.SignatureUrl)) { var file = rootPath + getApproveMan.SignatureUrl; builder.InsertImage(file, 80, 20); } else { builder.Write(getApproveMan.PersonName); } 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 = 150; builder.Write(""); } else { builder.CellFormat.Width = 150; builder.Font.Bold = false; if (!string.IsNullOrEmpty(getApproveMan.SignatureUrl) && File.Exists(rootPath + getApproveMan.SignatureUrl)) { var file = rootPath + getApproveMan.SignatureUrl; builder.InsertImage(file, 80, 20); } else { builder.Write(getApproveMan.PersonName); } } //判断还有没有数据 有的话继续加 if (ActionPlan_ActionPlanListApproveList.Count > i + 1) { 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 = 100; builder.Font.Bold = true; builder.Write("项目部审核人"); 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 = 50; var getApproveMan2 = Person_PersonsService.GetPerson_PersonsById(ActionPlan_ActionPlanListApproveList[i + 1].ApproveMan); builder.Font.Bold = false; if (!string.IsNullOrEmpty(getApproveMan2.SignatureUrl) && File.Exists(rootPath + getApproveMan2.SignatureUrl)) { var file = rootPath + getApproveMan2.SignatureUrl; builder.InsertImage(file, 80, 20); } else { builder.Write(getApproveMan2.PersonName); } builder.EndRow(); i += 1; } else { //没有数据 builder.EndRow(); } } #endregion } else { } var approves = db.ActionPlan_ActionPlanListApprove.Where(x => x.ActionPlanListId == Id && x.ApproveType == BLL.Const.ActionPlanList_Reviewing).ToList(); var ActionPlan_ActionPlanListApproveList2 = db.ActionPlan_ActionPlanListApprove.Where(x => x.ActionPlanListId == Id && x.ApproveType == "6").ToList(); DateTime date = DateTime.Now; if (ActionPlan_ActionPlanListApproveList2.Count > 0 || approves.Count > 0) { date = ActionPlan_ActionPlanListApproveList2.OrderByDescending(x => x.ApproveDate).FirstOrDefault().ApproveDate.Value; #region 主要评审部门 //主要评审部门 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 = 400; builder.Font.Bold = true; builder.Write("主要评审部门"); builder.EndRow(); #region 主要评审部门 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 = 150; builder.Font.Bold = true; builder.Write("评审部门"); 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 = 100; builder.Font.Bold = true; builder.Write("评审意见"); 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 = 150; builder.Font.Bold = true; builder.Write("评审部门负责人/日期"); builder.EndRow(); #endregion foreach (var item in approves) { if (item.ApproveDate != null) { //部门名称 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 = 150; builder.Font.Bold = false; builder.Write("施工管理部"); //评审意见 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 = 100; builder.Font.Bold = false; if (!string.IsNullOrEmpty(item.ApproveIdea)) { builder.Write(item.ApproveIdea); } else { builder.Write("无"); } //评审日期 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 = 150; builder.Font.Bold = false; if (item.ApproveDate != null) { var getUser = Person_PersonsService.GetPerson_PersonsById(item.ApproveMan); if (!string.IsNullOrEmpty(getUser.SignatureUrl) && File.Exists(rootPath + getUser.SignatureUrl)) { var file = rootPath + getUser.SignatureUrl; builder.InsertImage(file, 80, 20); builder.Write(item.ApproveDate.ToString().Split(' ')[0]); } else { builder.Write(getUser.PersonName + " " + item.ApproveDate.ToString().Split(' ')[0]); } } else { builder.Write(""); } builder.EndRow(); } } foreach (var item in ActionPlan_ActionPlanListApproveList2) { if (item.ApproveMan != "905a75d6-e733-449f-9742-4dcd71e8d2e1" && item.DepartId != BLL.Const.Depart_CompanyLeaderId && item.ApproveDate != null) { //部门名称 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 = 150; var departModel = db.Base_Depart.FirstOrDefault(x => x.DepartId == item.DepartId); builder.Font.Bold = false; if (departModel != null) { builder.Write(departModel.DepartName); } //评审意见 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 = 100; builder.Font.Bold = false; if (!string.IsNullOrEmpty(item.ApproveIdea)) { builder.Write(item.ApproveIdea); } else { builder.Write("无"); } //评审日期 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 = 150; builder.Font.Bold = false; if (item.ApproveDate != null) { var getUser = Person_PersonsService.GetPerson_PersonsById(item.ApproveMan); if (!string.IsNullOrEmpty(getUser.SignatureUrl) && File.Exists(rootPath + getUser.SignatureUrl)) { var file = rootPath + getUser.SignatureUrl; builder.InsertImage(file, 80, 20); builder.Write(item.ApproveDate.ToString().Split(' ')[0]); } else { builder.Write(getUser.PersonName + " " + item.ApproveDate.ToString().Split(' ')[0]); } } else { builder.Write(""); } builder.EndRow(); } } #endregion } #region 最后2行审核 //增加审核 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 = 100; builder.Font.Bold = true; builder.Write("审核"); //公司安全总监/部门负责人 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.Bottom;//底部对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中对齐 builder.CellFormat.Width = 300; builder.Font.Bold = true; builder.RowFormat.Height = 40; var AQApprove = (from x in db.ActionPlan_ActionPlanListApprove where x.ApproveMan == "905a75d6-e733-449f-9742-4dcd71e8d2e1" select x).FirstOrDefault(); if (AQApprove != null) { builder.Write(AQApprove.ApproveIdea + "\n\n"); } builder.Write("公司安全总监/部门负责人:"); var personAQ = BLL.Person_PersonsService.GetPerson_PersonsById("905a75d6-e733-449f-9742-4dcd71e8d2e1"); //安全总监任学宁 if (!string.IsNullOrEmpty(personAQ.SignatureUrl) && File.Exists(rootPath + personAQ.SignatureUrl)) { var file = rootPath + personAQ.SignatureUrl; builder.InsertImage(file, 80, 20); builder.Write(date.ToString().Split(' ')[0]); } else { builder.Write(personAQ.PersonName + " " + date.ToString().Split(' ')[0]); } //builder.Write(" 年"); //builder.Write(" 月"); //builder.Write(" 日"); builder.EndRow(); 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 = 100; builder.Font.Bold = true; builder.Write("审批"); //公司安全总监/部门负责人 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.Bottom;//底部对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中对齐 builder.CellFormat.Width = 300; builder.Font.Bold = true; builder.RowFormat.Height = 40; var GSLDApprove = (from x in db.ActionPlan_ActionPlanListApprove join y in db.Person_Persons on x.ApproveMan equals y.PersonId where x.ActionPlanListId == Id && x.DepartId == BLL.Const.Depart_CompanyLeaderId select x).FirstOrDefault(); if (GSLDApprove != null) { builder.Write(GSLDApprove.ApproveIdea + "\n\n"); } builder.Write("公司主管生产/安全领导:"); if (GSLDApprove != null) { var personGSLD = BLL.Person_PersonsService.GetPerson_PersonsById(GSLDApprove.ApproveMan); if (!string.IsNullOrEmpty(personGSLD.SignatureUrl) && File.Exists(rootPath + personGSLD.SignatureUrl)) { var file = rootPath + personGSLD.SignatureUrl; builder.InsertImage(file, 80, 20); builder.Write(GSLDApprove.ApproveDate.ToString().Split(' ')[0]); } else { builder.Write(personGSLD.PersonName + " " + GSLDApprove.ApproveDate.ToString().Split(' ')[0]); } } else { builder.Write(" 年"); builder.Write(" 月"); builder.Write(" 日"); } builder.EndRow(); builder.Font.Bold = false; builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中对齐 builder.Write("(公司主要评审部门指:安全质量监督部、运营管理部、施工管理部、工艺设计部、财务资产部、采购部、控制部等)"); #endregion } doc.Save(newUrl); //生成PDF文件 string pdfUrl = newUrl.Replace(".doc", ".pdf"); Document doc1 = new Aspose.Words.Document(newUrl); //验证参数 if (doc1 == null) { throw new Exception("Word文件无效"); } doc1.Save(pdfUrl, Aspose.Words.SaveFormat.Pdf);//还可以改成其它格式 string fileName = Path.GetFileName(filePath); FileInfo info = new FileInfo(pdfUrl); 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(pdfUrl, 0, fileSize); Response.Flush(); Response.Close(); File.Delete(newUrl); File.Delete(pdfUrl); } catch (Exception ex) { throw ex; } } else { Alert.ShowInTop("未查询到数据,请检查网络!", MessageBoxIcon.Warning); return; } } private string man(string manName) { string appman = string.Empty; if (Person_PersonsService.GetPerson_PersonsById(manName.ToString()) != null) { appman = Person_PersonsService.GetPerson_PersonsById(manName.ToString()).PersonName; } return appman; } #endregion } }