using Aspose.Words; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web.UI.WebControls; namespace BLL { public static class PHTGL_ActionPlanFormationService { /// /// 根据主键查询 /// /// /// public static Model.PHTGL_ActionPlanFormation GetPHTGL_ActionPlanFormationById(string ActionPlanID) { return Funs.DB.PHTGL_ActionPlanFormation.FirstOrDefault(e => e.ActionPlanID == ActionPlanID); } /// /// 根据编号查询 /// /// /// public static Model.PHTGL_ActionPlanFormation GetPHTGL_ActionPlanFormationByCode(string actionPlanCode) { return Funs.DB.PHTGL_ActionPlanFormation.FirstOrDefault(e => e.ActionPlanCode == actionPlanCode); } /// /// 添加 /// /// public static void AddPHTGL_ActionPlanFormation(Model.PHTGL_ActionPlanFormation newtable) { Model.PHTGL_ActionPlanFormation table = new Model.PHTGL_ActionPlanFormation(); table.ActionPlanID = newtable.ActionPlanID; table.ActionPlanCode = newtable.ActionPlanCode; table.CreateTime = newtable.CreateTime; table.CreatUser = newtable.CreatUser; table.State = newtable.State; table.ProjectID = newtable.ProjectID; table.ProjectName = newtable.ProjectName; table.Unit = newtable.Unit; table.ConstructionSite = newtable.ConstructionSite; table.BiddingProjectScope = newtable.BiddingProjectScope; table.BiddingProjectContent = newtable.BiddingProjectContent; table.TimeRequirements = newtable.TimeRequirements; table.QualityRequirement = newtable.QualityRequirement; table.HSERequirement = newtable.HSERequirement; table.TechnicalRequirement = newtable.TechnicalRequirement; table.CurrentRequirement = newtable.CurrentRequirement; table.Sub_Selection = newtable.Sub_Selection; table.Bid_Selection = newtable.Bid_Selection; table.ContractingMode_Select = newtable.ContractingMode_Select; table.PriceMode_Select = newtable.PriceMode_Select; table.MaterialsDifferentiate = newtable.MaterialsDifferentiate; table.ImportExplain = newtable.ImportExplain; table.ShortNameList = newtable.ShortNameList; table.EvaluationMethods = newtable.EvaluationMethods; table.EvaluationPlan = newtable.EvaluationPlan; table.BiddingMethods_Select = newtable.BiddingMethods_Select; table.SchedulePlan = newtable.SchedulePlan; table.BidProject = newtable.BidProject; table.BidPrice = newtable.BidPrice; table.PriceType = newtable.PriceType; table.BidType = newtable.BidType; table.EPCCode = newtable.EPCCode; table.ProjectCode = newtable.ProjectCode; table.ProjectShortName = newtable.ProjectShortName; table.AttachUrlContent = newtable.AttachUrlContent; Funs.DB.PHTGL_ActionPlanFormation.InsertOnSubmit(table); Funs.DB.SubmitChanges(); } /// /// 修改 /// /// public static void UpdatePHTGL_ActionPlanFormation(Model.PHTGL_ActionPlanFormation newtable) { Model.PHTGL_ActionPlanFormation table = Funs.DB.PHTGL_ActionPlanFormation.FirstOrDefault(e => e.ActionPlanID == newtable.ActionPlanID ); if (table != null) { table.ActionPlanID = newtable.ActionPlanID; table.ActionPlanCode = newtable.ActionPlanCode; table.CreateTime = newtable.CreateTime; table.CreatUser = newtable.CreatUser; table.State = newtable.State; table.ProjectID = newtable.ProjectID; table.ProjectName = newtable.ProjectName; table.Unit = newtable.Unit; table.ConstructionSite = newtable.ConstructionSite; table.BiddingProjectScope = newtable.BiddingProjectScope; table.BiddingProjectContent = newtable.BiddingProjectContent; table.TimeRequirements = newtable.TimeRequirements; table.QualityRequirement = newtable.QualityRequirement; table.HSERequirement = newtable.HSERequirement; table.TechnicalRequirement = newtable.TechnicalRequirement; table.CurrentRequirement = newtable.CurrentRequirement; table.Sub_Selection = newtable.Sub_Selection; table.Bid_Selection = newtable.Bid_Selection; table.ContractingMode_Select = newtable.ContractingMode_Select; table.PriceMode_Select = newtable.PriceMode_Select; table.MaterialsDifferentiate = newtable.MaterialsDifferentiate; table.ImportExplain = newtable.ImportExplain; table.ShortNameList = newtable.ShortNameList; table.EvaluationMethods = newtable.EvaluationMethods; table.EvaluationPlan = newtable.EvaluationPlan; table.BiddingMethods_Select = newtable.BiddingMethods_Select; table.SchedulePlan = newtable.SchedulePlan; table.BidProject = newtable.BidProject; table.BidPrice = newtable.BidPrice; table.PriceType = newtable.PriceType; table.BidType = newtable.BidType; table.EPCCode = newtable.EPCCode; table.ProjectCode = newtable.ProjectCode; table.ProjectShortName = newtable.ProjectShortName; table.AttachUrlContent = newtable.AttachUrlContent; Funs.DB.SubmitChanges(); } } public static void DeletePHTGL_ActionPlanFormationById(string ActionPlanID) { Model.PHTGL_ActionPlanFormation table = Funs.DB.PHTGL_ActionPlanFormation.FirstOrDefault(e => e.ActionPlanID == ActionPlanID); if (table != null) { Funs.DB.PHTGL_ActionPlanFormation.DeleteOnSubmit(table); Funs.DB.SubmitChanges(); } } public static List getEpcCode() { var q = (from x in Funs.DB.PHTGL_ActionPlanFormation where x.State == Const.ContractCreat_Complete select x).ToList(); return q; } /// /// 获取所有项目号 /// /// /// public static void InitAllProjectCodeDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "ProjectId"; dropName.DataTextField = "ProjectCode"; var projectlist = getEpcCode(); dropName.DataSource = projectlist; dropName.DataBind(); if (projectlist.Count() == 0) { isShowPlease = true; } if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } public static void InitGetAcpCompleteDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "ActionPlanCode"; dropName.DataTextField = "ActionPlanCode"; dropName.DataSource = GetCompleteActionPlanFormat(); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } public static object GetCompleteActionPlanFormat() { var list = (from x in Funs.DB.PHTGL_ActionPlanFormation join y in Funs.DB.PHTGL_ActionPlanReview on x.ActionPlanID equals y.ActionPlanID where y.State == Const.ContractReview_Complete select x).ToList(); return list; } public static ListItem[] GetPriceType() { ListItem[] list = new ListItem[5]; list[0] = new ListItem("固定总价", "固定总价"); list[1] = new ListItem("全费用固定综合单价", "全费用固定综合单价"); list[2] = new ListItem("定额计价总价下浮(税前)", "定额计价总价下浮(税前)"); list[3] = new ListItem("综合费率", "综合费率"); list[4] = new ListItem("费率下浮", "费率下浮"); return list; } /// /// 招标方式下拉框 /// /// 下拉框名字 /// 角色id /// 单位id /// 是否显示请选择 public static void InitGetBidTypeDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "Value"; dropName.DataTextField = "Text"; dropName.DataSource = BLL.DropListService.GetBidType(); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } public static void InitGetPriceTypeDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "Text"; dropName.DataTextField = "Value"; dropName.DataSource = GetPriceType(); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } /// /// ActionPlanID /// /// public static Document Print( string ActionPlanID) { string rootPath = Funs.RootPath; //string rootPath = Server.MapPath("~/"); string initTemplatePath = string.Empty; string uploadfilepath = string.Empty; string newUrl = string.Empty; string filePath = string.Empty; var lwfirwork = PHTGL_ActionPlanFormationService.GetPHTGL_ActionPlanFormationById(ActionPlanID); initTemplatePath = "File\\Word\\PHTGL\\施工招标实施计划审批表.docx"; 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); ///更新书签 var getFireWork = PHTGL_ActionPlanFormationService.GetPHTGL_ActionPlanFormationById(ActionPlanID); var Act = PHTGL_ActionPlanReviewService.GetPHTGL_ActionPlanReviewByActionPlanID(ActionPlanID); var list = PHTGL_ActionPlanFormation_Sch1Service.GetListPHTGL_ActionPlanFormation_Sch1ById(ActionPlanID); Document doc = new Aspose.Words.Document(newUrl); Bookmark txtActionPlanCode = doc.Range.Bookmarks["ActionPlanCode"]; Bookmark txtBidProject = doc.Range.Bookmarks["txtBidProject"]; Bookmark txtName = doc.Range.Bookmarks["txtName"]; Bookmark txtCreateTime = doc.Range.Bookmarks["CreateTime"]; Bookmark txtProjectName = doc.Range.Bookmarks["txtProjectName"]; Bookmark txtUnit = doc.Range.Bookmarks["txtUnit"]; Bookmark txtConstructionSite = doc.Range.Bookmarks["txtConstructionSite"]; Bookmark txtBiddingProjectScope = doc.Range.Bookmarks["txtBiddingProjectScope"]; Bookmark txtBiddingProjectContent = doc.Range.Bookmarks["txtBiddingProjectContent"]; Bookmark txtTimeRequirements = doc.Range.Bookmarks["txtTimeRequirements"]; Bookmark txtQualityRequirement = doc.Range.Bookmarks["txtQualityRequirement"]; Bookmark txtHSERequirement = doc.Range.Bookmarks["txtHSERequirement"]; Bookmark txtTechnicalRequirement = doc.Range.Bookmarks["txtTechnicalRequirement"]; Bookmark txtCurrentRequirement = doc.Range.Bookmarks["txtCurrentRequirement"]; Bookmark txtSub_Selection = doc.Range.Bookmarks["txtSub_Selection"]; Bookmark txtBid_Selection = doc.Range.Bookmarks["txtBid_Selection"]; Bookmark txtContractingMode_Select = doc.Range.Bookmarks["txtContractingMode_Select"]; Bookmark txtPriceMode_Select = doc.Range.Bookmarks["txtPriceMode_Select"]; Bookmark txtMaterialsDifferentiate = doc.Range.Bookmarks["txtMaterialsDifferentiate"]; Bookmark txtImportExplain = doc.Range.Bookmarks["txtImportExplain"]; Bookmark txtShortNameList = doc.Range.Bookmarks["txtShortNameList"]; Bookmark txtEvaluationMethods = doc.Range.Bookmarks["txtEvaluationMethods"]; Bookmark txtEvaluationPlan = doc.Range.Bookmarks["txtEvaluationPlan"]; Bookmark txtBiddingMethods_Select = doc.Range.Bookmarks["txtBiddingMethods_Select"]; Bookmark txtSchedulePlan = doc.Range.Bookmarks["txtSchedulePlan"]; #region 附件表 Dictionary Dic_File = new Dictionary(); for (int i = 1; i < 14; i++) { string txtPlanningContent = "txtPlanningContent" + Convert.ToString(i); string txtRemarks = "txtRemarks" + Convert.ToString(i); string value_ActionPlan = ""; string value_Remarks = ""; var model = list.Find(e => e.SortIndex == Convert.ToString(i)); if (model != null) { value_ActionPlan = model.ActionPlan; value_Remarks = model.Remarks; } string[] key = { txtPlanningContent, txtRemarks }; object[] value = { value_ActionPlan, value_Remarks }; doc.MailMerge.Execute(key, value); } #endregion if (txtActionPlanCode != null) { if (getFireWork != null) { txtActionPlanCode.Text = getFireWork.ActionPlanCode; } } if (txtName != null) { if (getFireWork != null) { txtName.Text = getFireWork.ProjectShortName; } } if (txtBidProject != null) { if (getFireWork != null) { txtBidProject.Text = getFireWork.BidProject; } } if (txtCreateTime != null) { if (getFireWork != null) { txtCreateTime.Text = string.Format("{0:D}", getFireWork.CreateTime); } } if (Act != null) { if (Act.State == Const.ContractReview_Complete) { AsposeWordHelper.InsertImg(doc, rootPath, "Approval_Construction", Act.Approval_Construction, ""); AsposeWordHelper.InsertImg(doc, rootPath, "ConstructionManager", Act.ConstructionManager, ""); AsposeWordHelper.InsertImg(doc, rootPath, "DeputyGeneralManager", Act.DeputyGeneralManager, ""); AsposeWordHelper.InsertImg(doc, rootPath, "ProjectManager", Act.ProjectManager, ""); } } if (txtProjectName != null) { if (getFireWork != null) { txtProjectName.Text = getFireWork.ProjectName; } } if (txtUnit != null) { if (getFireWork != null) { txtUnit.Text = getFireWork.Unit; } } if (txtConstructionSite != null) { if (getFireWork != null) { txtConstructionSite.Text = getFireWork.ConstructionSite; } } if (txtBiddingProjectScope != null) { if (getFireWork != null) { txtBiddingProjectScope.Text = getFireWork.BiddingProjectScope; } } if (txtBiddingProjectContent != null) { if (getFireWork != null) { txtBiddingProjectContent.Text = getFireWork.BiddingProjectContent; } } if (txtTimeRequirements != null) { if (getFireWork != null) { txtTimeRequirements.Text = getFireWork.TimeRequirements; } } if (txtQualityRequirement != null) { if (getFireWork != null) { txtQualityRequirement.Text = getFireWork.QualityRequirement; } } if (txtHSERequirement != null) { if (getFireWork != null) { txtHSERequirement.Text = getFireWork.HSERequirement; } } if (txtTechnicalRequirement != null) { if (getFireWork != null) { txtTechnicalRequirement.Text = getFireWork.TechnicalRequirement; } } if (txtCurrentRequirement != null) { if (getFireWork != null) { txtCurrentRequirement.Text = getFireWork.CurrentRequirement; } } if (txtSub_Selection != null) { if (getFireWork != null) { txtSub_Selection.Text = getFireWork.Sub_Selection; } } if (txtBid_Selection != null) { if (getFireWork != null) { txtBid_Selection.Text = getFireWork.Bid_Selection; } } if (txtContractingMode_Select != null) { if (getFireWork != null) { txtContractingMode_Select.Text = getFireWork.ContractingMode_Select; } } if (txtPriceMode_Select != null) { if (getFireWork != null) { txtPriceMode_Select.Text = getFireWork.PriceMode_Select; } } if (txtMaterialsDifferentiate != null) { if (getFireWork != null) { txtMaterialsDifferentiate.Text = getFireWork.MaterialsDifferentiate; } } if (txtImportExplain != null) { if (getFireWork != null) { txtImportExplain.Text = getFireWork.ImportExplain; } } if (txtShortNameList != null) { if (getFireWork != null) { txtShortNameList.Text = getFireWork.ShortNameList; } } if (txtEvaluationMethods != null) { if (getFireWork != null) { txtEvaluationMethods.Text = getFireWork.EvaluationMethods; } } if (txtEvaluationPlan != null) { if (getFireWork != null) { txtEvaluationPlan.Text = getFireWork.EvaluationPlan; } } if (txtBiddingMethods_Select != null) { if (getFireWork != null) { txtBiddingMethods_Select.Text = getFireWork.BiddingMethods_Select; } } if (txtSchedulePlan != null) { if (getFireWork != null) { txtSchedulePlan.Text = getFireWork.SchedulePlan; } } if (!string.IsNullOrEmpty(getFireWork.AttachUrlContent)) { var Path = newUrl.Replace(".docx", "编辑栏.docx"); //word文件保存路径 AsposeWordHelper.HtmlIntoWord(getFireWork.AttachUrlContent, Path); Document doc2 = new Document(Path); DocumentBuilder builder = new DocumentBuilder(doc2); //doc2.FirstSection.PageSetup.SectionStart = SectionStart.OddPage; builder.PageSetup.PaperSize = PaperSize.A4; doc.AppendDocument(doc2, ImportFormatMode.UseDestinationStyles); doc.UpdateWordCount(); File.Delete(Path); } 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 q = PHTGL_ActionPlanFormationService.GetPHTGL_ActionPlanFormationById(Id); var doc = BLL.PHTGL_ActionPlanFormationService.Print( Id); doc.Save(newUrl); //生成PDF文件 string pdfUrl = newUrl.Replace(".docx", ".pdf"); // BLL.AsposeWordHelper.WordIntoPdf(newUrl, pdfUrl); 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.ActionPlanCode + "施工分包实施计划"); 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); } } }