20240617 工作总结报告导出
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using BLL;
|
||||
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.CQMS.ManageReport
|
||||
@@ -241,5 +243,230 @@ namespace FineUIPro.Web.CQMS.ManageReport
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 导出
|
||||
/// <summary>
|
||||
/// 导出
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnPrinter_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||||
{
|
||||
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
string Id = Grid1.SelectedRowID;
|
||||
|
||||
string rootPath = Server.MapPath("~/");
|
||||
string initTemplatePath = string.Empty;
|
||||
string uploadfilepath = string.Empty;
|
||||
string newUrl = string.Empty;
|
||||
string filePath = string.Empty;
|
||||
|
||||
string projectId = this.CurrUser.LoginProjectId;
|
||||
|
||||
var pModel = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == projectId);
|
||||
|
||||
|
||||
initTemplatePath = Const.QuarterlyProjectQualityTemplateUrl;
|
||||
uploadfilepath = rootPath + initTemplatePath;
|
||||
|
||||
var report = BLL.ProjectQuarterlyProjectQualityService.GetQuarterlyProjectQualityById(Id);
|
||||
|
||||
newUrl = uploadfilepath.Replace("季度工程项目质量信息表", "季度工程项目质量信息表(" + pModel.ShortName + report.Year + "年第" + report.Quarter + "季度)");
|
||||
|
||||
if (File.Exists(newUrl))
|
||||
{
|
||||
File.Delete(newUrl);
|
||||
}
|
||||
|
||||
File.Copy(uploadfilepath, newUrl);
|
||||
Document doc = new Aspose.Words.Document(uploadfilepath);
|
||||
|
||||
|
||||
Bookmark yearId = doc.Range.Bookmarks["YearId"];
|
||||
if (yearId != null)
|
||||
{
|
||||
yearId.Text = report.Year + "年";
|
||||
}
|
||||
Bookmark quarter = doc.Range.Bookmarks["Quarter"];
|
||||
if (quarter != null)
|
||||
{
|
||||
quarter.Text = "第" + report.Quarter + "季度";
|
||||
}
|
||||
Bookmark compileDate = doc.Range.Bookmarks["CompileDate"];
|
||||
if (compileDate != null)
|
||||
{
|
||||
compileDate.Text = report.CompileDate.HasValue ? string.Format("{0:yyyy-MM-dd}", report.CompileDate) : "";
|
||||
}
|
||||
Bookmark responsiblePerson = doc.Range.Bookmarks["ResponsiblePerson"];
|
||||
if (responsiblePerson != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(report.ResponsiblePerson))
|
||||
{
|
||||
responsiblePerson.Text = BLL.UserService.GetUserNameByUserId(report.ResponsiblePerson);
|
||||
}
|
||||
}
|
||||
Bookmark compileMan = doc.Range.Bookmarks["CompileMan"];
|
||||
if (compileMan != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(report.CompileMan))
|
||||
{
|
||||
compileMan.Text = BLL.UserService.GetUserNameByUserId(report.CompileMan);
|
||||
}
|
||||
}
|
||||
Bookmark tel = doc.Range.Bookmarks["Tel"];
|
||||
if (tel != null)
|
||||
{
|
||||
tel.Text = report.Tel;
|
||||
}
|
||||
Bookmark qualityManagePersonNum = doc.Range.Bookmarks["QualityManagePersonNum"];
|
||||
if (qualityManagePersonNum != null)
|
||||
{
|
||||
qualityManagePersonNum.Text = report.QualityManagePersonNum.HasValue ? report.QualityManagePersonNum.ToString() : "";
|
||||
}
|
||||
Bookmark advancedTitlePersonNum = doc.Range.Bookmarks["AdvancedTitlePersonNum"];
|
||||
if (advancedTitlePersonNum != null)
|
||||
{
|
||||
advancedTitlePersonNum.Text = report.AdvancedTitlePersonNum.HasValue ? report.AdvancedTitlePersonNum.ToString() : "";
|
||||
}
|
||||
Bookmark intermediateTitlePersonNum = doc.Range.Bookmarks["IntermediateTitlePersonNum"];
|
||||
if (intermediateTitlePersonNum != null)
|
||||
{
|
||||
intermediateTitlePersonNum.Text = report.IntermediateTitlePersonNum.HasValue ? report.IntermediateTitlePersonNum.ToString() : "";
|
||||
}
|
||||
Bookmark beImplementedProjectNum = doc.Range.Bookmarks["BeImplementedProjectNum"];
|
||||
if (beImplementedProjectNum != null)
|
||||
{
|
||||
beImplementedProjectNum.Text = report.BeImplementedProjectNum.HasValue ? report.BeImplementedProjectNum.ToString() : "";
|
||||
}
|
||||
Bookmark startImplementedProjectNum = doc.Range.Bookmarks["StartImplementedProjectNum"];
|
||||
if (startImplementedProjectNum != null)
|
||||
{
|
||||
startImplementedProjectNum.Text = report.StartImplementedProjectNum.HasValue ? report.StartImplementedProjectNum.ToString():"";
|
||||
}
|
||||
Bookmark accumulativeStartImplemented = doc.Range.Bookmarks["AccumulativeStartImplemented"];
|
||||
if (accumulativeStartImplemented != null)
|
||||
{
|
||||
accumulativeStartImplemented.Text = report.AccumulativeStartImplemented.HasValue? report.AccumulativeStartImplemented.ToString():"";
|
||||
}
|
||||
Bookmark completeProjectNum = doc.Range.Bookmarks["CompleteProjectNum"];
|
||||
if (completeProjectNum != null)
|
||||
{
|
||||
completeProjectNum.Text = report.CompleteProjectNum.HasValue ? report.CompleteProjectNum.ToString() : "";
|
||||
}
|
||||
Bookmark yearCompleteProjectNum = doc.Range.Bookmarks["YearCompleteProjectNum"];
|
||||
if (yearCompleteProjectNum != null)
|
||||
{
|
||||
yearCompleteProjectNum.Text = report.YearCompleteProjectNum.HasValue? report.YearCompleteProjectNum.ToString():"";
|
||||
}
|
||||
Bookmark quarterTotal = doc.Range.Bookmarks["QuarterTotal"];
|
||||
if (quarterTotal != null)
|
||||
{
|
||||
quarterTotal.Text = report.QuarterTotal.HasValue? report.QuarterTotal.ToString():"";
|
||||
}
|
||||
Bookmark quarterFirstPassNum = doc.Range.Bookmarks["QuarterFirstPassNum"];
|
||||
if (quarterFirstPassNum != null)
|
||||
{
|
||||
quarterFirstPassNum.Text = report.QuarterFirstPassNum.HasValue? report.QuarterFirstPassNum.ToString():"";
|
||||
}
|
||||
Bookmark quarterFirstPassRate = doc.Range.Bookmarks["QuarterFirstPassRate"];
|
||||
if (quarterFirstPassRate != null)
|
||||
{
|
||||
quarterFirstPassRate.Text = report.QuarterFirstPassRate.HasValue? report.QuarterFirstPassRate.ToString():"";
|
||||
}
|
||||
Bookmark yearTotal = doc.Range.Bookmarks["YearTotal"];
|
||||
if (yearTotal != null)
|
||||
{
|
||||
yearTotal.Text = report.YearTotal.HasValue ? report.YearTotal.ToString() : "";
|
||||
}
|
||||
Bookmark yearFirstPassNum = doc.Range.Bookmarks["YearFirstPassNum"];
|
||||
if (yearFirstPassNum != null)
|
||||
{
|
||||
yearFirstPassNum.Text = report.YearFirstPassNum.HasValue ? report.YearFirstPassNum.ToString() : "";
|
||||
}
|
||||
Bookmark yearFirstPassRate = doc.Range.Bookmarks["YearFirstPassRate"];
|
||||
if (yearFirstPassRate != null)
|
||||
{
|
||||
yearFirstPassRate.Text = report.YearFirstPassRate.HasValue ? report.YearFirstPassRate.ToString() : "";
|
||||
}
|
||||
Bookmark quaterCheckSuperviseNum = doc.Range.Bookmarks["QuaterCheckSuperviseNum"];
|
||||
if (quaterCheckSuperviseNum != null)
|
||||
{
|
||||
quaterCheckSuperviseNum.Text = report.QuaterCheckSuperviseNum.HasValue ? report.QuaterCheckSuperviseNum.ToString() : "";
|
||||
}
|
||||
Bookmark quaterCorrectiveNoticeNum = doc.Range.Bookmarks["QuaterCorrectiveNoticeNum"];
|
||||
if (quaterCorrectiveNoticeNum != null)
|
||||
{
|
||||
quaterCorrectiveNoticeNum.Text = report.QuaterCorrectiveNoticeNum.HasValue ? report.QuaterCorrectiveNoticeNum.ToString() : "";
|
||||
}
|
||||
Bookmark quaterQualityProblemNum = doc.Range.Bookmarks["QuaterQualityProblemNum"];
|
||||
if (quaterQualityProblemNum != null)
|
||||
{
|
||||
quaterQualityProblemNum.Text = report.QuaterQualityProblemNum.HasValue ? report.QuaterQualityProblemNum.ToString() : "";
|
||||
}
|
||||
Bookmark quaterClosedQualityProblemNum = doc.Range.Bookmarks["QuaterClosedQualityProblemNum"];
|
||||
if (quaterClosedQualityProblemNum != null)
|
||||
{
|
||||
quaterClosedQualityProblemNum.Text = report.QuaterClosedQualityProblemNum.HasValue ? report.QuaterClosedQualityProblemNum.ToString() : "";
|
||||
}
|
||||
Bookmark yearCheckSuperviseNum = doc.Range.Bookmarks["YearCheckSuperviseNum"];
|
||||
if (yearCheckSuperviseNum != null)
|
||||
{
|
||||
yearCheckSuperviseNum.Text = report.YearCheckSuperviseNum.HasValue ? report.YearCheckSuperviseNum.ToString() : "";
|
||||
}
|
||||
Bookmark yearCorrectiveNoticeNum = doc.Range.Bookmarks["YearCorrectiveNoticeNum"];
|
||||
if (yearCorrectiveNoticeNum != null)
|
||||
{
|
||||
yearCorrectiveNoticeNum.Text = report.YearCorrectiveNoticeNum.HasValue ? report.YearCorrectiveNoticeNum.ToString() : "";
|
||||
}
|
||||
Bookmark yearQualityProblemNum = doc.Range.Bookmarks["YearQualityProblemNum"];
|
||||
if (yearQualityProblemNum != null)
|
||||
{
|
||||
yearQualityProblemNum.Text = report.YearQualityProblemNum.HasValue ? report.YearQualityProblemNum.ToString() : "";
|
||||
}
|
||||
Bookmark yearClosedQualityProblemNum = doc.Range.Bookmarks["YearClosedQualityProblemNum"];
|
||||
if (yearClosedQualityProblemNum != null)
|
||||
{
|
||||
yearClosedQualityProblemNum.Text = report.YearClosedQualityProblemNum.HasValue ? report.YearClosedQualityProblemNum.ToString() : "";
|
||||
}
|
||||
Bookmark quaterQualityAccidentNum = doc.Range.Bookmarks["QuaterQualityAccidentNum"];
|
||||
if (quaterQualityAccidentNum != null)
|
||||
{
|
||||
quaterQualityAccidentNum.Text = report.QuaterQualityAccidentNum.HasValue ? report.QuaterQualityAccidentNum.ToString() : "";
|
||||
}
|
||||
Bookmark quaterDirectEconomicLoss = doc.Range.Bookmarks["QuaterDirectEconomicLoss"];
|
||||
if (quaterDirectEconomicLoss != null)
|
||||
{
|
||||
quaterDirectEconomicLoss.Text = report.QuaterDirectEconomicLoss.HasValue ? report.QuaterDirectEconomicLoss.ToString() : "";
|
||||
}
|
||||
Bookmark yearQualityAccidentNum = doc.Range.Bookmarks["YearQualityAccidentNum"];
|
||||
if (yearQualityAccidentNum != null)
|
||||
{
|
||||
yearQualityAccidentNum.Text = report.YearQualityAccidentNum.HasValue ? report.YearQualityAccidentNum.ToString() : "";
|
||||
}
|
||||
Bookmark yearDirectEconomicLoss = doc.Range.Bookmarks["YearDirectEconomicLoss"];
|
||||
if (yearDirectEconomicLoss != null)
|
||||
{
|
||||
yearDirectEconomicLoss.Text = report.YearDirectEconomicLoss.HasValue ? report.YearDirectEconomicLoss.ToString() : "";
|
||||
}
|
||||
|
||||
doc.Save(newUrl);
|
||||
|
||||
string fileName = Path.GetFileName(newUrl);
|
||||
FileInfo info = new FileInfo(newUrl);
|
||||
long fileSize = info.Length;
|
||||
Response.Clear();
|
||||
Response.ContentType = "application/x-zip-compressed";
|
||||
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
||||
Response.AddHeader("Content-Length", fileSize.ToString());
|
||||
Response.TransmitFile(newUrl, 0, fileSize);
|
||||
Response.Flush();
|
||||
Response.Close();
|
||||
File.Delete(newUrl);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user