using System;
using System.Linq;

namespace FineUIPro.Web.SysManage
{
    public partial class SysSet : PageBase
    {
        #region 加载
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetButtonPower();

                //每月实际工时
                //Model.Sys_Set set1 = BLL.Sys_SetService.GetSetById(1);
                //if (set1 != null)
                //{
                //    this.txtMonthManHourA.Text = set1.SetValue;
                //}
                //每月每部门人数
                //Model.Sys_Set set2 = BLL.Sys_SetService.GetSetById(2);
                //if (set2 != null)
                //{
                //    this.txtMonthDepartManCount.Text = set2.SetValue;
                //}
                //每月发送邮件日时间
                Model.Sys_Set set3 = BLL.Sys_SetService.GetSetById(3);
                if (set3 != null)
                {
                    this.txtSendEMilaDate.Text = set3.SetValue;
                }
                ////SQIB manager
                //Model.Sys_Set set4 = BLL.Sys_SetService.GetSetById(4);
                //if (set4 != null)
                //{
                //    this.txtSQIBManager.Text = set4.SetValue;
                //}
                ////Permit Manager
                //Model.Sys_Set set5 = BLL.Sys_SetService.GetSetById(5);
                //if (set5!=null)
                //{
                //    this.txtPermitManager.Text = set5.SetValue;
                //}
                ////TDC Manager
                //Model.Sys_Set set6 = BLL.Sys_SetService.GetSetById(6);
                //if (set6!=null)
                //{
                //    this.txtTDCManager.Text = set6.SetValue;
                //}
            }
        }
        #endregion

        #region 保存
        /// <summary>
        /// 保存按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //Model.Sys_Set set1 = BLL.Sys_SetService.GetSetById(1);
            //if (set1 != null)
            //{
            //    set1.SetValue = this.txtMonthManHourA.Text.Trim();
            //    BLL.Sys_SetService.UpdateSysSet(set1);
            //}
            //else
            //{
            //    Model.Sys_Set newSet1 = new Model.Sys_Set();
            //    newSet1.SetId = 1;
            //    newSet1.SetName = "每月实际工时";
            //    newSet1.SetValue = this.txtMonthManHourA.Text.Trim();
            //    BLL.Sys_SetService.AddSysSet(newSet1);
            //}

            //Model.Sys_Set set2 = BLL.Sys_SetService.GetSetById(2);
            //if (set2 != null)
            //{
            //    set2.SetValue = this.txtMonthDepartManCount.Text.Trim();
            //    BLL.Sys_SetService.UpdateSysSet(set2);
            //}
            //else
            //{
            //    Model.Sys_Set newSet2 = new Model.Sys_Set();
            //    newSet2.SetId = 2;
            //    newSet2.SetName = "每月每部门人数";
            //    newSet2.SetValue = this.txtMonthDepartManCount.Text.Trim();
            //    BLL.Sys_SetService.AddSysSet(newSet2);
            //}

            Model.Sys_Set set3 = BLL.Sys_SetService.GetSetById(3);
            if (set3 != null)
            {
                set3.SetValue = this.txtSendEMilaDate.Text.Trim();
                BLL.Sys_SetService.UpdateSysSet(set3);
            }
            else
            {
                Model.Sys_Set newSet3 = new Model.Sys_Set();
                newSet3.SetId = 3;
                newSet3.SetName = "每月发送邮件时间";
                newSet3.SetValue = this.txtSendEMilaDate.Text.Trim();
                BLL.Sys_SetService.AddSysSet(newSet3);
            }

            //Model.Sys_Set set4 = BLL.Sys_SetService.GetSetById(4);
            //if (set4!=null)
            //{
            //    set4.SetValue = this.txtSQIBManager.Text.Trim();
            //    BLL.Sys_SetService.UpdateSysSet(set4);
            //}
            //else
            //{
            //    Model.Sys_Set newSet4 = new Model.Sys_Set();
            //    newSet4.SetId = 4;
            //    newSet4.SetName = "QIB Manager";
            //    newSet4.SetValue = this.txtSQIBManager.Text.Trim();
            //    BLL.Sys_SetService.AddSysSet(newSet4);
            //}

            //Model.Sys_Set set5 = BLL.Sys_SetService.GetSetById(5);
            //if (set5 != null)
            //{
            //    set5.SetValue = this.txtPermitManager.Text.Trim();
            //    BLL.Sys_SetService.UpdateSysSet(set5);
            //}
            //else
            //{
            //    Model.Sys_Set newSet5 = new Model.Sys_Set();
            //    newSet5.SetId = 5;
            //    newSet5.SetName = "Permit Manager";
            //    newSet5.SetValue = this.txtPermitManager.Text.Trim();
            //    BLL.Sys_SetService.AddSysSet(newSet5);
            //}

            //Model.Sys_Set set6 = BLL.Sys_SetService.GetSetById(6);
            //if (set6 != null)
            //{
            //    set6.SetValue = this.txtTDCManager.Text.Trim();
            //    BLL.Sys_SetService.UpdateSysSet(set6);
            //}
            //else
            //{
            //    Model.Sys_Set newSet6 = new Model.Sys_Set();
            //    newSet6.SetId = 6;
            //    newSet6.SetName = "TDC Manager";
            //    newSet6.SetValue = this.txtTDCManager.Text.Trim();
            //    BLL.Sys_SetService.AddSysSet(newSet6);
            //}
            ShowNotify("Save Succefully!", MessageBoxIcon.Success);
        }
        #endregion

        #region 权限设置
        /// <summary>
        /// 菜单按钮权限
        /// </summary>
        private void GetButtonPower()
        {
            var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.SysSetMenuId);
            if (buttonList.Count() > 0)
            {
                if (buttonList.Contains(BLL.Const.BtnSave))
                {
                    this.btnSave.Hidden = false;
                }
            }
        }
        #endregion
    }
}