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

274 lines
13 KiB
C#

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 CompanyConstructionLogWorkEfficiencySum : PageBase
{
/// <summary>
/// 加载表头
/// </summary>
protected void Page_Init(object sender, EventArgs e)
{
InitGrid();
}
#region
/// <summary>
/// 表头
/// </summary>
private void InitGrid()
{
Model.SGGLDB db = Funs.DB;
var projects = (from x in db.Base_Project
where x.ProjectState == null || x.ProjectState == BLL.Const.ProjectState_1
select x).ToList();
GroupField gf = new GroupField();
gf.ColumnID = "GX";
gf.HeaderText = "工效统计";
gf.HeaderTextAlign = TextAlign.Center;
for (int i = 0; i < projects.Count; i++)
{
RenderField rd1 = new RenderField();
rd1.ColumnID = "Project" + i.ToString();
rd1.Width = Unit.Pixel(100);
rd1.DataField = "Project" + i.ToString();
rd1.FieldType = FieldType.Double;
rd1.HeaderText = projects[i].ShortName;
rd1.HeaderTextAlign = TextAlign.Center;
gf.Columns.Add(rd1);
}
Grid1.Columns.Add(gf);
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
#endregion
private void GetData()
{
Model.SGGLDB db = Funs.DB;
var constructionLogWorkEfficiencyProjects = from x in db.ZHGL_ConstructionLogWorkEfficiencyProject
select new { x.TypeId, x.UnitOfMeasurement, x.AvgWorkEfficiency, x.ProjectId };
var persons = (from x in db.ZHGL_ConstructionLogWorkEfficiencyProject
join y in db.Base_WorkPost on x.TypeId equals y.WorkPostId
where x.Type == "Person"
select new { y.WorkPostName, x.UnitOfMeasurement, x.TypeId }).Distinct().OrderBy(x => x.WorkPostName).ToList();
var machines = (from x in db.ZHGL_ConstructionLogWorkEfficiencyProject
join y in db.Base_SpecialEquipment on x.TypeId equals y.SpecialEquipmentId
where x.Type == "Machine"
select new { y.SpecialEquipmentName, x.UnitOfMeasurement, x.TypeId }).Distinct().OrderBy(x => x.SpecialEquipmentName).ToList();
var projects = (from x in db.Base_Project
where x.ProjectState == null || x.ProjectState == BLL.Const.ProjectState_1
select x).ToList();
var workEfficiencyCompanys = from x in db.ZHGL_ConstructionLogWorkEfficiencyCompany select x;
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Id", typeof(String)));
table.Columns.Add(new DataColumn("Code", typeof(String)));
table.Columns.Add(new DataColumn("Name", typeof(String)));
table.Columns.Add(new DataColumn("UnitOfMeasurement", typeof(String)));
table.Columns.Add(new DataColumn("BaseWorkEfficiency", typeof(String)));
table.Columns.Add(new DataColumn("AvgWorkEfficiency", typeof(String)));
table.Columns.Add(new DataColumn("Type", typeof(String)));
table.Columns.Add(new DataColumn("TypeId", typeof(String)));
table.Columns.Add(new DataColumn("Project0", typeof(String)));
table.Columns.Add(new DataColumn("Project1", typeof(String)));
table.Columns.Add(new DataColumn("Project2", typeof(String)));
table.Columns.Add(new DataColumn("Project3", typeof(String)));
table.Columns.Add(new DataColumn("Project4", typeof(String)));
table.Columns.Add(new DataColumn("Project5", typeof(String)));
table.Columns.Add(new DataColumn("Project6", typeof(String)));
table.Columns.Add(new DataColumn("Project7", typeof(String)));
table.Columns.Add(new DataColumn("Project8", typeof(String)));
table.Columns.Add(new DataColumn("Project9", typeof(String)));
table.Columns.Add(new DataColumn("Project10", typeof(String)));
table.Columns.Add(new DataColumn("Project11", typeof(String)));
table.Columns.Add(new DataColumn("Project12", typeof(String)));
table.Columns.Add(new DataColumn("Project13", typeof(String)));
table.Columns.Add(new DataColumn("Project14", typeof(String)));
table.Columns.Add(new DataColumn("Project15", typeof(String)));
table.Columns.Add(new DataColumn("Project16", typeof(String)));
table.Columns.Add(new DataColumn("Project17", typeof(String)));
table.Columns.Add(new DataColumn("Project18", typeof(String)));
table.Columns.Add(new DataColumn("Project19", typeof(String)));
table.Columns.Add(new DataColumn("Project20", typeof(String)));
table.Columns.Add(new DataColumn("Project21", typeof(String)));
table.Columns.Add(new DataColumn("Project22", typeof(String)));
table.Columns.Add(new DataColumn("Project23", typeof(String)));
table.Columns.Add(new DataColumn("Project24", typeof(String)));
table.Columns.Add(new DataColumn("Project25", typeof(String)));
table.Columns.Add(new DataColumn("Project26", typeof(String)));
table.Columns.Add(new DataColumn("Project27", typeof(String)));
table.Columns.Add(new DataColumn("Project28", typeof(String)));
table.Columns.Add(new DataColumn("Project29", typeof(String)));
table.Columns.Add(new DataColumn("Project30", typeof(String)));
table.Columns.Add(new DataColumn("Project31", typeof(String)));
table.Columns.Add(new DataColumn("Project32", typeof(String)));
table.Columns.Add(new DataColumn("Project33", typeof(String)));
table.Columns.Add(new DataColumn("Project34", typeof(String)));
table.Columns.Add(new DataColumn("Project35", typeof(String)));
table.Columns.Add(new DataColumn("Project36", typeof(String)));
table.Columns.Add(new DataColumn("Project37", typeof(String)));
table.Columns.Add(new DataColumn("Project38", typeof(String)));
table.Columns.Add(new DataColumn("Project39", typeof(String)));
table.Columns.Add(new DataColumn("Project40", typeof(String)));
DataRow row;
row = table.NewRow();
row[0] = SQLHelper.GetNewID();
row[1] = "一";
row[2] = "人工";
table.Rows.Add(row);
int a = 1;
foreach (var person in persons)
{
row = table.NewRow();
row[0] = SQLHelper.GetNewID();
row[1] = a;
row[2] = person.WorkPostName;
row[3] = person.UnitOfMeasurement;
var workEfficiencyCompany = workEfficiencyCompanys.FirstOrDefault(x => x.TypeId == person.TypeId && x.UnitOfMeasurement == person.UnitOfMeasurement);
if (workEfficiencyCompany != null)
{
row[4] = workEfficiencyCompany.BaseWorkEfficiency;
}
int b = 0;
List<decimal> list = new List<decimal>();
foreach (var project in projects)
{
var workEfficiency = (from x in constructionLogWorkEfficiencyProjects
where x.TypeId == person.TypeId && x.UnitOfMeasurement == person.UnitOfMeasurement && x.ProjectId == project.ProjectId && x.AvgWorkEfficiency != null
select x).FirstOrDefault();
if (workEfficiency != null)
{
decimal d = decimal.Round(workEfficiency.AvgWorkEfficiency.Value, 2);
row[8 + b] = d;
list.Add(d);
}
b++;
}
if (list.Count > 0)
{
row[5] = decimal.Round(Convert.ToDecimal(list.Sum() / Convert.ToDecimal(list.Count)), 2);
}
row[6] = "Person";
row[7] = person.TypeId;
table.Rows.Add(row);
a++;
}
row = table.NewRow();
row[0] = SQLHelper.GetNewID();
row[1] = "二";
row[2] = "机械";
table.Rows.Add(row);
a = 1;
foreach (var machine in machines)
{
row = table.NewRow();
row[0] = SQLHelper.GetNewID();
row[1] = a;
row[2] = machine.SpecialEquipmentName;
row[3] = machine.UnitOfMeasurement;
var workEfficiencyCompany = workEfficiencyCompanys.FirstOrDefault(x => x.TypeId == machine.TypeId && x.UnitOfMeasurement == machine.UnitOfMeasurement);
if (workEfficiencyCompany != null)
{
row[4] = workEfficiencyCompany.BaseWorkEfficiency;
}
int b = 0;
List<decimal> list = new List<decimal>();
foreach (var project in projects)
{
var workEfficiency = (from x in constructionLogWorkEfficiencyProjects
where x.TypeId == machine.TypeId && x.UnitOfMeasurement == machine.UnitOfMeasurement && x.ProjectId == project.ProjectId && x.AvgWorkEfficiency != null
select x).FirstOrDefault();
if (workEfficiency != null)
{
decimal d = decimal.Round(workEfficiency.AvgWorkEfficiency.Value, 2);
row[8 + b] = d;
list.Add(d);
}
b++;
}
if (list.Count > 0)
{
row[5] = decimal.Round(Convert.ToDecimal(list.Sum() / Convert.ToDecimal(list.Count)), 2);
}
row[6] = "Machine";
row[7] = machine.TypeId;
table.Rows.Add(row);
a++;
}
Grid1.DataSource = table;
Grid1.DataBind();
}
#region
/// <summary>
/// 统计
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnAnalyse_Click(object sender, EventArgs e)
{
GetData();
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (this.Grid1.Rows.Count > 0)
{
BLL.ConstructionLogWorkEfficiencyCompanyService.DeleteConstructionLogWorkEfficiencyCompanys();
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int a = mergedRow.Value<int>("index");
string type = values.Value<string>("Type");
if (!string.IsNullOrEmpty(type))
{
string unitOfMeasurement = values.Value<string>("UnitOfMeasurement");
string baseWorkEfficiency = values.Value<string>("BaseWorkEfficiency");
string avgWorkEfficiency = values.Value<string>("AvgWorkEfficiency");
string typeId = values.Value<string>("TypeId");
Model.ZHGL_ConstructionLogWorkEfficiencyCompany workEfficiency = new Model.ZHGL_ConstructionLogWorkEfficiencyCompany();
workEfficiency.ConstructionLogWorkEfficiencyCompanyId = SQLHelper.GetNewID();
workEfficiency.Type = type;
workEfficiency.TypeId = typeId;
workEfficiency.UnitOfMeasurement = unitOfMeasurement;
workEfficiency.BaseWorkEfficiency = Funs.GetNewDecimal(baseWorkEfficiency);
workEfficiency.AvgWorkEfficiency = Funs.GetNewDecimal(avgWorkEfficiency);
BLL.ConstructionLogWorkEfficiencyCompanyService.AddConstructionLogWorkEfficiencyCompany(workEfficiency);
}
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop("请先统计后再保存!", MessageBoxIcon.Warning);
}
}
#endregion
}
}