提交代码
This commit is contained in:
parent
75689bb431
commit
65b1104ed7
|
@ -4700,6 +4700,14 @@ namespace BLL
|
|||
/// 质量共检通知单的虚拟路径
|
||||
/// </summary>
|
||||
public const string SpotCheckTemplateUrl = "File\\Word\\CQMS\\Check\\质量共检通知单.doc";
|
||||
/// <summary>
|
||||
/// 出差记录模板文件原始虚拟路径
|
||||
/// </summary>
|
||||
public const string BusinessTripTemplateUrl = "File\\Excel\\DataOut\\出差记录.xlsx";
|
||||
/// <summary>
|
||||
/// 员工开车绩效记录模板文件原始虚拟路径
|
||||
/// </summary>
|
||||
public const string TestRunPerformanceTemplateUrl = "File\\Excel\\DataOut\\员工开车绩效记录.xlsx";
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
|
||||
<LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<Use64BitIISExpress>false</Use64BitIISExpress>
|
||||
<IISExpressSSLPort />
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<Items>
|
||||
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" Title="出差记录" EnableCollapse="true"
|
||||
runat="server" BoxFlex="1" DataKeyNames="BusinessTripId" EnableColumnLines="true" DataIDField="BusinessTripId"
|
||||
AllowSorting="true" SortField="ArriveDate" SortDirection="DESC" OnSort="Grid1_Sort"
|
||||
AllowSorting="true" SortField="ArriveDate" SortDirection="DESC" OnSort="Grid1_Sort" EnableCheckBoxSelect="true"
|
||||
AllowPaging="true" IsDatabasePaging="true" PageSize="10" OnPageIndexChange="Grid1_PageIndexChange"
|
||||
EnableRowDoubleClickEvent="true" OnRowDoubleClick="Grid1_RowDoubleClick" EnableTextSelection="True" EnableSummary="true" SummaryPosition="Flow">
|
||||
<Toolbars>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<f:Button ID="btnNew" ToolTip="新增" Icon="Add" EnablePostBack="true" OnClick="btnNew_Click" runat="server"
|
||||
Hidden="true">
|
||||
</f:Button>
|
||||
<f:Button ID="btnOut" OnClick="btnOut_Click" runat="server" Text="导出" ToolTip="导出" Icon="FolderUp"
|
||||
<f:Button ID="btnOut" OnClick="btnOut_Click" runat="server" Text="" ToolTip="导出" Icon="FolderUp"
|
||||
EnableAjax="false" DisableControlBeforePostBack="false">
|
||||
</f:Button>
|
||||
</Items>
|
||||
|
|
|
@ -4,6 +4,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace FineUIPro.Web.Personal
|
||||
|
@ -243,7 +244,144 @@ namespace FineUIPro.Web.Personal
|
|||
/// <param name="e"></param>
|
||||
protected void btnOut_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
string ids = string.Empty;
|
||||
if (Grid1.SelectedRowIndexArray.Length > 0)
|
||||
{
|
||||
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
||||
{
|
||||
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
||||
ids += rowID + ",";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowNotify("请至少选中一行!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
string rootPath = Server.MapPath("~/");
|
||||
string initTemplatePath = string.Empty;
|
||||
string uploadfilepath = string.Empty;
|
||||
string newUrl = string.Empty;
|
||||
string filePath = string.Empty;
|
||||
initTemplatePath = Const.BusinessTripTemplateUrl;
|
||||
uploadfilepath = rootPath + initTemplatePath;
|
||||
newUrl = uploadfilepath.Replace(".xlsx", "(" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ").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;
|
||||
string[] strs = ids.Split(',');
|
||||
var projects = from x in db.Base_Project select x;
|
||||
var lists = from x in db.Person_BusinessTrip where strs.Contains(x.BusinessTripId) orderby x.ArriveDate descending select x;
|
||||
// 创建单元格样式
|
||||
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 = 10;
|
||||
//font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
|
||||
cellStyle.SetFont(font);
|
||||
// 第二步:创建新数据行
|
||||
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
|
||||
int i = 1;
|
||||
int sum = 0;
|
||||
foreach (var item in lists)
|
||||
{
|
||||
// 第二步:创建新数据行
|
||||
NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
|
||||
NPOI.SS.UserModel.ICell cell;
|
||||
// 添加数据
|
||||
cell = row.CreateCell(0);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(i.ToString());
|
||||
cell = row.CreateCell(1);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.Type == "1" ? "项目出差" : "其他出差");
|
||||
cell = row.CreateCell(2);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(BLL.UserService.GetUserNameByUserId(item.UserId));
|
||||
cell = row.CreateCell(3);
|
||||
cell.CellStyle = cellStyle;
|
||||
var project = projects.FirstOrDefault(x => x.ProjectId == item.ProjectId);
|
||||
if (project != null)
|
||||
{
|
||||
cell.SetCellValue(project.ProjectName);
|
||||
}
|
||||
cell = row.CreateCell(4);
|
||||
cell.CellStyle = cellStyle;
|
||||
string arriveDate = string.Empty;
|
||||
if (item.ArriveDate != null)
|
||||
{
|
||||
arriveDate = string.Format("{0:yyyy-MM-dd}", item.ArriveDate);
|
||||
}
|
||||
cell.SetCellValue(arriveDate);
|
||||
string leaveDate = string.Empty;
|
||||
if (item.LeaveDate != null)
|
||||
{
|
||||
leaveDate = string.Format("{0:yyyy-MM-dd}", item.LeaveDate);
|
||||
}
|
||||
cell = row.CreateCell(5);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(leaveDate);
|
||||
string days = "";
|
||||
if (item.ArriveDate != null && item.LeaveDate != null)
|
||||
{
|
||||
days = ((item.LeaveDate.Value - item.ArriveDate.Value).Days + 1).ToString();
|
||||
sum += (item.LeaveDate.Value - item.ArriveDate.Value).Days + 1;
|
||||
}
|
||||
cell = row.CreateCell(6);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(days);
|
||||
i++;
|
||||
}
|
||||
NPOI.SS.UserModel.IRow rows = sheet.GetRow(i);
|
||||
NPOI.SS.UserModel.ICell cells;
|
||||
cells = rows.CreateCell(0);
|
||||
cells.CellStyle = cellStyle;
|
||||
cells.SetCellValue(string.Empty);
|
||||
cells = rows.CreateCell(1);
|
||||
cells.CellStyle = cellStyle;
|
||||
cells.SetCellValue(string.Empty);
|
||||
cells = rows.CreateCell(2);
|
||||
cells.CellStyle = cellStyle;
|
||||
cells.SetCellValue(string.Empty);
|
||||
cells = rows.CreateCell(3);
|
||||
cells.CellStyle = cellStyle;
|
||||
cells.SetCellValue(string.Empty);
|
||||
cells = rows.CreateCell(4);
|
||||
cells.CellStyle = cellStyle;
|
||||
cells.SetCellValue(string.Empty);
|
||||
cells = rows.CreateCell(5);
|
||||
cells.CellStyle = cellStyle;
|
||||
cells.SetCellValue("合计:");
|
||||
cells = rows.CreateCell(6);
|
||||
cells.CellStyle = cellStyle;
|
||||
cells.SetCellValue(sum.ToString());
|
||||
// 第三步:写入文件流
|
||||
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);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<Items>
|
||||
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" Title="开车绩效记录" EnableCollapse="true"
|
||||
runat="server" BoxFlex="1" DataKeyNames="TestRunPerformanceId" EnableColumnLines="true" DataIDField="TestRunPerformanceId"
|
||||
AllowSorting="true" SortField="Months" SortDirection="DESC" OnSort="Grid1_Sort" ForceFit="true"
|
||||
AllowSorting="true" SortField="Months" SortDirection="DESC" OnSort="Grid1_Sort" ForceFit="true" EnableCheckBoxSelect="true"
|
||||
AllowPaging="true" IsDatabasePaging="true" PageSize="10" OnPageIndexChange="Grid1_PageIndexChange"
|
||||
EnableRowDoubleClickEvent="true" OnRowDoubleClick="Grid1_RowDoubleClick" EnableTextSelection="True">
|
||||
<Toolbars>
|
||||
|
@ -27,6 +27,9 @@
|
|||
<f:Button ID="btnNew" ToolTip="新增" Icon="Add" EnablePostBack="true" OnClick="btnNew_Click" runat="server"
|
||||
Hidden="true">
|
||||
</f:Button>
|
||||
<f:Button ID="btnOut" OnClick="btnOut_Click" runat="server" Text="" ToolTip="导出" Icon="FolderUp"
|
||||
EnableAjax="false" DisableControlBeforePostBack="false">
|
||||
</f:Button>
|
||||
</Items>
|
||||
</f:Toolbar>
|
||||
</Toolbars>
|
||||
|
|
|
@ -3,6 +3,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace FineUIPro.Web.Personal
|
||||
|
@ -201,5 +202,143 @@ namespace FineUIPro.Web.Personal
|
|||
{
|
||||
BindGrid();
|
||||
}
|
||||
|
||||
#region 导出按钮
|
||||
/// 导出按钮
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnOut_Click(object sender, EventArgs e)
|
||||
{
|
||||
string ids = string.Empty;
|
||||
if (Grid1.SelectedRowIndexArray.Length > 0)
|
||||
{
|
||||
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
||||
{
|
||||
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
||||
ids += rowID + ",";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowNotify("请至少选中一行!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
string rootPath = Server.MapPath("~/");
|
||||
string initTemplatePath = string.Empty;
|
||||
string uploadfilepath = string.Empty;
|
||||
string newUrl = string.Empty;
|
||||
string filePath = string.Empty;
|
||||
initTemplatePath = Const.TestRunPerformanceTemplateUrl;
|
||||
uploadfilepath = rootPath + initTemplatePath;
|
||||
newUrl = uploadfilepath.Replace(".xlsx", "(" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ").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;
|
||||
string[] strs = ids.Split(',');
|
||||
var projects = from x in db.Base_Project select x;
|
||||
var testRunPerformanceStandards = from x in db.Base_TestRunPerformanceStandard select x;
|
||||
var lists = from x in db.Person_TestRunPerformance where strs.Contains(x.TestRunPerformanceId) orderby x.Months descending select x;
|
||||
// 创建单元格样式
|
||||
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 = 10;
|
||||
//font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
|
||||
cellStyle.SetFont(font);
|
||||
// 第二步:创建新数据行
|
||||
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
|
||||
int i = 1;
|
||||
int sum = 0;
|
||||
foreach (var item in lists)
|
||||
{
|
||||
// 第二步:创建新数据行
|
||||
NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
|
||||
NPOI.SS.UserModel.ICell cell;
|
||||
// 添加数据
|
||||
cell = row.CreateCell(0);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(i.ToString());
|
||||
cell = row.CreateCell(1);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(BLL.UserService.GetUserNameByUserId(item.UserId));
|
||||
cell = row.CreateCell(2);
|
||||
cell.CellStyle = cellStyle;
|
||||
string months = string.Empty;
|
||||
if (item.Months != null)
|
||||
{
|
||||
months = string.Format("{0:yyyy-MM}", item.Months);
|
||||
}
|
||||
cell.SetCellValue(months);
|
||||
cell = row.CreateCell(3);
|
||||
cell.CellStyle = cellStyle;
|
||||
var project = projects.FirstOrDefault(x => x.ProjectId == item.ProjectId);
|
||||
if (project != null)
|
||||
{
|
||||
cell.SetCellValue(project.ProjectName);
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.SetCellValue("本部");
|
||||
}
|
||||
cell = row.CreateCell(4);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.JobContent);
|
||||
var testRunPerformanceStandard = testRunPerformanceStandards.FirstOrDefault(x => x.TestRunPerformanceStandardId == item.TestRunPerformanceStandardId);
|
||||
cell = row.CreateCell(5);
|
||||
cell.CellStyle = cellStyle;
|
||||
if (testRunPerformanceStandard != null)
|
||||
{
|
||||
cell.SetCellValue(testRunPerformanceStandard.Type);
|
||||
}
|
||||
cell = row.CreateCell(6);
|
||||
cell.CellStyle = cellStyle;
|
||||
if (testRunPerformanceStandard != null)
|
||||
{
|
||||
cell.SetCellValue(testRunPerformanceStandard.Item);
|
||||
}
|
||||
cell = row.CreateCell(7);
|
||||
cell.CellStyle = cellStyle;
|
||||
if (testRunPerformanceStandard != null)
|
||||
{
|
||||
cell.SetCellValue(testRunPerformanceStandard.Unit);
|
||||
}
|
||||
cell = row.CreateCell(8);
|
||||
cell.CellStyle = cellStyle;
|
||||
if (item.Days != null)
|
||||
{
|
||||
cell.SetCellValue(item.Days.ToString());
|
||||
}
|
||||
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);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -84,6 +84,15 @@ namespace FineUIPro.Web.Personal {
|
|||
/// </remarks>
|
||||
protected global::FineUIPro.Button btnNew;
|
||||
|
||||
/// <summary>
|
||||
/// btnOut 控件。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 自动生成的字段。
|
||||
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||
/// </remarks>
|
||||
protected global::FineUIPro.Button btnOut;
|
||||
|
||||
/// <summary>
|
||||
/// ToolbarSeparator1 控件。
|
||||
/// </summary>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<appSettings>
|
||||
<!--连接字符串-->
|
||||
<!--<add key="ConnectionString" value="Server=.;Database=SGGLDB_WH;Integrated Security=False;User ID=sa;Password=1111;MultipleActiveResultSets=true;Connect Timeout=1200"/>-->
|
||||
<add key="ConnectionString" value="Server=.\SQL2012;Database=SGGLDB_WH;Integrated Security=False;User ID=sa;Password=1111;MultipleActiveResultSets=true;Connect Timeout=1200"/>
|
||||
<add key="ConnectionString" value="Server=.;Database=SGGLDB_WH;Integrated Security=False;User ID=sa;Password=1111;MultipleActiveResultSets=true;Connect Timeout=1200"/>
|
||||
<!--系统名称-->
|
||||
<add key="SystemName" value="智慧施工管理信息系统V1.0"/>
|
||||
<add key="ChartImageHandler" value="storage=file;timeout=20;url=~/Images/;"/>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
|
||||
<LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<Use64BitIISExpress />
|
||||
<IISExpressSSLPort />
|
||||
|
|
Loading…
Reference in New Issue