380 lines
19 KiB
C#
380 lines
19 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.JDGL.Check
|
|
{
|
|
public partial class CompleteInput : PageBase
|
|
{
|
|
#region 定义变量
|
|
/// <summary>
|
|
/// 列数量
|
|
/// </summary>
|
|
public int ColumnNum
|
|
{
|
|
get
|
|
{
|
|
return (int)ViewState["ColumnNum"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["ColumnNum"] = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上传预设的虚拟路径
|
|
/// </summary>
|
|
private string initPath = Const.ExcelUrl;
|
|
|
|
/// <summary>
|
|
/// 错误集合
|
|
/// </summary>
|
|
public static string errorInfos = string.Empty;
|
|
|
|
/// <summary>
|
|
/// 月份集合
|
|
/// </summary>
|
|
public static List<DateTime> months = new List<DateTime>();
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 加载表头
|
|
/// </summary>
|
|
protected void Page_Init(object sender, EventArgs e)
|
|
{
|
|
InitGrid();
|
|
}
|
|
|
|
#region 表头
|
|
/// <summary>
|
|
/// 表头
|
|
/// </summary>
|
|
private void InitGrid()
|
|
{
|
|
ColumnNum = 0;
|
|
months.Clear();
|
|
var project = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId);
|
|
if (project != null)
|
|
{
|
|
DateTime startDate, endDate, startMonth, endMonth;
|
|
if (project.StartDate != null)
|
|
{
|
|
startDate = Convert.ToDateTime(project.StartDate);
|
|
endDate = DateTime.Now;
|
|
if (project.EndDate != null)
|
|
{
|
|
endDate = Convert.ToDateTime(project.EndDate);
|
|
}
|
|
startMonth = Convert.ToDateTime(startDate.Year + "-" + startDate.Month + "-01");
|
|
endMonth = Convert.ToDateTime(endDate.Year + "-" + endDate.Month + "-01");
|
|
do
|
|
{
|
|
months.Add(startMonth);
|
|
startMonth = startMonth.AddMonths(1);
|
|
} while (startMonth <= endMonth);
|
|
}
|
|
for (int i = 0; i < months.Count; i++)
|
|
{
|
|
RenderField rdPlan = new RenderField();
|
|
rdPlan.ColumnID = string.Format("{0:yyyy-MM}", months[i]) + "Plan";
|
|
rdPlan.Width = Unit.Pixel(100);
|
|
rdPlan.DataField = "PlanNum" + (i + 1).ToString();
|
|
rdPlan.FieldType = FieldType.Double;
|
|
rdPlan.HeaderText = string.Format("{0:yyyy年MM月}", months[i]) + "<br/>概算工程量";
|
|
rdPlan.HeaderTextAlign = TextAlign.Center;
|
|
NumberBox numPlan = new NumberBox();
|
|
numPlan.NoNegative = true;
|
|
numPlan.NoDecimal = false;
|
|
rdPlan.Editor.Add(numPlan);
|
|
Grid1.Columns.Add(rdPlan);
|
|
|
|
RenderField rdThis = new RenderField();
|
|
rdThis.ColumnID = string.Format("{0:yyyy-MM}", months[i]) + "This";
|
|
rdThis.Width = Unit.Pixel(100);
|
|
rdThis.DataField = "ThisNum" + (i + 1).ToString();
|
|
rdThis.FieldType = FieldType.Double;
|
|
rdThis.HeaderText = string.Format("{0:yyyy年MM月}", months[i]) + "<br/>实际工程量";
|
|
rdThis.HeaderTextAlign = TextAlign.Center;
|
|
NumberBox numReal = new NumberBox();
|
|
numReal.NoNegative = true;
|
|
numReal.NoDecimal = false;
|
|
rdThis.Editor.Add(numReal);
|
|
Grid1.Columns.Add(rdThis);
|
|
}
|
|
RenderField rdId = new RenderField();
|
|
rdId.ColumnID = "ShowId";
|
|
rdId.Width = Unit.Pixel(350);
|
|
rdId.DataField = "ShowId";
|
|
rdId.FieldType = FieldType.String;
|
|
rdId.HeaderText = "ShowId";
|
|
rdId.HeaderTextAlign = TextAlign.Center;
|
|
Grid1.Columns.Add(rdId);
|
|
rdId.Hidden = true;
|
|
ColumnNum = 9 + months.Count * 2 + 1;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 加载
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
errorInfos = string.Empty;
|
|
string Id = Request.Params["Id"];
|
|
UnitWorkService.InitUnitWorkDownList(drpUnitWork, this.CurrUser.LoginProjectId, true);
|
|
BindGrid();
|
|
}
|
|
}
|
|
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
|
|
private void BindGrid()
|
|
{
|
|
DataTable table = BLL.WorkPackageService.GetAllTreeDataTable(this.CurrUser.LoginProjectId, string.Empty, null, null, "0", this.drpUnitWork.SelectedValue);
|
|
Grid1.RecordCount = table.Rows.Count;
|
|
var table2 = this.GetPagedDataTable(Grid1, table);
|
|
Grid1.DataSource = table2;
|
|
Grid1.DataBind();
|
|
for (int i = 0; i < this.Grid1.Rows.Count; i++)
|
|
{
|
|
if (string.IsNullOrEmpty(this.Grid1.Rows[i].DataKeys[2].ToString()))
|
|
{
|
|
System.Web.UI.WebControls.CheckBox cbIsMileStone = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[i].FindControl("cbIsMileStone"));
|
|
cbIsMileStone.Visible = false;
|
|
foreach (GridColumn column in Grid1.Columns)
|
|
{
|
|
if (column.ColumnIndex != 0 && column.ColumnIndex != 1)
|
|
{
|
|
this.Grid1.Rows[i].CellCssClasses[column.ColumnIndex] = "f-grid-cell-uneditable";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
System.Web.UI.WebControls.CheckBox cbIsMileStone = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[i].FindControl("cbIsMileStone"));
|
|
Model.WBS_WorkPackage workPackage = BLL.WorkPackageService.GetWorkPackageByWorkPackageId(this.Grid1.Rows[i].DataKeys[2].ToString());
|
|
if (workPackage != null && workPackage.IsMileStone == true)
|
|
{
|
|
cbIsMileStone.Checked = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 保存
|
|
/// <summary>
|
|
/// 保存按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
Save();
|
|
ShowNotify("保存成功!", MessageBoxIcon.Success);
|
|
//PageContext.RegisterStartupScript(ActiveWindow.GetHideReference());
|
|
}
|
|
|
|
private void Save()
|
|
{
|
|
decimal changePlanNum = 0, changePlanValue = 0, changeThisNum = 0, //当月总变化完成成本、完成预算
|
|
oldPlanNum = 0, oldThisNum = 0, oldPlanValue = 0,
|
|
PlanNum = 0, ThisNum = 0, PlanValue = 0, PlanCost = 0, PlanProjectQuantity = 0;
|
|
Model.SGGLDB db = Funs.DB;
|
|
var oldViewInfos = from x in db.WBS_WorkPackage
|
|
where x.ProjectId == this.CurrUser.LoginProjectId
|
|
select x;
|
|
var unitWorks = from x in db.WBS_UnitWork
|
|
where x.ProjectId == this.CurrUser.LoginProjectId
|
|
select x;
|
|
string[] ids = this.hdId.Text.Split(',');
|
|
if (ids.Length > 0)
|
|
{
|
|
foreach (JObject mergedRow in Grid1.GetMergedData())
|
|
{
|
|
JObject values = mergedRow.Value<JObject>("values");
|
|
int i = mergedRow.Value<int>("index");
|
|
if (this.Grid1.Rows[i].DataKeys[2] != null && ids.Contains(this.Grid1.Rows[i].DataKeys[2].ToString()))
|
|
{
|
|
Model.WBS_WorkPackage WorkPackage = oldViewInfos.FirstOrDefault(x => x.WorkPackageId == this.Grid1.Rows[i].DataKeys[2].ToString());
|
|
if (WorkPackage != null)
|
|
{
|
|
string WorkPackageId = WorkPackage.WorkPackageId;
|
|
PlanCost = WorkPackage.PlanCost ?? 0;
|
|
PlanProjectQuantity = WorkPackage.PlanProjectQuantity ?? 0;
|
|
BLL.WorkPackageService.UpdateWorkPackage(WorkPackage);
|
|
for (int j = 0; j < months.Count; j++)
|
|
{
|
|
oldPlanNum = 0;
|
|
oldThisNum = 0;
|
|
oldPlanValue = 0;
|
|
changePlanNum = 0;
|
|
changeThisNum = 0;
|
|
changePlanValue = 0;
|
|
string planNum = values.Value<string>(string.Format("{0:yyyy-MM}", months[j]) + "Plan");
|
|
string thisNum = values.Value<string>(string.Format("{0:yyyy-MM}", months[j]) + "This");
|
|
Model.WBS_WorkPackageDetail WorkPackageDetail = BLL.WorkPackageDetailService.GetWorkPackageDetailByWorkPackageIdAndMonths(WorkPackageId, months[j]);
|
|
if (WorkPackageDetail != null)
|
|
{
|
|
oldPlanNum = WorkPackageDetail.PlanNum ?? 0;
|
|
oldThisNum = WorkPackageDetail.ThisNum ?? 0;
|
|
oldPlanValue = WorkPackageDetail.PlanValue ?? 0;
|
|
WorkPackageDetail.PlanNum = Funs.GetNewDecimalOrZero(planNum);
|
|
WorkPackageDetail.ThisNum = Funs.GetNewDecimalOrZero(thisNum);
|
|
if (PlanProjectQuantity > 0 && WorkPackageDetail.PlanNum > 0)
|
|
{
|
|
WorkPackageDetail.PlanValue = decimal.Round(PlanCost * Funs.GetNewDecimalOrZero(planNum) / PlanProjectQuantity, 2);
|
|
}
|
|
else
|
|
{
|
|
WorkPackageDetail.PlanValue = 0;
|
|
}
|
|
PlanNum = WorkPackageDetail.PlanNum ?? 0;
|
|
ThisNum = WorkPackageDetail.ThisNum ?? 0;
|
|
PlanValue = WorkPackageDetail.PlanValue ?? 0;
|
|
}
|
|
else
|
|
{
|
|
WorkPackageDetail = new Model.WBS_WorkPackageDetail();
|
|
WorkPackageDetail.WorkPackageDetailId = SQLHelper.GetNewID();
|
|
WorkPackageDetail.WorkPackageId = WorkPackageId;
|
|
WorkPackageDetail.Months = months[j];
|
|
WorkPackageDetail.PlanNum = Funs.GetNewDecimalOrZero(planNum);
|
|
WorkPackageDetail.ThisNum = Funs.GetNewDecimalOrZero(thisNum);
|
|
if (PlanProjectQuantity > 0 && WorkPackageDetail.PlanNum > 0)
|
|
{
|
|
WorkPackageDetail.PlanValue = decimal.Round(PlanCost * Funs.GetNewDecimalOrZero(planNum) / PlanProjectQuantity, 2);
|
|
}
|
|
else
|
|
{
|
|
WorkPackageDetail.PlanValue = 0;
|
|
}
|
|
PlanNum = WorkPackageDetail.PlanNum ?? 0;
|
|
ThisNum = WorkPackageDetail.ThisNum ?? 0;
|
|
PlanValue = WorkPackageDetail.PlanValue ?? 0;
|
|
db.WBS_WorkPackageDetail.InsertOnSubmit(WorkPackageDetail);
|
|
}
|
|
//累加变化值,计算总的变化值
|
|
changePlanNum += PlanNum - oldPlanNum;
|
|
changeThisNum += ThisNum - oldThisNum;
|
|
changePlanValue += PlanValue - oldPlanValue;
|
|
////更新分部分项
|
|
UpdateWorkPackageParent(db, WorkPackage.SuperWorkPackageId, months[j], changePlanNum, changeThisNum, changePlanValue);
|
|
////更新单位工程
|
|
Model.WBS_WorkPackageParentDetail unitWorkDetail = BLL.WorkPackageParentDetailService.GetWorkPackageParentDetailByParentIdAndMonths(WorkPackage.UnitWorkId, months[j]);
|
|
if (unitWorkDetail != null)
|
|
{
|
|
unitWorkDetail.PlanNum += changePlanNum;
|
|
unitWorkDetail.ThisNum += changeThisNum;
|
|
unitWorkDetail.PlanValue += changePlanValue;
|
|
//BLL.WorkPackageParentDetailService.UpdateWorkPackageParentDetail(unitWorkDetail);
|
|
}
|
|
else
|
|
{
|
|
unitWorkDetail = new Model.WBS_WorkPackageParentDetail();
|
|
unitWorkDetail.WorkPackageParentDetailId = SQLHelper.GetNewID();
|
|
unitWorkDetail.ParentId = WorkPackage.UnitWorkId;
|
|
unitWorkDetail.Months = months[j];
|
|
unitWorkDetail.PlanNum = changePlanNum;
|
|
unitWorkDetail.ThisNum = changeThisNum;
|
|
unitWorkDetail.PlanValue = changePlanValue;
|
|
//BLL.WorkPackageParentDetailService.AddWorkPackageParentDetail(unitWorkDetail);
|
|
db.WBS_WorkPackageParentDetail.InsertOnSubmit(unitWorkDetail);
|
|
}
|
|
////更新建筑、安装工程
|
|
Model.WBS_UnitWork unitWork = unitWorks.FirstOrDefault(x => x.UnitWorkId == WorkPackage.UnitWorkId);
|
|
if (unitWork != null)
|
|
{
|
|
Model.WBS_WorkPackageParentDetail projectType = BLL.WorkPackageParentDetailService.GetWorkPackageParentDetailByParentIdAndMonths(unitWork.ProjectType, this.CurrUser.LoginProjectId, months[j]);
|
|
if (projectType != null)
|
|
{
|
|
projectType.PlanNum += changePlanNum;
|
|
projectType.ThisNum += changeThisNum;
|
|
projectType.PlanValue += changePlanValue;
|
|
//BLL.WorkPackageParentDetailService.UpdateWorkPackageParentDetail(cnProfessionDetail);
|
|
}
|
|
else
|
|
{
|
|
projectType = new Model.WBS_WorkPackageParentDetail();
|
|
projectType.WorkPackageParentDetailId = SQLHelper.GetNewID();
|
|
projectType.ParentId = unitWork.ProjectType;
|
|
projectType.ProjectId = this.CurrUser.LoginProjectId;
|
|
projectType.Months = months[j];
|
|
projectType.PlanNum = changePlanNum;
|
|
projectType.ThisNum = changeThisNum;
|
|
projectType.PlanValue = changePlanValue;
|
|
//BLL.WorkPackageParentDetailService.AddWorkPackageParentDetail(cnProfessionDetail);
|
|
db.WBS_WorkPackageParentDetail.InsertOnSubmit(projectType);
|
|
}
|
|
}
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#region 更新分部分项
|
|
/// <summary>
|
|
/// 更新分部分项
|
|
/// </summary>
|
|
/// <param name="years"></param>
|
|
/// <param name="months"></param>
|
|
/// <param name="PlanNum"></param>
|
|
/// <param name="parentId"></param>
|
|
private void UpdateWorkPackageParent(Model.SGGLDB db, string SuperWorkPackageId, DateTime months, decimal changePlanNum, decimal changeThisNum, decimal changePlanValue)
|
|
{
|
|
Model.WBS_WorkPackage workPackage = db.WBS_WorkPackage.FirstOrDefault(x => x.WorkPackageId == SuperWorkPackageId);
|
|
if (workPackage != null)
|
|
{
|
|
Model.WBS_WorkPackageParentDetail parentDetail = BLL.WorkPackageParentDetailService.GetWorkPackageParentDetailByParentIdAndMonths(SuperWorkPackageId, months);
|
|
if (parentDetail != null)
|
|
{
|
|
parentDetail.PlanNum += changePlanNum;
|
|
parentDetail.ThisNum += changeThisNum;
|
|
parentDetail.PlanValue += changePlanValue;
|
|
//BLL.WorkPackageParentDetailService.UpdateWorkPackageParentDetail(parentDetail);
|
|
}
|
|
else
|
|
{
|
|
parentDetail = new Model.WBS_WorkPackageParentDetail();
|
|
parentDetail.WorkPackageParentDetailId = SQLHelper.GetNewID();
|
|
parentDetail.ParentId = SuperWorkPackageId;
|
|
parentDetail.Months = months;
|
|
parentDetail.PlanNum = changePlanNum;
|
|
parentDetail.ThisNum = changeThisNum;
|
|
parentDetail.PlanValue = changePlanValue;
|
|
//BLL.WorkPackageParentDetailService.AddWorkPackageParentDetail(parentDetail);
|
|
db.WBS_WorkPackageParentDetail.InsertOnSubmit(parentDetail);
|
|
}
|
|
if (workPackage.SuperWorkPackageId != null) //还存在上级节点,需要继续循环
|
|
{
|
|
UpdateWorkPackageParent(db, workPackage.SuperWorkPackageId, months, changePlanNum, changeThisNum, changePlanValue);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
protected void drpUnitWork_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
}
|
|
} |