using BLL; using Model; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.Report { public partial class StaffingPlanReport : PageBase { /// /// 加载表头 /// protected void Page_Init(object sender, EventArgs e) { InitGrid(); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower();//权限设置 var sessionTime = Session["GRID_TIME"] as List; if (sessionTime != null) { sessionTime = sessionTime.OrderBy(p => p).ToList(); txtStartData.Text = sessionTime[0].ToString("yyyy-MM"); txtEndData.Text = sessionTime[1].ToString("yyyy-MM"); BindGrid(ddlDeptList.SelectedValue); } Session["GRID_TIME"] = null; Session["Dep_Id"] = null; } } #region 首次加载 /// /// 表头 /// private void InitGrid() { //部门信息 var user = BLL.Sys_UserService.GetUsersByUserId(this.CurrUser.UserId); this.ddlDeptList.DataTextField = "DepartCode"; this.ddlDeptList.DataValueField = "DepartId"; this.ddlDeptList.DataSource = BLL.DepartService.GetDepartListBySupCheckItem(BLL.Const.CTE_DepartId); this.ddlDeptList.DataBind(); Funs.FineUIPleaseSelect(ddlDeptList, ""); if (Session["Dep_Id"] != null) ddlDeptList.SelectedValue = Session["Dep_Id"].ToString(); //绑定列头信息 var sessionTime = Session["GRID_TIME"] as List; if (sessionTime != null) { sessionTime = sessionTime.OrderBy(p => p).ToList(); var starts = sessionTime[0]; var ends = sessionTime[1]; for (DateTime time = starts; time <= ends; time = time.AddMonths(1)) { RenderField rd = new RenderField(); rd.Width = Unit.Pixel(70); var Year = time.Year; var Month = time.Month; var m = Month < 10 ? "0" + Month : Month.ToString(); rd.HeaderText = Year.ToString() + m; rd.FieldType = FieldType.Float; rd.ColumnID = Year.ToString() + "-" + m.ToString(); Grid1.Columns.Add(rd); } } } #endregion #region 数据绑定 /// /// 绑定数据 /// /// private void BindGrid(string sId) { if (sId == BLL.Const._Null) { Grid1.RecordCount = 0; Grid1.DataSource = null; Grid1.DataBind(); } DataTable table = new DataTable(); SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@departId", sId) }; DataSet ds = SQLHelper.RunProcedure("Proc_DepartManHoursPlanEditNew", parameter, "tt"); if (ds.Tables[0].Rows.Count > 0) { Grid1.RecordCount = ds.Tables[0].Rows.Count; table = this.GetPagedDataTable(Grid1, ds.Tables[0]); Grid1.DataSource = table; Grid1.DataBind(); } else { Grid1.RecordCount = 0; Grid1.DataSource = null; Grid1.DataBind(); } if (!string.IsNullOrWhiteSpace(txtStartData.Text) && !string.IsNullOrWhiteSpace(txtEndData.Text)) { if (Grid1.Rows.Count > 0) { int sMonth = DateTime.Now.Day >= 26 ? DateTime.Now.Month : DateTime.Now.Month - 1; var manHourDetails = new List(); var actHours = new List(); var manHoursPlanIds = table.AsEnumerable().Select(s => s.Field("ManHoursPlanId")).ToList(); manHoursPlanIds.Remove(""); if (manHoursPlanIds.Count > 0) { manHourDetails = Funs.DB.ManHours_PlanDetail.Where(p => manHoursPlanIds.Contains(p.PlanManHoursId)).ToList(); actHours = Funs.DB.ManHours_Actual.Where(p => manHoursPlanIds.Contains(p.ManHoursPlanId)).ToList(); } for (int b = 0; b < Grid1.Rows.Count; b++) { string manHoursPlanId = Grid1.DataKeys[b][0].ToString(); var manHourDetail = manHourDetails.Where(p => p.PlanManHoursId == manHoursPlanId); var actHour = actHours.Where(p => p.ManHoursPlanId == manHoursPlanId).ToList(); double? total = Convert.ToDouble(Grid1.Rows[b].Values[17]); // 实际人工时; double? planMan = Convert.ToDouble(Grid1.Rows[b].Values[16]); // 计划人工时 var starts = DateTime.Parse(txtStartData.Text + "-1"); var ends = DateTime.Parse(txtEndData.Text + "-1"); for (DateTime time = starts; time <= ends; time = time.AddMonths(1)) { RenderField rd; rd = Grid1.FindColumn(time.ToString("yyyy-MM")) as RenderField; double h = 0; if (time.Month == sMonth) { if (actHour.Count > 0) { var act = actHour.Where(p => p.ManHoursDate == time.ToString("yyyy-MM")).Select(p => p.Hours).ToList(); if (act.Count > 0) { act.Remove(null); Grid1.Rows[b].Values[rd.ColumnIndex] = act.Sum(p => p); } else { Grid1.Rows[b].Values[rd.ColumnIndex] = 0; } } else { Grid1.Rows[b].Values[rd.ColumnIndex] = 0; } } else { var hours = manHourDetail.FirstOrDefault(p => p.DateMonth.Value.Year == time.Year && p.DateMonth.Value.Month == time.Month); if (hours != null) { Grid1.Rows[b].Values[rd.ColumnIndex] = hours.Hour; h = hours != null ? hours.Hour.Value : 0; } else { Grid1.Rows[b].Values[rd.ColumnIndex] = 0; } } total += h; } if (total != null) { Grid1.Rows[b].Values[18] = total; } else { Grid1.Rows[b].Values[18] = 0; } if (planMan != null && planMan != 0 && total != null) { RenderField r = Grid1.FindColumn("Realization") as RenderField; double rate = (1.0 * total.Value / planMan.Value); string real = rate.ToString("0.00"); Grid1.Rows[b].Values[r.ColumnIndex] = real; if (rate > 1) { Grid1.Rows[b].CellCssClasses[r.ColumnIndex] = "totalRed"; } } } } } } #endregion /// /// 导出 /// protected void btnExport_Click(object sender, EventArgs e) { var fileName = "人工时"; XSSFWorkbook book = new XSSFWorkbook(); System.IO.MemoryStream ms = new System.IO.MemoryStream(); //选中的树节点 if (ddlDeptList.SelectedValue == BLL.Const._Null) { Alert.ShowInParent("请选择部门!"); return; } if (string.IsNullOrWhiteSpace(txtStartData.Text)) { Alert.ShowInParent("开始年月不能为空!"); return; } if (string.IsNullOrWhiteSpace(txtEndData.Text)) { Alert.ShowInParent("结束年月不能为空!"); return; } if (DateTime.Parse(txtStartData.Text + "-01") > DateTime.Parse(txtEndData.Text + "-01")) { Alert.ShowInParent("结束年月应该大于开始年月!"); return; } //绑定日期 var starts = DateTime.Parse(txtStartData.Text + "-1"); var ends = DateTime.Parse(txtEndData.Text + "-1"); //获取人员数据 var dt = new DataTable(); SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@departId", ddlDeptList.SelectedValue) }; var ds = SQLHelper.RunProcedure("Proc_DepartManHoursPlanEditNew", parameter, "tt"); if (ds.Tables.Count > 0) dt = ds.Tables[0]; var sysUsers = Funs.DB.Sys_User.Where(p => p.DepartId == ddlDeptList.SelectedValue && p.IsPost == true && p.Account != "gly").OrderBy(p => p.UserName).ToList(); foreach (var item in sysUsers) { //筛选对于的人员 var itemDtRow = dt.AsEnumerable().Where(s => s.Field("EngineerId") == item.UserId).ToList(); if (itemDtRow.Count == 0) continue; //sheet名称 XSSFSheet sheet = (XSSFSheet)book.CreateSheet(item.UserName); #region 样式 //列头居中样式 XSSFFont tfont = (XSSFFont)book.CreateFont(); tfont.FontHeightInPoints = 10; tfont.FontName = "Arial"; tfont.IsBold = true; ICellStyle titleStyle = book.CreateCellStyle(); titleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; titleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; titleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; titleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; titleStyle.VerticalAlignment = VerticalAlignment.Center; titleStyle.Alignment = HorizontalAlignment.Center; titleStyle.WrapText = true; titleStyle.SetFont(tfont); //全局边框靠左 XSSFFont lfont = (XSSFFont)book.CreateFont(); lfont.FontHeightInPoints = 10; lfont.FontName = "Arial"; ICellStyle lstyle = book.CreateCellStyle(); lstyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; lstyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; lstyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; lstyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; lstyle.VerticalAlignment = VerticalAlignment.Center; lstyle.Alignment = HorizontalAlignment.Left; lstyle.WrapText = true; lstyle.SetFont(lfont); //全局边框靠右 XSSFFont rfont = (XSSFFont)book.CreateFont(); rfont.FontHeightInPoints = 10; rfont.FontName = "Arial"; ICellStyle rstyle = book.CreateCellStyle(); rstyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; rstyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; rstyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; rstyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; rstyle.VerticalAlignment = VerticalAlignment.Center; rstyle.Alignment = HorizontalAlignment.Right; rstyle.WrapText = true; rstyle.SetFont(rfont); IDataFormat dataformat = book.CreateDataFormat(); ICellStyle styleDate = book.CreateCellStyle(); styleDate.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; styleDate.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; styleDate.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; styleDate.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; styleDate.VerticalAlignment = VerticalAlignment.Center; styleDate.Alignment = HorizontalAlignment.Left; styleDate.WrapText = true; styleDate.SetFont(lfont); styleDate.DataFormat = dataformat.GetFormat("yyyy/m/d"); #endregion #region 设置列宽度 sheet.SetColumnWidth(1, 90 * 256); sheet.SetColumnWidth(6, 20 * 256); sheet.SetColumnWidth(7, 20 * 256); sheet.SetColumnWidth(8, 12 * 256); sheet.SetColumnWidth(9, 12 * 256); sheet.SetColumnWidth(10, 12 * 256); sheet.SetColumnWidth(11, 12 * 256); sheet.SetColumnWidth(12, 12 * 256); sheet.SetColumnWidth(13, 12 * 256); sheet.SetColumnWidth(14, 12 * 256); sheet.SetColumnWidth(15, 12 * 256); sheet.SetColumnWidth(16, 12 * 256); sheet.SetColumnWidth(17, 12 * 256); sheet.SetColumnWidth(18, 12 * 256); sheet.SetColumnWidth(19, 12 * 256); #endregion #region 列头 XSSFRow headerRow = (XSSFRow)sheet.CreateRow(0); headerRow.CreateCell(0).SetCellValue("JobNo"); headerRow.GetCell(0).CellStyle = titleStyle; headerRow.CreateCell(1).SetCellValue("JobTitle"); headerRow.GetCell(1).CellStyle = titleStyle; headerRow.CreateCell(2).SetCellValue("JobStatus"); headerRow.GetCell(2).CellStyle = titleStyle; headerRow.CreateCell(3).SetCellValue("JobType"); headerRow.GetCell(3).CellStyle = titleStyle; headerRow.CreateCell(4).SetCellValue("Discipline"); headerRow.GetCell(4).CellStyle = titleStyle; headerRow.CreateCell(5).SetCellValue("Priority"); headerRow.GetCell(5).CellStyle = titleStyle; headerRow.CreateCell(6).SetCellValue("Roles"); headerRow.GetCell(6).CellStyle = titleStyle; headerRow.CreateCell(7).SetCellValue("Account"); headerRow.GetCell(7).CellStyle = titleStyle; headerRow.CreateCell(8).SetCellValue("ReceivedDate"); headerRow.GetCell(8).CellStyle = titleStyle; headerRow.CreateCell(9).SetCellValue("ApprovalDatePlan"); headerRow.GetCell(9).CellStyle = titleStyle; headerRow.CreateCell(10).SetCellValue("ApprovalDateActual"); headerRow.GetCell(10).CellStyle = titleStyle; headerRow.CreateCell(11).SetCellValue("Civil_RevisedEnd"); headerRow.GetCell(11).CellStyle = titleStyle; headerRow.CreateCell(12).SetCellValue("EI_RevisedEnd"); headerRow.GetCell(12).CellStyle = titleStyle; headerRow.CreateCell(13).SetCellValue("LLE_RevisedEnd"); headerRow.GetCell(13).CellStyle = titleStyle; headerRow.CreateCell(14).SetCellValue("Const_Civil_RevisedEnd"); headerRow.GetCell(14).CellStyle = titleStyle; headerRow.CreateCell(15).SetCellValue("Const_EI_RevisedEnd"); headerRow.GetCell(15).CellStyle = titleStyle; headerRow.CreateCell(16).SetCellValue("ManHours"); headerRow.GetCell(16).CellStyle = titleStyle; headerRow.CreateCell(17).SetCellValue("ManHoursActual"); headerRow.GetCell(17).CellStyle = titleStyle; headerRow.CreateCell(18).SetCellValue("ManhourActualForecast"); headerRow.GetCell(18).CellStyle = titleStyle; headerRow.CreateCell(19).SetCellValue("Realization"); headerRow.GetCell(19).CellStyle = titleStyle; int titleCellIndex = 20; for (DateTime time = starts; time <= ends; time = time.AddMonths(1)) { headerRow.CreateCell(titleCellIndex).SetCellValue(time.ToString("yyyy-MM")); headerRow.GetCell(titleCellIndex).CellStyle = titleStyle; titleCellIndex++; } #endregion #region 数据 int rowIndex = 1; if (itemDtRow.Count > 0) { int sMonth = DateTime.Now.Day >= 26 ? DateTime.Now.Month : DateTime.Now.Month - 1; var manHourDetails = new List(); var actHours = new List(); var manHoursPlanIds = itemDtRow.Select(s => s.Field("ManHoursPlanId")).ToList(); manHoursPlanIds.Remove(""); if (manHoursPlanIds.Count > 0) { manHourDetails = Funs.DB.ManHours_PlanDetail.Where(p => manHoursPlanIds.Contains(p.PlanManHoursId) && p.UserId == item.UserId).ToList(); actHours = Funs.DB.ManHours_Actual.Where(p => manHoursPlanIds.Contains(p.ManHoursPlanId) && p.UserId == item.UserId).ToList(); } for (int i = 0; i < itemDtRow.Count; i++) { double? dtotal = Convert.ToDouble(itemDtRow[i]["ManHoursActual"]); // 实际人工时; double? dplanMan = Convert.ToDouble(itemDtRow[i]["ManHours"]); // 计划人工时 string manHoursPlanId = itemDtRow[i]["ManHoursPlanId"].ToString(); var manHourDetail = manHourDetails.Where(p => p.PlanManHoursId == manHoursPlanId); var actHour = actHours.Where(p => p.ManHoursPlanId == manHoursPlanId).ToList(); //创建行 XSSFRow row = (XSSFRow)sheet.CreateRow(rowIndex); row.CreateCell(0).SetCellValue(valueNotNull(itemDtRow[i]["ProjectControl_JobNo"]) ? itemDtRow[i]["ProjectControl_JobNo"].ToString() : string.Empty); row.CreateCell(1).SetCellValue(valueNotNull(itemDtRow[i]["ProjectControl_JobTitle"]) ? itemDtRow[i]["ProjectControl_JobTitle"].ToString() : string.Empty); row.CreateCell(2).SetCellValue(valueNotNull(itemDtRow[i]["ProjectControl_JobStatus"]) ? itemDtRow[i]["ProjectControl_JobStatus"].ToString() : string.Empty); row.CreateCell(3).SetCellValue(valueNotNull(itemDtRow[i]["ProjectControl_JobType"]) ? itemDtRow[i]["ProjectControl_JobType"].ToString() : string.Empty); row.CreateCell(4).SetCellValue(valueNotNull(itemDtRow[i]["Discipline"]) ? itemDtRow[i]["Discipline"].ToString() : string.Empty); row.CreateCell(5).SetCellValue(valueNotNull(itemDtRow[i]["PM_General_Priority"]) ? itemDtRow[i]["PM_General_Priority"].ToString() : string.Empty); row.CreateCell(6).SetCellValue(valueNotNull(itemDtRow[i]["Roles"]) ? itemDtRow[i]["Roles"].ToString() : string.Empty); row.CreateCell(7).SetCellValue(valueNotNull(itemDtRow[i]["ProjectControl_Account"]) ? itemDtRow[i]["ProjectControl_Account"].ToString() : string.Empty); if (row.GetCell(8) == null) row.CreateCell(8); if (itemDtRow[i]["ReceivedDate"] != null && itemDtRow[i]["ReceivedDate"].ToString() != "") { row.GetCell(8).SetCellValue((DateTime)Convert.ToDateTime(itemDtRow[i]["ReceivedDate"].ToString())); } if (row.GetCell(9) == null) row.CreateCell(9); if (itemDtRow[i]["ApprovalDatePlan"] != null && itemDtRow[i]["ApprovalDatePlan"].ToString() != "") { row.GetCell(9).SetCellValue((DateTime)Convert.ToDateTime(itemDtRow[i]["ApprovalDatePlan"].ToString())); } if (row.GetCell(10) == null) row.CreateCell(10); if (itemDtRow[i]["ApprovalDateActual"] != null && itemDtRow[i]["ApprovalDateActual"].ToString() != "") { row.GetCell(10).SetCellValue((DateTime)Convert.ToDateTime(itemDtRow[i]["ApprovalDateActual"].ToString())); } if (row.GetCell(11) == null) row.CreateCell(11); if (itemDtRow[i]["Civil_RevisedEnd"] != null && itemDtRow[i]["Civil_RevisedEnd"].ToString() != "") { row.GetCell(11).SetCellValue((DateTime)Convert.ToDateTime(itemDtRow[i]["Civil_RevisedEnd"].ToString())); row.GetCell(11).CellStyle = styleDate; } if (row.GetCell(12) == null) row.CreateCell(12); if (itemDtRow[i]["EI_RevisedEnd"] != null && itemDtRow[i]["EI_RevisedEnd"].ToString() != "") { row.GetCell(12).SetCellValue((DateTime)Convert.ToDateTime(itemDtRow[i]["EI_RevisedEnd"].ToString())); } if (row.GetCell(13) == null) row.CreateCell(13); if (itemDtRow[i]["LLE_RevisedEnd"] != null && itemDtRow[i]["LLE_RevisedEnd"].ToString() != "") { row.GetCell(13).SetCellValue((DateTime)Convert.ToDateTime(itemDtRow[i]["LLE_RevisedEnd"].ToString())); } if (row.GetCell(14) == null) row.CreateCell(14); if (itemDtRow[i]["Const_Civil_RevisedEnd"] != null && itemDtRow[i]["Const_Civil_RevisedEnd"].ToString() != "") { row.GetCell(14).SetCellValue((DateTime)Convert.ToDateTime(itemDtRow[i]["Const_Civil_RevisedEnd"].ToString())); } if (row.GetCell(15) == null) row.CreateCell(15); if (itemDtRow[i]["Const_EI_RevisedEnd"] != null && itemDtRow[i]["Const_EI_RevisedEnd"].ToString() != "") { row.GetCell(15).SetCellValue((DateTime)Convert.ToDateTime(itemDtRow[i]["Const_EI_RevisedEnd"].ToString())); } //row.CreateCell(8).SetCellValue(""); //row.CreateCell(9).SetCellValue(valueNotNull(itemDtRow[i]["ApprovalDatePlan"]) ? DateTime.Parse(itemDtRow[i]["ApprovalDatePlan"].ToString()).ToString("yyyy/MM/dd") : string.Empty); //row.CreateCell(10).SetCellValue(valueNotNull(itemDtRow[i]["ApprovalDateActual"]) ? DateTime.Parse(itemDtRow[i]["ApprovalDateActual"].ToString()).ToString("yyyy/MM/dd") : string.Empty); //row.CreateCell(11).SetCellValue(valueNotNull(itemDtRow[i]["Civil_RevisedEnd"]) ? DateTime.Parse(itemDtRow[i]["Civil_RevisedEnd"].ToString()).ToString("yyyy/MM/dd") : string.Empty); //row.CreateCell(12).SetCellValue(valueNotNull(itemDtRow[i]["EI_RevisedEnd"]) ? DateTime.Parse(itemDtRow[i]["EI_RevisedEnd"].ToString()).ToString("yyyy/MM/dd") : string.Empty); //row.CreateCell(13).SetCellValue(valueNotNull(itemDtRow[i]["LLE_RevisedEnd"]) ? DateTime.Parse(itemDtRow[i]["LLE_RevisedEnd"].ToString()).ToString("yyyy/MM/dd") : string.Empty); //row.CreateCell(14).SetCellValue(valueNotNull(itemDtRow[i]["Const_Civil_RevisedEnd"]) ? DateTime.Parse(itemDtRow[i]["Const_Civil_RevisedEnd"].ToString()).ToString("yyyy/MM/dd") : string.Empty); //row.CreateCell(15).SetCellValue(valueNotNull(itemDtRow[i]["Const_EI_RevisedEnd"]) ? DateTime.Parse(itemDtRow[i]["Const_EI_RevisedEnd"].ToString()).ToString("yyyy/MM/dd") : string.Empty); row.CreateCell(16).SetCellValue(valueNotNull(itemDtRow[i]["ManHours"]) ? itemDtRow[i]["ManHours"].ToString() : string.Empty); row.CreateCell(17).SetCellValue(valueNotNull(itemDtRow[i]["ManHoursActual"]) ? itemDtRow[i]["ManHoursActual"].ToString() : string.Empty); row.CreateCell(18).SetCellValue(valueNotNull(itemDtRow[i]["ManhourActualForecast"]) ? itemDtRow[i]["ManhourActualForecast"].ToString() : string.Empty); row.CreateCell(19).SetCellValue(valueNotNull(itemDtRow[i]["Realization"]) ? itemDtRow[i]["Realization"].ToString() : string.Empty); int dtrowIndex = 20; for (DateTime time = starts; time <= ends; time = time.AddMonths(1)) { if (time.Month == sMonth) { if (actHour.Count > 0) { var act = actHour.Where(p => p.ManHoursDate == time.ToString("yyyy-MM")).Select(p => p.Hours).ToList(); if (act.Count > 0) { act.Remove(null); var actValue = (double)act.Sum(p => p); row.CreateCell(dtrowIndex).SetCellValue(actValue); } else { row.CreateCell(dtrowIndex).SetCellValue(0); } } else { row.CreateCell(dtrowIndex).SetCellValue(0); } } else { var hours = manHourDetail.FirstOrDefault(p => p.DateMonth.Value.Year == time.Year && p.DateMonth.Value.Month == time.Month); if (hours != null) { var h = hours.Hour != null ? hours.Hour.Value : 0; dtotal += h; row.CreateCell(dtrowIndex).SetCellValue(h); } else { row.CreateCell(dtrowIndex).SetCellValue(0); } } //样式 row.GetCell(dtrowIndex).CellStyle = rstyle; dtrowIndex++; } if (dtotal != null) { row.CreateCell(18).SetCellValue(dtotal.Value); double rate = (dtotal.Value > 0 && dplanMan.Value > 0) ? (1.0 * dtotal.Value / dplanMan.Value) : 0; string real = rate.ToString("0.##"); row.CreateCell(19).SetCellValue(real); } else { row.CreateCell(18).SetCellValue(0); row.CreateCell(19).SetCellValue("0"); } //统一添加样式 for (int r = 0; r < 8; r++) { row.GetCell(r).CellStyle = lstyle; } for (int r = 8; r < 16; r++) { row.GetCell(r).CellStyle = styleDate; } for (int r = 16; r < 20; r++) { row.GetCell(r).CellStyle = lstyle; } rowIndex++; } } #endregion } book.Write(ms); byte[] strmByte = ms.ToArray(); ms.Dispose(); Response.Clear(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 Response.AddHeader("Content-Disposition", "attachment; fileName=" + fileName + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"); // 添加头信息,指定文件大小,让浏览器能够显示下载进度 Response.AddHeader("Content-Length", strmByte.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载 Response.ContentType = "application/ms-excel"; // 把文件流发送到客户端 Response.BinaryWrite(strmByte); // 停止页面的执行 Response.End(); } #region 分页、排序 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(hidpersonnel.Text); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(hidpersonnel.Text); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(hidpersonnel.Text); } #endregion #region 搜索 /// /// 搜索 /// protected void btnSearch_Click(object sender, EventArgs e) { if (ddlDeptList.SelectedValue == Const._Null) { Alert.ShowInParent("请选择部门!"); return; } if (string.IsNullOrWhiteSpace(txtStartData.Text)) { Alert.ShowInParent("开始年月不能为空!"); return; } if (string.IsNullOrWhiteSpace(txtEndData.Text)) { Alert.ShowInParent("结束年月不能为空!"); return; } if (DateTime.Parse(txtStartData.Text + "-01") > DateTime.Parse(txtEndData.Text + "-01")) { Alert.ShowInParent("结束年月应该大于开始年月!"); return; } Session.Remove("GRID_TIME"); Session.Remove("Dep_Id"); //时间添加session var time = Session["GRID_TIME"] as List; if (time == null) time = new List(); time.Add(DateTime.Parse(txtStartData.Text.Trim() + "-01")); time.Add(DateTime.Parse(txtEndData.Text.Trim() + "-01")); Session["GRID_TIME"] = time; //部门添加session var depId = Session["Dep_Id"]; if (ddlDeptList.SelectedValue != Const._Null) Session["Dep_Id"] = ddlDeptList.SelectedValue; PageContext.Redirect("StaffingPlanReport.aspx"); } ///// ///// 筛选 ///// //protected void ddlDeptList_SelectedIndexChanged(object sender, EventArgs e) //{ // BindGrid(ddlDeptList.SelectedValue); // var depId = Session["Dep_Id"]; // if (ddlDeptList.SelectedValue != Const._Null) Session["Dep_Id"] = ddlDeptList.SelectedValue; //} #endregion /// /// 筛选是否为空 /// public bool valueNotNull(object values) { var result = false; if (values == null) values = string.Empty; if (!string.IsNullOrWhiteSpace(values.ToString())) result = true; return result; } #region 权限设置 /// /// 菜单按钮权限 /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.StaffingPlanReportMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnOut)) { this.btnExport.Hidden = false; } } } #endregion } }