2023-03-29 14:32:57 +08:00
|
|
|
|
using BLL;
|
2023-11-11 16:02:42 +08:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2023-03-29 14:32:57 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace FineUIPro.Web.DataShow
|
|
|
|
|
{
|
|
|
|
|
public partial class WorkingHours : PageBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region 加载页面
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载页面
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!IsPostBack)
|
|
|
|
|
{
|
|
|
|
|
Funs.DropDownPageSize(this.ddlPageSize);
|
|
|
|
|
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|
|
|
|
BLL.ProjectService.InitProjectDropDownList(this.drpProject, true);
|
|
|
|
|
// 绑定表格t
|
|
|
|
|
BindGrid();
|
2023-11-11 16:02:42 +08:00
|
|
|
|
// 合计
|
|
|
|
|
OutputSummaryData();
|
2023-06-10 10:55:18 +08:00
|
|
|
|
this.Panel1.Title = "工时数据(" + BLL.UnitService.GetUnitNameByUnitId(BLL.CommonService.GetThisUnitId()) + ")";
|
2023-03-29 14:32:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 绑定数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void BindGrid()
|
|
|
|
|
{
|
2023-11-02 15:40:43 +08:00
|
|
|
|
string strSql = @"select ProjectId,ProjectCode, ProjectName from Base_Project where (ProjectState2 is null or ProjectState2 !=9) and ProjectState =1 ";
|
2023-03-29 14:32:57 +08:00
|
|
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
|
|
|
string cpara = string.Empty;
|
|
|
|
|
if (this.drpProject.SelectedValue != Const._Null)
|
|
|
|
|
{
|
|
|
|
|
strSql += " AND projectId = @projectId"; ///状态为已完成
|
|
|
|
|
listStr.Add(new SqlParameter("@projectId", this.drpProject.SelectedValue));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(this.txtStartTime.Text))
|
|
|
|
|
//{
|
|
|
|
|
// strSql += " AND h.RegisterDate >=@StartTime";
|
|
|
|
|
// listStr.Add(new SqlParameter("@StartTime", this.txtStartTime.Text));
|
|
|
|
|
|
|
|
|
|
// cpara += " AND c.RegisterDate >=" + this.txtStartTime.Text;
|
|
|
|
|
//}
|
|
|
|
|
//if (!string.IsNullOrEmpty(this.txtEndTime.Text))
|
|
|
|
|
//{
|
|
|
|
|
// strSql += " AND h.RegisterDate <=@EndTime";
|
|
|
|
|
// listStr.Add(new SqlParameter("@EndTime", this.txtEndTime.Text));
|
|
|
|
|
|
|
|
|
|
// cpara += " AND c.RegisterDate <=" + this.txtEndTime.Text;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
|
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, 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 TextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.BindGrid();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 表排序、分页、关闭窗口
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
EditData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void EditData()
|
|
|
|
|
{
|
|
|
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WorkingHoursItem.aspx?projectId={0}", Grid1.SelectedRowID, "查看 - ")));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void btnView_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EditData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 总工时数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected decimal Count1(object projectId)
|
|
|
|
|
{
|
|
|
|
|
decimal cout1 = 0;
|
|
|
|
|
if (projectId != null)
|
|
|
|
|
{
|
|
|
|
|
var datetime1 = Funs.GetNewDateTime(this.txtStartTime.Text);
|
|
|
|
|
var datetime2 = Funs.GetNewDateTime(this.txtStartTime.Text);
|
|
|
|
|
var getD1 = from x in Funs.DB.SitePerson_DayReport
|
|
|
|
|
join y in Funs.DB.Base_Project on x.ProjectId equals y.ProjectId
|
2023-11-11 16:02:42 +08:00
|
|
|
|
where y.ProjectState == Const.ProjectState_1 && x.ProjectId == projectId.ToString() && x.CompileDate > Funs.minSysDate
|
2023-03-29 14:32:57 +08:00
|
|
|
|
select x;
|
|
|
|
|
if (datetime1.HasValue)
|
|
|
|
|
{
|
|
|
|
|
getD1 = getD1.Where(x => x.CompileDate >= datetime1);
|
|
|
|
|
}
|
|
|
|
|
if (datetime2.HasValue)
|
|
|
|
|
{
|
|
|
|
|
getD1 = getD1.Where(x => x.CompileDate <= datetime2);
|
|
|
|
|
}
|
|
|
|
|
var getC = from x in Funs.DB.SitePerson_DayReportDetail
|
|
|
|
|
join y in getD1 on x.DayReportId equals y.DayReportId
|
|
|
|
|
where y.ProjectId == projectId.ToString()
|
|
|
|
|
select x;
|
|
|
|
|
if (getC.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
cout1 = getC.Sum(x => x.PersonWorkTime ?? 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cout1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 损失工时数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected decimal Count2(object projectId)
|
|
|
|
|
{
|
|
|
|
|
decimal cout1 = 0;
|
|
|
|
|
if (projectId != null)
|
|
|
|
|
{
|
|
|
|
|
var datetime1 = Funs.GetNewDateTime(this.txtStartTime.Text);
|
|
|
|
|
var datetime2 = Funs.GetNewDateTime(this.txtStartTime.Text);
|
|
|
|
|
var getD1 = from x in Funs.DB.Accident_AccidentHandle
|
|
|
|
|
join y in Funs.DB.Base_Project on x.ProjectId equals y.ProjectId
|
2023-11-11 16:02:42 +08:00
|
|
|
|
where y.ProjectState == Const.ProjectState_1 && x.ProjectId == projectId.ToString() && x.CompileDate > Funs.minSysDate
|
2023-03-29 14:32:57 +08:00
|
|
|
|
select x;
|
|
|
|
|
var getD2 = from x in Funs.DB.Accident_AccidentReport
|
|
|
|
|
join y in Funs.DB.Base_Project on x.ProjectId equals y.ProjectId
|
2023-11-11 16:02:42 +08:00
|
|
|
|
where y.ProjectState == Const.ProjectState_1 && x.ProjectId == projectId.ToString() && x.CompileDate > Funs.minSysDate
|
2023-03-29 14:32:57 +08:00
|
|
|
|
select x;
|
|
|
|
|
if (datetime1.HasValue)
|
|
|
|
|
{
|
|
|
|
|
getD1 = getD1.Where(x => x.AccidentDate >= datetime1);
|
|
|
|
|
getD2 = getD2.Where(x => x.CompileDate >= datetime1);
|
|
|
|
|
}
|
|
|
|
|
if (datetime2.HasValue)
|
|
|
|
|
{
|
|
|
|
|
getD1 = getD1.Where(x => x.AccidentDate <= datetime2);
|
|
|
|
|
getD2 = getD2.Where(x => x.CompileDate <= datetime2);
|
|
|
|
|
}
|
|
|
|
|
if (getD1.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
cout1 += getD1.Sum(x => x.WorkHoursLoss ?? 0);
|
|
|
|
|
}
|
|
|
|
|
if (getD2.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
cout1 += getD2.Sum(x => x.WorkingHoursLoss ?? 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cout1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 安全工时数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected decimal Count3(object projectId)
|
|
|
|
|
{
|
|
|
|
|
decimal cout1 = 0;
|
|
|
|
|
if (projectId != null)
|
|
|
|
|
{
|
|
|
|
|
var datetime1 = Funs.GetNewDateTime(this.txtStartTime.Text);
|
|
|
|
|
var datetime2 = Funs.GetNewDateTime(this.txtStartTime.Text);
|
|
|
|
|
var getC1 = from x in Funs.DB.SitePerson_DayReport
|
|
|
|
|
join y in Funs.DB.Base_Project on x.ProjectId equals y.ProjectId
|
2023-11-11 16:02:42 +08:00
|
|
|
|
where y.ProjectState == Const.ProjectState_1 && x.ProjectId == projectId.ToString() && x.CompileDate > Funs.minSysDate
|
2023-03-29 14:32:57 +08:00
|
|
|
|
select x;
|
|
|
|
|
|
|
|
|
|
var getD1 = from x in Funs.DB.Accident_AccidentHandle
|
|
|
|
|
join y in Funs.DB.Base_Project on x.ProjectId equals y.ProjectId
|
2023-11-11 16:02:42 +08:00
|
|
|
|
where y.ProjectState == Const.ProjectState_1 && x.ProjectId == projectId.ToString() && x.CompileDate > Funs.minSysDate
|
2023-03-29 14:32:57 +08:00
|
|
|
|
select x;
|
|
|
|
|
var getD2 = from x in Funs.DB.Accident_AccidentReport
|
|
|
|
|
join y in Funs.DB.Base_Project on x.ProjectId equals y.ProjectId
|
2023-11-11 16:02:42 +08:00
|
|
|
|
where y.ProjectState == Const.ProjectState_1 && x.ProjectId == projectId.ToString() && x.CompileDate > Funs.minSysDate
|
2023-03-29 14:32:57 +08:00
|
|
|
|
select x;
|
|
|
|
|
|
|
|
|
|
if (datetime1.HasValue)
|
|
|
|
|
{
|
|
|
|
|
getC1 = getC1.Where(x => x.CompileDate >= datetime1);
|
|
|
|
|
getD1 = getD1.Where(x => x.AccidentDate >= datetime1);
|
|
|
|
|
getD2 = getD2.Where(x => x.CompileDate >= datetime1);
|
|
|
|
|
}
|
|
|
|
|
if (datetime2.HasValue)
|
|
|
|
|
{
|
|
|
|
|
getC1 = getC1.Where(x => x.CompileDate <= datetime2);
|
|
|
|
|
getD1 = getD1.Where(x => x.AccidentDate <= datetime2);
|
|
|
|
|
getD2 = getD2.Where(x => x.CompileDate <= datetime2);
|
|
|
|
|
}
|
|
|
|
|
var getC = from x in Funs.DB.SitePerson_DayReportDetail
|
|
|
|
|
join y in getC1 on x.DayReportId equals y.DayReportId
|
|
|
|
|
where y.ProjectId == projectId.ToString()
|
|
|
|
|
select x;
|
|
|
|
|
if (getC.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
cout1 = getC.Sum(x => x.PersonWorkTime ?? 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (getD1.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
cout1 = cout1 -getD1.Sum(x => x.WorkHoursLoss ?? 0);
|
|
|
|
|
}
|
|
|
|
|
if (getD2.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
cout1 = cout1- getD2.Sum(x => x.WorkingHoursLoss ?? 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cout1;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-11 16:02:42 +08:00
|
|
|
|
#region 合计
|
|
|
|
|
private void OutputSummaryData()
|
|
|
|
|
{
|
|
|
|
|
string strSql = @" select ProjectId,ProjectCode, ProjectName,
|
|
|
|
|
isnull((select sum(PersonWorkTime)
|
|
|
|
|
from SitePerson_DayReport x
|
|
|
|
|
left join(select PersonWorkTime,DayReportId from SitePerson_DayReportDetail) y on x.DayReportId=y.DayReportId
|
|
|
|
|
where x.ProjectId=p.ProjectId and x.CompileDate >'2023-01-01'),0) as count1,
|
|
|
|
|
isnull((select sum(WorkHoursLoss) from Accident_AccidentHandle a where a.ProjectId=p.ProjectId and a.AccidentDate >'2023-01-01'),0) as count2,
|
|
|
|
|
isnull((select sum(WorkingHoursLoss) from Accident_AccidentReport a where a.ProjectId=p.ProjectId and a.AccidentDate >'2023-01-01'),0) as count3
|
|
|
|
|
from Base_Project as P
|
|
|
|
|
where ProjectState =1 and (ProjectState2 is null or ProjectState2 !=9)";
|
|
|
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
|
|
|
|
|
|
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
|
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
|
|
|
|
|
|
|
|
double Count1 = 0.0f, Count2 = 0.0f, Count3 = 0.0f;
|
|
|
|
|
foreach (DataRow row in tb.Rows)
|
|
|
|
|
{
|
|
|
|
|
Count1 += Convert.ToDouble(row["Count1"]);
|
|
|
|
|
Count2 += Convert.ToDouble(row["Count2"]);
|
|
|
|
|
Count3 += Convert.ToDouble(row["Count3"]);
|
|
|
|
|
}
|
|
|
|
|
JObject summary = new JObject();
|
|
|
|
|
summary.Add("ProjectName", "合计:");
|
|
|
|
|
summary.Add("Count1", Count1.ToString("f2"));
|
|
|
|
|
summary.Add("Count2", (Count2+Count3).ToString("f2"));
|
|
|
|
|
summary.Add("Count3", (Count1- Count2- Count3).ToString("f2"));
|
|
|
|
|
Grid1.SummaryData = summary;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2023-03-29 14:32:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|