using BLL; 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 { /// /// id /// public string QuantityCompletionId { get { return (string)ViewState["QuantityCompletionId"]; } set { ViewState["QuantityCompletionId"] = value; } } /// /// 项目id /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); QuantityCompletionId = Request.Params["QuantityCompletionId"]; if (!string.IsNullOrEmpty(QuantityCompletionId)) { 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(); } } } } } protected void btnSave_Click(object sender, EventArgs e) { 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) { 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); } ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } }