using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; using Aspose.Words; using System.IO; namespace FineUIPro.Web.CQMS.Meeting { public partial class SpecialMeetingFile : PageBase { /// /// 项目id /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { // 表头过滤 //FilterDataRowItem = FilterDataRowItemImplement; if (!IsPostBack) { this.ProjectId = this.CurrUser.LoginProjectId; ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } #endregion protected DataTable insklistData() { string strSql = @"SELECT ins.*,un.UnitName,u.PersonName as CompileManName" + @" FROM Meeting_CQMSMeeting ins" + @" left join Base_Unit un on un.UnitId = ins.UnitId" + @" left join Person_Persons u on u.PersonId = ins.CompileMan" + @" where ins.ProjectId=@ProjectId and ins.MeetingType='S' and ins.State=@State "; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); listStr.Add(new SqlParameter("@State", BLL.Const.CQMSMeeting_Complete)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); return tb; } /// /// 绑定数据 /// public void BindGrid() { DataTable tb = insklistData(); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 过滤表头、排序、分页、关闭窗口 /// /// 过滤表头 /// /// /// protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { //Grid1.SortDirection = e.SortDirection; //Grid1.SortField = e.SortField; BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); string str = this.hdID.Text; if (!string.IsNullOrEmpty(str)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SpecialMeetingEdit.aspx?MeetingId={0}", str, "查看 - "))); } this.hdID.Text = string.Empty; } #endregion #region Grid双击事件 /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { btnMenuView_Click(null, null); } #endregion protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { object[] keys = Grid1.DataKeys[e.RowIndex]; string fileId = string.Empty; if (keys == null) { return; } else { fileId = keys[0].ToString(); } if (e.CommandName == "export") { string rootPath = Server.MapPath("~/"); string initTemplatePath = string.Empty; string uploadfilepath = string.Empty; string newUrl = string.Empty; string filePath = string.Empty; Model.Meeting_CQMSMeeting meeting = CQMS_MeetingService.GetCQMSMeetingById(fileId); initTemplatePath = Const.CQMSMeetingTemplateUrl; uploadfilepath = rootPath + initTemplatePath; newUrl = uploadfilepath.Replace(".doc", meeting.MeetingCode.Replace("/", "-") + ".doc"); filePath = initTemplatePath.Replace(".doc", meeting.MeetingCode.Replace("/", "-") + ".pdf"); File.Copy(uploadfilepath, newUrl); //更新书签内容 Document doc = new Aspose.Words.Document(newUrl); Bookmark bookmarkProjectName = doc.Range.Bookmarks["ProjectName"]; if (bookmarkProjectName != null) { var project = ProjectService.GetProjectByProjectId(meeting.ProjectId); if (project != null) { bookmarkProjectName.Text = project.ProjectName; } } Bookmark bookmarkMeetingCode = doc.Range.Bookmarks["MeetingCode"]; if (bookmarkMeetingCode != null) { bookmarkMeetingCode.Text = meeting.MeetingCode; } Bookmark bookmarkMeetingDate = doc.Range.Bookmarks["MeetingDate"]; if (bookmarkMeetingDate != null) { if (meeting.MeetingDate != null) { bookmarkMeetingDate.Text = string.Format("{0:yyyy-MM-dd}", meeting.MeetingDate); } } Bookmark bookmarkPlace = doc.Range.Bookmarks["Place"]; if (bookmarkPlace != null) { bookmarkPlace.Text = meeting.Place; } Bookmark bookmarkHostMan = doc.Range.Bookmarks["HostMan"]; if (bookmarkHostMan != null) { bookmarkHostMan.Text = ConvertHostMan(meeting.HostMan); } Bookmark bookmarkAttentPerson = doc.Range.Bookmarks["AttentPerson"]; if (bookmarkAttentPerson != null) { bookmarkAttentPerson.Text = ConvertHostMan(meeting.AttentPerson); } Bookmark bookmarkMeetingTheme = doc.Range.Bookmarks["MeetingTheme"]; if (bookmarkMeetingTheme != null) { bookmarkMeetingTheme.Text = meeting.MeetingTheme; } Bookmark bookmarkMeetingContents = doc.Range.Bookmarks["MeetingContents"]; if (bookmarkMeetingContents != null) { bookmarkMeetingContents.Text = meeting.MeetingContents; } var compileApprove = (from x in Funs.DB.Meeting_CQMSMeetingApprove where x.MeetingId == fileId && x.ApproveType == Const.CQMSMeeting_Compile orderby x.ApproveDate descending select x).FirstOrDefault(); var auditApprove = (from x in Funs.DB.Meeting_CQMSMeetingApprove where x.MeetingId == fileId && x.ApproveType == Const.CQMSMeeting_Audit orderby x.ApproveDate descending select x).FirstOrDefault(); Bookmark bookmarkCompileMan = doc.Range.Bookmarks["CompileMan"]; if (bookmarkCompileMan != null) { var user = Person_PersonsService.GetPerson_PersonsById(compileApprove.ApproveMan); if (user != null) { bookmarkCompileMan.Text = user.PersonName; } } Bookmark bookmarkAuditMan = doc.Range.Bookmarks["AuditMan"]; if (bookmarkAuditMan != null) { var user = Person_PersonsService.GetPerson_PersonsById(auditApprove.ApproveMan); if (user != null) { bookmarkAuditMan.Text = user.PersonName; } } 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); } if (e.CommandName.Equals("download")) { string menuId = Const.CQMSSpecialMeetingMenuId; PageContext.RegisterStartupScript(Windowtt.GetShowReference( String.Format("../../AttachFile/webuploader.aspx?type=-1&source=1&toKeyId={0}&path=FileUpload/CQMS/Meeting&menuId={1}", fileId, menuId))); } } // //获取主持人 // // // protected string ConvertHostMan(object HostMan) { string names = string.Empty; if (HostMan != null) { string[] strs = HostMan.ToString().Split(','); foreach (var item in strs) { names += BLL.Person_PersonsService.GetPersonsNameById(item) + ","; } if (!string.IsNullOrEmpty(names)) { names = names.Substring(0, names.Length - 1); } } return names; } /// /// 把状态转换代号为文字形式 /// /// /// protected string ConvertState(object state) { if (state != null) { if (state.ToString() == BLL.Const.CQMSMeeting_ReCompile) { return "重新编制"; } else if (state.ToString() == BLL.Const.CQMSMeeting_Compile) { return "编制"; } else if (state.ToString() == BLL.Const.CQMSMeeting_Audit) { return "总包质量经理审批"; } else if (state.ToString() == BLL.Const.CQMSMeeting_Complete) { return "审批完成"; } else { return ""; } } return ""; } // //获取办理人姓名 // // // protected string ConvertMan(object MeetingId) { if (MeetingId != null) { Model.Meeting_CQMSMeetingApprove a = BLL.CQMS_MeetingApproveService.GetCQMSMeetingApproveByMeetingId(MeetingId.ToString()); if (a != null) { if (a.ApproveMan != null) { return BLL.Person_PersonsService.GetPersonsNameById(a.ApproveMan); } } else { return ""; } } return ""; } protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { } protected void btnMenuView_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; var ins = BLL.CQMS_MeetingService.GetCQMSMeetingById(id); if (ins != null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SpecialMeetingView.aspx?MeetingId={0}", id, "查看 - "))); } } protected void btnQuery_Click(object sender, EventArgs e) { BindGrid(); } protected void btnRset_Click(object sender, EventArgs e) { BindGrid(); } } }