375 lines
17 KiB
C#
375 lines
17 KiB
C#
|
using BLL;
|
|||
|
using NPOI.HSSF.Util;
|
|||
|
using NPOI.SS.UserModel;
|
|||
|
using NPOI.XSSF.UserModel;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace FineUIPro.Web.Report
|
|||
|
{
|
|||
|
public partial class OthersManhours : PageBase
|
|||
|
{
|
|||
|
#region 加载
|
|||
|
/// <summary>
|
|||
|
/// 加载页面
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (!IsPostBack)
|
|||
|
{
|
|||
|
GetButtonPower();//权限设置
|
|||
|
|
|||
|
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|||
|
// 绑定表格
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 绑定数据
|
|||
|
/// </summary>
|
|||
|
private void BindGrid()
|
|||
|
{
|
|||
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|||
|
if (!string.IsNullOrEmpty(this.txtJobNo.Text.Trim()))
|
|||
|
{
|
|||
|
listStr.Add(new SqlParameter("@jobNo", this.txtJobNo.Text.Trim()));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()))
|
|||
|
{
|
|||
|
|
|||
|
listStr.Add(new SqlParameter("@statedate", this.txtStartDate.Text.Trim()));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
|
|||
|
{
|
|||
|
listStr.Add(new SqlParameter("@enddate", this.txtEndDate.Text.Trim()));
|
|||
|
}
|
|||
|
SqlParameter[] parameter = listStr.ToArray();
|
|||
|
DataTable tb = SQLHelper.GetDataTableRunProc("Proc_OtherManhours", parameter);
|
|||
|
Grid1.RecordCount = tb.Rows.Count;
|
|||
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|||
|
Grid1.DataSource = table;
|
|||
|
Grid1.DataBind();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
protected void btnSearch_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
#region 分页、排序
|
|||
|
/// <summary>
|
|||
|
/// 分页
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|||
|
{
|
|||
|
Grid1.PageIndex = e.NewPageIndex;
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页显示条数下拉框
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 排序
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|||
|
{
|
|||
|
Grid1.SortDirection = e.SortDirection;
|
|||
|
Grid1.SortField = e.SortField;
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 导出
|
|||
|
/// <summary>
|
|||
|
/// 导出按钮
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void btnExport_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
|
|||
|
//模板文件
|
|||
|
string TempletFileName = rootPath + "Manhours_others_summary Report.xlsx";
|
|||
|
//导出文件
|
|||
|
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
|
|||
|
if (!Directory.Exists(filePath))
|
|||
|
{
|
|||
|
Directory.CreateDirectory(filePath);
|
|||
|
}
|
|||
|
string ReportFileName = filePath + "out.xlsx";
|
|||
|
|
|||
|
FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
|
|||
|
XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
|
|||
|
|
|||
|
#region Time_Sheet_Summary
|
|||
|
XSSFSheet reportModel = (XSSFSheet)hssfworkbook.GetSheet("Manhours_others_summary Report");
|
|||
|
|
|||
|
XSSFFont cs_content_Font = (XSSFFont)hssfworkbook.CreateFont(); //创建字体
|
|||
|
cs_content_Font.FontName = "sans-serif";//字体
|
|||
|
cs_content_Font.FontHeightInPoints = 10; //字体大小
|
|||
|
|
|||
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|||
|
if (!string.IsNullOrEmpty(this.txtJobNo.Text.Trim()))
|
|||
|
{
|
|||
|
listStr.Add(new SqlParameter("@jobNo", this.txtJobNo.Text.Trim()));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()))
|
|||
|
{
|
|||
|
listStr.Add(new SqlParameter("@statedate", this.txtStartDate.Text.Trim()));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
|
|||
|
{
|
|||
|
listStr.Add(new SqlParameter("@enddate", this.txtEndDate.Text.Trim()));
|
|||
|
}
|
|||
|
SqlParameter[] parameter = listStr.ToArray();
|
|||
|
DataTable table = SQLHelper.GetDataTableRunProc("Proc_OtherManhours", parameter);
|
|||
|
|
|||
|
if (table.Rows.Count > 0)
|
|||
|
{
|
|||
|
var rowIndex = 1;
|
|||
|
for (int i = 0; i < table.Rows.Count; i++)
|
|||
|
{
|
|||
|
if (reportModel.GetRow(rowIndex) == null) reportModel.CreateRow(rowIndex);
|
|||
|
|
|||
|
#region 列赋值
|
|||
|
//Job No.
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(0) == null) reportModel.GetRow(rowIndex).CreateCell(0);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(0).SetCellValue(table.Rows[i]["ProjectControl_JobNo"].ToString());
|
|||
|
|
|||
|
reportModel.GetRow(rowIndex).GetCell(0).CellStyle.SetFont(cs_content_Font);//将字体绑定到样式
|
|||
|
|
|||
|
//ProjectControl_JobTitle
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(1) == null) reportModel.GetRow(rowIndex).CreateCell(1);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(1).SetCellValue(table.Rows[i]["ProjectControl_JobTitle"].ToString());
|
|||
|
//ProjectControl_JobStatus
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(2) == null) reportModel.GetRow(rowIndex).CreateCell(2);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(2).SetCellValue(table.Rows[i]["ProjectControl_JobStatus"].ToString());
|
|||
|
//MANHOURS_DISP_CODE
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(3) == null) reportModel.GetRow(rowIndex).CreateCell(3);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(3).SetCellValue(table.Rows[i]["Roles"].ToString());
|
|||
|
//Account
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(4) == null) reportModel.GetRow(rowIndex).CreateCell(4);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(4).SetCellValue(table.Rows[i]["Account"].ToString());
|
|||
|
//UserName
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(5) == null) reportModel.GetRow(rowIndex).CreateCell(5);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(5).SetCellValue(table.Rows[i]["UserName"].ToString());
|
|||
|
//ManHours
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(6) == null) reportModel.GetRow(rowIndex).CreateCell(6);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(6).SetCellValue(Convert.ToDouble(table.Rows[i]["ManHours"].ToString()));
|
|||
|
//Hourss
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(7) == null) reportModel.GetRow(rowIndex).CreateCell(7);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(7).SetCellValue(Convert.ToDouble(table.Rows[i]["Hourss"].ToString()));
|
|||
|
#endregion
|
|||
|
|
|||
|
rowIndex++;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
reportModel.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=P07_Manhours_Report_" + Server.UrlEncode(DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx"));
|
|||
|
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
|
|||
|
Response.AddHeader("Content-Length", filet.Length.ToString());
|
|||
|
// 指定返回的是一个不能被客户端读取的流,必须被下载
|
|||
|
Response.ContentType = "application/ms-excel";
|
|||
|
// 把文件流发送到客户端
|
|||
|
Response.WriteFile(filet.FullName);
|
|||
|
// 停止页面的执行
|
|||
|
Response.End();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 导出按钮
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void btnActual_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
|
|||
|
//模板文件
|
|||
|
string TempletFileName = rootPath + "Manhours_Actual_Month.xlsx";
|
|||
|
//导出文件
|
|||
|
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
|
|||
|
if (!Directory.Exists(filePath))
|
|||
|
{
|
|||
|
Directory.CreateDirectory(filePath);
|
|||
|
}
|
|||
|
string ReportFileName = filePath + "out.xlsx";
|
|||
|
|
|||
|
FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
|
|||
|
XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
|
|||
|
|
|||
|
#region Time_Sheet_Summary
|
|||
|
XSSFSheet reportModel = (XSSFSheet)hssfworkbook.GetSheet("Actual_ManHour");
|
|||
|
|
|||
|
XSSFFont cs_content_Font = (XSSFFont)hssfworkbook.CreateFont(); //创建字体
|
|||
|
cs_content_Font.FontName = "sans-serif";//字体
|
|||
|
cs_content_Font.FontHeightInPoints = 10; //字体大小
|
|||
|
|
|||
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|||
|
if (!string.IsNullOrEmpty(this.txtJobNo.Text.Trim()))
|
|||
|
{
|
|||
|
listStr.Add(new SqlParameter("@jobNo", this.txtJobNo.Text.Trim()));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()))
|
|||
|
{
|
|||
|
listStr.Add(new SqlParameter("@statedate", this.txtStartDate.Text.Trim()));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
|
|||
|
{
|
|||
|
listStr.Add(new SqlParameter("@enddate", this.txtEndDate.Text.Trim()));
|
|||
|
}
|
|||
|
SqlParameter[] parameter = listStr.ToArray();
|
|||
|
DataTable table = SQLHelper.GetDataTableRunProc("Proc_Month_OtherManhours", parameter);
|
|||
|
|
|||
|
if (table.Rows.Count > 0)
|
|||
|
{
|
|||
|
var rowIndex = 1;
|
|||
|
for (int i = 0; i < table.Rows.Count; i++)
|
|||
|
{
|
|||
|
if (reportModel.GetRow(rowIndex) == null) reportModel.CreateRow(rowIndex);
|
|||
|
|
|||
|
#region 列赋值
|
|||
|
// Month
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(0) == null) reportModel.GetRow(rowIndex).CreateCell(0);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(0).SetCellValue(table.Rows[i]["Months"].ToString());
|
|||
|
reportModel.GetRow(rowIndex).GetCell(0).CellStyle.SetFont(cs_content_Font);
|
|||
|
//Job No.
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(1) == null) reportModel.GetRow(rowIndex).CreateCell(1);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(1).SetCellValue(table.Rows[i]["ProjectControl_JobNo"].ToString());
|
|||
|
reportModel.GetRow(rowIndex).GetCell(1).CellStyle.SetFont(cs_content_Font);//将字体绑定到样式
|
|||
|
|
|||
|
//ProjectControl_JobTitle
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(2) == null) reportModel.GetRow(rowIndex).CreateCell(2);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(2).SetCellValue(table.Rows[i]["ProjectControl_JobTitle"].ToString());
|
|||
|
//ProjectControl_JobStatus
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(3) == null) reportModel.GetRow(rowIndex).CreateCell(3);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(3).SetCellValue(table.Rows[i]["ProjectControl_JobStatus"].ToString());
|
|||
|
//MANHOURS_DISP_CODE
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(4) == null) reportModel.GetRow(rowIndex).CreateCell(4);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(4).SetCellValue(table.Rows[i]["Roles"].ToString());
|
|||
|
//Account
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(5) == null) reportModel.GetRow(rowIndex).CreateCell(5);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(5).SetCellValue(table.Rows[i]["Account"].ToString());
|
|||
|
//UserName
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(6) == null) reportModel.GetRow(rowIndex).CreateCell(6);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(6).SetCellValue(table.Rows[i]["UserName"].ToString());
|
|||
|
//ManHours
|
|||
|
//if (reportModel.GetRow(rowIndex).GetCell(6) == null) reportModel.GetRow(rowIndex).CreateCell(6);
|
|||
|
//reportModel.GetRow(rowIndex).GetCell(6).SetCellValue(Convert.ToDouble(table.Rows[i]["ManHours"].ToString()));
|
|||
|
//Hourss
|
|||
|
if (reportModel.GetRow(rowIndex).GetCell(7) == null) reportModel.GetRow(rowIndex).CreateCell(7);
|
|||
|
reportModel.GetRow(rowIndex).GetCell(7).SetCellValue(Convert.ToDouble(table.Rows[i]["Hourss"].ToString()));
|
|||
|
#endregion
|
|||
|
|
|||
|
rowIndex++;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
reportModel.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=P07_Manhours_Actual_Report_" + Server.UrlEncode(DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx"));
|
|||
|
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
|
|||
|
Response.AddHeader("Content-Length", filet.Length.ToString());
|
|||
|
// 指定返回的是一个不能被客户端读取的流,必须被下载
|
|||
|
Response.ContentType = "application/ms-excel";
|
|||
|
// 把文件流发送到客户端
|
|||
|
Response.WriteFile(filet.FullName);
|
|||
|
// 停止页面的执行
|
|||
|
Response.End();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据sql获取数据
|
|||
|
/// </summary>
|
|||
|
/// <param name="strSql"></param>
|
|||
|
/// <param name="tableName"></param>
|
|||
|
/// <param name="parameters"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static DataTable GetDataTableNameRunText(string strSql, string tableName = "", params SqlParameter[] parameters)
|
|||
|
{
|
|||
|
DataTable dataTable = string.IsNullOrEmpty(tableName) ? new DataTable() : new DataTable(tableName);
|
|||
|
using (SqlConnection Connection = new SqlConnection(Funs.ConnString))
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
Connection.Open();
|
|||
|
SqlCommand command = new SqlCommand(strSql, Connection);
|
|||
|
command.CommandType = CommandType.Text;
|
|||
|
if (parameters != null)
|
|||
|
{
|
|||
|
command.Parameters.AddRange(parameters);
|
|||
|
}
|
|||
|
|
|||
|
SqlDataAdapter adapter = new SqlDataAdapter(command);
|
|||
|
adapter.Fill(dataTable);
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
Connection.Close();
|
|||
|
}
|
|||
|
}
|
|||
|
return dataTable;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 权限设置
|
|||
|
/// <summary>
|
|||
|
/// 菜单按钮权限
|
|||
|
/// </summary>
|
|||
|
private void GetButtonPower()
|
|||
|
{
|
|||
|
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.OthersManhoursMenuId);
|
|||
|
if (buttonList.Count() > 0)
|
|||
|
{
|
|||
|
if (buttonList.Contains(BLL.Const.BtnOut))
|
|||
|
{
|
|||
|
this.btnExport.Hidden = false;
|
|||
|
this.btnActual.Hidden = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
}
|