CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/JDGL/Check/QuantityCompletionEdit.aspx.cs

199 lines
8.5 KiB
C#
Raw Normal View History

2021-08-13 11:15:59 +08:00
using BLL;
2024-05-06 15:57:32 +08:00
using Newtonsoft.Json.Linq;
2021-08-13 11:15:59 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.JDGL.Check
{
public partial class QuantityCompletionEdit : PageBase
{
/// <summary>
/// 项目id
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
2024-05-06 15:57:32 +08:00
DateTime months = Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-01");
if (!string.IsNullOrEmpty(Request.Params["Months"]))
2021-08-13 11:15:59 +08:00
{
2024-05-06 15:57:32 +08:00
months = Convert.ToDateTime(Request.Params["Months"] + "-01");
2021-08-13 11:15:59 +08:00
}
2024-05-06 15:57:32 +08:00
this.txtMonth.Text = string.Format("{0:yyyy-MM}", months);
BindGrid();
2021-08-13 11:15:59 +08:00
}
}
2024-05-06 15:57:32 +08:00
/// <summary>
/// 加载Grid
/// </summary>
private void BindGrid()
{
DateTime months = Convert.ToDateTime(this.txtMonth.Text + "-01");
Model.SGGLDB db = Funs.DB;
Grid1.DataSource = from x in db.JDGL_QuantityList
where x.ProjectId == this.CurrUser.LoginProjectId
orderby x.SortIndex, x.Name
select new
{
x.QuantityListId,
x.Name,
x.Unit,
x.DesignNum,
PlanNum = (from y in db.JDGL_QuantityCompletion where y.ProjectId == this.CurrUser.LoginProjectId && y.Months == months && y.QuantityListId == x.QuantityListId select y.PlanNum).First(),
RealNum = (from y in db.JDGL_QuantityCompletion where y.ProjectId == this.CurrUser.LoginProjectId && y.Months == months && y.QuantityListId == x.QuantityListId select y.RealNum).First(),
NextNum = (from y in db.JDGL_QuantityCompletion where y.ProjectId == this.CurrUser.LoginProjectId && y.Months == months && y.QuantityListId == x.QuantityListId select y.NextNum).First(),
};
Grid1.DataBind();
}
#region
/// <summary>
/// 月份选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtMonths_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
2021-08-13 11:15:59 +08:00
protected void btnSave_Click(object sender, EventArgs e)
{
2024-05-06 15:57:32 +08:00
if (string.IsNullOrEmpty(this.txtMonth.Text))
{
ShowNotify("请选择月份!", MessageBoxIcon.Warning);
}
2021-08-13 11:15:59 +08:00
SaveData(true);
}
private void SaveData(bool bl)
{
2024-05-06 15:57:32 +08:00
DateTime months = Convert.ToDateTime(this.txtMonth.Text + "-01");
var list = GetDetails();
Model.SGGLDB db = Funs.DB;
foreach (var item in list)
2024-05-05 17:12:18 +08:00
{
2024-05-06 15:57:32 +08:00
string quantityListId = string.Empty;
var oldQuantityList = db.JDGL_QuantityList.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.Name == item.Name);
if (oldQuantityList == null)
{
Model.JDGL_QuantityList newQuantityList = new Model.JDGL_QuantityList();
quantityListId = SQLHelper.GetNewID(typeof(Model.JDGL_QuantityList));
newQuantityList.QuantityListId = quantityListId;
newQuantityList.ProjectId = this.CurrUser.LoginProjectId;
newQuantityList.Name = item.Name;
newQuantityList.Unit = item.Unit;
newQuantityList.DesignNum = item.DesignNum;
BLL.QuantityListService.AddQuantityList(newQuantityList);
}
else
{
quantityListId = oldQuantityList.QuantityListId;
oldQuantityList.Unit = item.Unit;
oldQuantityList.DesignNum = item.DesignNum;
BLL.QuantityListService.UpdateQuantityList(oldQuantityList);
}
var oldQuantityCompletion = db.JDGL_QuantityCompletion.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.QuantityListId == quantityListId && x.Months == months);
2024-05-07 09:45:10 +08:00
if (oldQuantityCompletion == null)
2024-05-06 15:57:32 +08:00
{
Model.JDGL_QuantityCompletion QuantityCompletion = new Model.JDGL_QuantityCompletion();
QuantityCompletion.QuantityCompletionId = SQLHelper.GetNewID(typeof(Model.JDGL_QuantityCompletion));
QuantityCompletion.PlanNum = item.PlanNum;
QuantityCompletion.RealNum = item.RealNum;
QuantityCompletion.NextNum = item.NextNum;
QuantityCompletion.Months = months;
QuantityCompletion.QuantityListId = quantityListId;
QuantityCompletion.CompileMan = this.CurrUser.UserId;
QuantityCompletion.CompileDate = DateTime.Now;
QuantityCompletion.ProjectId = this.CurrUser.LoginProjectId;
BLL.QuantityCompletionService.AddQuantityCompletion(QuantityCompletion);
}
else
{
oldQuantityCompletion.PlanNum = item.PlanNum;
oldQuantityCompletion.RealNum = item.RealNum;
oldQuantityCompletion.NextNum = item.NextNum;
BLL.QuantityCompletionService.UpdateQuantityCompletion(oldQuantityCompletion);
}
2024-05-05 17:12:18 +08:00
}
2024-05-06 15:57:32 +08:00
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#region
/// <summary>
/// 增加按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
var list = GetDetails();
Model.View_JDGL_QuantityCompletion ql = new Model.View_JDGL_QuantityCompletion();
ql.QuantityListId = SQLHelper.GetNewID();
list.Add(ql);
Grid1.DataSource = list;
Grid1.DataBind();
}
private List<Model.View_JDGL_QuantityCompletion> GetDetails()
{
List<Model.View_JDGL_QuantityCompletion> list = new List<Model.View_JDGL_QuantityCompletion>();
foreach (JObject mergedRow in Grid1.GetMergedData())
2021-08-13 11:15:59 +08:00
{
2024-05-06 15:57:32 +08:00
JObject values = mergedRow.Value<JObject>("values");
int i = mergedRow.Value<int>("index");
Model.View_JDGL_QuantityCompletion ql = new Model.View_JDGL_QuantityCompletion();
ql.QuantityListId = Grid1.Rows[i].RowID;
ql.Name = values.Value<string>("Name");
ql.Unit = values.Value<string>("Unit");
ql.DesignNum = Funs.GetNewDecimal(values.Value<string>("DesignNum"));
ql.PlanNum = Funs.GetNewDecimal(values.Value<string>("PlanNum"));
ql.RealNum = Funs.GetNewDecimal(values.Value<string>("RealNum"));
ql.NextNum = Funs.GetNewDecimal(values.Value<string>("NextNum"));
list.Add(ql);
2021-08-13 11:15:59 +08:00
}
2024-05-06 15:57:32 +08:00
return list;
}
#endregion
#region
/// <summary>
/// Grid行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
string quantityListId = Grid1.DataKeys[e.RowIndex][0].ToString();
var list = GetDetails();
if (e.CommandName == "del")//删除
2021-08-13 11:15:59 +08:00
{
2024-05-06 15:57:32 +08:00
var Report = list.FirstOrDefault(x => x.QuantityListId == quantityListId);
if (Report != null)
{
list.Remove(Report);
}
this.Grid1.DataSource = list;
this.Grid1.DataBind();
2021-08-13 11:15:59 +08:00
}
}
2024-05-06 15:57:32 +08:00
#endregion
2021-08-13 11:15:59 +08:00
}
}