using Aspose.Words; using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; namespace FineUIPro.Web.PHTGL.BiddingManagement { public partial class BidDocumentsReview : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); this.DropState.DataValueField = "Value"; DropState.DataTextField = "Text"; DropState.DataSource = BLL.DropListService.GetState(); DropState.DataBind(); Funs.FineUIPleaseSelect(DropState); DropState.SelectedValueArray = new string[] { Const.ContractCreating.ToString(), Const.ContractCreat_Complete.ToString (), Const.ContractReviewing.ToString (), Const.ContractReview_Refuse.ToString() }; GetButtonPower(); BindGrid(); } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { string strSql = @"SELECT Bid.BidDocumentsReviewId ,Bid.ProjectId ,Pro.ProjectName ,Pro.ProjectCode ,Acp.ActionPlanCode ,Acp.ProjectShortName ,(CASE Bid.State WHEN @ContractCreating THEN '编制中' WHEN @ContractCreat_Complete THEN '编制完成' WHEN @ContractReviewing THEN '审批中' WHEN @ContractReview_Complete THEN '审批成功' WHEN @ContractReview_Refuse THEN '审批被拒'END) AS State ,ApproveType =stuff((select ','+ ApproveType from PHTGL_Approve app2 where app2.ContractId = Bid.BidDocumentsReviewId and app2 .state =0 for xml path('')), 1, 1, '') ,Bid.BidContent ,Bid.BidType ,Bid.BidDocumentsName ,Bid.BidDocumentsCode ,Bid.Bidding_SendTime ,Bid.Bidding_StartTime ,Bid.url ,U.PersonName AS CreateUser ,Bid.CreatTime" + @" FROM PHTGL_BidDocumentsReview AS Bid " + @" LEFT JOIN Person_Persons AS U ON U.PersonId =Bid.CreateUser " + @" LEFT JOIN PHTGL_ActionPlanFormation AS Acp ON Acp.ActionPlanID =Bid.ActionPlanID " + @" LEFT JOIN Base_Project AS Pro ON Pro.ProjectId = Bid.ProjectId WHERE 1=1 "; List listStr = new List(); listStr.Add(new SqlParameter("@ContractCreating", Const.ContractCreating.ToString())); listStr.Add(new SqlParameter("@ContractCreat_Complete", Const.ContractCreat_Complete.ToString())); listStr.Add(new SqlParameter("@ContractReviewing", Const.ContractReviewing)); listStr.Add(new SqlParameter("@ContractReview_Complete", Const.ContractReview_Complete)); listStr.Add(new SqlParameter("@ContractReview_Refuse", Const.ContractReview_Refuse)); if (!(this.CurrUser.PersonId == Const.sysglyId)) { strSql += " and Bid.ProjectID =@ProjectId"; listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); } if (!string.IsNullOrEmpty(txtBidDocumentsCode.Text)) { strSql += " and Bid.BidDocumentsCode like @BidDocumentsCode "; listStr.Add(new SqlParameter("@BidDocumentsCode", "%" + txtBidDocumentsCode.Text + "%")); } if (DropState.SelectedItemArray.Length > 0) { strSql += string.Format(" and Bid.State in ({0}) ", string.Join(",", DropState.SelectedValueArray)); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 分页 排序 /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { BindGrid(); } protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { object[] keys = Grid1.DataKeys[e.RowIndex]; string fileId = string.Empty; if (keys == null) { return; } else { fileId = keys[0].ToString(); } if (e.CommandName == "LooK") { string id = fileId; var Bid = BLL.PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(id); PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("BidDocumentsReviewEdit.aspx?BidDocumentsReviewId={0}", Bid.BidDocumentsReviewId, "审批 - "))); return; } } #endregion #region 关闭弹出窗体 /// /// 关闭弹出窗体 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region 查询 /// /// 查询按钮 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); OAWebSevice.Pushoa(); } protected void btnQueryApprove_Click(object sender, EventArgs e) { this.EditData(); } protected void btnRset_Click(object sender, EventArgs e) { txtBidDocumentsCode.Text = ""; DropState.SelectedValueArray = new string[] { Const.ContractCreating.ToString(), Const.ContractCreat_Complete.ToString (), Const.ContractReviewing.ToString (), Const.ContractReview_Refuse.ToString() }; BindGrid(); } #endregion #region 编辑 /// /// 双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 编辑 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; var Bid = BLL.PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(id); PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("BidDocumentsReviewEdit.aspx?BidDocumentsReviewId={0}", Bid.BidDocumentsReviewId, "审批 - "))); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; var Bid = BLL.PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(id); PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("BidDocumentsReviewDetail.aspx?BidDocumentsReviewId={0}", Bid.BidDocumentsReviewId, "审批 - "))); } protected void btnNew_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("BidDocumentsReviewEdit.aspx"))); } else { string id = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("BidDocumentsReviewEdit.aspx?BidDocumentsReviewId={0}&&State=Edit", id, "审批 - "))); } } protected void btnEditAgain_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; var Bid = BLL.PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(id); if (Bid.CreateUser != this.CurrUser.PersonId) { string name = Person_PersonsService.GetPersonsNameById(Bid.CreateUser); Alert.ShowInTop("!此审批不是您创建,无法重新提交【创建者:" + name + "】", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("BidDocumentsReviewEdit.aspx?BidDocumentsReviewId={0}&&State=Again", Bid.BidDocumentsReviewId, "审批 - "))); } #endregion #region 删除 /// /// 删除事件 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { bool isShow = false; if (Grid1.SelectedRowIndexArray.Length == 1) { isShow = true; } foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); if (this.judgementDelete(rowID, isShow)) { var p = BLL.PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(rowID); if (p != null) { BLL.LogService.AddSys_Log(this.CurrUser, p.BidDocumentsReviewId, p.ProjectId, BLL.Const.BidDocumentsReviewIdMenuid, BLL.Const.BtnDelete); PHTGL_ApproveService.DeletePHTGL_ApproveBycontractId(rowID); BLL.AttachFileService.DeleteAttachFile(Funs.RootPath, rowID, BLL.Const.BidDocumentsReviewIdMenuid); PHTGL_BidDocumentsReviewService.DeletePHTGL_BidDocumentsReviewById(rowID); } } } BindGrid(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content); } return false; } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = CommonService.GetAllButtonList(CurrUser.LoginProjectId, CurrUser.PersonId, Const.BidDocumentsReviewIdMenuid); if (buttonList.Count() > 0) { if (buttonList.Contains(Const.BtnAdd)) { btnNew.Hidden = false; } if (buttonList.Contains(Const.BtnModify)) { btnMenuEdit.Hidden = false; } if (buttonList.Contains(Const.BtnDelete)) { btnDelete.Hidden = false; } } } protected void Grid1_RowClick(object sender, GridRowClickEventArgs e) { string id = Grid1.SelectedRowID; var actReview = PHTGL_BidDocumentsReviewService.GetPHTGL_BidDocumentsReviewById(id); if (actReview == null) { return; } if (actReview.State == Const.ContractReview_Refuse) { btnEditAgain.Hidden = false; } else { btnEditAgain.Hidden = true; } if (actReview.State >= Const.ContractCreat_Complete) { btnDelete.Hidden = true; } else { var buttonList = CommonService.GetAllButtonList(CurrUser.LoginProjectId, CurrUser.PersonId, Const.ActionPlanFormation); if (buttonList.Count() > 0) { if (buttonList.Contains(Const.BtnDelete)) { btnDelete.Hidden = false; } } } } #endregion #region 打印 /// /// BidDocumentsReviewId /// /// public void Print(string Id) { string rootPath = Server.MapPath("~/"); 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 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); //生成PDF文件 string pdfUrl = newUrl.Replace(".doc", ".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(filePath).Replace("招标文件审批表", getFireWork.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); } protected void btnPrinter_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string Id = Grid1.SelectedRowID; Print(Id); } #endregion } }