using BLL; using NPOI.HSSF.UserModel; 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.Globalization; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.Report { public partial class FTEReport : PageBase { protected void Page_Init(object sender, EventArgs e) { InitGrid(); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower();//权限设置 BindGrid1(); } } private void InitGrid() { DateTime dateTime = DateTime.Now; for (int i = 0; i <= 12; i++) { RenderField rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Double; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid1.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Int; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid2.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Double; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid3.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Int; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid4.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Double; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid5.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Int; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid6.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Double; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid7.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Int; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid8.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Double; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid9.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Int; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid10.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Double; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid11.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Int; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid12.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Double; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid13.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Int; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid14.Columns.Add(rd); rd = new RenderField(); rd.Width = Unit.Pixel(90); rd.HeaderText = dateTime.ToString("yyyyMM"); rd.FieldType = FieldType.Double; rd.ColumnID = dateTime.ToString("yyyyMM"); rd.DataField = dateTime.ToString("yyyyMM"); Grid15.Columns.Add(rd); dateTime = dateTime.AddMonths(1); } } #region 点击TAB数据切换 /// /// 点击TAB数据切换 /// protected void TabStrip1_TabIndexChanged(object sender, EventArgs e) { if (TabStrip1.ActiveTabIndex == 0) { BindGrid1(); } else if (TabStrip1.ActiveTabIndex == 1) { BindGrid2(); } else if (TabStrip1.ActiveTabIndex == 2) { BindGrid3(); } else if (TabStrip1.ActiveTabIndex == 3) { BindGrid4(); } else if (TabStrip1.ActiveTabIndex == 4) { BindGrid5(); } else if (TabStrip1.ActiveTabIndex == 5) { BindGrid6(); } else if (TabStrip1.ActiveTabIndex == 6) { BindGrid7(); } else if (TabStrip1.ActiveTabIndex == 7) { BindGrid8(); } else if (TabStrip1.ActiveTabIndex == 8) { BindGrid9(); } else if (TabStrip1.ActiveTabIndex == 9) { BindGrid10(); } else if (TabStrip1.ActiveTabIndex == 10) { BindGrid11(); } else if (TabStrip1.ActiveTabIndex == 11) { BindGrid12(); } else if (TabStrip1.ActiveTabIndex == 12) { BindGrid13(); } else if (TabStrip1.ActiveTabIndex == 13) { BindGrid14(); } else if (TabStrip1.ActiveTabIndex == 14) { BindGrid15(); } } #endregion #region 查询 /// /// 查询 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { if (TabStrip1.ActiveTabIndex == 0) { BindGrid1(); } else if (TabStrip1.ActiveTabIndex == 1) { BindGrid2(); } else if (TabStrip1.ActiveTabIndex == 2) { BindGrid3(); } else if (TabStrip1.ActiveTabIndex == 3) { BindGrid4(); } else if (TabStrip1.ActiveTabIndex == 4) { BindGrid5(); } else if (TabStrip1.ActiveTabIndex == 5) { BindGrid6(); } else if (TabStrip1.ActiveTabIndex == 6) { BindGrid7(); } else if (TabStrip1.ActiveTabIndex == 7) { BindGrid8(); } else if (TabStrip1.ActiveTabIndex == 8) { BindGrid9(); } else if (TabStrip1.ActiveTabIndex == 9) { BindGrid10(); } else if (TabStrip1.ActiveTabIndex == 10) { BindGrid11(); } else if (TabStrip1.ActiveTabIndex == 11) { BindGrid12(); } else if (TabStrip1.ActiveTabIndex == 12) { BindGrid13(); } else if (TabStrip1.ActiveTabIndex == 13) { BindGrid14(); } else if (TabStrip1.ActiveTabIndex == 14) { BindGrid15(); } } #endregion #region CTE_Overall_FTE /// /// 绑定数据 /// private void BindGrid1() { SqlParameter[] parameter = new SqlParameter[] { }; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_CTEOverallFTE", parameter, "tt"); DataTable table = ds.Tables[0]; table= procOverAll(table); if (table.Rows.Count > 1) { //Grid1.RecordCount = table.Rows.Count; //var tb = this.GetPagedDataTable(Grid1, table); Grid1.DataSource = table; Grid1.DataBind(); } } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid1(); } /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid1(); } #endregion #region CTE-A_Manhour /// /// 绑定数据 /// private void BindGrid2() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/A"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_Manhour", parameter, "tt"); DataTable table = procManHours( ds.Tables[0]); if (table.Rows.Count > 1) { Grid2.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid2, table); Grid2.DataSource = tb; Grid2.DataBind(); } } /// /// 分页 /// /// /// protected void Grid2_PageIndexChange(object sender, GridPageEventArgs e) { Grid2.PageIndex = e.NewPageIndex; BindGrid2(); } /// /// 排序 /// /// /// protected void Grid2_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid2.SortDirection = e.SortDirection; Grid2.SortField = e.SortField; BindGrid2(); } #endregion #region CTE-A_FTE /// /// 绑定数据 /// private void BindGrid3() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/A"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_FTE", parameter, "tt"); DataTable table = procManHours(ds.Tables[0],"FTE"); if (table.Rows.Count > 1) { Grid3.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid3, table); Grid3.DataSource = tb; Grid3.DataBind(); } } /// /// 分页 /// /// /// protected void Grid3_PageIndexChange(object sender, GridPageEventArgs e) { Grid3.PageIndex = e.NewPageIndex; BindGrid3(); } /// /// 排序 /// /// /// protected void Grid3_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid3.SortDirection = e.SortDirection; Grid3.SortField = e.SortField; BindGrid3(); } #endregion #region CTE-C_Manhour /// /// 绑定数据 /// private void BindGrid4() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/C"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_Manhour", parameter, "tt"); DataTable table = procManHours(ds.Tables[0]); if (table.Rows.Count > 1) { Grid4.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid4, table); Grid4.DataSource = tb; Grid4.DataBind(); } } /// /// 分页 /// /// /// protected void Grid4_PageIndexChange(object sender, GridPageEventArgs e) { Grid4.PageIndex = e.NewPageIndex; BindGrid4(); } /// /// 排序 /// /// /// protected void Grid4_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid4.SortDirection = e.SortDirection; Grid4.SortField = e.SortField; BindGrid4(); } #endregion #region CTE-C_FTE /// /// 绑定数据 /// private void BindGrid5() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/C"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_FTE", parameter, "tt"); DataTable table = procManHours(ds.Tables[0], "FTE"); if (table.Rows.Count > 1) { Grid5.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid5, table); Grid5.DataSource = tb; Grid5.DataBind(); } } /// /// 分页 /// /// /// protected void Grid5_PageIndexChange(object sender, GridPageEventArgs e) { Grid5.PageIndex = e.NewPageIndex; BindGrid5(); } /// /// 排序 /// /// /// protected void Grid5_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid5.SortDirection = e.SortDirection; Grid5.SortField = e.SortField; BindGrid5(); } #endregion #region CTE-D_Manhour /// /// 绑定数据 /// private void BindGrid6() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/D"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_Manhour", parameter, "tt"); DataTable table = procManHours(ds.Tables[0]); if (table.Rows.Count > 1) { Grid6.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid6, table); Grid6.DataSource = tb; Grid6.DataBind(); } } /// /// 分页 /// /// /// protected void Grid6_PageIndexChange(object sender, GridPageEventArgs e) { Grid6.PageIndex = e.NewPageIndex; BindGrid6(); } /// /// 排序 /// /// /// protected void Grid6_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid6.SortDirection = e.SortDirection; Grid6.SortField = e.SortField; BindGrid6(); } #endregion #region CTE-D_FTE /// /// 绑定数据 /// private void BindGrid7() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/D"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_FTE", parameter, "tt"); DataTable table = procManHours(ds.Tables[0], "FTE"); if (table.Rows.Count > 1) { Grid7.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid7, table); Grid7.DataSource = tb; Grid7.DataBind(); } } /// /// 分页 /// /// /// protected void Grid7_PageIndexChange(object sender, GridPageEventArgs e) { Grid7.PageIndex = e.NewPageIndex; BindGrid7(); } /// /// 排序 /// /// /// protected void Grid7_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid7.SortDirection = e.SortDirection; Grid7.SortField = e.SortField; BindGrid7(); } #endregion #region CTE-M_Manhour /// /// 绑定数据 /// private void BindGrid8() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/M"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_Manhour", parameter, "tt"); DataTable table = procManHours(ds.Tables[0]); if (table.Rows.Count > 1) { Grid8.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid8, table); Grid8.DataSource = tb; Grid8.DataBind(); } } /// /// 分页 /// /// /// protected void Grid8_PageIndexChange(object sender, GridPageEventArgs e) { Grid8.PageIndex = e.NewPageIndex; BindGrid8(); } /// /// 排序 /// /// /// protected void Grid8_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid8.SortDirection = e.SortDirection; Grid8.SortField = e.SortField; BindGrid8(); } #endregion #region CTE-M_FTE /// /// 绑定数据 /// private void BindGrid9() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/M"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_FTE", parameter, "tt"); DataTable table = procManHours(ds.Tables[0], "FTE"); if (table.Rows.Count > 1) { Grid9.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid9, table); Grid9.DataSource = tb; Grid9.DataBind(); } } /// /// 分页 /// /// /// protected void Grid9_PageIndexChange(object sender, GridPageEventArgs e) { Grid9.PageIndex = e.NewPageIndex; BindGrid9(); } /// /// 排序 /// /// /// protected void Grid9_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid9.SortDirection = e.SortDirection; Grid9.SortField = e.SortField; BindGrid9(); } #endregion #region CTE-P_Manhour /// /// 绑定数据 /// private void BindGrid10() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/P"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_Manhour", parameter, "tt"); DataTable table = procManHours(ds.Tables[0]); if (table.Rows.Count > 1) { Grid10.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid10, table); Grid10.DataSource = tb; Grid10.DataBind(); } } /// /// 分页 /// /// /// protected void Grid10_PageIndexChange(object sender, GridPageEventArgs e) { Grid10.PageIndex = e.NewPageIndex; BindGrid10(); } /// /// 排序 /// /// /// protected void Grid10_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid10.SortDirection = e.SortDirection; Grid10.SortField = e.SortField; BindGrid10(); } #endregion #region CTE-P_FTE /// /// 绑定数据 /// private void BindGrid11() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/P"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_FTE", parameter, "tt"); DataTable table = procManHours(ds.Tables[0], "FTE"); if (table.Rows.Count > 1) { Grid11.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid11, table); Grid11.DataSource = tb; Grid11.DataBind(); } } /// /// 分页 /// /// /// protected void Grid11_PageIndexChange(object sender, GridPageEventArgs e) { Grid11.PageIndex = e.NewPageIndex; BindGrid11(); } /// /// 排序 /// /// /// protected void Grid11_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid11.SortDirection = e.SortDirection; Grid11.SortField = e.SortField; BindGrid11(); } #endregion #region CTE-Q_Manhour /// /// 绑定数据 /// private void BindGrid12() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/Q"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_Manhour", parameter, "tt"); DataTable table = procManHours(ds.Tables[0]); if (table.Rows.Count > 1) { Grid12.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid12, table); Grid12.DataSource = tb; Grid12.DataBind(); } } /// /// 分页 /// /// /// protected void Grid12_PageIndexChange(object sender, GridPageEventArgs e) { Grid12.PageIndex = e.NewPageIndex; BindGrid12(); } /// /// 排序 /// /// /// protected void Grid12_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid12.SortDirection = e.SortDirection; Grid12.SortField = e.SortField; BindGrid12(); } #endregion #region CTE-Q_FTE /// /// 绑定数据 /// private void BindGrid13() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/Q"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_FTE", parameter, "tt"); DataTable table = procManHours(ds.Tables[0], "FTE"); if (table.Rows.Count > 1) { Grid13.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid13, table); Grid13.DataSource = tb; Grid13.DataBind(); } } /// /// 分页 /// /// /// protected void Grid13_PageIndexChange(object sender, GridPageEventArgs e) { Grid13.PageIndex = e.NewPageIndex; BindGrid13(); } /// /// 排序 /// /// /// protected void Grid13_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid13.SortDirection = e.SortDirection; Grid13.SortField = e.SortField; BindGrid13(); } #endregion #region CTE-S_Manhour /// /// 绑定数据 /// private void BindGrid14() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/S"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_Manhour", parameter, "tt"); DataTable table = procManHours(ds.Tables[0]); if (table.Rows.Count > 1) { Grid14.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid14, table); Grid14.DataSource = tb; Grid14.DataBind(); } } /// /// 分页 /// /// /// protected void Grid14_PageIndexChange(object sender, GridPageEventArgs e) { Grid14.PageIndex = e.NewPageIndex; BindGrid14(); } /// /// 排序 /// /// /// protected void Grid14_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid14.SortDirection = e.SortDirection; Grid14.SortField = e.SortField; BindGrid14(); } #endregion #region CTE-S_FTE /// /// 绑定数据 /// private void BindGrid15() { SqlParameter sqlParameter = new SqlParameter("departName", "CTE/S"); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = sqlParameter; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_FTE", parameter, "tt"); DataTable table = procManHours(ds.Tables[0], "FTE"); if (table.Rows.Count > 1) { Grid15.RecordCount = table.Rows.Count; var tb = this.GetPagedDataTable(Grid15, table); Grid15.DataSource = tb; Grid15.DataBind(); } } /// /// 分页 /// /// /// protected void Grid15_PageIndexChange(object sender, GridPageEventArgs e) { Grid15.PageIndex = e.NewPageIndex; BindGrid15(); } /// /// 排序 /// /// /// protected void Grid15_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid15.SortDirection = e.SortDirection; Grid15.SortField = e.SortField; BindGrid15(); } #endregion #region 导出Excel /// /// 导出Excel /// /// /// protected void btnExport_Click(object sender, EventArgs e) { string rootPath = Server.MapPath("~/") + Const.ExcelUrl; //模板文件 string TempletFileName = rootPath + "FTE_Report_April.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); //XSSFFont cs_content_Font = (XSSFFont)hssfworkbook.CreateFont(); //创建字体 //cs_content_Font.FontName = "Arial";//字体 //cs_content_Font.FontHeightInPoints = 10; //字体大小 //列赋值 //overview.ForceFormulaRecalculation = true; #region XSSFSheet overview = (XSSFSheet)hssfworkbook.GetSheet("CTE_Overall_FTE"); IFont cs_content_Font = overview.Workbook.CreateFont(); //创建字体 cs_content_Font.FontName = "sans-serif";//字体 cs_content_Font.FontHeightInPoints = 10; //字体大小 IFont red_content_Font = overview.Workbook.CreateFont(); //创建字体 red_content_Font.FontName = "sans-serif";//字体 red_content_Font.FontHeightInPoints = 10; //字体大小 red_content_Font.Color = HSSFColor.Red.Index; ICellStyle redCellStyle = hssfworkbook.CreateCellStyle(); redCellStyle.SetFont(red_content_Font); ICellStyle mCellStyle = hssfworkbook.CreateCellStyle(); mCellStyle.SetFont(cs_content_Font); DateTime dateTime = DateTime.Now; for (int i = 0; i <= 12; i++) { overview.GetRow(0).GetCell(i+2).SetCellValue(dateTime.ToString("yyyyMM")); dateTime = dateTime.AddMonths(1); } SqlParameter[] parameter = new SqlParameter[] { }; DataSet ds = SQLHelper.RunProcedure("Proc_FTE_CTEOverallFTE", parameter, "tt"); DataTable table = ds.Tables[0]; table = procOverAll(table); for (int i = 0; i < table.Rows.Count; i++) { for (int j = 0; j < table.Columns.Count - 1; j++) { if (overview.GetRow(i + 1).GetCell(j) == null) { overview.GetRow(i + 1).CreateCell(j); } if (table.Rows[i][j + 1] != DBNull.Value) { overview.GetRow(i + 1).GetCell(j).SetCellValue(table.Rows[i][j + 1].ToString()); } else { if (j >= 2) { overview.GetRow(i + 1).GetCell(j).SetCellValue("0"); } } try { if (j >= 2 && Double.Parse(overview.GetRow(i + 1).GetCell(j).StringCellValue) > 0.85) { overview.GetRow(i + 1).GetCell(j).CellStyle = redCellStyle; } else { overview.GetRow(i + 1).GetCell(j).CellStyle = mCellStyle; } } catch (Exception e1) { // overview.GetRow(i + 1).GetCell(j).CellStyle.SetFont(red_content_Font); } } } #endregion #region fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-A_Manhour"), "CTE/A", "Proc_FTE_Manhour"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-A_FTE"), "CTE/A", "Proc_FTE_FTE"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-C_Manhour"), "CTE/C", "Proc_FTE_Manhour"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-C_FTE"), "CTE/C", "Proc_FTE_FTE"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-D_Manhour"), "CTE/D", "Proc_FTE_Manhour"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-D_FTE"), "CTE/D", "Proc_FTE_FTE"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-M_Manhour"), "CTE/M", "Proc_FTE_Manhour"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-M_FTE"), "CTE/M", "Proc_FTE_FTE"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-P_Manhour"), "CTE/P", "Proc_FTE_Manhour"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-P_FTE"), "CTE/P", "Proc_FTE_FTE"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-Q_Manhour"), "CTE/Q", "Proc_FTE_Manhour"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-Q_FTE"), "CTE/Q", "Proc_FTE_FTE"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-S_Manhour"), "CTE/S", "Proc_FTE_Manhour"); fillSheetData((XSSFSheet)hssfworkbook.GetSheet("CTE-S_FTE"), "CTE/S", "Proc_FTE_FTE"); #endregion 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=P14_FTE_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(); } /// /// 根据sql获取数据 /// /// /// /// /// 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 权限设置 /// /// 菜单按钮权限 /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.FTEReportAprilMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnOut)) { this.btnExport.Hidden = false; } } } #endregion /// /// 表格处理 /// /// /// protected DataTable procManHours(DataTable dt,string dataColumnsName = "TaskPlan") { DataTable dtres = new DataTable(); dtres.Columns.Add("UserId", System.Type.GetType("System.String")); dtres.Columns.Add("UserCode", System.Type.GetType("System.String")); dtres.Columns.Add("UserName", System.Type.GetType("System.String")); DateTime dateTime = DateTime.Now; for (int i = 0; i <= 12; i++) { if (dataColumnsName == "TaskPlan") { dtres.Columns.Add(dateTime.ToString("yyyyMM"), System.Type.GetType("System.Int32")); } else { dtres.Columns.Add(dateTime.ToString("yyyyMM"), System.Type.GetType("System.Double")); } dateTime = dateTime.AddMonths(1); } DataRow dr = null; for (int i = 0; i < dt.Rows.Count; i++) { DataRow tempRow = dt.Rows[i]; if (dr == null) { dr = dtres.NewRow(); for(int c = 3; c < dtres.Columns.Count; c++) { dr[c] = 0; } dr["UserId"] = tempRow["UserId"]; dr["UserCode"] = tempRow["UserCode"]; dr["UserName"] = tempRow["UserName"]; dtres.Rows.Add(dr); } if (dr["UserId"].ToString() != tempRow["UserId"].ToString()) { try { dr = dtres.NewRow(); for (int c = 3; c < dtres.Columns.Count; c++) { dr[c] = 0; } dr["UserId"] = tempRow["UserId"]; dr["UserCode"] = tempRow["UserCode"]; dr["UserName"] = tempRow["UserName"]; dtres.Rows.Add(dr); } catch (Exception e) { string s = e.Message; } } if (tempRow["Years"] != DBNull.Value) { try { int year = (int)tempRow["Years"]; int month = (int)tempRow["Months"]; if (month < 10) { if (dtres.Columns.Contains(year + "0" + month)) if (tempRow[dataColumnsName] != DBNull.Value) { dr[year + "0" + month] = tempRow[dataColumnsName]; } } else { if (dtres.Columns.Contains(year + "" + month)) { if (tempRow[dataColumnsName] != DBNull.Value) { dr[year + "" + month] = tempRow[dataColumnsName]; } } } } catch (Exception e) { string s = e.Message; } } } return dtres; } protected DataTable procOverAll(DataTable dt) { DataTable dtres = new DataTable(); dtres.Columns.Add("DepartId", System.Type.GetType("System.String")); dtres.Columns.Add("StaffNum", System.Type.GetType("System.String")); dtres.Columns.Add("DepartName", System.Type.GetType("System.String")); DateTime dateTime = DateTime.Now; for (int i = 0; i <= 12; i++) { dtres.Columns.Add(dateTime.ToString("yyyyMM"), System.Type.GetType("System.Double")); dateTime = dateTime.AddMonths(1); } DataRow dr = null; for (int i = 0; i < dt.Rows.Count; i++) { DataRow tempRow = dt.Rows[i]; if (dr == null) { dr = dtres.NewRow(); for (int c = 3; c < dtres.Columns.Count; c++) { dr[c] = 0; } dr["DepartId"] = tempRow["DepartId"]; dr["DepartName"] = tempRow["DepartName"]; if (!tempRow["DepartName"].ToString().Contains("_")) { dr["StaffNum"] = tempRow["StaffNum"]; } dtres.Rows.Add(dr); } if (dr["DepartName"].ToString() != tempRow["DepartName"].ToString()) { try { dr = dtres.NewRow(); for (int c = 3; c < dtres.Columns.Count; c++) { dr[c] = 0; } dr["DepartId"] = tempRow["DepartId"]; dr["DepartName"] = tempRow["DepartName"]; if (!tempRow["DepartName"].ToString().Contains("_")) { dr["StaffNum"] = tempRow["StaffNum"]; } dtres.Rows.Add(dr); } catch (Exception e) { string s = e.Message; } } if (tempRow["Years"] != DBNull.Value) { try { int year = (int)tempRow["Years"]; int month = (int)tempRow["Months"]; if (month < 10) { if (dtres.Columns.Contains(year + "0" + month)) if (tempRow["FTE"] != DBNull.Value) dr[year + "0" + month] = tempRow["FTE"]; } else { if (dtres.Columns.Contains(year + "" + month)) if (tempRow["FTE"] != DBNull.Value) dr[year + "" + month] = tempRow["FTE"]; } } catch (Exception e) { string s = e.Message; } } } return dtres; } protected DataTable divForDataTable(DataTable dt1,DataTable dt2) { DataTable dtres = new DataTable(); dtres.Columns.Add("UserId", System.Type.GetType("System.String")); dtres.Columns.Add("UserCode", System.Type.GetType("System.String")); dtres.Columns.Add("UserName", System.Type.GetType("System.String")); DateTime dateTime = DateTime.Now; for (int i = 0; i <= 12; i++) { dtres.Columns.Add(dateTime.ToString("yyyyMM"), System.Type.GetType("System.Int32")); dateTime = dateTime.AddMonths(1); } DataRow dr = null; for (int i = 0; i < dt1.Rows.Count; i++) { DataRow tempRow1 = dt1.Rows[i]; if (dr == null) { dr = dtres.NewRow(); dr["UserId"] = tempRow1["UserId"]; dr["UserCode"] = tempRow1["UserCode"]; dr["UserName"] = tempRow1["UserName"]; dtres.Rows.Add(dr); } if (dr["UserId"].ToString() != tempRow1["UserId"].ToString()) { try { dr = dtres.NewRow(); dr["UserId"] = tempRow1["UserId"]; dr["UserCode"] = tempRow1["UserCode"]; dr["UserName"] = tempRow1["UserName"]; dtres.Rows.Add(dr); } catch (Exception e) { string s = e.Message; } } if (tempRow1["UserId"] != DBNull.Value) { DataRow []dataRows = dt2.Select("UserId = '" + tempRow1["UserId"].ToString() + "'"); if (dataRows != null && dataRows.Length > 0) { DataRow tempRow2 = dataRows[0]; for (int j = 3; j < dtres.Columns.Count; j++) { try { if (tempRow1[dtres.Columns[j].ColumnName] != DBNull.Value && tempRow2[dtres.Columns[j].ColumnName] != DBNull.Value) dr[dtres.Columns[j].ColumnName] = 1.0 * (int)tempRow1[dtres.Columns[j].ColumnName] / (int)tempRow2[dtres.Columns[j].ColumnName]; } catch (Exception e) { string s = e.Message; } } } } } return dtres; } /// /// 标红 /// /// /// protected void Grid_RowDataBound(object sender, GridRowEventArgs e) { for (int i = 2; i < e.Values.Length; i++) { if (e.Values[i] != null && (double)e.Values[i] >= 0.85) { e.CellCssClasses[i] = "totalRed"; } } } protected void fillSheetData(XSSFSheet sheet, string departMent,string pro) { XSSFFont cs_content_Font = (XSSFFont)sheet.Workbook.CreateFont(); //创建字体 cs_content_Font.FontName = "Arial";//字体 cs_content_Font.FontHeightInPoints = 10; //字体大小 XSSFFont red_content_Font = (XSSFFont)sheet.Workbook.CreateFont(); //创建字体 red_content_Font.FontName = "Arial";//字体 red_content_Font.FontHeightInPoints = 10; //字体大小 red_content_Font.Color = NPOI.HSSF.Util.HSSFColor.Red.Index; ICellStyle redCellStyle = sheet.Workbook.CreateCellStyle(); redCellStyle.SetFont(red_content_Font); ICellStyle mCellStyle = sheet.Workbook.CreateCellStyle(); mCellStyle.SetFont(cs_content_Font); DateTime dateTime = DateTime.Now; for (int i = 0; i <= 12; i++) { sheet.GetRow(0).GetCell(i + 2).SetCellValue(dateTime.ToString("yyyyMM")); dateTime = dateTime.AddMonths(1); } SqlParameter sqlParameter2 = new SqlParameter("departName",departMent ); SqlParameter[] parameter2 = new SqlParameter[1]; parameter2[0] = sqlParameter2; DataSet ds2 = SQLHelper.RunProcedure(pro, parameter2, "tt"); DataTable table2; if ("Proc_FTE_FTE" == pro) { table2 = procManHours(ds2.Tables[0], "FTE"); } else { table2 = procManHours(ds2.Tables[0]); } for (int i = 0; i < table2.Rows.Count; i++) { for (int j = 0; j < table2.Columns.Count-1; j++) { if (sheet.GetRow(i + 1).GetCell(j) == null) { sheet.GetRow(i + 1).CreateCell(j); } if (table2.Rows[i][j+1] != DBNull.Value) { sheet.GetRow(i + 1).GetCell(j).SetCellValue(table2.Rows[i][j+1].ToString()); } else { sheet.GetRow(i + 1).GetCell(j).SetCellValue("0"); } try { if (j>=2&&"Proc_FTE_FTE" == pro && Double.Parse(sheet.GetRow(i + 1).GetCell(j).StringCellValue) >= 0.85) { sheet.GetRow(i + 1).GetCell(j).CellStyle=redCellStyle ; } else { sheet.GetRow(i + 1).GetCell(j).CellStyle=mCellStyle; } } catch (Exception e) { // sheet.GetRow(i + 1).GetCell(j).CellStyle.SetFont(cs_content_Font); } } } } } }