using System;
using System.Linq;
using BLL;

namespace FineUIPro.Web.SysManage
{
    public partial class SystemMenuSetEdit : PageBase
    {
        #region 单位主键
        /// <summary>
        /// 单位主键
        /// </summary>
        public string MenuId
        {
            get
            {
                return (string)ViewState["MenuId"];
            }
            set
            {
                ViewState["MenuId"] = value;
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               this.MenuId=Request.Params["MenuId"];
                if (!string.IsNullOrEmpty(MenuId))
                {
                    var menu=BLL.SysMenuService.GetSys_MenuById(MenuId);
                    if (menu != null)
                    {
                        this.txtMenuName.Text = menu.MenuName; 
                        this.txtUrl.Text = menu.Url;
                        this.txtSortIndex.Text = menu.SortIndex.ToString();
                        this.rbIsUsed.SelectedValue=menu.IsUsed.ToString()=="True"?"1":"0";

                    }
                    
                }
            }
        }

        /// <summary>
        /// 保存按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var menu = BLL.SysMenuService.GetSys_MenuById(MenuId);
            if (menu != null)
            {

                 menu.MenuName=this.txtMenuName.Text;
                 menu.Url= this.txtUrl.Text ;
                 menu.SortIndex = Funs.GetNewInt(this.txtSortIndex.Text);
                if (this.rbIsUsed.SelectedValue=="1")
                {
                    menu.IsUsed =true ;

                }
                else
                {
                    menu.IsUsed = false;

                }
                SysMenuService.UpdateSys_Menu(menu);
            }

            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
        }

        #region 获取按钮权限
        /// <summary>
        /// 获取按钮权限
        /// </summary>
        /// <param name="button"></param>
        /// <returns></returns>
        private void GetButtonPower()
        {
            var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.UnitMenuId);
            if (buttonList.Count() > 0)
            {
                if (buttonList.Contains(BLL.Const.BtnSave))
                {
                    this.btnSave.Hidden = false;
                }
            }
        }
        #endregion        

    }
}