提交代码
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using BLL;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,20 +11,6 @@ namespace FineUIPro.Web.JDGL.Check
|
||||
{
|
||||
public partial class QuantityCompletionEdit : PageBase
|
||||
{
|
||||
/// <summary>
|
||||
/// id
|
||||
/// </summary>
|
||||
public string QuantityCompletionId
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)ViewState["QuantityCompletionId"];
|
||||
}
|
||||
set
|
||||
{
|
||||
ViewState["QuantityCompletionId"] = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 项目id
|
||||
/// </summary>
|
||||
@@ -42,110 +29,171 @@ namespace FineUIPro.Web.JDGL.Check
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
|
||||
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
|
||||
QuantityCompletionId = Request.Params["QuantityCompletionId"];
|
||||
if (!string.IsNullOrEmpty(QuantityCompletionId))
|
||||
DateTime months = Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-01");
|
||||
if (!string.IsNullOrEmpty(Request.Params["Months"]))
|
||||
{
|
||||
|
||||
Model.JDGL_QuantityCompletion QuantityCompletion = BLL.QuantityCompletionService.GetQuantityCompletionById(QuantityCompletionId);
|
||||
if (QuantityCompletion != null)
|
||||
{
|
||||
this.ProjectId = QuantityCompletion.ProjectId;
|
||||
if (QuantityCompletion.StartDate != null)
|
||||
{
|
||||
this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", QuantityCompletion.StartDate);
|
||||
}
|
||||
if (QuantityCompletion.EndDate != null)
|
||||
{
|
||||
this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", QuantityCompletion.EndDate);
|
||||
}
|
||||
Model.JDGL_QuantityList list = BLL.QuantityListService.GetQuantityListById(QuantityCompletion.QuantityListId);
|
||||
if (list != null)
|
||||
{
|
||||
this.txtName.Text = list.Name;
|
||||
this.txtUnit.Text = list.Unit;
|
||||
if (list.DesignNum != null)
|
||||
{
|
||||
this.txtDesignNum.Text = list.DesignNum.ToString();
|
||||
}
|
||||
}
|
||||
if (QuantityCompletion.PlanNum != null)
|
||||
{
|
||||
this.txtPlanNum.Text = QuantityCompletion.PlanNum.ToString();
|
||||
}
|
||||
if (QuantityCompletion.RealNum != null)
|
||||
{
|
||||
this.txtRealNum.Text = QuantityCompletion.RealNum.ToString();
|
||||
}
|
||||
if (QuantityCompletion.NextNum != null)
|
||||
{
|
||||
this.txtNextNum.Text = QuantityCompletion.NextNum.ToString();
|
||||
}
|
||||
}
|
||||
months = Convert.ToDateTime(Request.Params["Months"] + "-01");
|
||||
}
|
||||
this.txtMonth.Text = string.Format("{0:yyyy-MM}", months);
|
||||
BindGrid();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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
|
||||
|
||||
protected void btnSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(this.txtMonth.Text))
|
||||
{
|
||||
ShowNotify("请选择月份!", MessageBoxIcon.Warning);
|
||||
}
|
||||
SaveData(true);
|
||||
}
|
||||
|
||||
private void SaveData(bool bl)
|
||||
{
|
||||
string QuantityCompletionId = Request.Params["QuantityCompletionId"];
|
||||
string quantityListId = string.Empty;
|
||||
var oldQuantityList = Funs.DB.JDGL_QuantityList.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.Name == this.txtName.Text.Trim());
|
||||
if (oldQuantityList == null)
|
||||
DateTime months = Convert.ToDateTime(this.txtMonth.Text + "-01");
|
||||
var list = GetDetails();
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
foreach (var item in list)
|
||||
{
|
||||
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 = this.txtName.Text.Trim();
|
||||
newQuantityList.Unit = this.txtUnit.Text.Trim();
|
||||
newQuantityList.DesignNum = Convert.ToDecimal(this.txtDesignNum.Text.Trim());
|
||||
BLL.QuantityListService.AddQuantityList(newQuantityList);
|
||||
}
|
||||
else
|
||||
{
|
||||
quantityListId = oldQuantityList.QuantityListId;
|
||||
oldQuantityList.Unit = this.txtUnit.Text.Trim();
|
||||
oldQuantityList.DesignNum = Convert.ToDecimal(this.txtDesignNum.Text.Trim());
|
||||
BLL.QuantityListService.UpdateQuantityList(oldQuantityList);
|
||||
}
|
||||
Model.JDGL_QuantityCompletion QuantityCompletion = new Model.JDGL_QuantityCompletion();
|
||||
if (!string.IsNullOrEmpty(this.txtPlanNum.Text.Trim()))
|
||||
{
|
||||
QuantityCompletion.PlanNum = Convert.ToDecimal(this.txtPlanNum.Text.Trim());
|
||||
}
|
||||
if (!string.IsNullOrEmpty(this.txtRealNum.Text.Trim()))
|
||||
{
|
||||
QuantityCompletion.RealNum = Convert.ToDecimal(this.txtRealNum.Text.Trim());
|
||||
}
|
||||
if (!string.IsNullOrEmpty(this.txtNextNum.Text.Trim()))
|
||||
{
|
||||
QuantityCompletion.NextNum = Convert.ToDecimal(this.txtNextNum.Text.Trim());
|
||||
}
|
||||
QuantityCompletion.QuantityListId = quantityListId;
|
||||
QuantityCompletion.CompileMan = this.CurrUser.UserId;
|
||||
QuantityCompletion.CompileDate = DateTime.Now;
|
||||
QuantityCompletion.StartDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
|
||||
QuantityCompletion.EndDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
|
||||
if (!string.IsNullOrEmpty(QuantityCompletionId))
|
||||
{
|
||||
QuantityCompletion.QuantityCompletionId = QuantityCompletionId;
|
||||
BLL.QuantityCompletionService.UpdateQuantityCompletion(QuantityCompletion);
|
||||
}
|
||||
else
|
||||
{
|
||||
QuantityCompletion.QuantityCompletionId = SQLHelper.GetNewID(typeof(Model.JDGL_QuantityCompletion));
|
||||
QuantityCompletion.ProjectId = this.CurrUser.LoginProjectId;
|
||||
BLL.QuantityCompletionService.AddQuantityCompletion(QuantityCompletion);
|
||||
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);
|
||||
if (oldQuantityCompletion==null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
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())
|
||||
{
|
||||
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);
|
||||
}
|
||||
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")//删除
|
||||
{
|
||||
var Report = list.FirstOrDefault(x => x.QuantityListId == quantityListId);
|
||||
if (Report != null)
|
||||
{
|
||||
list.Remove(Report);
|
||||
}
|
||||
this.Grid1.DataSource = list;
|
||||
this.Grid1.DataBind();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user