提交代码

This commit is contained in:
2024-06-14 16:52:37 +08:00
parent 0860e6b9b1
commit 2a16ec833a
60 changed files with 114585 additions and 1272 deletions
@@ -15,7 +15,7 @@
<Items>
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" Title="开车绩效记录" EnableCollapse="true"
runat="server" BoxFlex="1" DataKeyNames="TestRunPerformanceMonthReportId" EnableColumnLines="true" DataIDField="TestRunPerformanceMonthReportId"
AllowSorting="true" SortField="Year" SortDirection="DESC" OnSort="Grid1_Sort" ForceFit="true"
AllowSorting="true" SortField="Year" SortDirection="DESC" OnSort="Grid1_Sort" ForceFit="true" OnRowCommand="Grid1_RowCommand"
AllowPaging="true" IsDatabasePaging="true" PageSize="10" OnPageIndexChange="Grid1_PageIndexChange"
EnableRowDoubleClickEvent="true" OnRowDoubleClick="Grid1_RowDoubleClick" EnableTextSelection="True">
<Toolbars>
@@ -41,6 +41,7 @@
<f:RenderField Width="100px" ColumnID="CompileDate" DataField="CompileDate"
FieldType="Date" Renderer="Date" RendererArgument="yyyy-MM-dd" HeaderText="编制日期" TextAlign="Center" HeaderTextAlign="Center">
</f:RenderField>
<f:LinkButtonField ID="lk" ColumnID="export" Hidden="true" HeaderText="导出" Width="60px" Icon="ArrowUp" TextAlign="Center" HeaderTextAlign="Center" CommandName="export" EnableAjax="false" />
</Columns>
<Listeners>
<f:Listener Event="beforerowcontextmenu" Handler="onRowContextMenu" />
@@ -1,9 +1,12 @@
using BLL;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web.UI;
namespace FineUIPro.Web.ZHGL.TestRunPerformance
{
@@ -199,5 +202,794 @@ namespace FineUIPro.Web.ZHGL.TestRunPerformance
{
BindGrid();
}
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "export")
{
this.EnableViewState = false;
string testRunPerformanceMonthReportId = this.Grid1.Rows[e.RowIndex].RowID;
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = Const.TestRunPerformanceMonthReportTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
Model.ZHGL_TestRunPerformanceMonthReport report = BLL.TestRunPerformanceMonthReportService.GetTestRunPerformanceMonthReportById(testRunPerformanceMonthReportId);
if (report != null)
{
string userName = BLL.UserService.GetUserNameByUserId(report.UserId);
newUrl = uploadfilepath.Replace(".xlsx", "(" + userName + "-" + report.Year.ToString() + ").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);
}
Model.SGGLDB db = Funs.DB;
var projects = from x in db.Base_Project select x;
int year = report.Year.Value;
string userId = report.UserId;
DateTime startDate = Convert.ToDateTime(year.ToString() + "-01" + "-01");
DateTime endDate = startDate.AddYears(1);
var getTestRunPerformances = (from x in db.Person_TestRunPerformance
join y in db.Base_TestRunPerformanceStandard on x.TestRunPerformanceStandardId equals y.TestRunPerformanceStandardId
where x.UserId == userId && x.Months >= startDate && x.Months < endDate
orderby x.ProjectId
select new { x.Months, x.ProjectId, x.JobContent, y.Type, y.Item, y.Unit, x.Days, y.Code1 }).ToList();
IQueryable<Model.Person_BusinessTrip> getTrips = from x in db.Person_BusinessTrip
where x.UserId == userId && x.LeaveDate >= startDate && x.ArriveDate < endDate
select x;
if (getTestRunPerformances.Count() > 0)
{
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyleT = workbook.CreateCellStyle();
cellStyleT.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleT.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleT.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleT.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleT.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyleT.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyleT.WrapText = true;
var fontT = workbook.CreateFont();
fontT.FontHeightInPoints = 16;
cellStyleT.SetFont(fontT);
NPOI.SS.UserModel.ICellStyle cellStyleTP = workbook.CreateCellStyle();
cellStyleTP.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleTP.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleTP.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleTP.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleTP.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyleTP.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyleTP.WrapText = true;
var fontTP = workbook.CreateFont();
fontTP.FontHeightInPoints = 10;
fontTP.IsBold = true;
cellStyleTP.SetFont(fontTP);
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;
cellStyle.WrapText = true;
var font = workbook.CreateFont();
font.FontHeightInPoints = 10;
cellStyle.SetFont(font);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
int i = 0;
// 第二步:创建新数据行
NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
NPOI.SS.UserModel.ICell cell;
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyleT;
cell.SetCellValue(userName + " " + year.ToString() + "年度开车绩效数据报告");
i = 3;
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyleTP;
cell.SetCellValue("年度累计数据");
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 0, 2));
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "部门基础工作").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 4, 6));
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "公司培训").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 7, 8));
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "项目投标").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 9, 10));
cell = row.CreateCell(11);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "开车策划").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(12);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 11, 12));
cell = row.CreateCell(13);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "开车培训").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(14);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(15);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 13, 15));
cell = row.CreateCell(16);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "合同管理").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(17);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 16, 17));
cell = row.CreateCell(18);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "预试车").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(19);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(20);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 18, 20));
cell = row.CreateCell(21);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "试车").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(22);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 21, 22));
cell = row.CreateCell(23);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "试运行及考核").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(24);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(25);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 23, 25));
cell = row.CreateCell(26);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "开车收尾").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(27);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(28);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 26, 28));
cell = row.CreateCell(29);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "项目协调").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(30);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 29, 30));
cell = row.CreateCell(31);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Type == "其他").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(32);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(33);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 31, 33));
double sumDaysA = 0, sumDays1A = 0, SumDays3A = 0;
foreach (var item in getTestRunPerformances)
{
bool isForeign = false;
var project = projects.FirstOrDefault(x => x.ProjectId == item.ProjectId);
if (project != null)
{
if (project.IsForeign == true)
{
isForeign = true;
}
}
if (isForeign) //境外项目
{
if (item.Code1 != 1 && item.Code1 != 2 && item.Code1 != 12)
{
sumDaysA += item.Days * 1.2 ?? 0;
if (item.Code1 == 3)
{
SumDays3A += item.Days * 1.2 ?? 0;
}
}
else
{
sumDaysA += item.Days ?? 0;
if (item.Code1 == 3)
{
SumDays3A += item.Days ?? 0;
}
}
}
else
{
sumDaysA += item.Days ?? 0;
if (item.Code1 == 3)
{
SumDays3A += item.Days ?? 0;
}
}
if (item.Code1 == 1)
{
sumDays1A += item.Days ?? 0;
}
}
int projectTripDaysA = 0;
var monthProjectTripsA = getTrips.Where(x => x.Type == "1");
foreach (var item in monthProjectTripsA)
{
if (item.ArriveDate < startDate)
{
if (item.LeaveDate == null || item.LeaveDate >= endDate)
{
projectTripDaysA += (endDate - startDate).Days;
}
else
{
projectTripDaysA += (item.LeaveDate.Value - startDate).Days + 1;
}
}
else
{
if (item.LeaveDate == null || item.LeaveDate >= endDate)
{
projectTripDaysA += (endDate - item.ArriveDate.Value).Days;
}
else
{
projectTripDaysA += (item.LeaveDate.Value - item.ArriveDate.Value).Days + 1;
}
}
}
int otherTripDaysA = 0;
var monthOtherTripsA = getTrips.Where(x => x.Type == "2");
foreach (var item in monthOtherTripsA)
{
if (item.ArriveDate < startDate)
{
if (item.LeaveDate == null || item.LeaveDate >= endDate)
{
otherTripDaysA += (endDate - startDate).Days;
}
else
{
otherTripDaysA += (item.LeaveDate.Value - startDate).Days + 1;
}
}
else
{
if (item.LeaveDate == null || item.LeaveDate >= endDate)
{
otherTripDaysA += (endDate - item.ArriveDate.Value).Days;
}
else
{
otherTripDaysA += (item.LeaveDate.Value - item.ArriveDate.Value).Days + 1;
}
}
}
cell = row.CreateCell(34);
cell.CellStyle = cellStyle;
cell.SetCellValue(sumDaysA.ToString());
cell = row.CreateCell(35);
cell.CellStyle = cellStyle;
cell.SetCellValue(projectTripDaysA.ToString());
cell = row.CreateCell(36);
cell.CellStyle = cellStyle;
cell.SetCellValue(otherTripDaysA.ToString());
cell = row.CreateCell(37);
cell.CellStyle = cellStyle;
cell.SetCellValue(sumDays1A.ToString());
cell = row.CreateCell(38);
cell.CellStyle = cellStyle;
cell.SetCellValue(SumDays3A.ToString());
DateTime startMonth;
List<DateTime> months = new List<DateTime>();
startMonth = startDate;
do
{
months.Add(startMonth);
startMonth = startMonth.AddMonths(1);
} while (startMonth < endDate);
i++;
int a = 1;
for (int j = 0; j < months.Count; j++)
{
row = sheet.CreateRow(i);
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue(GetNum(j + 1));
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(months[j].Year + "年" + months[j].Month + "月开车绩效");
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 1, 2));
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "部门基础工作").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 4, 6));
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "公司培训").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 7, 8));
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "项目投标").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 9, 10));
cell = row.CreateCell(11);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "开车策划").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(12);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 11, 12));
cell = row.CreateCell(13);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "开车培训").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(14);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(15);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 13, 15));
cell = row.CreateCell(16);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "合同管理").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(17);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 16, 17));
cell = row.CreateCell(18);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "预试车").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(19);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(20);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 18, 20));
cell = row.CreateCell(21);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "试车").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(22);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 21, 22));
cell = row.CreateCell(23);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "试运行及考核").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(24);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(25);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 23, 25));
cell = row.CreateCell(26);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "开车收尾").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(27);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(28);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 26, 28));
cell = row.CreateCell(29);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "项目协调").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(30);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 29, 30));
cell = row.CreateCell(31);
cell.CellStyle = cellStyle;
cell.SetCellValue((getTestRunPerformances.Where(x => x.Months == months[j] && x.Type == "其他").Sum(x => x.Days ?? 0)).ToString());
cell = row.CreateCell(32);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(33);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 31, 33));
var monthList = getTestRunPerformances.Where(x => x.Months == months[j]);
double sumDays = 0, sumDays1 = 0, SumDays3 = 0;
foreach (var item in monthList)
{
bool isForeign = false;
var project = projects.FirstOrDefault(x => x.ProjectId == item.ProjectId);
if (project != null)
{
if (project.IsForeign == true)
{
isForeign = true;
}
}
if (isForeign) //境外项目
{
if (item.Code1 != 1 && item.Code1 != 2 && item.Code1 != 12)
{
sumDays += item.Days * 1.2 ?? 0;
if (item.Code1 == 3)
{
SumDays3 += item.Days * 1.2 ?? 0;
}
}
else
{
sumDays += item.Days ?? 0;
if (item.Code1 == 3)
{
SumDays3 += item.Days ?? 0;
}
}
}
else
{
sumDays += item.Days ?? 0;
if (item.Code1 == 3)
{
SumDays3 += item.Days ?? 0;
}
}
if (item.Code1 == 1)
{
sumDays1 += item.Days ?? 0;
}
}
int projectTripDays = 0;
var monthProjectTrips = getTrips.Where(x => x.LeaveDate >= months[j] && x.ArriveDate < months[j].AddMonths(1) && x.Type == "1");
foreach (var item in monthProjectTrips)
{
if (item.ArriveDate < months[j])
{
if (item.LeaveDate == null || item.LeaveDate >= months[j].AddMonths(1))
{
projectTripDays += (months[j].AddMonths(1) - months[j]).Days;
}
else
{
projectTripDays += (item.LeaveDate.Value - months[j]).Days + 1;
}
}
else
{
if (item.LeaveDate == null || item.LeaveDate >= months[j].AddMonths(1))
{
projectTripDays += (months[j].AddMonths(1) - item.ArriveDate.Value).Days;
}
else
{
projectTripDays += (item.LeaveDate.Value - item.ArriveDate.Value).Days + 1;
}
}
}
int otherTripDays = 0;
var monthOtherTrips = getTrips.Where(x => x.LeaveDate >= months[j] && x.ArriveDate < months[j].AddMonths(1) && x.Type == "2");
foreach (var item in monthOtherTrips)
{
if (item.ArriveDate < months[j])
{
if (item.LeaveDate == null || item.LeaveDate >= months[j].AddMonths(1))
{
otherTripDays += (months[j].AddMonths(1) - months[j]).Days;
}
else
{
otherTripDays += (item.LeaveDate.Value - months[j]).Days + 1;
}
}
else
{
if (item.LeaveDate == null || item.LeaveDate >= months[j].AddMonths(1))
{
otherTripDays += (months[j].AddMonths(1) - item.ArriveDate.Value).Days;
}
else
{
otherTripDays += (item.LeaveDate.Value - item.ArriveDate.Value).Days + 1;
}
}
}
cell = row.CreateCell(34);
cell.CellStyle = cellStyle;
cell.SetCellValue(sumDays.ToString());
cell = row.CreateCell(35);
cell.CellStyle = cellStyle;
cell.SetCellValue(projectTripDays.ToString());
cell = row.CreateCell(36);
cell.CellStyle = cellStyle;
cell.SetCellValue(otherTripDays.ToString());
cell = row.CreateCell(37);
cell.CellStyle = cellStyle;
cell.SetCellValue(sumDays1.ToString());
cell = row.CreateCell(38);
cell.CellStyle = cellStyle;
cell.SetCellValue(SumDays3.ToString());
i++;
row = sheet.CreateRow(i);
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue("序号");
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue("工作地点 (本部/项目现场/其他)");
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue("工作内容");
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 4, 6));
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 7, 8));
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 9, 10));
cell = row.CreateCell(11);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(12);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 11, 12));
cell = row.CreateCell(13);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(14);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(15);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 13, 15));
cell = row.CreateCell(16);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(17);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 16, 17));
cell = row.CreateCell(18);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(19);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(20);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 18, 20));
cell = row.CreateCell(21);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(22);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 21, 22));
cell = row.CreateCell(23);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(24);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(25);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 23, 25));
cell = row.CreateCell(26);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(27);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(28);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 26, 28));
cell = row.CreateCell(29);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(30);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 29, 30));
cell = row.CreateCell(31);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(32);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(33);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i, i, 31, 33));
cell = row.CreateCell(34);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i-1, i, 34, 34));
cell = row.CreateCell(35);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i - 1, i, 35, 35));
cell = row.CreateCell(36);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i - 1, i, 36, 36));
cell = row.CreateCell(37);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i - 1, i, 37, 37));
cell = row.CreateCell(38);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
sheet.AddMergedRegion(new CellRangeAddress(i - 1, i, 38, 38));
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);
}
}
}
}
private string GetNum(int i)
{
string num = string.Empty;
if (i == 1)
{
num = "一";
}
else if (i == 2)
{
num = "二";
}
else if (i == 3)
{
num = "三";
}
else if (i == 4)
{
num = "四";
}
else if (i == 5)
{
num = "五";
}
else if (i == 6)
{
num = "六";
}
else if (i == 7)
{
num = "七";
}
else if (i == 8)
{
num = "八";
}
else if (i == 9)
{
num = "九";
}
else if (i == 10)
{
num = "十";
}
else if (i == 11)
{
num = "十一";
}
else if (i == 12)
{
num = "十二";
}
return num;
}
}
}
@@ -84,6 +84,15 @@ namespace FineUIPro.Web.ZHGL.TestRunPerformance {
/// </remarks>
protected global::FineUIPro.Button btnNew;
/// <summary>
/// lk 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.LinkButtonField lk;
/// <summary>
/// ToolbarSeparator1 控件。
/// </summary>