update test run

This commit is contained in:
2024-01-25 16:16:18 +08:00
parent 9b01a40341
commit 78fc801b71
7 changed files with 240 additions and 73 deletions
@@ -1,5 +1,6 @@
using BLL;
using Newtonsoft.Json.Linq;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
@@ -38,6 +39,18 @@ namespace FineUIPro.Web.TestRun.DriverPrepare
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
var solutionType = (from x in Funs.DB.DriverPrepare_SchemePlan
join y in Funs.DB.DriverPrepare_SchemePlanItem on x.SchemePlanId equals y.SchemePlanId
where y.SolutionType != null && x.ProjectId == this.CurrUser.LoginProjectId
select y).FirstOrDefault();
if (solutionType == null)
{
this.Grid1.Columns[1].Hidden = true;
}
else
{
this.Grid1.Columns[1].Hidden = false;
}
}
#endregion
@@ -178,87 +191,201 @@ namespace FineUIPro.Web.TestRun.DriverPrepare
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = Const.SchemePlanTemplateUrl;
var solutionType = (from x in Funs.DB.DriverPrepare_SchemePlan
join y in Funs.DB.DriverPrepare_SchemePlanItem on x.SchemePlanId equals y.SchemePlanId
where y.SolutionType != null && x.ProjectId == this.CurrUser.LoginProjectId
select y).FirstOrDefault();
if (solutionType == null)
{
initTemplatePath = Const.SchemePlanTemplateUrl;
}
else
{
initTemplatePath = Const.SchemePlan2TemplateUrl;
}
uploadfilepath = rootPath + initTemplatePath;
Model.DriverPrepare_SchemePlan plan = BLL.DriverPrepareSchemePlanService.GetDriverPlanByProjectId(this.CurrUser.LoginProjectId);
if (plan != null)
{
string projectName = BLL.ProjectService.GetProjectNameByProjectId(plan.ProjectId);
newUrl = uploadfilepath.Replace(".xlsx", "(" + projectName + ")" + ".xlsx");
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font = workbook.CreateFont();
font.FontHeightInPoints = 11;
cellStyle.SetFont(font);
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font0 = workbook.CreateFont();
font0.FontHeightInPoints = 12;
font0.IsBold = true;
cellStyle0.SetFont(font0);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell;
cell = row.GetCell(0);
cell.CellStyle = cellStyle0;
cell.SetCellValue(projectName + "试车方案");
var items = BLL.DriverPrepareSchemePlanItemService.GetSchemePlanItemByschemePlanId(plan.SchemePlanId);
int i = 2;
foreach (var item in items)
if (solutionType == null)
{
newUrl = uploadfilepath.Replace(".xlsx", "(" + projectName + ")" + ".xlsx");
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font = workbook.CreateFont();
font.FontHeightInPoints = 11;
cellStyle.SetFont(font);
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font0 = workbook.CreateFont();
font0.FontHeightInPoints = 12;
font0.IsBold = true;
cellStyle0.SetFont(font0);
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue((i-1).ToString());
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.SolutionName);
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
i++;
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell;
cell = row.GetCell(0);
cell.CellStyle = cellStyle0;
cell.SetCellValue(projectName + "试车方案");
var items = BLL.DriverPrepareSchemePlanItemService.GetSchemePlanItemByschemePlanId(plan.SchemePlanId);
int i = 2;
foreach (var item in items)
{
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue((i - 1).ToString());
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.SolutionName);
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
i++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
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);
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
else
{
workbook.Write(stream);
workbook.Close();
newUrl = uploadfilepath.Replace("2.xlsx", "(" + projectName + ")" + ".xlsx");
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font = workbook.CreateFont();
font.FontHeightInPoints = 11;
cellStyle.SetFont(font);
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font0 = workbook.CreateFont();
font0.FontHeightInPoints = 12;
font0.IsBold = true;
cellStyle0.SetFont(font0);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell;
cell = row.GetCell(0);
cell.CellStyle = cellStyle0;
cell.SetCellValue(projectName + "试车方案");
var items = BLL.DriverPrepareSchemePlanItemService.GetSchemePlanItemByschemePlanId(plan.SchemePlanId);
int i = 2;
string type = string.Empty;
int firstRow = 2;
foreach (var item in items)
{
if (string.IsNullOrEmpty(type))
{
type = item.SolutionType;
}
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue((i - 1).ToString());
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.SolutionType);
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.SolutionName);
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
if (type != item.SolutionType)
{
type = item.SolutionType;
sheet.AddMergedRegion(new CellRangeAddress(firstRow, i - 1, 1, 1));
firstRow = i;
}
else
{
if (i == 1 + items.Count)
{
sheet.AddMergedRegion(new CellRangeAddress(firstRow, i, 1, 1));
}
}
i++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
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);
}
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);
}
else
{