394 lines
18 KiB
C#
394 lines
18 KiB
C#
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 ProjectClosureReport : PageBase
|
|
{
|
|
#region 加载
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
GetButtonPower();//权限设置
|
|
//项目类型
|
|
//this.drpJobType.DataTextField = "ConstText";
|
|
//this.drpJobType.DataValueField = "ConstValue";
|
|
//this.drpJobType.DataSource = BLL.ConstService.GetConstListByGroupId(BLL.Const.ProjectPlanner_JobType);
|
|
//this.drpJobType.DataBind();
|
|
//Funs.FineUIPleaseSelectJobType(this.drpJobType);
|
|
|
|
////项目状态
|
|
//this.drpJobStatus.DataTextField = "ConstText";
|
|
//this.drpJobStatus.DataValueField = "ConstValue";
|
|
//this.drpJobStatus.DataSource = BLL.ConstService.GetConstListByGroupId(BLL.Const.ProjectPlanner_JobStatus);
|
|
//this.drpJobStatus.DataBind();
|
|
//Funs.FineUIPleaseSelectJobStatus(this.drpJobStatus);
|
|
|
|
//BLL.ConstService.InitConstValueDropDownList(this.drpJobStatus, BLL.Const.ProjectPlanner_JobStatus, true);
|
|
|
|
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|
// 绑定表格
|
|
BindGrid();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string strSql = @"SELECT * FROM View_Project_Closure_Report WHERE 1=1 ";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
if (!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() + "%"));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
// 2.获取当前分页数据
|
|
//var table = this.GetPagedDataTable(Grid1, tb1);
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
}
|
|
#endregion
|
|
|
|
#region 查询
|
|
/// <summary>
|
|
/// 下拉框选择事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#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 + "Project_Closure_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 Project_Closure_Report
|
|
XSSFSheet reportModel = (XSSFSheet)hssfworkbook.GetSheet("Project_Closure_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");
|
|
|
|
#region 红底
|
|
//创建单元格样式
|
|
XSSFCellStyle redbackgroundstyle = (XSSFCellStyle)hssfworkbook.CreateCellStyle();
|
|
//填充模式
|
|
redbackgroundstyle.FillPattern = FillPattern.SolidForeground;
|
|
//创建颜色
|
|
XSSFColor xssfredcolor = new XSSFColor();
|
|
//rbg值
|
|
byte[] rgbRed = { (byte)244, (byte)164, (byte)96 };
|
|
//写入rgb
|
|
xssfredcolor.SetRgb(rgbRed);
|
|
//设置颜色值
|
|
redbackgroundstyle.SetFillForegroundColor(xssfredcolor);
|
|
//redbackgroundstyle.SetFont(cs_content_Font);
|
|
#endregion
|
|
|
|
var list = (from x in Funs.DB.View_Project_Closure_Report orderby x.ProjectControl_JobNo descending select x).ToList();
|
|
|
|
if (this.drpJobStatus.SelectedValue != BLL.Const._Null&&!string.IsNullOrEmpty(this.drpJobStatus.SelectedValue))
|
|
{
|
|
list = list.Where(x => x.ProjectControl_JobStatus == this.drpJobStatus.SelectedValue).ToList();
|
|
}
|
|
if (!string.IsNullOrEmpty(this.txtJobNo.Text.Trim()))
|
|
{
|
|
list = list.Where(x => x.ProjectControl_JobNo.Contains(this.txtJobNo.Text.Trim())).ToList();
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
var rowIndex = 1;
|
|
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);//将字体绑定到样式
|
|
|
|
//Job Type
|
|
if (reportModel.GetRow(rowIndex).GetCell(1) == null) reportModel.GetRow(rowIndex).CreateCell(1);
|
|
reportModel.GetRow(rowIndex).GetCell(1).SetCellValue(itemOver.ProjectControl_JobType);
|
|
//Lead By
|
|
if (reportModel.GetRow(rowIndex).GetCell(2) == null) reportModel.GetRow(rowIndex).CreateCell(2);
|
|
reportModel.GetRow(rowIndex).GetCell(2).SetCellValue(itemOver.ProjectControl_LeadByName);
|
|
//Job Title
|
|
if (reportModel.GetRow(rowIndex).GetCell(3) == null) reportModel.GetRow(rowIndex).CreateCell(3);
|
|
reportModel.GetRow(rowIndex).GetCell(3).SetCellValue(itemOver.ProjectControl_JobTitle);
|
|
//Budget
|
|
if (reportModel.GetRow(rowIndex).GetCell(4) == null) reportModel.GetRow(rowIndex).CreateCell(4);
|
|
reportModel.GetRow(rowIndex).GetCell(4).SetCellValue(itemOver.ProjectControl_OrginalBudget.HasValue ? string.Format("{0:N}",itemOver.ProjectControl_OrginalBudget) : "0");
|
|
//PM
|
|
if (reportModel.GetRow(rowIndex).GetCell(5) == null) reportModel.GetRow(rowIndex).CreateCell(5);
|
|
reportModel.GetRow(rowIndex).GetCell(5).SetCellValue(itemOver.ProjectControl_ProjectManager);
|
|
//Job Status
|
|
if (reportModel.GetRow(rowIndex).GetCell(6) == null) reportModel.GetRow(rowIndex).CreateCell(6);
|
|
reportModel.GetRow(rowIndex).GetCell(6).SetCellValue(itemOver.ProjectControl_JobStatus);
|
|
//Completed Date
|
|
if (reportModel.GetRow(rowIndex).GetCell(7) == null) reportModel.GetRow(rowIndex).CreateCell(7);
|
|
if (itemOver.CompletedDate.HasValue)
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(7).SetCellValue((DateTime)itemOver.CompletedDate.Value);
|
|
reportModel.GetRow(rowIndex).GetCell(7).CellStyle = styleDate;
|
|
}
|
|
|
|
//Close Date
|
|
if (reportModel.GetRow(rowIndex).GetCell(8) == null) reportModel.GetRow(rowIndex).CreateCell(8);
|
|
if (itemOver.CloseDate.HasValue)
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(8).SetCellValue((DateTime)itemOver.CloseDate.Value);
|
|
reportModel.GetRow(rowIndex).GetCell(8).CellStyle = styleDate;
|
|
}
|
|
//As-Built Received
|
|
if (reportModel.GetRow(rowIndex).GetCell(9) == null) reportModel.GetRow(rowIndex).CreateCell(9);
|
|
if (itemOver.AsBuiltReceived.HasValue)
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(9).SetCellValue((DateTime)itemOver.AsBuiltReceived.Value);
|
|
reportModel.GetRow(rowIndex).GetCell(9).CellStyle = styleDate;
|
|
}
|
|
//MC Signed
|
|
if (reportModel.GetRow(rowIndex).GetCell(10) == null) reportModel.GetRow(rowIndex).CreateCell(10);
|
|
if (itemOver.ProjectControl_JobType == "MOC" || itemOver.ProjectControl_JobType == "Other")
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(10).SetCellValue(itemOver.MC_Signed.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.MC_Signed) : "N/A");
|
|
}
|
|
else
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(10).SetCellValue(itemOver.MC_Signed.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.MC_Signed) : "");
|
|
}
|
|
|
|
// RFSU
|
|
if (reportModel.GetRow(rowIndex).GetCell(11) == null) reportModel.GetRow(rowIndex).CreateCell(11);
|
|
if (itemOver.ProjectControl_JobType == "MOC" || itemOver.ProjectControl_JobType == "Other")
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(11).SetCellValue(itemOver.RFSU.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.RFSU) : "N/A");
|
|
}
|
|
else
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(11).SetCellValue(itemOver.RFSU.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.RFSU) : "");
|
|
}
|
|
|
|
//Punch C Killed
|
|
if (reportModel.GetRow(rowIndex).GetCell(12) == null) reportModel.GetRow(rowIndex).CreateCell(12);
|
|
if (itemOver.CM_Punch_CKilledDate1.HasValue && Convert.ToDateTime(itemOver.CM_Punch_CKilledDate1) == Convert.ToDateTime("1900-01-01"))
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(12).SetCellValue("不适用");
|
|
//reportModel.GetRow(rowIndex).GetCell(12).CellStyle = redbackgroundstyle;
|
|
}
|
|
else
|
|
{
|
|
if (itemOver.ProjectControl_JobType == "MOC" || itemOver.ProjectControl_JobType == "Other")
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(12).SetCellValue(itemOver.CM_Punch_CKilledDate.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.CM_Punch_CKilledDate) : "N/A");
|
|
}
|
|
else
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(12).SetCellValue(itemOver.CM_Punch_CKilledDate.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.CM_Punch_CKilledDate) : "");
|
|
}
|
|
}
|
|
//FC Signed
|
|
if (reportModel.GetRow(rowIndex).GetCell(13) == null) reportModel.GetRow(rowIndex).CreateCell(13);
|
|
if (itemOver.ProjectControl_JobType == "Projects")
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(13).SetCellValue(itemOver.FC_Signed.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.FC_Signed) : "");
|
|
}
|
|
else
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(13).SetCellValue(itemOver.FC_Signed.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.FC_Signed) : "N/A");
|
|
}
|
|
|
|
//Business Colsed
|
|
if (reportModel.GetRow(rowIndex).GetCell(14) == null) reportModel.GetRow(rowIndex).CreateCell(14);
|
|
if (itemOver.Business_Colsed.HasValue)
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(14).SetCellValue((DateTime)itemOver.Business_Colsed.Value);
|
|
reportModel.GetRow(rowIndex).GetCell(14).CellStyle = styleDate;
|
|
}
|
|
//MD Updated
|
|
if (reportModel.GetRow(rowIndex).GetCell(15) == null) reportModel.GetRow(rowIndex).CreateCell(15);
|
|
if (itemOver.MD_Updated.HasValue)
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(15).SetCellValue((DateTime)itemOver.MD_Updated.Value);
|
|
reportModel.GetRow(rowIndex).GetCell(15).CellStyle = styleDate;
|
|
}
|
|
// Date_of_Registeration
|
|
if (reportModel.GetRow(rowIndex).GetCell(16) == null) reportModel.GetRow(rowIndex).CreateCell(16);
|
|
if (itemOver.ProjectControl_JobType == "Other")
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(16).SetCellValue(itemOver.Date_of_Registeration.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.Date_of_Registeration) : "N/A");
|
|
}
|
|
else
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(16).SetCellValue(itemOver.Date_of_Registeration.HasValue ? string.Format("{0:yyyy/MM/dd}", itemOver.Date_of_Registeration) : "");
|
|
}
|
|
|
|
|
|
#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=P04_Project_Closure_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.ProjectClosureReportMenuId);
|
|
if (buttonList.Count() > 0)
|
|
{
|
|
if (buttonList.Contains(BLL.Const.BtnOut))
|
|
{
|
|
this.btnExport.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |