using Aspose.Words; using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace BLL { public static class PHTGL_BidDocumentsReviewService { public static Model.PHTGL_BidDocumentsReview GetPHTGL_BidDocumentsReviewById(string BidDocumentsReviewId) { return Funs.DB.PHTGL_BidDocumentsReview.FirstOrDefault(e => e.BidDocumentsReviewId == BidDocumentsReviewId); } public static void AddPHTGL_BidDocumentsReview(Model.PHTGL_BidDocumentsReview newtable) { Model.PHTGL_BidDocumentsReview table = new Model.PHTGL_BidDocumentsReview(); table.BidDocumentsReviewId = newtable.BidDocumentsReviewId; table.ActionPlanReviewId = newtable.ActionPlanReviewId; table.ActionPlanID = newtable.ActionPlanID; table.Bidding_StartTime = newtable.Bidding_StartTime; table.Url = newtable.Url; table.CreateUser = newtable.CreateUser; table.CreatTime = newtable.CreatTime; table.ConstructionManager = newtable.ConstructionManager; table.ControlManager = newtable.ControlManager; table.PreliminaryMan = newtable.PreliminaryMan; table.ProjectManager = newtable.ProjectManager; table.ProjectId = newtable.ProjectId; table.Approval_Construction = newtable.Approval_Construction; table.State = newtable.State; table.BidContent = newtable.BidContent; table.BidType = newtable.BidType; table.BidDocumentsName = newtable.BidDocumentsName; table.BidDocumentsCode = newtable.BidDocumentsCode; table.Bidding_SendTime = newtable.Bidding_SendTime; table.DepartId = newtable.DepartId; Funs.DB.PHTGL_BidDocumentsReview.InsertOnSubmit(table); Funs.DB.SubmitChanges(); } public static void UpdatePHTGL_BidDocumentsReview(Model.PHTGL_BidDocumentsReview newtable) { Model.PHTGL_BidDocumentsReview table = Funs.DB.PHTGL_BidDocumentsReview.FirstOrDefault(e => e.BidDocumentsReviewId == newtable.BidDocumentsReviewId); if (table != null) { table.BidDocumentsReviewId = newtable.BidDocumentsReviewId; table.ActionPlanReviewId = newtable.ActionPlanReviewId; table.ActionPlanID = newtable.ActionPlanID; table.Bidding_StartTime = newtable.Bidding_StartTime; table.Url = newtable.Url; table.CreateUser = newtable.CreateUser; table.CreatTime = newtable.CreatTime; table.ConstructionManager = newtable.ConstructionManager; table.ControlManager = newtable.ControlManager; table.PreliminaryMan = newtable.PreliminaryMan; table.ProjectManager = newtable.ProjectManager; table.ProjectId = newtable.ProjectId; table.Approval_Construction = newtable.Approval_Construction; table.State = newtable.State; table.BidContent = newtable.BidContent; table.BidType = newtable.BidType; table.BidDocumentsName = newtable.BidDocumentsName; table.BidDocumentsCode = newtable.BidDocumentsCode; table.Bidding_SendTime = newtable.Bidding_SendTime; table.DepartId = newtable.DepartId; Funs.DB.SubmitChanges(); } } public static void DeletePHTGL_BidDocumentsReviewById(string BidDocumentsReviewId) { Model.PHTGL_BidDocumentsReview table = Funs.DB.PHTGL_BidDocumentsReview.FirstOrDefault(e => e.BidDocumentsReviewId == BidDocumentsReviewId); if (table != null) { Funs.DB.PHTGL_BidDocumentsReview.DeleteOnSubmit(table); Funs.DB.SubmitChanges(); } } /// /// 获取审批人员 /// /// /// public static Dictionary Get_DicApproveman(string projectid, string BidDocumentsReviewId) { Dictionary Dic_Approveman = new Dictionary(); Model.PHTGL_BidDocumentsReview table = GetPHTGL_BidDocumentsReviewById(BidDocumentsReviewId); Dic_Approveman.Add(1, table.ConstructionManager); Dic_Approveman.Add(2, table.ControlManager); Dic_Approveman.Add(3, table.ProjectManager); Dic_Approveman.Add(4, table.PreliminaryMan); Dic_Approveman.Add(5, table.Approval_Construction); return Dic_Approveman; } public static List GetApproveManModels(string projectid, string BidDocumentsReviewId) { Model.PHTGL_BidDocumentsReview table = GetPHTGL_BidDocumentsReviewById(BidDocumentsReviewId); List approveManModels = new List(); approveManModels.Add(new ApproveManModel { Number = 1, userid = table.ConstructionManager, Rolename = "施工经理" }); approveManModels.Add(new ApproveManModel { Number = 2, userid = table.ControlManager, Rolename = "控制经理" }); approveManModels.Add(new ApproveManModel { Number = 3, userid = table.ProjectManager, Rolename = "项目经理" }); approveManModels.Add(new ApproveManModel { Number = 4, userid = table.PreliminaryMan, Rolename = "预审人员" }); approveManModels.Add(new ApproveManModel { Number = 5, userid = table.Approval_Construction, Rolename = "施工管理部" }); return approveManModels; } /// /// 招标方式下拉框 /// /// 下拉框名字 /// 角色id /// 单位id /// 是否显示请选择 public static void InitGetBidTypeDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "Text"; dropName.DataTextField = "Value"; dropName.DataSource = BLL.DropListService.GetBidType(); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } /// /// 获取审批完成的招标文件审批 /// /// /// public static void InitGetBidCompleteDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "BidDocumentsReviewId"; dropName.DataTextField = "BidDocumentsCode"; dropName.DataSource = GetCompleteBidDocument(); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } public static List GetCompleteBidDocument() { var list = (from x in Funs.DB.PHTGL_BidDocumentsReview where x.State == Const.ContractReview_Complete select x).ToList(); return list; } /// /// BidDocumentsReview /// /// /// public static Document Print(string BidDocumentsReviewId) { 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(BidDocumentsReviewId); 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(BidDocumentsReviewId); var Act = PHTGL_ActionPlanFormationService.GetPHTGL_ActionPlanFormationById(getFireWork.ActionPlanID); var model_ConstructionManager = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(BidDocumentsReviewId, getFireWork.ConstructionManager); var model_ControlManager = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(BidDocumentsReviewId, getFireWork.ControlManager); var model_Approval_Construction = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(BidDocumentsReviewId, getFireWork.Approval_Construction); var model_ProjectManager = PHTGL_ApproveService.GetPHTGL_ApproveByContractIdandUserId(BidDocumentsReviewId, getFireWork.ProjectManager); Dictionary Dic_File = new Dictionary(); 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); } } }