using Aspose.Words; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; namespace BLL { public static class PHTGL_BidApproveUserReviewService { public static Model.PHTGL_BidApproveUserReview GetPHTGL_BidApproveUserReviewById(string ApproveUserReviewID) { return Funs.DB.PHTGL_BidApproveUserReview.FirstOrDefault(e => e.ApproveUserReviewID == ApproveUserReviewID); } public static void AddPHTGL_BidApproveUserReview(Model.PHTGL_BidApproveUserReview newtable) { Model.PHTGL_BidApproveUserReview table = new Model.PHTGL_BidApproveUserReview(); table.ApproveUserReviewID = newtable.ApproveUserReviewID; table.BidDocumentsReviewId = newtable.BidDocumentsReviewId; table.ActionPlanID = newtable.ActionPlanID; table.ProjectId = newtable.ProjectId; table.BidProject = newtable.BidProject; table.State = newtable.State; table.CreateUser = newtable.CreateUser; table.ConstructionManager = newtable.ConstructionManager; table.ProjectManager = newtable.ProjectManager; table.Approval_Construction = newtable.Approval_Construction; table.DeputyGeneralManager = newtable.DeputyGeneralManager; table.DepartId = newtable.DepartId; Funs.DB.PHTGL_BidApproveUserReview.InsertOnSubmit(table); Funs.DB.SubmitChanges(); } public static void UpdatePHTGL_BidApproveUserReview(Model.PHTGL_BidApproveUserReview newtable) { Model.PHTGL_BidApproveUserReview table = Funs.DB.PHTGL_BidApproveUserReview.FirstOrDefault(e => e.ApproveUserReviewID == newtable.ApproveUserReviewID); if (table != null) { table.ApproveUserReviewID = newtable.ApproveUserReviewID; table.BidDocumentsReviewId = newtable.BidDocumentsReviewId; table.ActionPlanID = newtable.ActionPlanID; table.ProjectId = newtable.ProjectId; table.BidProject = newtable.BidProject; table.State = newtable.State; table.CreateUser = newtable.CreateUser; table.ConstructionManager = newtable.ConstructionManager; table.ProjectManager = newtable.ProjectManager; table.Approval_Construction = newtable.Approval_Construction; table.DeputyGeneralManager = newtable.DeputyGeneralManager; table.DepartId = newtable.DepartId; Funs.DB.SubmitChanges(); } } public static void DeletePHTGL_BidApproveUserReviewById(string ApproveUserReviewID) { Model.PHTGL_BidApproveUserReview table = Funs.DB.PHTGL_BidApproveUserReview.FirstOrDefault(e => e.ApproveUserReviewID == ApproveUserReviewID); if (table != null) { Funs.DB.PHTGL_BidApproveUserReview.DeleteOnSubmit(table); Funs.DB.SubmitChanges(); } } public static Dictionary Get_DicApproveman(string ApproveUserReviewID) { Dictionary Dic_Approveman = new Dictionary(); Model.PHTGL_BidApproveUserReview table = GetPHTGL_BidApproveUserReviewById(ApproveUserReviewID); Dic_Approveman.Add(1, table.ConstructionManager); Dic_Approveman.Add(2, table.ProjectManager); Dic_Approveman.Add(3, table.Approval_Construction); Dic_Approveman.Add(4, table.DeputyGeneralManager); return Dic_Approveman; } public static List GetApproveManModels(string ApproveUserReviewID) { Model.PHTGL_BidApproveUserReview table = GetPHTGL_BidApproveUserReviewById(ApproveUserReviewID); List approveManModels = new List(); approveManModels.Add(new ApproveManModel { Number = 1, userid = table.ConstructionManager, Rolename = "施工经理" }); // approveManModels.Add(new ApproveManModel { Number = 2, userid = table.ProjectManager, Rolename = "项目经理" }); approveManModels.Add(new ApproveManModel { Number = 2, userid = table.Approval_Construction, Rolename = "施工管理部" }); //approveManModels.Add(new ApproveManModel { Number = 4, userid = table.DeputyGeneralManager, Rolename = "分管副总经理" }); return approveManModels; } public static void InitGetBidCompleteDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "ApproveUserReviewID"; dropName.DataTextField = "BidDocumentsCode"; dropName.DataSource = GetCompleteBidDocument(); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } public static object GetCompleteBidDocument() { var list = (from x in Funs.DB.PHTGL_BidApproveUserReview join y in Funs.DB.PHTGL_BidDocumentsReview on x.BidDocumentsReviewId equals y.BidDocumentsReviewId where x.State == Const.ContractReview_Complete select new { x.ApproveUserReviewID, y.BidDocumentsCode }); return list; } public static Document Print(string ApproveUserReviewById) { 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"; 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); ///更新书签 var getFireWork = PHTGL_BidApproveUserReviewService.GetPHTGL_BidApproveUserReviewById(ApproveUserReviewById); var Bid = PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(getFireWork.BidDocumentsReviewId); var Act = BLL.PHTGL_ActionPlanFormationService.GetPHTGL_ActionPlanFormationById(Bid.ActionPlanID); #region 评标小组成员名单 string strSql = @" SELECT Number = row_number() over(order by ID) ,APP.ApproveUserName as Name ,APP.ApproveUserSpecial as Special ,APP.ApproveUserUnit as Unit ,APP.Remarks as Remarks" + @" FROM PHTGL_BidApproveUserReview_Sch1 AS APP " + @"where 1=1 AND ApproveUserReviewID = @ApproveUserReviewID "; List listStr = new List(); listStr.Add(new SqlParameter("@ApproveUserReviewID", ApproveUserReviewById)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); tb.TableName = "Table"; Document doc = new Aspose.Words.Document(newUrl); doc.MailMerge.ExecuteWithRegions(tb); #endregion Dictionary Dic_File = new Dictionary(); Dic_File.Add("txtProjectName", Act.ProjectShortName); Dic_File.Add("txtBidProject", getFireWork.BidProject); Dic_File.Add("txtBidDocumentCode", Bid.BidDocumentsCode); foreach (var item in Dic_File) { string[] key = { item.Key }; object[] value = { item.Value }; doc.MailMerge.Execute(key, value); } if (getFireWork.State == Const.ContractReview_Complete) { 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, ""); } 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; 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); 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); } } }