提交代码
This commit is contained in:
@@ -6,7 +6,6 @@ using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Model;
|
||||
using System.Collections;
|
||||
using Apache.NMS.ActiveMQ.Threads;
|
||||
@@ -14,6 +13,14 @@ using FineUIPro.Web.DataShow;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Aspose.Words.Lists;
|
||||
using System.Web.UI.DataVisualization.Charting;
|
||||
using static FineUIPro.Web.TestRun.Report.PreRunSchedule;
|
||||
using System.Reflection;
|
||||
using static FineUIPro.Web.TestRun.Report.TestRunSchedule;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.SS.Util;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System.IO;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
|
||||
namespace FineUIPro.Web.TestRun.Report
|
||||
{
|
||||
@@ -35,6 +42,25 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
/// </summary>
|
||||
public void DataBridYsc()
|
||||
{
|
||||
var result = YscData();
|
||||
GridYsc.DataSource = result;
|
||||
TabStrip1.ActiveTabIndex = 0;
|
||||
GridYsc.DataBind();
|
||||
JObject summary = new JObject();
|
||||
summary.Add("AllNum", result.Sum(x => x.AllNum));
|
||||
summary.Add("ProgressNum", result.Sum(x => x.ProgressNum));
|
||||
summary.Add("CompleteNum", result.Sum(x => x.CompleteNum));
|
||||
GridYsc.SummaryData = summary;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预试车数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<Run_ScheduleSetUpDto> YscData()
|
||||
{
|
||||
var result = new List<Run_ScheduleSetUpDto>();
|
||||
|
||||
if (Funs.DB.Run_ScheduleSetUp.Count(x => x.ProjectId == this.CurrUser.LoginProjectId && x.States == 1) > 0)
|
||||
{
|
||||
var query = from a in Funs.DB.Run_ScheduleSetUp
|
||||
@@ -56,29 +82,75 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
AddTime = a.AddTime,
|
||||
Sort = a.Sort
|
||||
};
|
||||
GridYsc.DataSource = query.ToList();
|
||||
result = query.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = new List<Run_ScheduleSetUpDto>();
|
||||
string strSql = @"select a.WorkPackId,a.WorkPackName,(select COUNT(1) from PreRun_SubInspectTerm as b where b.WorkPackId=a.WorkPackId and b.ProjectId=@ProjectId) as AllNum,(select COUNT(1) from PreRun_SubInspectTerm as b where b.WorkPackId=a.WorkPackId and b.ProjectId=@ProjectId and ISNULL(b.InspectIsClose,0)=0) as ProgressNum,(select COUNT(1) from PreRun_SubInspectTerm as b where b.WorkPackId=a.WorkPackId and b.ProjectId=@ProjectId and ISNULL(b.InspectIsClose,0)=1) as CompleteNum from PreRun_WorkPackage as a order by a.Sort"; List<SqlParameter> listStr = new List<SqlParameter>();
|
||||
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
||||
SqlParameter[] parameter = listStr.ToArray();
|
||||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||||
if (tb.Rows.Count > 0)
|
||||
List<string> SubSystemIds = new List<string>();
|
||||
var devices = Funs.DB.PreRun_SysDevice.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && x.PreRunLevel == 4).ToList();
|
||||
if (devices.Count > 0)
|
||||
{
|
||||
int i = 1;
|
||||
foreach (DataRow row in tb.Rows)
|
||||
SubSystemIds = devices.ConvertAll(x => x.PreRunId);
|
||||
}
|
||||
string allStr = $"select a.SubSystemId,a.SystemId,b.WorkPackId,b.WorkPackName,b.WorkPackType,(select count(1) from PreRun_SubPropertySelect as gd where gd.SubSystemId = a.SubSystemId) as GdallNum,(select count(1) from PreRun_SubTechnologySelect as sb where sb.SubSystemId = a.SubSystemId) as SballNum,(select count(1) from PreRun_SubInstrumentSelect as sy where sy.SubSystemId = a.SubSystemId) as SyallNum from PreRun_SubSysWorkPackage as a inner join PreRun_WorkPackage as b on a.WorkPackId = b.WorkPackId where a.SubSystemId in ('{string.Join("','", SubSystemIds)}') order by a.WorkPackCode asc";
|
||||
var dt = SQLHelper.GetDataTableRunText(allStr);
|
||||
string inspectStr = $"select a.WorkPackId,b.WorkPackName,b.Sort,SUM(case ISNULL(a.InspectIsClose, 0) when 1 then 1 else 0 end) as CloseNum,SUM(case ISNULL(a.InspectIsClose, 0) when 0 then 1 else 0 end) as NoCloseNum,COUNT(1) as AllNum from PreRun_SubInspectTerm as a inner join PreRun_WorkPackage as b on a.WorkPackId = b.WorkPackId where 1=1 and a.ProjectId = '{this.CurrUser.LoginProjectId}' and a.SubSystemId in ('{string.Join("','", SubSystemIds)}') group by a.WorkPackId,b.WorkPackName,b.Sort order by b.Sort asc";
|
||||
var inspectDt = SQLHelper.GetDataTableRunText(inspectStr);
|
||||
var inspectlist = DataTableToList<WorkPackageInspectDto>(inspectDt);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
//获取所有子系统数量
|
||||
var inspects = Funs.DB.PreRun_SubInspectTerm.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && SubSystemIds.Contains(x.SubSystemId));
|
||||
var querylist = DataTableToList<QuerySubSysWorkPackage>(dt);
|
||||
var queryGroup = querylist.GroupBy(x => new { x.WorkPackId, x.WorkPackName, x.WorkPackType }).Select(p => new
|
||||
{
|
||||
p.Key.WorkPackId,
|
||||
p.Key.WorkPackName,
|
||||
p.Key.WorkPackType
|
||||
});
|
||||
int i = 1;
|
||||
foreach (var itemPack in queryGroup)
|
||||
{
|
||||
var itemQueryList = querylist.Where(x => x.WorkPackId == itemPack.WorkPackId).ToList();
|
||||
var model = new Run_ScheduleSetUpDto();
|
||||
model.ScheduleId = Guid.NewGuid().ToString();
|
||||
model.WorkPackId = row["WorkPackId"].ToString();
|
||||
model.WorkPackName = row["WorkPackName"].ToString();
|
||||
model.WorkPackId = itemPack.WorkPackId;
|
||||
model.WorkPackName = itemPack.WorkPackName;
|
||||
model.ProjectId = this.CurrUser.LoginProjectId;
|
||||
model.States = 1;
|
||||
model.AllNum = int.Parse(row["AllNum"].ToString());
|
||||
model.ProgressNum = int.Parse(row["ProgressNum"].ToString());
|
||||
model.CompleteNum = int.Parse(row["CompleteNum"].ToString());
|
||||
model.AllNum = itemQueryList.Count(x => x.WorkPackId == itemPack.WorkPackId);
|
||||
model.ProgressNum = 0;
|
||||
model.CompleteNum = 0;
|
||||
var subsystemids = itemQueryList.ConvertAll(a => a.SubSystemId).Distinct();
|
||||
foreach (var itemsubid in subsystemids)
|
||||
{
|
||||
if (inspects.Count(x => x.SubSystemId == itemsubid) > 0)
|
||||
{
|
||||
var itemQuerylist = itemQueryList.FirstOrDefault(x => x.SubSystemId == itemsubid && x.WorkPackId == itemPack.WorkPackId);
|
||||
var allNum = itemQuerylist.GdallNum + itemQuerylist.SballNum + itemQuerylist.SyallNum;
|
||||
if (inspects.Count(x => x.SubInspectId == itemsubid && x.InspectIsClose != 1) > 0)
|
||||
{
|
||||
model.ProgressNum += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
var closeInspect = inspects.Where(x => x.SubInspectId == itemsubid && x.InspectIsClose == 1);
|
||||
var closeNums = closeInspect.Count() > 0 ? closeInspect.Select(x => x.PropertyTechnologyId.Split(',').Count()).Sum(x => x) : 0;
|
||||
if (allNum > closeNums)
|
||||
{
|
||||
model.ProgressNum += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
model.CompleteNum += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model.ProgressNum += 1;
|
||||
}
|
||||
}
|
||||
var rate = model.CompleteNum > 0 ? (decimal)Math.Round((float)model.CompleteNum / (float)model.AllNum * 100, 2, MidpointRounding.AwayFromZero) : 0;
|
||||
if (rate > 100) rate = 100;
|
||||
model.CompleteRate = rate;
|
||||
@@ -89,10 +161,9 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
i++;
|
||||
}
|
||||
}
|
||||
GridYsc.DataSource = result;
|
||||
}
|
||||
TabStrip1.ActiveTabIndex = 0;
|
||||
GridYsc.DataBind();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -155,6 +226,115 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预试车导出
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnYscExport_Click(object sender, EventArgs e)
|
||||
{
|
||||
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
|
||||
//导出文件
|
||||
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
string ReportFileName = filePath + "预试车进度.xlsx";
|
||||
|
||||
var result = YscData();
|
||||
|
||||
if (result.Count > 0)
|
||||
{
|
||||
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
|
||||
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("预试车进度");
|
||||
|
||||
#region 列宽
|
||||
|
||||
ws.SetColumnWidth(0, (30 * 256));
|
||||
ws.SetColumnWidth(1, (20 * 256));
|
||||
ws.SetColumnWidth(2, (20 * 256));
|
||||
ws.SetColumnWidth(3, (20 * 256));
|
||||
|
||||
#endregion
|
||||
|
||||
#region 样式
|
||||
//公共样式
|
||||
ICellStyle style = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true);
|
||||
//公共样式加粗
|
||||
ICellStyle styleBold = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true, true);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 头部
|
||||
|
||||
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, 0, 0, 0, 3);
|
||||
//行1
|
||||
ws.GetRow(0).GetCell(0).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(0).SetCellValue("工作包名称");
|
||||
ws.GetRow(0).GetCell(1).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(1).SetCellValue("全部数量");
|
||||
ws.GetRow(0).GetCell(2).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(2).SetCellValue("进行中数量");
|
||||
ws.GetRow(0).GetCell(3).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(3).SetCellValue("已完成数量");
|
||||
|
||||
#endregion
|
||||
|
||||
#region 表格
|
||||
|
||||
var start = 1;
|
||||
var end = result.Count;
|
||||
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, start, end, 0, 3);
|
||||
|
||||
//数据
|
||||
var dataIndex = 1;
|
||||
foreach (var item in result)
|
||||
{
|
||||
ws.GetRow(dataIndex).GetCell(0).SetCellValue(item.WorkPackName);
|
||||
ws.GetRow(dataIndex).GetCell(1).SetCellValue(item.AllNum.ToString());
|
||||
ws.GetRow(dataIndex).GetCell(2).SetCellValue(item.ProgressNum.ToString());
|
||||
ws.GetRow(dataIndex).GetCell(3).SetCellValue(item.CompleteNum.ToString());
|
||||
dataIndex++;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 尾部
|
||||
|
||||
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, end + 1, end + 1, 0, 3);
|
||||
ws.GetRow(end + 1).GetCell(0).SetCellValue("合计");
|
||||
ws.GetRow(end + 1).GetCell(1).SetCellValue(result.Count > 0 ? result.Sum(x => x.AllNum).ToString() : "0");
|
||||
ws.GetRow(end + 1).GetCell(2).SetCellValue(result.Count > 0 ? result.Sum(x => x.ProgressNum).ToString() : "0");
|
||||
ws.GetRow(end + 1).GetCell(3).SetCellValue(result.Count > 0 ? result.Sum(x => x.CompleteNum).ToString() : "0");
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
ws.PrintSetup.Landscape = false;
|
||||
ws.PrintSetup.PaperSize = 9;
|
||||
ws.ForceFormulaRecalculation = true;
|
||||
using (FileStream filess = File.OpenWrite(ReportFileName))
|
||||
{
|
||||
hssfworkbook.Write(filess);
|
||||
}
|
||||
FileInfo filet = new FileInfo(ReportFileName);
|
||||
Response.Clear();
|
||||
Response.Charset = "GB2312";
|
||||
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
|
||||
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("预试车进度.xlsx"));
|
||||
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
|
||||
Response.AddHeader("Content-Length", filet.Length.ToString());
|
||||
// 指定返回的是一个不能被客户端读取的流,必须被下载
|
||||
Response.ContentType = "application/ms-excel";
|
||||
// 把文件流发送到客户端
|
||||
Response.WriteFile(filet.FullName);
|
||||
// 停止页面的执行
|
||||
Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 试车
|
||||
@@ -164,6 +344,26 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
/// </summary>
|
||||
public void DataBridSc()
|
||||
{
|
||||
var result = ScData();
|
||||
GridSc.DataSource = result;
|
||||
TabStrip1.ActiveTabIndex = 1;
|
||||
GridSc.DataBind();
|
||||
|
||||
JObject summary = new JObject();
|
||||
summary.Add("AllNum", result.Sum(x => x.AllNum));
|
||||
summary.Add("ProgressNum", result.Sum(x => x.ProgressNum));
|
||||
summary.Add("CompleteNum", result.Sum(x => x.CompleteNum));
|
||||
GridSc.SummaryData = summary;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 试车数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<Run_ScheduleSetUpDto> ScData()
|
||||
{
|
||||
var result = new List<Run_ScheduleSetUpDto>();
|
||||
|
||||
if (Funs.DB.Run_ScheduleSetUp.Count(x => x.ProjectId == this.CurrUser.LoginProjectId && x.States == 2) > 0)
|
||||
{
|
||||
var query = from a in Funs.DB.Run_ScheduleSetUp
|
||||
@@ -185,29 +385,48 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
AddTime = a.AddTime,
|
||||
Sort = a.Sort
|
||||
};
|
||||
GridSc.DataSource = query.ToList();
|
||||
result = query.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = new List<Run_ScheduleSetUpDto>();
|
||||
string strSql = @"select a.WorkPackId,a.WorkPackName,(select COUNT(1) from TestRun_SubInspectTerm as b where b.WorkPackId=a.WorkPackId and b.ProjectId=@ProjectId) as AllNum,(select COUNT(1) from TestRun_SubInspectTerm as b where b.WorkPackId=a.WorkPackId and b.ProjectId=@ProjectId and ISNULL(b.InspectIsClose,0)=0) as ProgressNum,(select COUNT(1) from TestRun_SubInspectTerm as b where b.WorkPackId=a.WorkPackId and b.ProjectId=@ProjectId and ISNULL(b.InspectIsClose,0)=1) as CompleteNum from TestRun_WorkPackage as a order by a.Sort"; List<SqlParameter> listStr = new List<SqlParameter>();
|
||||
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
||||
SqlParameter[] parameter = listStr.ToArray();
|
||||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||||
if (tb.Rows.Count > 0)
|
||||
List<string> SystemIds = new List<string>();
|
||||
var devices = Funs.DB.PreRun_SysDevice.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && x.PreRunLevel == 3).ToList();
|
||||
if (devices.Count > 0)
|
||||
{
|
||||
SystemIds = devices.ConvertAll(x => x.PreRunId);
|
||||
}
|
||||
string allStr = $"select b.WorkPackId,b.WorkPackName,COUNT(a.SystemId) as WorkPackNum from TestRun_SubSysWorkPackage as a inner join TestRun_WorkPackage as b on a.WorkPackId = b.WorkPackId where a.SystemId in ('{string.Join("','", SystemIds)}') group by b.WorkPackId,b.WorkPackName";
|
||||
var dt = SQLHelper.GetDataTableRunText(allStr);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
string inspectStr = $"select a.WorkPackId,b.WorkPackName,b.Sort,SUM(case ISNULL(a.InspectIsClose, 0) when 1 then 1 else 0 end) as CloseNum,SUM(case ISNULL(a.InspectIsClose, 0) when 0 then 1 else 0 end) as NoCloseNum,COUNT(1) as AllNum from TestRun_SubInspectTerm as a inner join TestRun_WorkPackage as b on a.WorkPackId = b.WorkPackId where 1=1 and a.ProjectId = '{this.CurrUser.LoginProjectId}' group by a.WorkPackId,b.WorkPackName,b.Sort order by b.Sort asc";
|
||||
var inspectDt = SQLHelper.GetDataTableRunText(inspectStr);
|
||||
var inspectlist = DataTableToList<WorkPackageInspectDto>(inspectDt);
|
||||
|
||||
int i = 1;
|
||||
foreach (DataRow row in tb.Rows)
|
||||
var list = DataTableToList<TestRunScheduleDto>(dt);
|
||||
foreach (var item in list)
|
||||
{
|
||||
var model = new Run_ScheduleSetUpDto();
|
||||
model.ScheduleId = Guid.NewGuid().ToString();
|
||||
model.WorkPackId = row["WorkPackId"].ToString();
|
||||
model.WorkPackName = row["WorkPackName"].ToString();
|
||||
model.WorkPackId = item.WorkPackId;
|
||||
model.WorkPackName = item.WorkPackName;
|
||||
model.ProjectId = this.CurrUser.LoginProjectId;
|
||||
model.States = 2;
|
||||
model.AllNum = int.Parse(row["AllNum"].ToString());
|
||||
model.ProgressNum = int.Parse(row["ProgressNum"].ToString());
|
||||
model.CompleteNum = int.Parse(row["CompleteNum"].ToString());
|
||||
|
||||
if (inspectlist.Count(x => x.WorkPackId == item.WorkPackId) > 0)
|
||||
{
|
||||
var itemInspect = inspectlist.FirstOrDefault(x => x.WorkPackId == item.WorkPackId);
|
||||
model.AllNum = itemInspect.AllNum;
|
||||
model.ProgressNum = itemInspect.NoCloseNum;
|
||||
model.CompleteNum = itemInspect.CloseNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
model.AllNum = 0;
|
||||
model.ProgressNum = 0;
|
||||
model.CompleteNum = 0;
|
||||
}
|
||||
model.CompleteRate = model.CompleteNum > 0 ? (decimal)Math.Round((float)model.CompleteNum / (float)model.AllNum, 2, MidpointRounding.AwayFromZero) : 0;
|
||||
model.AddUser = this.CurrUser.UserId;
|
||||
model.AddTime = DateTime.Now;
|
||||
@@ -216,10 +435,9 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
i++;
|
||||
}
|
||||
}
|
||||
GridSc.DataSource = result;
|
||||
}
|
||||
TabStrip1.ActiveTabIndex = 1;
|
||||
GridSc.DataBind();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -280,10 +498,389 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 试车导出
|
||||
/// </summary>
|
||||
protected void btnScExport_Click(object sender, EventArgs e)
|
||||
{
|
||||
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
|
||||
//导出文件
|
||||
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
string ReportFileName = filePath + "试车进度.xlsx";
|
||||
|
||||
var result = ScData();
|
||||
|
||||
if (result.Count > 0)
|
||||
{
|
||||
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
|
||||
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("试车进度");
|
||||
|
||||
#region 列宽
|
||||
|
||||
ws.SetColumnWidth(0, (30 * 256));
|
||||
ws.SetColumnWidth(1, (20 * 256));
|
||||
ws.SetColumnWidth(2, (20 * 256));
|
||||
ws.SetColumnWidth(3, (20 * 256));
|
||||
|
||||
#endregion
|
||||
|
||||
#region 样式
|
||||
//公共样式
|
||||
ICellStyle style = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true);
|
||||
//公共样式加粗
|
||||
ICellStyle styleBold = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true, true);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 头部
|
||||
|
||||
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, 0, 0, 0, 3);
|
||||
//行1
|
||||
ws.GetRow(0).GetCell(0).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(0).SetCellValue("工作包名称");
|
||||
ws.GetRow(0).GetCell(1).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(1).SetCellValue("全部数量");
|
||||
ws.GetRow(0).GetCell(2).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(2).SetCellValue("进行中数量");
|
||||
ws.GetRow(0).GetCell(3).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(3).SetCellValue("已完成数量");
|
||||
|
||||
#endregion
|
||||
|
||||
#region 表格
|
||||
|
||||
var start = 1;
|
||||
var end = result.Count;
|
||||
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, start, end, 0, 3);
|
||||
|
||||
//数据
|
||||
var dataIndex = 1;
|
||||
foreach (var item in result)
|
||||
{
|
||||
ws.GetRow(dataIndex).GetCell(0).SetCellValue(item.WorkPackName);
|
||||
ws.GetRow(dataIndex).GetCell(1).SetCellValue(item.AllNum.ToString());
|
||||
ws.GetRow(dataIndex).GetCell(2).SetCellValue(item.ProgressNum.ToString());
|
||||
ws.GetRow(dataIndex).GetCell(3).SetCellValue(item.CompleteNum.ToString());
|
||||
dataIndex++;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 尾部
|
||||
|
||||
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, end + 1, end + 1, 0, 3);
|
||||
ws.GetRow(end + 1).GetCell(0).SetCellValue("合计");
|
||||
ws.GetRow(end + 1).GetCell(1).SetCellValue(result.Count > 0 ? result.Sum(x => x.AllNum).ToString() : "0");
|
||||
ws.GetRow(end + 1).GetCell(2).SetCellValue(result.Count > 0 ? result.Sum(x => x.ProgressNum).ToString() : "0");
|
||||
ws.GetRow(end + 1).GetCell(3).SetCellValue(result.Count > 0 ? result.Sum(x => x.CompleteNum).ToString() : "0");
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
ws.PrintSetup.Landscape = false;
|
||||
ws.PrintSetup.PaperSize = 9;
|
||||
ws.ForceFormulaRecalculation = true;
|
||||
using (FileStream filess = File.OpenWrite(ReportFileName))
|
||||
{
|
||||
hssfworkbook.Write(filess);
|
||||
}
|
||||
FileInfo filet = new FileInfo(ReportFileName);
|
||||
Response.Clear();
|
||||
Response.Charset = "GB2312";
|
||||
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
|
||||
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("试车进度.xlsx"));
|
||||
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
|
||||
Response.AddHeader("Content-Length", filet.Length.ToString());
|
||||
// 指定返回的是一个不能被客户端读取的流,必须被下载
|
||||
Response.ContentType = "application/ms-excel";
|
||||
// 把文件流发送到客户端
|
||||
Response.WriteFile(filet.FullName);
|
||||
// 停止页面的执行
|
||||
Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 三查四定
|
||||
|
||||
/// <summary>
|
||||
/// 三查四定绑定
|
||||
/// </summary>
|
||||
public void DataBridScsd()
|
||||
{
|
||||
var result = ScsdData();
|
||||
GridScsd.DataSource = result;
|
||||
TabStrip1.ActiveTabIndex = 2;
|
||||
GridScsd.DataBind();
|
||||
JObject summary = new JObject();
|
||||
summary.Add("AllNum", result.Sum(x => x.AllNum));
|
||||
summary.Add("ProgressNum", result.Sum(x => x.ProgressNum));
|
||||
summary.Add("CompleteNum", result.Sum(x => x.CompleteNum));
|
||||
GridScsd.SummaryData = summary;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 三查四定数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<Run_ScheduleSetUp> ScsdData()
|
||||
{
|
||||
var result = new List<Run_ScheduleSetUp>();
|
||||
|
||||
if (Funs.DB.Run_ScheduleSetUp.Count(x => x.ProjectId == this.CurrUser.LoginProjectId && x.States == 3) > 0)
|
||||
{
|
||||
result = Funs.DB.Run_ScheduleSetUp.Where(a => a.States == 3 && a.ProjectId == this.CurrUser.LoginProjectId).OrderBy(o => o.LevelName).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<FourDecisionScheduleBridDto>();
|
||||
string allStr = $"select Level,COUNT(1) as AllNum,SUM(case ISNULL(a.DecisionIsClose,0) when 0 then 1 else 0 end) as NoCloseNum,SUM(case ISNULL(a.DecisionIsClose,0) when 1 then 1 else 0 end) as CloseNum from PreRun_SubThreeChecksFourDecision as a where a.ProjectId='{this.CurrUser.LoginProjectId}' group by a.Level order by a.Level asc";
|
||||
var dt = SQLHelper.GetDataTableRunText(allStr);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
int i = 1;
|
||||
list = DataTableToList<FourDecisionScheduleBridDto>(dt);
|
||||
foreach (var item in list)
|
||||
{
|
||||
var model = new Run_ScheduleSetUp();
|
||||
model.ScheduleId = Guid.NewGuid().ToString();
|
||||
model.ProjectId = this.CurrUser.LoginProjectId;
|
||||
model.LevelName = item.Level;
|
||||
model.States = 3;
|
||||
model.AllNum = item.AllNum;
|
||||
model.ProgressNum = item.NoCloseNum;
|
||||
model.CompleteNum = item.CloseNum;
|
||||
model.CompleteRate = model.CompleteNum > 0 ? (decimal)Math.Round((float)model.CompleteNum / (float)model.AllNum, 2, MidpointRounding.AwayFromZero) : 0;
|
||||
model.AddUser = this.CurrUser.UserId;
|
||||
model.AddTime = DateTime.Now;
|
||||
model.Sort = i;
|
||||
result.Add(model);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 三查四定重置
|
||||
/// </summary>
|
||||
protected void btnScsdReset_Click(object sender, EventArgs e)
|
||||
{
|
||||
var list = Funs.DB.Run_ScheduleSetUp.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && x.States == 3);
|
||||
if (list.Count() > 0)
|
||||
{
|
||||
Funs.DB.Run_ScheduleSetUp.DeleteAllOnSubmit(list);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
DataBridScsd();
|
||||
ShowNotify("重置成功!", MessageBoxIcon.Success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 三查四定保存
|
||||
/// </summary>
|
||||
protected void btnScsdSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var deletelist = Funs.DB.Run_ScheduleSetUp.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && x.States == 3);
|
||||
Funs.DB.Run_ScheduleSetUp.DeleteAllOnSubmit(deletelist);
|
||||
Funs.DB.SubmitChanges();
|
||||
var addList = new List<Run_ScheduleSetUp>();
|
||||
JArray mergedData = GridScsd.GetMergedData();
|
||||
foreach (JObject mergedRow in mergedData)
|
||||
{
|
||||
string status = mergedRow.Value<string>("status");
|
||||
JObject values = mergedRow.Value<JObject>("values");
|
||||
int i = mergedRow.Value<int>("index");
|
||||
var model = new Run_ScheduleSetUp();
|
||||
model.ScheduleId = this.GridScsd.Rows[i].DataKeys[0].ToString();
|
||||
model.LevelName = this.GridScsd.Rows[i].DataKeys[1].ToString();
|
||||
model.ProjectId = this.CurrUser.LoginProjectId;
|
||||
model.States = 3;
|
||||
model.AllNum = !string.IsNullOrWhiteSpace(values.Value<string>("AllNum")) ? int.Parse(values.Value<string>("AllNum")) : 0;
|
||||
model.ProgressNum = !string.IsNullOrWhiteSpace(values.Value<string>("ProgressNum")) ? int.Parse(values.Value<string>("ProgressNum")) : 0;
|
||||
model.CompleteNum = !string.IsNullOrWhiteSpace(values.Value<string>("CompleteNum")) ? int.Parse(values.Value<string>("CompleteNum")) : 0;
|
||||
model.CompleteRate = model.CompleteNum > 0 ? (decimal)Math.Round((float)model.CompleteNum / (float)model.AllNum, 2, MidpointRounding.AwayFromZero) : 0;
|
||||
model.AddUser = this.CurrUser.UserId;
|
||||
model.AddTime = DateTime.Now;
|
||||
model.Sort = i;
|
||||
addList.Add(model);
|
||||
}
|
||||
|
||||
Funs.DB.Run_ScheduleSetUp.InsertAllOnSubmit(addList);
|
||||
Funs.DB.SubmitChanges();
|
||||
DataBridScsd();
|
||||
ShowNotify("保存成功!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowNotify(ex.Message, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 三查四定导出
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnScsdExport_Click(object sender, EventArgs e)
|
||||
{
|
||||
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
|
||||
//导出文件
|
||||
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
string ReportFileName = filePath + "三查四定进度.xlsx";
|
||||
|
||||
var result = ScsdData();
|
||||
|
||||
if (result.Count > 0)
|
||||
{
|
||||
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
|
||||
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("三查四定进度");
|
||||
|
||||
#region 列宽
|
||||
|
||||
ws.SetColumnWidth(0, (30 * 256));
|
||||
ws.SetColumnWidth(1, (20 * 256));
|
||||
ws.SetColumnWidth(2, (20 * 256));
|
||||
ws.SetColumnWidth(3, (20 * 256));
|
||||
|
||||
#endregion
|
||||
|
||||
#region 样式
|
||||
//公共样式
|
||||
ICellStyle style = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true);
|
||||
//公共样式加粗
|
||||
ICellStyle styleBold = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true, true);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 头部
|
||||
|
||||
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, 0, 0, 0, 3);
|
||||
//行1
|
||||
ws.GetRow(0).GetCell(0).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(0).SetCellValue("类别名称");
|
||||
ws.GetRow(0).GetCell(1).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(1).SetCellValue("全部数量");
|
||||
ws.GetRow(0).GetCell(2).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(2).SetCellValue("进行中数量");
|
||||
ws.GetRow(0).GetCell(3).CellStyle = styleBold;
|
||||
ws.GetRow(0).GetCell(3).SetCellValue("已完成数量");
|
||||
|
||||
#endregion
|
||||
|
||||
#region 表格
|
||||
|
||||
var start = 1;
|
||||
var end = result.Count;
|
||||
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, start, end, 0, 3);
|
||||
|
||||
//数据
|
||||
var dataIndex = 1;
|
||||
foreach (var item in result)
|
||||
{
|
||||
ws.GetRow(dataIndex).GetCell(0).SetCellValue(item.LevelName);
|
||||
ws.GetRow(dataIndex).GetCell(1).SetCellValue(item.AllNum.ToString());
|
||||
ws.GetRow(dataIndex).GetCell(2).SetCellValue(item.ProgressNum.ToString());
|
||||
ws.GetRow(dataIndex).GetCell(3).SetCellValue(item.CompleteNum.ToString());
|
||||
dataIndex++;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 尾部
|
||||
|
||||
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, end + 1, end + 1, 0, 3);
|
||||
ws.GetRow(end + 1).GetCell(0).SetCellValue("合计");
|
||||
ws.GetRow(end + 1).GetCell(1).SetCellValue(result.Count > 0 ? result.Sum(x => x.AllNum).ToString() : "0");
|
||||
ws.GetRow(end + 1).GetCell(2).SetCellValue(result.Count > 0 ? result.Sum(x => x.ProgressNum).ToString() : "0");
|
||||
ws.GetRow(end + 1).GetCell(3).SetCellValue(result.Count > 0 ? result.Sum(x => x.CompleteNum).ToString() : "0");
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
ws.PrintSetup.Landscape = false;
|
||||
ws.PrintSetup.PaperSize = 9;
|
||||
ws.ForceFormulaRecalculation = true;
|
||||
using (FileStream filess = File.OpenWrite(ReportFileName))
|
||||
{
|
||||
hssfworkbook.Write(filess);
|
||||
}
|
||||
FileInfo filet = new FileInfo(ReportFileName);
|
||||
Response.Clear();
|
||||
Response.Charset = "GB2312";
|
||||
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
|
||||
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("三查四定进度.xlsx"));
|
||||
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
|
||||
Response.AddHeader("Content-Length", filet.Length.ToString());
|
||||
// 指定返回的是一个不能被客户端读取的流,必须被下载
|
||||
Response.ContentType = "application/ms-excel";
|
||||
// 把文件流发送到客户端
|
||||
Response.WriteFile(filet.FullName);
|
||||
// 停止页面的执行
|
||||
Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 私有方法
|
||||
|
||||
/// <summary>
|
||||
/// 创建头部
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private XSSFSheet ExcelCreateRowTitle(XSSFSheet ws, XSSFWorkbook hssfworkbook, ICellStyle style, int sRows, int eRows, int cStart, int cEnd, float height = 21)
|
||||
{
|
||||
for (int i = sRows; i <= eRows; i++)
|
||||
{
|
||||
ws.CreateRow(i);
|
||||
ws.GetRow(i).HeightInPoints = height;
|
||||
for (int j = cStart; j <= cEnd; j++)
|
||||
{
|
||||
ws.GetRow(i).CreateCell(j);
|
||||
ws.GetRow(i).CreateCell(j).CellStyle = style;
|
||||
}
|
||||
}
|
||||
return ws;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建样式
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static ICellStyle SetExcelStyle(XSSFWorkbook wb, BorderStyle Bottom, BorderStyle Left, BorderStyle Right, BorderStyle Top, VerticalAlignment VerAig, HorizontalAlignment HorAig, double FontSize, bool WrapText = true, bool Bold = false, string FontName = "宋体")
|
||||
{
|
||||
ICellStyle style = wb.CreateCellStyle();
|
||||
style.BorderBottom = Bottom;
|
||||
style.BorderLeft = Left;
|
||||
style.BorderRight = Right;
|
||||
style.BorderTop = Top;
|
||||
style.VerticalAlignment = VerAig;
|
||||
style.Alignment = HorAig;
|
||||
IFont font = wb.CreateFont();
|
||||
font.FontHeightInPoints = FontSize;
|
||||
font.IsBold = Bold;
|
||||
font.FontName = FontName;
|
||||
style.SetFont(font);
|
||||
style.WrapText = WrapText;
|
||||
return style;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 私有方法
|
||||
/// </summary>
|
||||
@@ -299,6 +896,11 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
//试车
|
||||
DataBridSc();
|
||||
}
|
||||
else if (TabStrip1.ActiveTabIndex == 2)
|
||||
{
|
||||
//三查四定
|
||||
DataBridScsd();
|
||||
}
|
||||
}
|
||||
|
||||
public class Run_ScheduleSetUpDto : Run_ScheduleSetUp
|
||||
@@ -309,7 +911,92 @@ namespace FineUIPro.Web.TestRun.Report
|
||||
public string WorkPackName { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 试车检查表实体
|
||||
/// </summary>
|
||||
public class WorkPackageInspectDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 工作包主键
|
||||
/// </summary>
|
||||
public string WorkPackId { get; set; }
|
||||
/// <summary>
|
||||
/// 工作包名称
|
||||
/// </summary>
|
||||
public string WorkPackName { get; set; }
|
||||
/// <summary>
|
||||
/// 检查表数量
|
||||
/// </summary>
|
||||
public int AllNum { get; set; }
|
||||
/// <summary>
|
||||
/// 未关闭任务单数量
|
||||
/// </summary>
|
||||
public int NoCloseNum { get; set; }
|
||||
/// <summary>
|
||||
/// 已关闭任务单数量
|
||||
/// </summary>
|
||||
public int CloseNum { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 三查四定统计实体
|
||||
/// </summary>
|
||||
public class FourDecisionScheduleBridDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 级别
|
||||
/// </summary>
|
||||
public string Level { get; set; }
|
||||
/// <summary>
|
||||
/// 尾项数量
|
||||
/// </summary>
|
||||
public int AllNum { get; set; }
|
||||
/// <summary>
|
||||
/// 未关闭尾项数量
|
||||
/// </summary>
|
||||
public int NoCloseNum { get; set; }
|
||||
/// <summary>
|
||||
/// 已关闭尾项数量
|
||||
/// </summary>
|
||||
public int CloseNum { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 转换
|
||||
|
||||
/// <summary>
|
||||
/// DataTable转换List
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<T> DataTableToList<T>(DataTable table)
|
||||
{
|
||||
List<T> list = new List<T>();
|
||||
T t = default(T);
|
||||
PropertyInfo[] propertypes = null;
|
||||
string tempName = string.Empty;
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
t = Activator.CreateInstance<T>();
|
||||
propertypes = t.GetType().GetProperties();
|
||||
foreach (PropertyInfo pro in propertypes)
|
||||
{
|
||||
tempName = pro.Name;
|
||||
if (table.Columns.Contains(tempName))
|
||||
{
|
||||
object value = row[tempName];
|
||||
if (!value.ToString().Equals(""))
|
||||
{
|
||||
pro.SetValue(t, value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
list.Add(t);
|
||||
}
|
||||
return list.Count == 0 ? new List<T>() : list;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user