CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/JDGL/WBS/CostControlDetailEdit.aspx.cs

168 lines
6.2 KiB
C#
Raw Normal View History

2021-08-13 11:15:59 +08:00
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Newtonsoft.Json.Linq;
namespace FineUIPro.Web.JDGL.WBS
{
public partial class CostControlDetailEdit : PageBase
{
/// <summary>
/// 控制项主键
/// </summary>
public string Id
{
get
{
return (string)ViewState["Id"];
}
set
{
ViewState["Id"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Id = Request.Params["Id"];
Model.WBS_CostControl costControl = BLL.CostControlService.GetCostControlByCostControlId(this.Id);
if (costControl != null)
{
this.txtCostControlName.Text = costControl.CostControlName;
}
2021-09-15 14:50:52 +08:00
var list = BLL.CostControlDetailService.GetMonthCostControlDetailsByCostControlId(this.Id);
2021-08-13 11:15:59 +08:00
this.Grid1.DataSource = list;
this.Grid1.DataBind();
}
}
#region
/// <summary>
/// 增加按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
var list = GetDetails();
Model.WBS_CostControlDetail detail = new Model.WBS_CostControlDetail();
detail.CostControlDetailId = SQLHelper.GetNewID();
list.Add(detail);
Grid1.DataSource = list;
Grid1.DataBind();
}
#endregion
private List<Model.WBS_CostControlDetail> GetDetails()
{
List<Model.WBS_CostControlDetail> details = new List<Model.WBS_CostControlDetail>();
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int i = mergedRow.Value<int>("index");
Model.WBS_CostControlDetail detail = new Model.WBS_CostControlDetail();
detail.CostControlDetailId = Grid1.Rows[i].RowID;
detail.CostControlId = this.Id;
detail.Months = Funs.GetNewDateTime(values.Value<string>("Months") + "-01");
detail.PlanNum = Funs.GetNewDecimal(values.Value<string>("PlanNum"));
details.Add(detail);
}
return details;
}
#region
/// <summary>
/// Grid行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
string detailId = Grid1.DataKeys[e.RowIndex][0].ToString();
var list = GetDetails();
if (e.CommandName == "del")//删除
{
var detail = list.FirstOrDefault(x => x.CostControlDetailId == detailId);
Model.WBS_CostControlDetail oldDetail = BLL.CostControlDetailService.GetCostControlDetailByCostControlDetailId(detailId);
if (detail != null)
{
list.Remove(detail);
}
if (oldDetail != null)
{
BLL.CostControlDetailService.DeleteCostControlDetail(detailId);
}
this.Grid1.DataSource = list;
this.Grid1.DataBind();
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
var list = GetDetails();
foreach (var item in list)
{
Model.WBS_CostControlDetail oldDetail = BLL.CostControlDetailService.GetCostControlDetailByCostControlDetailId(item.CostControlDetailId);
if (oldDetail == null)
{
BLL.CostControlDetailService.AddCostControlDetail(item);
}
else
{
item.ThisNum = oldDetail.ThisNum;
BLL.CostControlDetailService.UpdateCostControlDetail(item);
}
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHideReference());
}
#endregion
#region
/// <summary>
/// 调整计划按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnUpdate_Click(object sender, EventArgs e)
{
var list = GetDetails();
2021-09-15 14:50:52 +08:00
int versionNum = BLL.CostControlDetailHistoryService.GetMonthMaxVersionNumByCostControlId(this.Id);
2021-08-13 11:15:59 +08:00
foreach (var item in list)
{
Model.WBS_CostControlDetailHistory detailHistory = new Model.WBS_CostControlDetailHistory();
detailHistory.CostControlDetailHistoryId = SQLHelper.GetNewID();
detailHistory.CostControlId = item.CostControlId;
detailHistory.Months = item.Months;
detailHistory.PlanNum = item.PlanNum;
detailHistory.VersionNum = versionNum + 1;
BLL.CostControlDetailHistoryService.AddCostControlDetailHistory(detailHistory);
}
ShowNotify("历史版本保存成功!", MessageBoxIcon.Success);
}
#endregion
#region
/// <summary>
/// 查看历史版本
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSee_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CostControlDetailHistoryShow.aspx?Id={0}", this.Id, "编辑 - ")));
}
#endregion
}
}