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,10 @@
using System.Collections.Generic;
using Aspose.Words;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web.UI.WebControls;
@@ -16,7 +22,6 @@ namespace BLL
/// </summary>
public const int Type_MinPrice = 1;
public const string BidReport = "SetSubReview_sch";
public static ListItem[] GetCreateType()
{
@@ -166,6 +171,224 @@ namespace BLL
select x).ToList();
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;
string strSql = "";
var getFireWork = PHTGL_SetSubReviewService.GetPHTGL_SetSubReviewById(Id);
var BidUser = PHTGL_BidApproveUserReviewService.GetPHTGL_BidApproveUserReviewById(getFireWork.ApproveUserReviewID);
var BidDoc = PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(BidUser.BidDocumentsReviewId);
var Act = BLL.PHTGL_ActionPlanFormationService.GetPHTGL_ActionPlanFormationById(BidDoc.ActionPlanID);
switch (getFireWork.Type)
{
case PHTGL_SetSubReviewService.Type_ConEvaluation:
if (Act != null)
{
if (PHTGL_ActionPlanReviewService.IsSpecialProject(Act.ProjectID))
{
initTemplatePath = "File\\Word\\PHTGL\\确定分包商审批表(用于综合评估法)LW.docx";
}
else
{
initTemplatePath = "File\\Word\\PHTGL\\确定分包商审批表(用于综合评估法).docx";
}
}
strSql = @" SELECT
Sch2.Company as Company
,Sch2.Price_ReviewResults as Price_ReviewResults
,Sch2.Skill_ReviewResults as Skill_ReviewResults
,Sch2.Business_ReviewResults as Business_ReviewResults
,Sch2.Synthesize_ReviewResults as Synthesize_ReviewResults
,Sch2.Remarks as Remarks "
+ @" FROM PHTGL_SetSubReview_Sch2 AS Sch2 "
+ @"where 1=1 AND SetSubReviewID = @SetSubReviewID order by SortIndex ";
break;
case PHTGL_SetSubReviewService.Type_MinPrice:
if (Act != null)
{
if (PHTGL_ActionPlanReviewService.IsSpecialProject(Act.ProjectID))
{
initTemplatePath = "File\\Word\\PHTGL\\确定分包商审批表(用于经评审的最低投标报价法)LW.docx";
}
else
{
initTemplatePath = "File\\Word\\PHTGL\\确定分包商审批表(用于经评审的最低投标报价法).docx";
}
}
strSql = @" SELECT
Sch1.Company as Company
,Sch1.ReviewResults as ReviewResults
,Sch1.Remarks as Remarks "
+ @" FROM PHTGL_SetSubReview_Sch1 AS Sch1 "
+ @"where 1=1 AND SetSubReviewID = @SetSubReviewID order by SortIndex ";
break;
}
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);
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@SetSubReviewID", Id));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
tb.TableName = "Table";
Document doc = new Aspose.Words.Document(newUrl);
doc.MailMerge.ExecuteWithRegions(tb);
var model_ConstructionManager = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(Id, getFireWork.ConstructionManager);
var model_ProjectManager = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(Id, getFireWork.ProjectManager);
var model_Approval_Construction = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(Id, getFireWork.Approval_Construction);
var model_DeputyGeneralManager = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(Id, getFireWork.DeputyGeneralManager);
Dictionary<string, object> Dic_File = new Dictionary<string, object>();
Dic_File.Add("txtSetSubReviewCode", getFireWork.SetSubReviewCode);
Dic_File.Add("txtBidDocumentsCode", BidDoc.BidDocumentsCode);
Dic_File.Add("txtProjectName", Act.ProjectShortName);
Dic_File.Add("txtBidContent", BidDoc.BidContent);
Dic_File.Add("txtBidding_StartTime", string.Format("{0:D}", BidDoc.Bidding_StartTime));
if (getFireWork.State == Const.ContractReview_Complete)
{
Dic_File.Add("txtConstructionManagerIdea", model_ConstructionManager.ApproveIdea.Length > 3 ? model_ConstructionManager.ApproveIdea : "同意");
Dic_File.Add("ConstructionManagerTime", string.Format("{0:D}", DateTime.Parse(model_ConstructionManager.ApproveDate)));
Dic_File.Add("txtApproval_ConstructionIdea", model_Approval_Construction.ApproveIdea.Length > 3 ? model_Approval_Construction.ApproveIdea : "同意");
Dic_File.Add("Approval_ConstructionTime", string.Format("{0:D}", DateTime.Parse(model_Approval_Construction.ApproveDate)));
Dic_File.Add("ProjectManagerIdea", model_ProjectManager.ApproveIdea.Length > 3 ? model_ProjectManager.ApproveIdea : "同意");
Dic_File.Add("ProjectManagerTime", string.Format("{0:D}", DateTime.Parse(model_ProjectManager.ApproveDate)));
Dic_File.Add("txtDeputyGeneralManagerIdea", model_DeputyGeneralManager.ApproveIdea.Length > 3 ? model_DeputyGeneralManager.ApproveIdea : "同意");
Dic_File.Add("DeputyGeneralManagerTime", string.Format("{0:D}", DateTime.Parse(model_DeputyGeneralManager.ApproveDate)));
AsposeWordHelper.InsertImg(doc, rootPath, "Approval_Construction", getFireWork.Approval_Construction, "");
AsposeWordHelper.InsertImg(doc, rootPath, "ConstructionManager", getFireWork.ConstructionManager, "");
AsposeWordHelper.InsertImg(doc, rootPath, "DeputyGeneralManager", getFireWork.DeputyGeneralManager, "");
AsposeWordHelper.InsertImg(doc, rootPath, "ProjectManager", getFireWork.ProjectManager, "");
}
else
{
Dic_File.Add("txtConstructionManagerIdea", "");
Dic_File.Add("ConstructionManagerTime", " 年 月 日");
Dic_File.Add("txtApproval_ConstructionIdea", "");
Dic_File.Add("Approval_ConstructionTime", " 年 月 日");
Dic_File.Add("ProjectManagerIdea", "");
Dic_File.Add("ProjectManagerTime", " 年 月 日");
Dic_File.Add("txtDeputyGeneralManagerIdea", "");
Dic_File.Add("DeputyGeneralManagerTime", " 年 月 日");
}
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;
string newUrl = string.Empty;
string initTemplatePath = string.Empty;
var getFireWork = PHTGL_SetSubReviewService.GetPHTGL_SetSubReviewById(Id);
var BidUser = PHTGL_BidApproveUserReviewService.GetPHTGL_BidApproveUserReviewById(getFireWork.ApproveUserReviewID);
var BidDoc = PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(BidUser.BidDocumentsReviewId);
var Act = BLL.PHTGL_ActionPlanFormationService.GetPHTGL_ActionPlanFormationById(BidDoc.ActionPlanID);
switch (getFireWork.Type)
{
case PHTGL_SetSubReviewService.Type_ConEvaluation:
if (Act != null)
{
if (PHTGL_ActionPlanReviewService.IsSpecialProject(Act.ProjectID))
{
initTemplatePath = "File\\Word\\PHTGL\\确定分包商审批表(用于综合评估法)LW.docx";
}
else
{
initTemplatePath = "File\\Word\\PHTGL\\确定分包商审批表(用于综合评估法).docx";
}
}
break;
case PHTGL_SetSubReviewService.Type_MinPrice:
if (Act != null)
{
if (PHTGL_ActionPlanReviewService.IsSpecialProject(Act.ProjectID))
{
initTemplatePath = "File\\Word\\PHTGL\\确定分包商审批表(用于经评审的最低投标报价法)LW.docx";
}
else
{
initTemplatePath = "File\\Word\\PHTGL\\确定分包商审批表(用于经评审的最低投标报价法).docx";
}
}
break;
}
newUrl = rootPath + initTemplatePath;
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);
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);
}
}
}