2025-08-11 14:21:24 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.UI;
|
|
|
|
|
using System.Web.UI.WebControls;
|
|
|
|
|
using BLL;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
|
|
|
|
|
namespace FineUIPro.Web.JDGL.SGManPower
|
|
|
|
|
{
|
|
|
|
|
public partial class ManPowerWorkChart : PageBase
|
|
|
|
|
{
|
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!IsPostBack)
|
|
|
|
|
{
|
|
|
|
|
// 初始化图表数据
|
|
|
|
|
InitializeChartData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeChartData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 获取查询参数
|
|
|
|
|
string unitId = Request.Params["UnitId"];
|
|
|
|
|
string startTime = Request.Params["StartTime"];
|
|
|
|
|
string endTime = Request.Params["EndTime"];
|
|
|
|
|
string workPostId = Request.Params["WorkPostId"];
|
2025-08-21 11:37:06 +08:00
|
|
|
|
string unitWorkId = Request.Params["UnitWorkId"];
|
2025-08-11 14:21:24 +08:00
|
|
|
|
|
|
|
|
|
// 检查必要参数
|
|
|
|
|
if (string.IsNullOrEmpty(startTime) || string.IsNullOrEmpty(endTime))
|
|
|
|
|
{
|
|
|
|
|
ShowNotify("缺少必要的参数,无法生成图表", MessageBoxIcon.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DateTime startDate = Convert.ToDateTime(startTime);
|
|
|
|
|
DateTime endDate = Convert.ToDateTime(endTime);
|
|
|
|
|
|
|
|
|
|
// 使用原生SQL查询直接在数据库中进行聚合计算,提高性能
|
|
|
|
|
string strSql = @"
|
2025-08-21 11:37:06 +08:00
|
|
|
|
SELECT e.UnitId, e.PostId, e.RecordDate, p.WorkAreaId as UnitWorkId
|
|
|
|
|
FROM T_d_EmployInOutRecord e INNER JOIN SitePerson_Person p ON e.IDCardNo = p.IdentityCard AND e.ProjectId = p.ProjectId
|
|
|
|
|
WHERE e.PostId IS NOT NULL AND e.PostId != ''
|
|
|
|
|
AND e.ProjectId = @ProjectId
|
|
|
|
|
AND e.RecordDate >= @StartDate
|
|
|
|
|
AND e.RecordDate <= @EndDate";
|
2025-08-11 14:21:24 +08:00
|
|
|
|
|
|
|
|
|
var parameters = new List<SqlParameter>
|
|
|
|
|
{
|
|
|
|
|
new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId),
|
|
|
|
|
new SqlParameter("@StartDate", startDate),
|
|
|
|
|
new SqlParameter("@EndDate", endDate)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 添加单位筛选条件
|
|
|
|
|
if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null)
|
|
|
|
|
{
|
2025-08-21 11:37:06 +08:00
|
|
|
|
strSql += " AND e.UnitId = @UnitId";
|
2025-08-11 14:21:24 +08:00
|
|
|
|
parameters.Add(new SqlParameter("@UnitId", unitId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加岗位筛选条件
|
|
|
|
|
if (!string.IsNullOrEmpty(workPostId) && workPostId != Const._Null)
|
|
|
|
|
{
|
2025-08-21 11:37:06 +08:00
|
|
|
|
strSql += " AND e.PostId = @WorkPostId";
|
2025-08-11 14:21:24 +08:00
|
|
|
|
parameters.Add(new SqlParameter("@WorkPostId", workPostId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行查询
|
|
|
|
|
var dt = SQLHelper.GetDataTableRunText(strSql, parameters.ToArray());
|
2025-08-21 11:37:06 +08:00
|
|
|
|
|
|
|
|
|
// 创建一个新的DataTable来存储处理后的数据
|
|
|
|
|
DataTable processedDt = dt.Clone();
|
|
|
|
|
foreach (System.Data.DataRow row in dt.Rows)
|
|
|
|
|
{
|
|
|
|
|
string ids = row["UnitWorkId"] != DBNull.Value ? row["UnitWorkId"].ToString() : string.Empty;
|
|
|
|
|
if (!string.IsNullOrEmpty(ids))
|
|
|
|
|
{
|
|
|
|
|
string[] unitWorkIdArray = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
foreach (string id in unitWorkIdArray)
|
|
|
|
|
{
|
|
|
|
|
// 往processedDt里面添加数据,每个UnitWorkId一行
|
|
|
|
|
DataRow newRow = processedDt.NewRow();
|
|
|
|
|
newRow["UnitId"] = row["UnitId"];
|
|
|
|
|
newRow["PostId"] = row["PostId"];
|
|
|
|
|
newRow["RecordDate"] = row["RecordDate"];
|
|
|
|
|
newRow["UnitWorkId"] = id.Trim();
|
|
|
|
|
processedDt.Rows.Add(newRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DataRow newRow = processedDt.NewRow();
|
|
|
|
|
newRow["UnitId"] = row["UnitId"];
|
|
|
|
|
newRow["PostId"] = row["PostId"];
|
|
|
|
|
newRow["RecordDate"] = row["RecordDate"];
|
|
|
|
|
newRow["UnitWorkId"] = string.Empty;
|
|
|
|
|
processedDt.Rows.Add(newRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 确定要用于后续处理的数据源
|
|
|
|
|
IEnumerable<DataRow> dataSource = processedDt.AsEnumerable();
|
|
|
|
|
|
|
|
|
|
// 如果选择了特定的装置进行筛选
|
|
|
|
|
if (!string.IsNullOrEmpty(unitWorkId) && unitWorkId != Const._Null)
|
|
|
|
|
{
|
|
|
|
|
dataSource = dataSource.Where(x => x["UnitWorkId"] != DBNull.Value && x["UnitWorkId"].ToString() == unitWorkId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//针对dt中的数据进行分组
|
|
|
|
|
var data = dataSource
|
|
|
|
|
.GroupBy(row => new {
|
|
|
|
|
RecordDate = row["RecordDate"]
|
|
|
|
|
}).Select(group => new
|
|
|
|
|
{
|
|
|
|
|
RecordDate = group.Key.RecordDate,
|
|
|
|
|
RecordCount = group.Count()
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
2025-08-11 14:21:24 +08:00
|
|
|
|
|
|
|
|
|
// 如果没有数据,显示提示信息
|
2025-08-21 11:37:06 +08:00
|
|
|
|
if (data.Count == 0)
|
2025-08-11 14:21:24 +08:00
|
|
|
|
{
|
|
|
|
|
ShowNotify("在指定时间范围内没有找到人力统计数据", MessageBoxIcon.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据数据点数量动态调整图表宽度,确保每个数据点有足够的显示空间
|
2025-08-21 11:37:06 +08:00
|
|
|
|
int chartWidth = Math.Max(1000, data.Count * 50); // 每个数据点至少50像素宽,最小1000像素
|
2025-08-11 14:21:24 +08:00
|
|
|
|
|
|
|
|
|
// 创建图表数据对象
|
|
|
|
|
Model.DataSourceChart dataSourceChart = new Model.DataSourceChart
|
|
|
|
|
{
|
|
|
|
|
Title = "现场考勤人力统计图表",
|
|
|
|
|
ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Column,
|
|
|
|
|
Width = chartWidth,
|
|
|
|
|
Height = 500,
|
|
|
|
|
IsNotEnable3D = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 创建数据系列
|
|
|
|
|
Model.DataSourceTeam dataSourceTeam = new Model.DataSourceTeam
|
|
|
|
|
{
|
|
|
|
|
DataPointName = "人员数量",
|
|
|
|
|
DataSourcePoints = new List<Model.DataSourcePoint>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 添加数据点
|
2025-08-21 11:37:06 +08:00
|
|
|
|
foreach (var item in data)
|
2025-08-11 14:21:24 +08:00
|
|
|
|
{
|
2025-08-21 11:37:06 +08:00
|
|
|
|
if (item.RecordDate != null)
|
2025-08-11 14:21:24 +08:00
|
|
|
|
{
|
2025-08-21 11:37:06 +08:00
|
|
|
|
DateTime recordDate = Convert.ToDateTime(item.RecordDate);
|
2025-08-11 14:21:24 +08:00
|
|
|
|
|
|
|
|
|
Model.DataSourcePoint point = new Model.DataSourcePoint
|
|
|
|
|
{
|
|
|
|
|
PointText = recordDate.ToString("MM-dd"),
|
2025-08-21 11:37:06 +08:00
|
|
|
|
PointValue = item.RecordCount.ToString()
|
2025-08-11 14:21:24 +08:00
|
|
|
|
};
|
|
|
|
|
dataSourceTeam.DataSourcePoints.Add(point);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dataSourceChart.DataSourceTeams = new List<Model.DataSourceTeam> { dataSourceTeam };
|
|
|
|
|
|
|
|
|
|
// 生成图表
|
|
|
|
|
Chart1.CreateChart(dataSourceChart);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ShowNotify($"生成图表时发生错误: {ex.Message}", MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|