2023-03-03 合同打印修改,在线编辑文档控件增加

This commit is contained in:
2023-03-03 10:46:14 +08:00
parent 1cf35eb878
commit 1a8b21b64f
38 changed files with 3465 additions and 695 deletions
@@ -1,4 +1,7 @@
using System.Collections.Generic;
using Aspose.Words;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace BLL
@@ -157,7 +160,120 @@ namespace BLL
return list;
}
public static Document Print(string Id)
{
string rootPath = Funs.RootPath;
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = "File\\Word\\PHTGL\\招标文件审批表.docx";
var lwfirwork = PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(Id);
if (lwfirwork != null)
{
if (PHTGL_ActionPlanReviewService.IsSpecialProject(lwfirwork.ProjectId))
{
initTemplatePath = "File\\Word\\PHTGL\\招标文件审批表LW.docx";
}
}
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".docx", string.Format("{0:yyyy-MM}", DateTime.Now) + ".docx");
filePath = initTemplatePath.Replace(".docx", string.Format("{0:yyyy-MM}", DateTime.Now) + ".pdf");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
Document doc = new Aspose.Words.Document(newUrl);
///更新书签
var getFireWork = PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(Id);
var Act = PHTGL_ActionPlanFormationService.GetPHTGL_ActionPlanFormationById(getFireWork.ActionPlanID);
var model_ConstructionManager = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(Id, getFireWork.ConstructionManager);
var model_ControlManager = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(Id, getFireWork.ControlManager);
var model_Approval_Construction = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(Id, getFireWork.Approval_Construction);
var model_ProjectManager = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(Id, getFireWork.ProjectManager);
Dictionary<string, object> Dic_File = new Dictionary<string, object>();
Dic_File.Add("txtCode", string.Format("{0:yyyyMMdd}", Convert.ToDateTime(getFireWork.CreatTime)));
Dic_File.Add("txtBidDocumentCode", getFireWork.BidDocumentsCode);
Dic_File.Add("txtProjectName", Act.ProjectShortName);
Dic_File.Add("txtProjectCode", Act.ProjectCode);
Dic_File.Add("txtBidContent", getFireWork.BidContent);
Dic_File.Add("txtBidType", getFireWork.BidType);
Dic_File.Add("txtBidDocumentsName", getFireWork.BidDocumentsName);
Dic_File.Add("Bidding_SendTime", string.Format("{0:D}", getFireWork.Bidding_SendTime));
Dic_File.Add("Bidding_StartTime", string.Format("{0:D}", getFireWork.Bidding_StartTime));
if (getFireWork.State == Const.ContractReview_Complete)
{
Dic_File.Add("ConstructionManagerTime", string.Format("{0:D}", DateTime.Parse(model_ConstructionManager.ApproveDate)));
Dic_File.Add("ControlManagerTime", string.Format("{0:D}", DateTime.Parse(model_ControlManager.ApproveDate)));
Dic_File.Add("Approval_ConstructionTime", string.Format("{0:D}", DateTime.Parse(model_Approval_Construction.ApproveDate)));
Dic_File.Add("ProjectManagerTime", string.Format("{0:D}", DateTime.Parse(model_ProjectManager.ApproveDate)));
AsposeWordHelper.InsertImg(doc, rootPath, "Approval_Construction", getFireWork.Approval_Construction, "");
AsposeWordHelper.InsertImg(doc, rootPath, "ConstructionManager", getFireWork.ConstructionManager, "");
AsposeWordHelper.InsertImg(doc, rootPath, "ControlManager", getFireWork.ControlManager, "");
AsposeWordHelper.InsertImg(doc, rootPath, "ProjectManager", getFireWork.ProjectManager, "");
}
else
{
Dic_File.Add("ConstructionManagerTime", " 年 月 日");
Dic_File.Add("ControlManagerTime", " 年 月 日");
Dic_File.Add("Approval_ConstructionTime", " 年 月 日");
Dic_File.Add("ProjectManagerTime", " 年 月 日");
}
foreach (var item in Dic_File)
{
string[] key = { item.Key };
object[] value = { item.Value };
doc.MailMerge.Execute(key, value);
}
doc.Save(newUrl);
Document doc1 = new Aspose.Words.Document(newUrl);
File.Delete(newUrl);
return doc1;
}
public static void PrintFile( string Id)
{
string rootPath = Funs.RootPath;
var q = GetPHTGL_BidDocumentsReviewById(Id);
string newUrl = string.Empty;
newUrl = rootPath + "File\\Word\\PHTGL\\招标文件审批表.docx";
newUrl = newUrl.Replace(".docx", string.Format("{0:yyyy-MM}", DateTime.Now) + ".docx");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
var doc = Print( Id);
doc.Save(newUrl);
//生成PDF文件
string pdfUrl = newUrl.Replace(".docx", ".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(pdfUrl).Replace("招标文件审批表", q.BidDocumentsCode + "招标文件审批表");
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);
}
}
}