199 lines
		
	
	
		
			8.5 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			199 lines
		
	
	
		
			8.5 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | |
| using Newtonsoft.Json.Linq;
 | |
| 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)
 | |
|             {
 | |
|                 DateTime months = Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-01");
 | |
|                 if (!string.IsNullOrEmpty(Request.Params["Months"]))
 | |
|                 {
 | |
|                     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)
 | |
|         {
 | |
|             DateTime months = Convert.ToDateTime(this.txtMonth.Text + "-01");
 | |
|             var list = GetDetails();
 | |
|             Model.SGGLDB db = Funs.DB;
 | |
|             foreach (var item in list)
 | |
|             {
 | |
|                 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
 | |
|     }
 | |
| } |