297 lines
13 KiB
C#
297 lines
13 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 MCReport : 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() + "%"));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunProc("Proc_MC_Report", parameter);
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
}
|
|
#endregion
|
|
|
|
#region 查询
|
|
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 + "MC_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("MC_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");
|
|
styleDate.SetFont(cs_content_Font);
|
|
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
if (!string.IsNullOrEmpty(txtJobNo.Text.Trim()))
|
|
{
|
|
listStr.Add(new SqlParameter("@jobNo", "%"+txtJobNo.Text.Trim()+"%"));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable table = SQLHelper.GetDataTableRunProc("Proc_MC_Report", 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);//将字体绑定到样式
|
|
//Job Type
|
|
if (reportModel.GetRow(rowIndex).GetCell(1) == null) reportModel.GetRow(rowIndex).CreateCell(1);
|
|
reportModel.GetRow(rowIndex).GetCell(1).SetCellValue(table.Rows[i]["ProjectControl_JobType"].ToString());
|
|
//Lead By
|
|
if (reportModel.GetRow(rowIndex).GetCell(2) == null) reportModel.GetRow(rowIndex).CreateCell(2);
|
|
reportModel.GetRow(rowIndex).GetCell(2).SetCellValue(table.Rows[i]["ProjectControl_LeadByName"].ToString());
|
|
//Job Title
|
|
if (reportModel.GetRow(rowIndex).GetCell(3) == null) reportModel.GetRow(rowIndex).CreateCell(3);
|
|
reportModel.GetRow(rowIndex).GetCell(3).SetCellValue(table.Rows[i]["ProjectControl_JobTitle"].ToString());
|
|
//MC Actual
|
|
if (reportModel.GetRow(rowIndex).GetCell(4) == null) reportModel.GetRow(rowIndex).CreateCell(4);
|
|
if (table.Rows[i]["CM_MA_MC"] != null && table.Rows[i]["CM_MA_MC"].ToString() != "")
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(4).SetCellValue((DateTime)Convert.ToDateTime(table.Rows[i]["CM_MA_MC"].ToString()));
|
|
reportModel.GetRow(rowIndex).GetCell(4).CellStyle = styleDate;
|
|
}
|
|
//MC Signed
|
|
if (reportModel.GetRow(rowIndex).GetCell(5) == null) reportModel.GetRow(rowIndex).CreateCell(5);
|
|
if (table.Rows[i]["MC_Signed"] != null && table.Rows[i]["MC_Signed"].ToString() != string.Empty)
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(5).SetCellValue(table.Rows[i]["MC_Signed"].ToString());
|
|
}
|
|
else
|
|
{
|
|
if (table.Rows[i]["ProjectControl_JobType"].ToString() == "MOC" || table.Rows[i]["ProjectControl_JobType"].ToString() == "Other")
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(5).SetCellValue("N/A");
|
|
}
|
|
else
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(5).SetCellValue("");
|
|
}
|
|
}
|
|
|
|
//RFSU
|
|
if (reportModel.GetRow(rowIndex).GetCell(6) == null) reportModel.GetRow(rowIndex).CreateCell(6);
|
|
if (table.Rows[i]["RFSU"] != null && table.Rows[i]["RFSU"].ToString() != string.Empty)
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(6).SetCellValue(table.Rows[i]["RFSU"].ToString());
|
|
}
|
|
else
|
|
{
|
|
if (table.Rows[i]["ProjectControl_JobType"].ToString() == "MOC" || table.Rows[i]["ProjectControl_JobType"].ToString() == "Other")
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(6).SetCellValue("N/A");
|
|
}
|
|
else
|
|
{
|
|
reportModel.GetRow(rowIndex).GetCell(6).SetCellValue("");
|
|
}
|
|
}
|
|
|
|
//CAPEX Plan No
|
|
if (reportModel.GetRow(rowIndex).GetCell(7) == null) reportModel.GetRow(rowIndex).CreateCell(7);
|
|
reportModel.GetRow(rowIndex).GetCell(7).SetCellValue(table.Rows[i]["CAPEXPlanNo"].ToString());
|
|
//Job Status
|
|
if (reportModel.GetRow(rowIndex).GetCell(8) == null) reportModel.GetRow(rowIndex).CreateCell(8);
|
|
reportModel.GetRow(rowIndex).GetCell(8).SetCellValue(table.Rows[i]["ProjectControl_JobStatus"].ToString());
|
|
//Project Manager
|
|
if (reportModel.GetRow(rowIndex).GetCell(9) == null) reportModel.GetRow(rowIndex).CreateCell(9);
|
|
reportModel.GetRow(rowIndex).GetCell(9).SetCellValue(table.Rows[i]["ProjectControl_ProjectManager"].ToString());
|
|
//Construction Manager
|
|
if (reportModel.GetRow(rowIndex).GetCell(10) == null) reportModel.GetRow(rowIndex).CreateCell(10);
|
|
reportModel.GetRow(rowIndex).GetCell(10).SetCellValue(table.Rows[i]["ProjectControl_ConstManager"].ToString());
|
|
//TDC
|
|
if (reportModel.GetRow(rowIndex).GetCell(11) == null) reportModel.GetRow(rowIndex).CreateCell(11);
|
|
reportModel.GetRow(rowIndex).GetCell(11).SetCellValue(table.Rows[i]["TDCManager"].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=P42_MC_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.MCReportMenuId);
|
|
if (buttonList.Count() > 0)
|
|
{
|
|
if (buttonList.Contains(BLL.Const.BtnOut))
|
|
{
|
|
this.btnExport.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |