initProject
This commit is contained in:
@@ -0,0 +1,277 @@
|
||||
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 TaskListReport : PageBase
|
||||
{
|
||||
#region 加载
|
||||
/// <summary>
|
||||
/// 加载页面
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
GetButtonPower();//权限设置
|
||||
|
||||
BLL.DepartService.InitCTEDepartDropDownList(this.drpDepart, false);
|
||||
|
||||
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
||||
// 绑定表格
|
||||
BindGrid();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绑定数据
|
||||
/// </summary>
|
||||
private void BindGrid()
|
||||
{
|
||||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||||
if (this.drpDepart.SelectedValue != BLL.Const._Null && this.drpDepart.SelectedItem.Text != "CTE")
|
||||
{
|
||||
listStr.Add(new SqlParameter("@departId", this.drpDepart.SelectedValue.Trim()));
|
||||
}
|
||||
if (this.drpUser.SelectedValue != BLL.Const._Null && this.drpUser.SelectedValue != null)
|
||||
{
|
||||
listStr.Add(new SqlParameter("@userId", this.drpUser.SelectedValue.Trim()));
|
||||
}
|
||||
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_TaskListReport", parameter);
|
||||
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
|
||||
|
||||
protected void drpDepart_OnSelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
drpUser.DataValueField = "UserId";
|
||||
drpUser.DataTextField = "UserName";
|
||||
drpUser.DataSource = BLL.Sys_UserService.GetUserListByDepartId(drpDepart.SelectedValue.Trim());
|
||||
drpUser.DataBind();
|
||||
Funs.FineUIPleaseSelect(drpUser);
|
||||
}
|
||||
|
||||
#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 + "TaskListReport.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 TaskListReport
|
||||
XSSFSheet reportModel = (XSSFSheet)hssfworkbook.GetSheet("TaskList");
|
||||
|
||||
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");
|
||||
|
||||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||||
if (this.drpDepart.SelectedValue != BLL.Const._Null && this.drpDepart.SelectedItem.Text != "CTE")
|
||||
{
|
||||
listStr.Add(new SqlParameter("@departId", this.drpDepart.SelectedValue.Trim()));
|
||||
}
|
||||
if (this.drpUser.SelectedValue != BLL.Const._Null && this.drpUser.SelectedValue != null)
|
||||
{
|
||||
listStr.Add(new SqlParameter("@userId", this.drpUser.SelectedValue.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(this.txtJobNo.Text.Trim()))
|
||||
{
|
||||
listStr.Add(new SqlParameter("@jobNo", "%" + this.txtJobNo.Text.Trim() + "%"));
|
||||
}
|
||||
SqlParameter[] parameter = listStr.ToArray();
|
||||
DataTable table = SQLHelper.GetDataTableRunProc("Proc_TaskListReport", 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 Title
|
||||
if (reportModel.GetRow(rowIndex).GetCell(1) == null) reportModel.GetRow(rowIndex).CreateCell(1);
|
||||
reportModel.GetRow(rowIndex).GetCell(1).SetCellValue(table.Rows[i]["ProjectControl_JobTitle"].ToString());
|
||||
//Received Date
|
||||
if (reportModel.GetRow(rowIndex).GetCell(2) == null) reportModel.GetRow(rowIndex).CreateCell(2);
|
||||
if (table.Rows[i]["PM_MA_JobReveive"] != null && table.Rows[i]["PM_MA_JobReveive"].ToString() != "")
|
||||
{
|
||||
reportModel.GetRow(rowIndex).GetCell(2).SetCellValue((DateTime)Convert.ToDateTime(table.Rows[i]["PM_MA_JobReveive"].ToString()));
|
||||
reportModel.GetRow(rowIndex).GetCell(2).CellStyle = styleDate;
|
||||
}
|
||||
//Manhours(Plan)
|
||||
if (reportModel.GetRow(rowIndex).GetCell(3) == null) reportModel.GetRow(rowIndex).CreateCell(3);
|
||||
reportModel.GetRow(rowIndex).GetCell(3).SetCellValue(Convert.ToDouble(table.Rows[i]["PlanManHours"]));
|
||||
//Manhours(∑Actual)
|
||||
if (reportModel.GetRow(rowIndex).GetCell(4) == null) reportModel.GetRow(rowIndex).CreateCell(4);
|
||||
reportModel.GetRow(rowIndex).GetCell(4).SetCellValue(Convert.ToDouble(table.Rows[i]["ActualManHours"]));
|
||||
#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=P13_TaskList_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.TaskListReportMenuId);
|
||||
if (buttonList.Count() > 0)
|
||||
{
|
||||
if (buttonList.Contains(BLL.Const.BtnOut))
|
||||
{
|
||||
this.btnExport.Hidden = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user