在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using VanCloud.HPCCloud.UserManager; using VanCloud.HPCCloud.ReportManager; using System.IO; using System.Drawing; using Microsoft.Office.Interop.Word; using VanCloud.HPCCloud.DataReport; using VanCloud.HPCCloud.SystemConfig; using System.Text; namespace SimCloud.Admin { public partial class GenerateReport : System.Web.UI.Page { log4net.ILog log = log4net.LogManager.GetLogger(typeof(GenerateReport)); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetAllGroup(); } } /// <summary> /// confirm click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnConfirm_Click(object sender, EventArgs e) { try { DateTime startTime = DateTime.MinValue; if (!string.IsNullOrEmpty(txtFromDt.Text.Trim())) { if (!DateTime.TryParse(txtFromDt.Text.Trim(), out startTime)) { lblErrorMessage.Text = "TimeFormatError"; return; } } DateTime endTime = DateTime.Now.Date; if (!string.IsNullOrEmpty(txtToDt.Text.Trim())) { if (!DateTime.TryParse(txtToDt.Text.Trim(), out endTime)) { lblErrorMessage.Text = "TimeFormatError"; return; } } if (startTime.CompareTo(endTime) > 0) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('开始时间不能大于结束时间')", true); return; } TimeSpan s = new TimeSpan(endTime.Ticks - startTime.Ticks); if (endTime.Date >= DateTime.Now.Date || startTime.Date >= DateTime.Now.Date) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('当天和当天之后的日期不能选择')", true); return; } if (s.TotalDays >= 32) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('时间不能大于一个月')", true); return; } string start = "开始" + DateTime.Now.ToString(); try { CreateWordFile(startTime, endTime); } catch (Exception ex) { log.Error(ex); } string end = "结束" + DateTime.Now.ToString(); // ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('Word报表生成成功" + start + "" + end + "!')", true); log.Info("Word报表生成成功" + start + "" + end + "!"); lblErrorMessage.Text = ""; } catch (Exception ex) { log.Error(ex.Message); log.Error(ex.StackTrace); } } public void CreateWordFile(DateTime startTime, DateTime endTime) { System.Data.DataTable dt = new ReportUtilityFactory(VanCloud.HPCCloud.HPCJobManager.SystemHPCTypeEnum.All, "VanCloud.HPCCloud.DataReport.Properties.Settings.HPCReportingConnectionString", CommonConfig.SystemBasicInfo.LinuxRestAPIPath).GetHistryJobListForServiceReport_SHDQ(startTime, endTime, this.ddlGroupName.SelectedValue); UserPermission userPerm = new UserPermission("SimCloudConnectionString"); userPerm.Domain = CommonConfig.SystemBasicInfo.DomainNames[0]; System.Data.DataTable dtUser = userPerm.GetUsersList(); string groupname = this.ddlGroupName.SelectedItem.Text; groupname = groupname.Substring(groupname.IndexOf('\\')+1); userPerm.GroupName = groupname; MonthReport MR = new MonthReport(startTime, endTime, "SimCloudConnectionString", userPerm.Domain, groupname, dt, dtUser); ReportGroupBasicInfo RGBI = MR.GetGroupBasicInfo(); System.Data.DataTable dtComputerTimeInfo = MR.GetAllComputerTimeInfo(); System.Data.DataTable dtAllQueueInfo = MR.GetAllQueueInfo(); System.Data.DataTable dtAllSystemInfo = MR.GetAllSystemInfo(); System.Data.DataTable dtAllJobsInfo = MR.GetAllJobsInfo(); System.Data.DataTable dtUserComputerTimeInfo = MR.GetUserComputerTimeInfo(); System.Data.DataTable dtUserQueueInfo = MR.GetUserQueueInfo(); System.Data.DataTable dtUserSystemInfo = MR.GetUserSystemInfo(); System.Data.DataTable dtAllDailyInfo = MR.GetAllDailyInfo(); System.Data.DataTable dtAllJobsList = MR.GetAllJobsList(); string message = ""; try { Object Nothing = System.Reflection.Missing.Value; //Directory.CreateDirectory("D:/Report"); //创建文件所在目录 PortalUser puUser = (PortalUser)(Session[@"PortalUser"]); string name = "Report_" + DateTime.Now.ToString("yyyyMMddHHmmss") + puUser.UserName + ".doc";//文件名 //object filename = "D://Report//" + name; //文件保存路径 object filename = Server.MapPath("~/Admin/Temp/" + name + ""); //创建Word文档 Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); WordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距 //移动焦点并换行 object count = 14; object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行; WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara1; oPara1 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara1.Range.Text = startTime.Year + "年" + startTime.Month + "." + startTime.Day + "-" + endTime.Month + "." + endTime.Day + "上海电气中央研究院服务情况小结"; oPara1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; oPara1.Range.Font.Bold = 0;//不加粗 oPara1.Range.Font.Name = "黑体"; oPara1.Range.Font.Size = 16; oPara1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; int start1 = (startTime.Year + "年" + startTime.Month + "." + startTime.Day + "-" + endTime.Month + "." + endTime.Day).Length+1; int end1 = start1 + 9; object oStart = (object)start1; object oEnd = (object)end1; Microsoft.Office.Interop.Word.Range rBold = WordDoc.Range(ref oStart, ref oEnd); rBold.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineSingle; oPara1.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara2; oPara1.Range.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone; oPara2 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara2.Range.Text = DateTime.Now.Year + "年" + DateTime.Now.Month + "月" + DateTime.Now.Day + "日"; oPara2.Range.Font.Bold = 0;//不加粗 oPara2.Range.Font.Name = "黑体"; oPara2.Range.Font.Size = (float)10.5; oPara2.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; oPara2.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara3; oPara3 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara3.Range.Text = "1. 用户基本信息"; oPara3.Range.Font.Bold = 1; oPara3.Range.Font.Name = "黑体"; oPara3.Range.Font.Size = 14; oPara3.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara3.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara4; oPara4 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara4.Range.Text = "用户:" + RGBI.UserName; oPara4.Range.Font.Bold = 0; oPara4.Range.Font.Name = "宋体"; oPara4.Range.Font.Size = (float)10.5; oPara4.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara4.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara5; oPara5 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara5.Range.Text = "联系人" + RGBI.Linkman; oPara5.Range.Font.Bold = 0; oPara5.Range.Font.Name = "宋体"; oPara5.Range.Font.Size = (float)10.5; oPara5.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara5.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara6; oPara6 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara6.Range.Text = "账号有效时间:" + RGBI.Expires; oPara6.Range.Font.Bold = 0; oPara6.Range.Font.Name = "宋体"; oPara6.Range.Font.Size = (float)10.5; oPara6.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara6.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara7; oPara7 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara7.Range.Text = "账号:" + RGBI.Account; oPara7.Range.Font.Name = "宋体"; oPara7.Range.Font.Bold = 0; oPara7.Range.Font.Size = (float)10.5; oPara7.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara7.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara8; oPara8 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara8.Range.Text = "可用资源:"; oPara8.Range.Font.Name = "宋体"; oPara8.Range.Font.Size = (float)10.5; oPara8.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara8.Range.InsertParagraphAfter(); WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 CreateTabel1(WordDoc, WordApp, 2, 3, RGBI);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara9; oPara9 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara9.Range.Text = "2.总体使用情况(" + startTime.Year + "年" + startTime.Month + "." + startTime.Day + "-" + endTime.Month + "." + endTime.Day + ")"; oPara9.Range.Font.Bold = 1; oPara9.Range.Font.Name = "黑体"; oPara9.Range.Font.Size = 14; oPara9.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara9.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara10; oPara10 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara10.Range.Text = "机时使用情况"; oPara10.Range.Font.Name = "宋体"; oPara10.Range.Font.Bold = 0; oPara10.Range.Font.Size = (float)10.5; oPara10.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; oPara10.Range.InsertParagraphAfter(); for (int i = 0; i < 2; i++) { WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 } WordApp.Selection.TypeParagraph();//插入段落 CreateTabel2(WordDoc, WordApp, dtComputerTimeInfo.Rows.Count + 1, 3, dtComputerTimeInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara11; oPara11 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara11.Range.Text = "队列使用情况"; oPara11.Range.Font.Name = "宋体"; oPara11.Range.Font.Bold = 0; oPara11.Range.Font.Size = (float)10.5; oPara11.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; oPara11.Range.InsertParagraphAfter(); for (int i = 0; i < dtComputerTimeInfo.Rows.Count; i++) { WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 } CreateTabel3(WordDoc, WordApp, dtAllQueueInfo.Rows.Count + 1, 4, dtAllQueueInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara12; oPara12 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara12.Range.Text = "操作系统情况"; oPara12.Range.Font.Name = "宋体"; oPara12.Range.Font.Bold = 0; oPara12.Range.Font.Size = (float)10.5; oPara12.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; oPara12.Range.InsertParagraphAfter(); for (int i = 0; i < dtAllQueueInfo.Rows.Count; i++) { WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 } CreateTabel4(WordDoc, WordApp, dtAllSystemInfo.Rows.Count + 1, 4, dtAllSystemInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara13; oPara13 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara13.Range.Text = "作业规模情况"; oPara13.Range.Font.Name = "宋体"; oPara13.Range.Font.Bold = 0; oPara13.Range.Font.Size = (float)10.5; oPara13.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; oPara13.Range.InsertParagraphAfter(); for (int i = 0; i < dtAllSystemInfo.Rows.Count; i++) { WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 } CreateTabel5(WordDoc, WordApp, dtAllJobsInfo.Rows.Count + 1, 4, dtAllJobsInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara14; oPara14 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara14.Range.Text = "3.个体使用情况"; oPara14.Range.Font.Bold = 1; oPara14.Range.Font.Name = "黑体"; oPara14.Range.Font.Size = 14; oPara14.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara14.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara15; oPara15 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara15.Range.Text = "机时使用情况"; oPara15.Range.Font.Name = "宋体"; oPara15.Range.Font.Bold = 0; oPara15.Range.Font.Size = (float)10.5; oPara15.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; oPara15.Range.InsertParagraphAfter(); for (int i = 0; i < dtAllJobsInfo.Rows.Count; i++) { WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 } CreateTabel6(WordDoc, WordApp, dtUserComputerTimeInfo.Rows.Count + 1, 4, dtUserComputerTimeInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara16; oPara16 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara16.Range.Text = "队列使用情况"; oPara16.Range.Font.Name = "宋体"; oPara16.Range.Font.Bold = 0; oPara16.Range.Font.Size = (float)10.5; oPara16.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; oPara16.Range.InsertParagraphAfter(); for (int i = 0; i < dtUserComputerTimeInfo.Rows.Count; i++) { WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 } CreateTabel7(WordDoc, WordApp, dtUserQueueInfo.Rows.Count + 1, 4, dtUserQueueInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara17; oPara17 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara17.Range.Text = "操作系统情况"; oPara17.Range.Font.Name = "宋体"; oPara17.Range.Font.Bold = 0; oPara17.Range.Font.Size = (float)10.5; oPara17.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; oPara17.Range.InsertParagraphAfter(); WordApp.Selection.TypeParagraph();//插入段落 for (int i = 0; i < dtUserQueueInfo.Rows.Count; i++) { WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 } CreateTabel8(WordDoc, WordApp, dtUserSystemInfo.Rows.Count + 1, 5, dtUserSystemInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara18; oPara18 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara18.Range.Text = "4.每日使用情况"; oPara18.Range.Font.Bold = 1; oPara18.Range.Font.Name = "黑体"; oPara18.Range.Font.Size = 14; oPara18.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara18.Range.InsertParagraphAfter(); WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara27; oPara27 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara27.Range.Text = ""; oPara27.Range.Font.Name = "宋体"; oPara27.Range.Font.Bold = 0; oPara27.Range.Font.Size = (float)10.5; oPara27.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara27.Range.InsertParagraphAfter(); for (int i = 0; i < dtUserSystemInfo.Rows.Count ; i++) { WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 } CreateTabel9(WordDoc, WordApp, dtAllDailyInfo.Rows.Count + 1, 8, dtAllDailyInfo);//创建表格 Microsoft.Office.Interop.Word.Paragraph oPara19; oPara19 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara19.Range.Text = "5.异常情况及排队原因"; oPara19.Range.Font.Bold = 1; oPara19.Range.Font.Name = "黑体"; oPara19.Range.Font.Size = 14; oPara19.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara19.Range.InsertParagraphAfter(); WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara20; oPara20 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara20.Range.Text = ""; oPara20.Range.Font.Name = "宋体"; oPara20.Range.Font.Bold = 0; oPara20.Range.Font.Size = (float)10.5; oPara20.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; oPara20.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara21; oPara21 = WordDoc.Content.Paragraphs.Add(ref Nothing); oPara21.Range.Text = "6.本月使用情况分析"; oPara21.Range.Font.Bold = 1; oPara21.Range.Font.Name = "黑体"; oPara21.Range.Font.Size = 14; oPara21.Range.ParagraphFormat.Alignment = |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论