using BLL;
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();

                //this.drpCTSS.DataTextField = "UserName";
                //this.drpCTSS.DataValueField = "UserId";
                //this.drpCTSS.DataSource = BLL.Sys_UserService.GetUserListByDepartId(BLL.Const.CTSSId);
                //this.drpCTSS.DataBind();
                //Funs.FineUIPleaseSelect(this.drpCTSS);

                //this.drpCTSC.DataTextField = "UserName";
                //this.drpCTSC.DataValueField = "UserId";
                //this.drpCTSC.DataSource = BLL.Sys_UserService.GetUserListByDepartId(BLL.Const.CTSCId);
                //this.drpCTSC.DataBind();
                //Funs.FineUIPleaseSelect(this.drpCTSC);

                //this.drpCTMT.DataTextField = "UserName";
                //this.drpCTMT.DataValueField = "UserId";
                //this.drpCTMT.DataSource = BLL.Sys_UserService.GetUserListByDepartId(BLL.Const.CTMTId);
                //this.drpCTMT.DataBind();
                //Funs.FineUIPleaseSelect(this.drpCTMT);

                ////CT_GM
                //Model.Sys_Set set1 = BLL.Sys_SetService.GetSetById(1);
                //if (set1 != null)
                //{
                //    this.txtCT_GM.Text = set1.SetValue;
                //}
                ////总监
                //Model.Sys_Set set2 = BLL.Sys_SetService.GetSetById(2);
                //if (set2 != null)
                //{
                //    this.txtDirector.Text = set2.SetValue;
                //}
                //CTS / S
                //Model.Sys_Set set3 = BLL.Sys_SetService.GetSetById(3);
                //if (set3 != null)
                //{
                //    this.drpCTSS.SelectedValue = set3.SetValue;
                //}
                ////CTS/C
                //Model.Sys_Set set4 = BLL.Sys_SetService.GetSetById(4);
                //if (set4 != null)
                //{
                //    this.drpCTSC.SelectedValue = set4.SetValue;
                //}
                ////CTM/T
                //Model.Sys_Set set5 = BLL.Sys_SetService.GetSetById(5);
                //if (set5 != null)
                //{
                //    this.drpCTMT.SelectedValue = set5.SetValue;
                //}
                //评价说明
                Model.Sys_Set set6 = BLL.Sys_SetService.GetSetById(6);
                if (set6 != null)
                {
                    this.txtDes.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.txtCT_GM.Text.Trim();
            //    BLL.Sys_SetService.UpdateSysSet(set1);
            //}
            //else
            //{
            //    Model.Sys_Set newSet1 = new Model.Sys_Set();
            //    newSet1.SetId = 1;
            //    newSet1.SetName = "CT_GM";
            //    newSet1.SetValue = this.txtCT_GM.Text.Trim();
            //    BLL.Sys_SetService.AddSysSet(newSet1);
            //}

            //Model.Sys_Set set2 = BLL.Sys_SetService.GetSetById(2);
            //if (set2 != null)
            //{
            //    set2.SetValue = this.txtDirector.Text.Trim();
            //    BLL.Sys_SetService.UpdateSysSet(set2);
            //}
            //else
            //{
            //    Model.Sys_Set newSet2 = new Model.Sys_Set();
            //    newSet2.SetId = 2;
            //    newSet2.SetName = "总监";
            //    newSet2.SetValue = this.txtDirector.Text.Trim();
            //    BLL.Sys_SetService.AddSysSet(newSet2);
            //}

            //if (this.drpCTSS.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpCTSS.SelectedValue))
            //{
            //    Model.Sys_Set set3 = BLL.Sys_SetService.GetSetById(3);
            //    if (set3 != null)
            //    {
            //        set3.SetValue = this.drpCTSS.SelectedValue;
            //        BLL.Sys_SetService.UpdateSysSet(set3);
            //    }
            //    else
            //    {
            //        Model.Sys_Set newSet3 = new Model.Sys_Set();
            //        newSet3.SetId = 3;
            //        newSet3.SetName = "CTS/S";
            //        newSet3.SetValue = this.drpCTSS.SelectedValue;
            //        BLL.Sys_SetService.AddSysSet(newSet3);
            //    }
            //}

            //if (this.drpCTSC.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpCTSC.SelectedValue))
            //{
            //    Model.Sys_Set set4 = BLL.Sys_SetService.GetSetById(4);
            //    if (set4 != null)
            //    {
            //        set4.SetValue = this.drpCTSC.SelectedValue;
            //        BLL.Sys_SetService.UpdateSysSet(set4);
            //    }
            //    else
            //    {
            //        Model.Sys_Set newSet4 = new Model.Sys_Set();
            //        newSet4.SetId = 4;
            //        newSet4.SetName = "CTS/C";
            //        newSet4.SetValue = this.drpCTSC.SelectedValue;
            //        BLL.Sys_SetService.AddSysSet(newSet4);
            //    }
            //}

            //if (this.drpCTMT.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpCTMT.SelectedValue))
            //{
            //    Model.Sys_Set set5 = BLL.Sys_SetService.GetSetById(5);
            //    if (set5 != null)
            //    {
            //        set5.SetValue = this.drpCTMT.SelectedValue;
            //        BLL.Sys_SetService.UpdateSysSet(set5);
            //    }
            //    else
            //    {
            //        Model.Sys_Set newSet5 = new Model.Sys_Set();
            //        newSet5.SetId = 5;
            //        newSet5.SetName = "CTM/T";
            //        newSet5.SetValue = this.drpCTMT.SelectedValue;
            //        BLL.Sys_SetService.AddSysSet(newSet5);
            //    }
            //}
            if (!string.IsNullOrEmpty(this.txtDes.Text.Trim()))
            {
                Model.Sys_Set set6 = BLL.Sys_SetService.GetSetById(6);
                if (set6 != null)
                {
                    set6.SetValue = this.txtDes.Text.Trim();
                    BLL.Sys_SetService.UpdateSysSet(set6);
                }
                else
                {
                    Model.Sys_Set newSet6 = new Model.Sys_Set();
                    newSet6.SetId = 6;
                    newSet6.SetName = "评价说明";
                    newSet6.SetValue = this.txtDes.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
    }
}