191 lines
		
	
	
		
			7.4 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			191 lines
		
	
	
		
			7.4 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Data;
							 | 
						|||
| 
								 | 
							
								using System.Data.SqlClient;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using System.Text;
							 | 
						|||
| 
								 | 
							
								using System.Web.UI.WebControls;
							 | 
						|||
| 
								 | 
							
								using BLL;
							 | 
						|||
| 
								 | 
							
								using Model;
							 | 
						|||
| 
								 | 
							
								using AspNet = System.Web.UI.WebControls;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace FineUIPro.Web.CQMS.Performance
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public partial class PerformanceConfig : PageBase
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        protected void Page_Load(object sender, EventArgs e)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (!IsPostBack)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                //当前年份
							 | 
						|||
| 
								 | 
							
								                dpYear.Text = DateTime.Now.Year.ToString();
							 | 
						|||
| 
								 | 
							
								                var model = Funs.DB.CQMS_Performance_SetUp.FirstOrDefault(x => x.CreateYear == dpYear.Text);
							 | 
						|||
| 
								 | 
							
								                if (model != null)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    BindGrid();
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        protected void btnSearch_searach(object sender, EventArgs e)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (string.IsNullOrEmpty(dpYear.Text.Trim()))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                ShowNotify("年份不能为空。", MessageBoxIcon.Warning);
							 | 
						|||
| 
								 | 
							
								                PageContext.RegisterStartupScript("CloseRefresh()");
							 | 
						|||
| 
								 | 
							
								                return;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            else
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                BindGrid();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 判断生成操作
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        protected void btnNew_Juge(object sender, EventArgs e)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (string.IsNullOrEmpty(dpYear.Text.Trim()))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                ShowNotify("年份不能为空。", MessageBoxIcon.Warning);
							 | 
						|||
| 
								 | 
							
								                PageContext.RegisterStartupScript("CloseRefresh()");
							 | 
						|||
| 
								 | 
							
								                return;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            //根据年份查询是否有数据
							 | 
						|||
| 
								 | 
							
								            var modelSum = Funs.DB.CQMS_Performance_SetUp.Where(x => x.CreateYear == dpYear.Text.Trim()).FirstOrDefault();
							 | 
						|||
| 
								 | 
							
								            //查到数据,二次确认
							 | 
						|||
| 
								 | 
							
								            if (modelSum != null)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                PageContext.RegisterStartupScript(Confirm.GetShowReference("该日期已生成数据,是否确认重新生成?", String.Empty, MessageBoxIcon.Question,
							 | 
						|||
| 
								 | 
							
								                    PageManager1.GetCustomEventReference(false, "Confirmgd_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
							 | 
						|||
| 
								 | 
							
								                PageContext.RegisterStartupScript("CloseRefresh()");
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            else
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                //生成数据
							 | 
						|||
| 
								 | 
							
								                AddPerformanceConfig();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        private void BindGrid()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            string strSql = @"SELECT * FROM CQMS_Performance_SetUp  where 1=1 ";
							 | 
						|||
| 
								 | 
							
								            List<SqlParameter> listStr = new List<SqlParameter>();
							 | 
						|||
| 
								 | 
							
								            if (!string.IsNullOrEmpty(dpYear.Text.Trim()))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                strSql += " AND CreateYear = @CreateYear";
							 | 
						|||
| 
								 | 
							
								                listStr.Add(new SqlParameter("@CreateYear", dpYear.Text.Trim()));
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            strSql += " order by SortIndex ";
							 | 
						|||
| 
								 | 
							
								            SqlParameter[] parameter = listStr.ToArray();
							 | 
						|||
| 
								 | 
							
								            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            Grid1.RecordCount = tb.Rows.Count;
							 | 
						|||
| 
								 | 
							
								            var table = tb;
							 | 
						|||
| 
								 | 
							
								            Grid1.DataSource = table;
							 | 
						|||
| 
								 | 
							
								            Grid1.DataBind();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 生成
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        private void AddPerformanceConfig()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            List<Model.CQMS_Performance_SetUp> modelList = new List<CQMS_Performance_SetUp>();
							 | 
						|||
| 
								 | 
							
								            for (int i = 0; i < 12; i++)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Model.CQMS_Performance_SetUp model = new CQMS_Performance_SetUp();
							 | 
						|||
| 
								 | 
							
								                model.PerformanceSteUpGid = Guid.NewGuid().ToString();
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                //第一次是上一年的12月份
							 | 
						|||
| 
								 | 
							
								                if (i==0)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    model.SetUpMonth = (Convert.ToInt32(dpYear.Text.Trim()) - 1).ToString() +"-" + 12;
							 | 
						|||
| 
								 | 
							
								                    model.SetUpStartDate = (Convert.ToInt32(dpYear.Text.Trim()) - 1).ToString() + "-" + 12 + "-" + "01";
							 | 
						|||
| 
								 | 
							
								                    var dates = Convert.ToDateTime((dpYear.Text.Trim() + "-" + (i + 1) + "-" + "01")).AddMonths(1).AddDays(-1);
							 | 
						|||
| 
								 | 
							
								                    model.SetUpEndDate = (Convert.ToInt32(dpYear.Text.Trim()) - 1).ToString() + "-12-" + dates.Day;
							 | 
						|||
| 
								 | 
							
								                    model.CreateDate = Convert.ToDateTime(dpYear.Text.Trim() + "-" + 12);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    model.SetUpMonth = dpYear.Text.Trim() + "-" + (i);
							 | 
						|||
| 
								 | 
							
								                    model.SetUpStartDate = dpYear.Text.Trim() + "-" + (i ) + "-" + "01";
							 | 
						|||
| 
								 | 
							
								                    var dates = Convert.ToDateTime((dpYear.Text.Trim() + "-" + (i ) + "-" + "01")).AddMonths(1).AddDays(-1);
							 | 
						|||
| 
								 | 
							
								                    model.SetUpEndDate = dates.Year.ToString() + "-" + dates.Month + "-" + dates.Day;
							 | 
						|||
| 
								 | 
							
								                    model.CreateDate = Convert.ToDateTime(dpYear.Text.Trim() + "-" + (i));
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                model.SetUpWeek = 4;
							 | 
						|||
| 
								 | 
							
								                model.CreateYear = dpYear.Text.Trim();
							 | 
						|||
| 
								 | 
							
								                model.SortIndex = (i + 1);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                
							 | 
						|||
| 
								 | 
							
								                modelList.Add(model);
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            Funs.DB.CQMS_Performance_SetUp.InsertAllOnSubmit(modelList);
							 | 
						|||
| 
								 | 
							
								            Funs.DB.SubmitChanges();
							 | 
						|||
| 
								 | 
							
								            BindGrid();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        // <summary>
							 | 
						|||
| 
								 | 
							
								        /// 重新生成确认按钮
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="sender"></param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="e"></param>
							 | 
						|||
| 
								 | 
							
								        protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (e.EventArgument == "Confirmgd_OK" || e.EventArgument == "Confirmgy_OK")
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                // 根据日期查询是否有数据
							 | 
						|||
| 
								 | 
							
								                var modelSum = Funs.DB.CQMS_Performance_SetUp.Where(x => x.CreateYear == dpYear.Text.Trim()).ToList();
							 | 
						|||
| 
								 | 
							
								                if (modelSum.Count > 0)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    //删除所有数据
							 | 
						|||
| 
								 | 
							
								                    using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        db.CQMS_Performance_SetUp.DeleteAllOnSubmit(modelSum);
							 | 
						|||
| 
								 | 
							
								                        //生成数据
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        protected void Button2_Click(object sender, EventArgs e)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Dictionary<int, Dictionary<string, object>> modifiedDict = Grid1.GetModifiedDict();
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                foreach (int rowIndex in modifiedDict.Keys)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    Model.CQMS_Performance_SetUp model = new CQMS_Performance_SetUp();
							 | 
						|||
| 
								 | 
							
								                    model.PerformanceSteUpGid = Grid1.DataKeys[rowIndex][0].ToString();
							 | 
						|||
| 
								 | 
							
								                    model = db.CQMS_Performance_SetUp.FirstOrDefault(x => x.PerformanceSteUpGid == model.PerformanceSteUpGid);
							 | 
						|||
| 
								 | 
							
								                    if (modifiedDict[rowIndex].ContainsKey("SetUpStartDate"))
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        model.SetUpStartDate = modifiedDict[rowIndex]["SetUpStartDate"].ToString();
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                    if (modifiedDict[rowIndex].ContainsKey("SetUpEndDate"))
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        model.SetUpEndDate = modifiedDict[rowIndex]["SetUpEndDate"].ToString();
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                    if (modifiedDict[rowIndex].ContainsKey("SetUpWeek"))
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        model.SetUpWeek = Convert.ToInt32(modifiedDict[rowIndex]["SetUpWeek"].ToString());
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                    db.SubmitChanges();
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                BindGrid();
							 | 
						|||
| 
								 | 
							
								                ShowNotify("保存成功。", MessageBoxIcon.Success);
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |