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.CQMS.Performance
{
    public partial class MonthTargetEdit : PageBase
    {
        //主键
        public string PerformanceGid
        {
            get
            {
                return (string)ViewState["PerformanceGid"];
            }
            set
            {
                ViewState["PerformanceGid"] = value;
            }
        }
        /// 
        /// 页面加载
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //主键
                PerformanceGid = Request.Params["PerformanceGid"];
                //根据主键加载CQMS_Performance_Child1
                var child1List = Funs.DB.CQMS_Performance_Child1.Where(x => x.PerformanceGid == PerformanceGid).OrderBy(x => x.SortIndex).ToList();
                if (child1List.Count > 0)
                {
                    txtWorkArea.Text = child1List[0].WorkArea.ToString();
                    txtMonthTarget1.Text= child1List[0].MonthTarget.ToString();
                    txtMonthTarget2.Text = child1List[1].MonthTarget.ToString();
                    txtMonthTarget3.Text = child1List[2].MonthTarget.ToString();
                    txtMonthTarget4.Text = child1List[3].MonthTarget.ToString();
                    txtMonthTarget5.Text = child1List[4].MonthTarget.ToString();
                    txtMonthTarget6.Text = child1List[5].MonthTarget.ToString();
                }
                else {
                    ShowNotify("未查询到月节点目标数据,请重新生成。", MessageBoxIcon.Warning);
                    return;
                }
            }
        }
        /// 
        /// 确认修改
        /// 
        /// 
        /// 
        protected void btnEdit_Click(object sender, EventArgs e) {
            using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
            {
                //依次修改6个类别的月节点目标
                var child2Model1 = db.CQMS_Performance_Child1.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.SortIndex == 1);
                child2Model1.WorkArea = txtWorkArea.Text.Trim();
                child2Model1.MonthTarget = txtMonthTarget1.Text.Trim();
                db.SubmitChanges();
                var child2Model2 = db.CQMS_Performance_Child1.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.SortIndex == 2);
                child2Model2.MonthTarget = txtMonthTarget2.Text.Trim();
                db.SubmitChanges();
                var child2Model3 = db.CQMS_Performance_Child1.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.SortIndex == 3);
                child2Model3.MonthTarget = txtMonthTarget3.Text.Trim();
                db.SubmitChanges();
                var child2Model4 = db.CQMS_Performance_Child1.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.SortIndex == 4);
                child2Model4.MonthTarget = txtMonthTarget4.Text.Trim();
                db.SubmitChanges();
                var child2Model5 = db.CQMS_Performance_Child1.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.SortIndex == 5);
                child2Model5.MonthTarget = txtMonthTarget5.Text.Trim();
                db.SubmitChanges();
                var child2Model6 = db.CQMS_Performance_Child1.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.SortIndex == 6);
                child2Model6.MonthTarget = txtMonthTarget6.Text.Trim();
                db.SubmitChanges();
                ShowNotify("修改成功。", MessageBoxIcon.Success);
            }
        }
    }
}