387 lines
15 KiB
C#
387 lines
15 KiB
C#
using BLL;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.ReportManage.SafeEnvBudget
|
|
{
|
|
public partial class HSEMonthReport : PageBase
|
|
{
|
|
#region 加载页面
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
this.txtReportDate.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
|
|
Funs.DropDownPageSize(this.ddlPageSize);
|
|
///单位
|
|
UnitService.InitBranchUnitDropDownList(this.drpUnitId, true, true);
|
|
if (!string.IsNullOrWhiteSpace(this.CurrUser.UnitId) && this.CurrUser.Base_Unit.IsBranch == true)
|
|
{
|
|
//分公司只能查看本分公司填报数据
|
|
this.drpUnitId.SelectedValue = this.CurrUser.UnitId;
|
|
this.drpUnitId.Readonly = true;
|
|
}
|
|
////权限按钮方法
|
|
this.GetButtonPower();
|
|
btnNew.OnClientClick = Window1.GetShowReference("HSEMonthReportEdit.aspx") + "return false;";
|
|
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|
// 绑定表格
|
|
BindGrid();
|
|
}
|
|
}
|
|
|
|
private DataTable GetSourceDataTable()
|
|
{
|
|
string strSql = @" SELECT report.ReportId,
|
|
report.UnitId,
|
|
report.ReportDate,
|
|
report.TotalEmployees,
|
|
report.TotalHours,
|
|
report.ContractorEmployees,
|
|
report.ContractorHours,
|
|
report.MonthHours,
|
|
report.MonthHoursAvg,
|
|
report.YearHours,
|
|
report.Remark,
|
|
report.BranchTraining,
|
|
report.ProjectTraining,
|
|
report.TeamGroupTraining,
|
|
report.SelfTraining,
|
|
report.ContractorOrganizeTraining,
|
|
report.ContractorTraining,
|
|
report.CompileMan,
|
|
report.CompileDate,
|
|
unit.UnitName
|
|
FROM Report_HSEMonthReport AS report
|
|
LEFT JOIN Base_Unit AS unit ON unit.UnitId = report.UnitId where 1=1 ";// s.ProjectId=@projectId
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
if (!string.IsNullOrEmpty(this.drpUnitId.SelectedValue) && this.drpUnitId.SelectedValue != Const._Null)
|
|
{
|
|
strSql += " AND report.UnitId=@UnitId";
|
|
listStr.Add(new SqlParameter("@UnitId", this.drpUnitId.SelectedValue));
|
|
}
|
|
if (!string.IsNullOrEmpty(this.txtReportDate.Text.Trim()))
|
|
{
|
|
strSql += " AND report.ReportDate = @reportDate";
|
|
listStr.Add(new SqlParameter("@reportDate", Funs.GetNewDateTime(this.txtReportDate.Text.Trim())));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
return tb;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
DataTable tb = GetSourceDataTable();
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
|
|
JObject summary = new JObject();
|
|
int TotalEmployees = 0;
|
|
decimal TotalHours = 0;
|
|
int ContractorEmployees = 0;
|
|
decimal ContractorHours = 0;
|
|
decimal MonthHours = 0;
|
|
decimal MonthHoursAvg = 0;
|
|
decimal YearHours = 0;
|
|
int BranchTraining = 0;
|
|
int ProjectTraining = 0;
|
|
int TeamGroupTraining = 0;
|
|
int SelfTraining = 0;
|
|
int ContractorOrganizeTraining = 0;
|
|
int ContractorTraining = 0;
|
|
|
|
foreach (DataRow row in tb.Rows)
|
|
{
|
|
TotalEmployees += Funs.GetNewIntOrZero(row["TotalEmployees"].ToString());
|
|
TotalHours += Funs.GetNewDecimalOrZero(row["TotalHours"].ToString());
|
|
ContractorEmployees += Funs.GetNewIntOrZero(row["ContractorEmployees"].ToString());
|
|
ContractorHours += Funs.GetNewDecimalOrZero(row["ContractorHours"].ToString());
|
|
MonthHours += Funs.GetNewDecimalOrZero(row["MonthHours"].ToString());
|
|
MonthHoursAvg += Funs.GetNewDecimalOrZero(row["MonthHoursAvg"].ToString());
|
|
YearHours += Funs.GetNewDecimalOrZero(row["YearHours"].ToString());
|
|
BranchTraining += Funs.GetNewIntOrZero(row["BranchTraining"].ToString());
|
|
ProjectTraining += Funs.GetNewIntOrZero(row["ProjectTraining"].ToString());
|
|
TeamGroupTraining += Funs.GetNewIntOrZero(row["TeamGroupTraining"].ToString());
|
|
SelfTraining += Funs.GetNewIntOrZero(row["SelfTraining"].ToString());
|
|
ContractorOrganizeTraining += Funs.GetNewIntOrZero(row["ContractorOrganizeTraining"].ToString());
|
|
ContractorTraining += Funs.GetNewIntOrZero(row["ContractorTraining"].ToString());
|
|
}
|
|
summary.Add("UnitName", "合计");
|
|
summary.Add("TotalEmployees", TotalEmployees);
|
|
summary.Add("TotalHours", TotalHours);
|
|
summary.Add("ContractorEmployees", ContractorEmployees);
|
|
summary.Add("ContractorHours", ContractorHours);
|
|
summary.Add("MonthHours", MonthHours);
|
|
summary.Add("MonthHoursAvg", MonthHoursAvg);
|
|
summary.Add("YearHours", YearHours);
|
|
summary.Add("BranchTraining", BranchTraining);
|
|
summary.Add("ProjectTraining", ProjectTraining);
|
|
summary.Add("TeamGroupTraining", TeamGroupTraining);
|
|
summary.Add("SelfTraining", SelfTraining);
|
|
summary.Add("ContractorOrganizeTraining", ContractorOrganizeTraining);
|
|
summary.Add("ContractorTraining", ContractorTraining);
|
|
Grid1.SummaryData = summary;
|
|
|
|
}
|
|
#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 Grid1_Sort(object sender, GridSortEventArgs e)
|
|
{
|
|
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 Window1_Close(object sender, WindowCloseEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region Grid双击事件
|
|
/// <summary>
|
|
/// Grid行双击事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|
{
|
|
btnMenuModify_Click(null, null);
|
|
}
|
|
#endregion
|
|
|
|
#region 编辑
|
|
/// <summary>
|
|
/// 编辑按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuModify_Click(object sender, EventArgs e)
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
{
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
string rowId = Grid1.SelectedRowID;
|
|
if (!string.IsNullOrEmpty(rowId))
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HSEMonthReportEdit.aspx?reportId={0}", rowId, "编辑 - ")));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 批量删除
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuDel_Click(object sender, EventArgs e)
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length > 0)
|
|
{
|
|
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
|
{
|
|
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
|
var data = BLL.HSEMonthReportService.GetHSEMonthReportById(rowID);
|
|
if (data != null)
|
|
{
|
|
BLL.LogService.AddSys_Log(this.CurrUser, data.ReportId, data.ReportId, BLL.Const.HSEMonthReportMenuId, BLL.Const.BtnDelete);
|
|
BLL.HSEMonthReportService.DeleteHSEMonthReportByReportId(rowID);
|
|
}
|
|
}
|
|
BindGrid();
|
|
ShowNotify("删除数据成功!");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取按钮权限
|
|
/// <summary>
|
|
/// 获取按钮权限
|
|
/// </summary>
|
|
/// <param name="button"></param>
|
|
/// <returns></returns>
|
|
private void GetButtonPower()
|
|
{
|
|
try
|
|
{
|
|
if (Request.Params["value"] == "0")
|
|
{
|
|
return;
|
|
}
|
|
var buttonList = BLL.CommonService.GetAllButtonList(null, this.CurrUser.UserId, BLL.Const.HSEMonthReportMenuId);
|
|
if (buttonList.Count() > 0)
|
|
{
|
|
if (buttonList.Contains(BLL.Const.BtnAdd))
|
|
{
|
|
this.btnNew.Hidden = false;
|
|
}
|
|
if (buttonList.Contains(BLL.Const.BtnModify))
|
|
{
|
|
this.btnMenuModify.Hidden = false;
|
|
}
|
|
if (buttonList.Contains(BLL.Const.BtnDelete))
|
|
{
|
|
this.btnMenuDel.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 查询
|
|
/// <summary>
|
|
/// 查询
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void TextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 导出按钮
|
|
/// 导出按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnOut_Click(object sender, EventArgs e)
|
|
{
|
|
Response.ClearContent();
|
|
string fileName = System.Web.HttpUtility.UrlEncode($"HSE月报" + Funs.GetNewFileName(), System.Text.Encoding.UTF8);
|
|
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".xls");
|
|
Response.ContentType = "application/excel";
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
|
|
DataTable dtAll = GetSourceDataTable();
|
|
string html = GetGridMultiHeaderTableHtml(Grid1, dtAll);
|
|
Response.Write(html);
|
|
Response.End();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 多表头导出
|
|
/// </summary>
|
|
public string GetGridMultiHeaderTableHtml(Grid grid, DataTable dtSource)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
|
|
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
|
|
|
|
MultiHeaderTable mht = new MultiHeaderTable();
|
|
mht.ResolveMultiHeaderTable(grid.Columns);
|
|
|
|
foreach (List<object[]> rows in mht.MultiTable)
|
|
{
|
|
sb.Append("<tr>");
|
|
foreach (object[] cell in rows)
|
|
{
|
|
int rowspan = Convert.ToInt32(cell[0]);
|
|
int colspan = Convert.ToInt32(cell[1]);
|
|
GridColumn column = cell[2] as GridColumn;
|
|
if (column.Hidden == false)
|
|
{
|
|
sb.AppendFormat("<th{0}{1}{2}>{3}</th>",
|
|
rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "",
|
|
colspan != 1 ? " colspan=\"" + colspan + "\"" : "",
|
|
colspan != 1 ? " style=\"text-align:center;\"" : "",
|
|
column.HeaderText);
|
|
}
|
|
}
|
|
sb.Append("</tr>");
|
|
}
|
|
|
|
int rowIndex = 0;
|
|
foreach (DataRow dr in dtSource.Rows)
|
|
{
|
|
sb.Append("<tr>");
|
|
foreach (GridColumn column in mht.Columns)
|
|
{
|
|
if (column.ColumnID == "ckbIsSelected" || column.ColumnID == "Punish" || column.ColumnID == "Del")
|
|
continue;
|
|
|
|
string cellValue = "";
|
|
if (column.ColumnID == "tfNumber")
|
|
{
|
|
//导出序号:全部数据的序号
|
|
cellValue = (rowIndex + 1).ToString();
|
|
}
|
|
else if (column.ColumnID == "ReportDate")
|
|
{
|
|
cellValue = string.Format("{0:yyyy-MM}", dr[column.ColumnID]);
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(column.ColumnID) && dtSource.Columns.Contains(column.ColumnID))
|
|
{
|
|
cellValue = dr[column.ColumnID] == DBNull.Value ? "" : dr[column.ColumnID].ToString();
|
|
}
|
|
}
|
|
sb.AppendFormat("<td style=\"mso-number-format:'\\@';\">{0}</td>", System.Web.HttpUtility.HtmlEncode(cellValue));
|
|
}
|
|
sb.Append("</tr>");
|
|
rowIndex++;
|
|
}
|
|
sb.Append("</table>");
|
|
return sb.ToString();
|
|
}
|
|
#endregion
|
|
}
|
|
} |