SGGL_SHJ/SGGL/FineUIPro.Web/PZHGL/InformationProject/MonthConstructionLogWorkEff...

257 lines
13 KiB
C#
Raw Normal View History

2023-10-18 09:40:57 +08:00
using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.PZHGL.InformationProject
{
public partial class MonthConstructionLogWorkEfficiencySum : PageBase
{
/// <summary>
/// 加载表头
/// </summary>
protected void Page_Init(object sender, EventArgs e)
{
InitGrid();
}
#region
/// <summary>
/// 表头
/// </summary>
private void InitGrid()
{
Model.SGGLDB db = Funs.DB;
var workEfficiencys = from x in db.ZHGL_ConstructionLogWorkEfficiency
join y in db.ZHGL_ConstructionLog on x.ConstructionLogId equals y.ConstructionLogId
where y.ProjectId == this.CurrUser.LoginProjectId
select x;
List<string> workPostIds = (from x in workEfficiencys
where x.Type == "Person"
select x.TypeId).Distinct().ToList();
List<string> machineIds = (from x in workEfficiencys
where x.Type == "Machine"
select x.TypeId).Distinct().ToList();
GroupField gf1 = new GroupField();
gf1.ColumnID = "Person";
gf1.HeaderText = "人工消耗工·h";
gf1.HeaderTextAlign = TextAlign.Center;
for (int i = 0; i < workPostIds.Count; i++)
{
GroupField gf = new GroupField();
gf.ColumnID = "Person" + i.ToString();
gf.HeaderText = BLL.WorkPostService.getWorkPostNameById(workPostIds[i]);
gf.HeaderTextAlign = TextAlign.Center;
RenderField rd1 = new RenderField();
rd1.ColumnID = "PersonConsumeHours" + i.ToString();
rd1.Width = Unit.Pixel(100);
rd1.DataField = "PersonConsumeHours" + i.ToString();
rd1.FieldType = FieldType.Double;
rd1.HeaderText = "消耗工时";
rd1.HeaderTextAlign = TextAlign.Center;
gf.Columns.Add(rd1);
RenderField rd2 = new RenderField();
rd2.ColumnID = "PersonWorkEfficiency" + i.ToString();
rd2.Width = Unit.Pixel(100);
rd2.DataField = "PersonWorkEfficiency" + i.ToString();
rd2.FieldType = FieldType.Double;
rd2.HeaderText = "工效";
rd2.HeaderTextAlign = TextAlign.Center;
gf.Columns.Add(rd2);
gf1.Columns.Add(gf);
}
Grid1.Columns.Add(gf1);
GroupField gf2 = new GroupField();
gf2.ColumnID = "Machine";
gf2.HeaderText = "机械消耗台·h";
gf2.HeaderTextAlign = TextAlign.Center;
for (int i = 0; i < machineIds.Count; i++)
{
GroupField gf = new GroupField();
gf.ColumnID = "Machine" + i.ToString();
gf.HeaderText = BLL.SpecialEquipmentService.GetSpecialEquipmentNameById(machineIds[i]);
gf.HeaderTextAlign = TextAlign.Center;
RenderField rd1 = new RenderField();
rd1.ColumnID = "MachineConsumeHours" + i.ToString();
rd1.Width = Unit.Pixel(100);
rd1.DataField = "MachineConsumeHours" + i.ToString();
rd1.FieldType = FieldType.Double;
rd1.HeaderText = "消耗台时";
rd1.HeaderTextAlign = TextAlign.Center;
gf.Columns.Add(rd1);
RenderField rd2 = new RenderField();
rd2.ColumnID = "MachineWorkEfficiency" + i.ToString();
rd2.Width = Unit.Pixel(100);
rd2.DataField = "MachineWorkEfficiency" + i.ToString();
rd2.FieldType = FieldType.Double;
rd2.HeaderText = "工效";
rd2.HeaderTextAlign = TextAlign.Center;
gf.Columns.Add(rd2);
gf2.Columns.Add(gf);
}
Grid1.Columns.Add(gf2);
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtMonth.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
}
}
#endregion
private void GetData()
{
Model.SGGLDB db = Funs.DB;
DateTime startDate = Funs.GetNewDateTimeOrNow(this.txtMonth.Text.Trim() + "-01");
DateTime endDate = startDate.AddMonths(1);
string contractNo = string.Empty, professional = string.Empty;
var personLogs = from x in db.ZHGL_ConstructionLog
where x.ProjectId == this.CurrUser.LoginProjectId && x.CompileDate >= startDate && x.CompileDate < endDate
orderby x.CompileDate descending
select x;
if (personLogs.Count() > 0)
{
foreach (var personLog in personLogs)
{
if (!string.IsNullOrEmpty(personLog.ContractNo))
{
contractNo += "," + personLog.ContractNo;
}
if (!string.IsNullOrEmpty(personLog.Professional))
{
professional += "," + personLog.Professional;
}
}
}
List<string> contractNoList = Funs.GetStrListByStr(contractNo, ',');
List<string> professionalList = Funs.GetStrListByStr(professional, ',');
var workEfficiencys = from x in db.ZHGL_ConstructionLogWorkEfficiency
join y in db.ZHGL_ConstructionLog on x.ConstructionLogId equals y.ConstructionLogId
where y.ProjectId == this.CurrUser.LoginProjectId
select x;
List<string> workPostIds = (from x in workEfficiencys
where x.Type == "Person"
select x.TypeId).Distinct().ToList();
List<string> machineIds = (from x in workEfficiencys
where x.Type == "Machine"
select x.TypeId).Distinct().ToList();
DataTable table = BLL.PhtglContractTrackService.GetMonthProjectAllTreeDataTable(this.CurrUser.LoginProjectId, string.Empty, contractNoList, professionalList, workPostIds, machineIds, startDate, endDate);
Grid1.DataSource = table;
Grid1.DataBind();
}
2023-10-20 14:34:35 +08:00
#region
/// <summary>
/// 统计
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnAnalyse_Click(object sender, EventArgs e)
2023-10-18 09:40:57 +08:00
{
if (!string.IsNullOrEmpty(this.txtMonth.Text.Trim()))
{
GetData();
}
else
{
Grid1.DataSource = null;
Grid1.DataBind();
Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning);
}
}
2023-10-20 14:34:35 +08:00
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.txtMonth.Text.Trim()))
{
Model.SGGLDB db = Funs.DB;
DateTime month = Funs.GetNewDateTimeOrNow(this.txtMonth.Text.Trim() + "-01");
BLL.ConstructionLogWorkEfficiencyMonthService.DeleteConstructionLogWorkEfficiencyMonthsByConstructionLogId(this.CurrUser.LoginProjectId, month);
var workEfficiencys = from x in db.ZHGL_ConstructionLogWorkEfficiency
join y in db.ZHGL_ConstructionLog on x.ConstructionLogId equals y.ConstructionLogId
where y.ProjectId == this.CurrUser.LoginProjectId
select x;
List<string> workPostIds = (from x in workEfficiencys
where x.Type == "Person"
select x.TypeId).Distinct().ToList();
List<string> machineIds = (from x in workEfficiencys
where x.Type == "Machine"
select x.TypeId).Distinct().ToList();
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int a = mergedRow.Value<int>("index");
if (this.Grid1.Rows[a].DataKeys[2] != null)
{
string physicalCompletionQuantity = values.Value<string>("PhysicalCompletionQuantity");
string materialConsumption = values.Value<string>("MaterialConsumption");
string unitOfMeasurement = values.Value<string>("UnitOfMeasurement");
for (int i = 0; i < workPostIds.Count; i++)
{
Model.ZHGL_ConstructionLogWorkEfficiencyMonth workEfficiency = new Model.ZHGL_ConstructionLogWorkEfficiencyMonth();
workEfficiency.ConstructionLogWorkEfficiencyMonthId = SQLHelper.GetNewID();
workEfficiency.ProjectId = this.CurrUser.LoginProjectId;
workEfficiency.Month = month;
workEfficiency.ContractTrackId = this.Grid1.Rows[a].DataKeys[2].ToString();
workEfficiency.PhysicalCompletionQuantity = Funs.GetNewDecimal(physicalCompletionQuantity);
workEfficiency.MaterialConsumption = Funs.GetNewDecimal(materialConsumption);
workEfficiency.UnitOfMeasurement = unitOfMeasurement;
workEfficiency.Type = "Person";
workEfficiency.TypeId = workPostIds[i];
workEfficiency.ConsumeHours = Funs.GetNewDecimal(values.Value<string>("PersonConsumeHours" + i.ToString()));
workEfficiency.WorkEfficiency = Funs.GetNewDecimal(values.Value<string>("PersonWorkEfficiency" + i.ToString()));
BLL.ConstructionLogWorkEfficiencyMonthService.AddConstructionLogWorkEfficiencyMonth(workEfficiency);
}
for (int i = 0; i < machineIds.Count; i++)
{
Model.ZHGL_ConstructionLogWorkEfficiencyMonth workEfficiency = new Model.ZHGL_ConstructionLogWorkEfficiencyMonth();
workEfficiency.ConstructionLogWorkEfficiencyMonthId = SQLHelper.GetNewID();
workEfficiency.ProjectId = this.CurrUser.LoginProjectId;
workEfficiency.Month = month;
workEfficiency.ContractTrackId = this.Grid1.Rows[a].DataKeys[2].ToString();
workEfficiency.PhysicalCompletionQuantity = Funs.GetNewDecimal(physicalCompletionQuantity);
workEfficiency.MaterialConsumption = Funs.GetNewDecimal(materialConsumption);
workEfficiency.UnitOfMeasurement = unitOfMeasurement;
workEfficiency.Type = "Machine";
workEfficiency.TypeId = machineIds[i];
workEfficiency.ConsumeHours = Funs.GetNewDecimal(values.Value<string>("MachineConsumeHours" + i.ToString()));
workEfficiency.WorkEfficiency = Funs.GetNewDecimal(values.Value<string>("MachineWorkEfficiency" + i.ToString()));
BLL.ConstructionLogWorkEfficiencyMonthService.AddConstructionLogWorkEfficiencyMonth(workEfficiency);
}
}
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning);
}
}
#endregion
2023-10-20 15:42:49 +08:00
protected void txtMonth_TextChanged(object sender, EventArgs e)
{
Grid1.DataSource = null;
Grid1.DataBind();
}
2023-10-18 09:40:57 +08:00
}
}