using BLL; using NPOI.XSSF.UserModel; using NPOI.SS.UserModel; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.Report { public partial class DocumentationTakeoverReport : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { // 表头过滤 FilterDataRowItem = FilterDataRowItemImplement; if (!IsPostBack) { GetButtonPower();//权限设置 ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); BLL.ConstService.InitConstValueDropDownList(this.drpJobStatus, BLL.Const.ProjectPlanner_JobStatus, true); // 绑定表格 BindGrid(); } else if (GetRequestEventArgument() == "FilterChange") { BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT * FROM View_Report_DocumentationTakeoverReport WHERE 1=1 "; List listStr = new List(); if (this.drpJobStatus.SelectedValue != BLL.Const._Null&&!string.IsNullOrEmpty(this.drpJobStatus.SelectedValue)) { strSql += " AND ProjectControl_JobStatus=@jobStatus "; listStr.Add(new SqlParameter("@jobStatus", this.drpJobStatus.SelectedItem.Text.Trim())); } if (!string.IsNullOrEmpty(this.txtJobNo.Text.Trim())) { strSql += " AND ProjectControl_JobNo LIKE @JobNO "; listStr.Add(new SqlParameter("@JobNO", this.txtJobNo.Text.Trim() + "%")); } strSql += "ORDER BY ProjectControl_JobNo DESC"; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 过滤表头 /// /// 过滤表头 /// /// /// protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } /// /// 根据表头信息过滤列表数据 /// /// /// /// /// /// private bool FilterDataRowItemImplement(object sourceObj, string fillteredOperator, object fillteredObj, string column) { bool valid = false; if (column == "ProjectControl_JobNo") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "ProjectControl_BUCode") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "IFC_HC_A1_Pages") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "IFC_Hard_Copy") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "IFC_PDF_in_X_Drive") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "IFC_Native_in_X_Drive") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "IFC_PDF_in_DCTM") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "BUILT_HC_A1_Pages") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "BUILT_Hard_Copy") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "BUILT_PDF_in_X_Drive") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "BUILT_Native_in_X_Drive") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "BUILT_PDF_in_DCTM") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "BUILT_Native_in_DCTM") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "Vendor_Hard_Copy") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "Vendor_PDF_in_X_Drive") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "Vendor_Native_in_X_Drive") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "Vendor_PDF_in_DCTM") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "Vendor_Native_in_DCTM") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "Construction_Hard_Copy") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "Construction_PDF_in_X_Drive") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "To_Plant") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } if (column == "To_CHA") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal" && sourceValue == fillteredValue) { valid = true; } else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue)) { valid = true; } } return valid; } #endregion #region 分页、排序 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 导出 /// /// 导出按钮 /// /// /// protected void btnExport_Click(object sender, EventArgs e) { string rootPath = Server.MapPath("~/") + Const.ExcelUrl; //模板文件 string TempletFileName = rootPath + "Documentation_Status_Takeover.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 Documentation_Status_Takeover XSSFSheet reportModel = (XSSFSheet)hssfworkbook.GetSheet("Documentation_Takeover_Report"); XSSFFont cs_content_Font = (XSSFFont)hssfworkbook.CreateFont(); //创建字体 cs_content_Font.FontName = "sans-serif";//字体 cs_content_Font.FontHeightInPoints = 10; //字体大小 IDataFormat dataformat = hssfworkbook.CreateDataFormat(); ICellStyle styleDate = hssfworkbook.CreateCellStyle(); styleDate.DataFormat = dataformat.GetFormat("yyyy/m/d"); var docReport = from x in Funs.DB.View_Report_DocumentationTakeoverReport select x; if (this.drpJobStatus.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpJobStatus.SelectedValue)) { docReport = from x in docReport where x.ProjectControl_JobStatus == this.drpJobStatus.SelectedValue.Trim() select x; } if (!string.IsNullOrEmpty(this.txtJobNo.Text.Trim())) { docReport = from x in docReport where x.ProjectControl_JobNo.Contains(this.txtJobNo.Text.Trim()) select x; } var list = (docReport.OrderByDescending(x => x.ProjectControl_JobNo)).ToList(); if (list.Count > 0) { var rowIndex = 2; foreach (var itemOver in list) { 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(itemOver.ProjectControl_JobNo); reportModel.GetRow(rowIndex).GetCell(0).CellStyle.SetFont(cs_content_Font);//将字体绑定到样式 //BU if (reportModel.GetRow(rowIndex).GetCell(1) == null) reportModel.GetRow(rowIndex).CreateCell(1); reportModel.GetRow(rowIndex).GetCell(1).SetCellValue(itemOver.ProjectControl_BUCode); #region Design/IFC //HC A1 Pages if (reportModel.GetRow(rowIndex).GetCell(2) == null) reportModel.GetRow(rowIndex).CreateCell(2); if (itemOver.IFC_HC_A1_Pages.HasValue) { reportModel.GetRow(rowIndex).GetCell(2).SetCellValue(Convert.ToDouble(itemOver.IFC_HC_A1_Pages.Value)); } //Hard Copy if (reportModel.GetRow(rowIndex).GetCell(3) == null) reportModel.GetRow(rowIndex).CreateCell(3); if (!string.IsNullOrEmpty(itemOver.IFC_Hard_Copy)) { reportModel.GetRow(rowIndex).GetCell(3).SetCellValue((DateTime)Convert.ToDateTime(itemOver.IFC_Hard_Copy)); reportModel.GetRow(rowIndex).GetCell(3).CellStyle = styleDate; } //PDF in X Drive if (reportModel.GetRow(rowIndex).GetCell(4) == null) reportModel.GetRow(rowIndex).CreateCell(4); if (!string.IsNullOrEmpty(itemOver.IFC_PDF_in_X_Drive)) { reportModel.GetRow(rowIndex).GetCell(4).SetCellValue((DateTime)Convert.ToDateTime(itemOver.IFC_PDF_in_X_Drive)); reportModel.GetRow(rowIndex).GetCell(4).CellStyle = styleDate; } //Native in X Drive if (reportModel.GetRow(rowIndex).GetCell(5) == null) reportModel.GetRow(rowIndex).CreateCell(5); if (!string.IsNullOrEmpty(itemOver.IFC_Native_in_X_Drive)) { reportModel.GetRow(rowIndex).GetCell(5).SetCellValue((DateTime)Convert.ToDateTime(itemOver.IFC_Native_in_X_Drive)); reportModel.GetRow(rowIndex).GetCell(5).CellStyle = styleDate; } //PDF in DCTM if (reportModel.GetRow(rowIndex).GetCell(6) == null) reportModel.GetRow(rowIndex).CreateCell(6); if (!string.IsNullOrEmpty(itemOver.IFC_PDF_in_DCTM)) { reportModel.GetRow(rowIndex).GetCell(6).SetCellValue((DateTime)Convert.ToDateTime(itemOver.IFC_PDF_in_DCTM)); reportModel.GetRow(rowIndex).GetCell(6).CellStyle = styleDate; } #endregion #region Design/As-Built //HC A1 Pages if (reportModel.GetRow(rowIndex).GetCell(7) == null) reportModel.GetRow(rowIndex).CreateCell(7); if (itemOver.BUILT_HC_A1_Pages.HasValue) { reportModel.GetRow(rowIndex).GetCell(7).SetCellValue(Convert.ToDouble(itemOver.BUILT_HC_A1_Pages.Value)); } //Hard Copy if (reportModel.GetRow(rowIndex).GetCell(8) == null) reportModel.GetRow(rowIndex).CreateCell(8); if (!string.IsNullOrEmpty(itemOver.BUILT_Hard_Copy)) { reportModel.GetRow(rowIndex).GetCell(8).SetCellValue((DateTime)Convert.ToDateTime(itemOver.BUILT_Hard_Copy)); reportModel.GetRow(rowIndex).GetCell(8).CellStyle = styleDate; } //PDF in X Drive if (reportModel.GetRow(rowIndex).GetCell(9) == null) reportModel.GetRow(rowIndex).CreateCell(9); if (!string.IsNullOrEmpty(itemOver.BUILT_PDF_in_X_Drive)) { reportModel.GetRow(rowIndex).GetCell(9).SetCellValue((DateTime)Convert.ToDateTime(itemOver.BUILT_PDF_in_X_Drive)); reportModel.GetRow(rowIndex).GetCell(9).CellStyle = styleDate; } //Native in X Drive if (reportModel.GetRow(rowIndex).GetCell(10) == null) reportModel.GetRow(rowIndex).CreateCell(10); if (!string.IsNullOrEmpty(itemOver.BUILT_Native_in_X_Drive)) { reportModel.GetRow(rowIndex).GetCell(10).SetCellValue((DateTime)Convert.ToDateTime(itemOver.BUILT_Native_in_X_Drive)); reportModel.GetRow(rowIndex).GetCell(10).CellStyle = styleDate; } //PDF in DCTM if (reportModel.GetRow(rowIndex).GetCell(11) == null) reportModel.GetRow(rowIndex).CreateCell(11); if (!string.IsNullOrEmpty(itemOver.BUILT_PDF_in_DCTM)) { reportModel.GetRow(rowIndex).GetCell(11).SetCellValue((DateTime)Convert.ToDateTime(itemOver.BUILT_PDF_in_DCTM)); reportModel.GetRow(rowIndex).GetCell(11).CellStyle = styleDate; } //Native in DCTM if (reportModel.GetRow(rowIndex).GetCell(12) == null) reportModel.GetRow(rowIndex).CreateCell(12); if (!string.IsNullOrEmpty(itemOver.BUILT_Native_in_DCTM)) { reportModel.GetRow(rowIndex).GetCell(12).SetCellValue((DateTime)Convert.ToDateTime(itemOver.BUILT_Native_in_DCTM)); reportModel.GetRow(rowIndex).GetCell(12).CellStyle = styleDate; } #endregion #region Vendor Document //Hard Copy if (reportModel.GetRow(rowIndex).GetCell(13) == null) reportModel.GetRow(rowIndex).CreateCell(13); if (!string.IsNullOrEmpty(itemOver.Vendor_Hard_Copy)) { reportModel.GetRow(rowIndex).GetCell(13).SetCellValue((DateTime)Convert.ToDateTime(itemOver.Vendor_Hard_Copy)); reportModel.GetRow(rowIndex).GetCell(13).CellStyle = styleDate; } //PDF in X Drive if (reportModel.GetRow(rowIndex).GetCell(14) == null) reportModel.GetRow(rowIndex).CreateCell(14); if (!string.IsNullOrEmpty(itemOver.Vendor_PDF_in_X_Drive)) { reportModel.GetRow(rowIndex).GetCell(14).SetCellValue((DateTime)Convert.ToDateTime(itemOver.Vendor_PDF_in_X_Drive)); reportModel.GetRow(rowIndex).GetCell(14).CellStyle = styleDate; } //Native in X Drive if (reportModel.GetRow(rowIndex).GetCell(15) == null) reportModel.GetRow(rowIndex).CreateCell(15); if (!string.IsNullOrEmpty(itemOver.Vendor_Native_in_X_Drive)) { reportModel.GetRow(rowIndex).GetCell(15).SetCellValue((DateTime)Convert.ToDateTime(itemOver.Vendor_Native_in_X_Drive)); reportModel.GetRow(rowIndex).GetCell(15).CellStyle = styleDate; } //PDF in DCTM if (reportModel.GetRow(rowIndex).GetCell(16) == null) reportModel.GetRow(rowIndex).CreateCell(16); if (!string.IsNullOrEmpty(itemOver.Vendor_PDF_in_DCTM)) { reportModel.GetRow(rowIndex).GetCell(16).SetCellValue((DateTime)Convert.ToDateTime(itemOver.Vendor_PDF_in_DCTM)); reportModel.GetRow(rowIndex).GetCell(16).CellStyle = styleDate; } //Native in DTCM if (reportModel.GetRow(rowIndex).GetCell(17) == null) reportModel.GetRow(rowIndex).CreateCell(17); if (!string.IsNullOrEmpty(itemOver.Vendor_Native_in_DCTM)) { reportModel.GetRow(rowIndex).GetCell(17).SetCellValue((DateTime)Convert.ToDateTime(itemOver.Vendor_Native_in_DCTM)); reportModel.GetRow(rowIndex).GetCell(17).CellStyle = styleDate; } #endregion #region Construction Dossier //Hard Copy if (reportModel.GetRow(rowIndex).GetCell(18) == null) reportModel.GetRow(rowIndex).CreateCell(18); if (!string.IsNullOrEmpty(itemOver.Construction_Hard_Copy)) { reportModel.GetRow(rowIndex).GetCell(18).SetCellValue((DateTime)Convert.ToDateTime(itemOver.Construction_Hard_Copy)); reportModel.GetRow(rowIndex).GetCell(18).CellStyle = styleDate; } //PDF in X Drive if (reportModel.GetRow(rowIndex).GetCell(19) == null) reportModel.GetRow(rowIndex).CreateCell(19); if (!string.IsNullOrEmpty(itemOver.Construction_PDF_in_X_Drive)) { reportModel.GetRow(rowIndex).GetCell(19).SetCellValue((DateTime)Convert.ToDateTime(itemOver.Construction_PDF_in_X_Drive)); reportModel.GetRow(rowIndex).GetCell(19).CellStyle = styleDate; } #endregion #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=P21_Document_Status_Takeover_" + 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.DocumentationTakeoverReportMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnOut)) { this.btnExport.Hidden = false; } } } #endregion #region 查询 /// /// 查询 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); } #endregion } }