public string RightUnitExe()
 {
     if (RightType == RightType.MvcFilter)
     {
         var type = RightUtil.RightVerification(RegName);
         return(type.ToString());
     }
     else
     {
         return("");
     }
 }
        private PageHeader ValidHeader()
        {
            PageHeader header = new PageHeader();

            header.IsValid = true;
            if (!AtawAppContext.Current.IsAuthenticated)
            {
                header.IsValid = false;
                header.Message = "未登录";
            }
            else
            {
                if (PageStyle != PageStyle.None && ModuleConfig.Right != null && ModuleConfig.Right.FunctionRights != null)
                {
                    var pageStyleRight = ModuleConfig.Right.FunctionRights.PageStyleRights.FirstOrDefault(a => a.PageStyle == PageStyle);
                    if (pageStyleRight != null)
                    {
                        var rightUnit = ModuleConfig.Right.FunctionRights.RightUnits.FirstOrDefault(a => a.Name == pageStyleRight.Name);
                        AtawDebug.AssertNotNull(rightUnit, string.Format("需要配置名为{0}的RightUnit", pageStyleRight.Name), this);
                        //if (!AtawAppContext.Current.IsAuthenticated)
                        //{
                        //    header.IsValid = false;
                        //    header.Message = "未登录";
                        //}
                        //else
                        //{
                        if (rightUnit.RightType == RightType.MvcFilter)
                        {
                            var type = RightUtil.RightVerification(rightUnit.RegName);
                            switch (type)
                            {
                            case RightFilterType.UnRenew:
                                header.IsValid = false;
                                header.Message = "未续费";
                                break;

                            case RightFilterType.DenyPermission:
                                header.IsValid = false;
                                header.Message = "没有权限";
                                break;
                            }
                        }
                        // }
                    }
                }
            }
            BasePageView.Header = header;
            return(header);
        }
        public virtual AtawPageConfigView Create()
        {
            //BasePageView.Title = ModuleConfig.Title;
            #region 验证
            PageHeader header = ValidHeader();
            if (!header.IsValid)
            {
                return(BasePageView);
            }
            #endregion

            #region  钮初始化



            SetDefaultButton();
            ModuleConfig.Buttons.ToList().ForEach(
                a =>
            {
                bool isData = a.IsData;
                var bt      = new CustomButtonConfigView()
                {
                    Client      = a.Client,
                    Name        = a.Name,
                    Server      = a.Server,
                    Text        = a.Text,
                    Unbatchable = a.Unbatchable,
                    BtnCss      = a.BtnCss,
                    Icon        = a.Icon
                };

                #region  钮验证
                bool IsAuthenticated = true;
                if (ModuleConfig.Right != null && ModuleConfig.Right.FunctionRights != null)
                {
                    var buttonRight = ModuleConfig.Right.FunctionRights.ButtonRights.FirstOrDefault(b => b.ButtonName == a.Name);
                    if (buttonRight != null)
                    {
                        var rightUnit = ModuleConfig.Right.FunctionRights.RightUnits.FirstOrDefault(b => b.Name == buttonRight.Name);
                        AtawDebug.AssertNotNull(rightUnit, string.Format("需要配置名为{0}的RightUnit", buttonRight.Name), this);
                        if (rightUnit.RightType == RightType.MvcFilter)
                        {
                            var type        = RightUtil.RightVerification(rightUnit.RegName);
                            IsAuthenticated = type == RightFilterType.Success;
                        }
                    }
                }
                #endregion
                if (IsAuthenticated)
                {
                    if (isData)
                    {
                        if (!BasePageView.DataButtons.Keys.Contains(a.Name))
                        {
                            BasePageView.DataButtons.Add(a.Name, bt);
                        }
                    }
                    else
                    {
                        if (!BasePageView.PageButtons.Keys.Contains(a.Name))
                        {
                            BasePageView.PageButtons.Add(a.Name, bt);
                        }
                    }
                }
            }
                );
            #endregion

            Dictionary <string, AtawFormConfigView> formViewDict = new Dictionary <string, AtawFormConfigView>();
            //创建Form
            FormConfigs.ToList().ForEach(form =>
            {
                FillDataSet(form);
                AtawBaseFormViewCreator formViewCreator = null;
                if (PageStyle != PageStyle.None)
                {
                    formViewCreator = (PageStyle.ToString() + "Form").InstanceByPage <AtawBaseFormViewCreator>(form.Name);
                }
                else
                {
                    form.Action = form.Action == PageStyle.None ? PageStyle.List : form.Action;
                    if (form.Action == PageStyle.Insert)  //ModulePage中如果Form的Action为Insert,则视为Update状态下的批量新增
                    {
                        formViewCreator = ("UpdateForm").InstanceByPage <AtawBaseFormViewCreator>(form.Name);
                    }
                    else
                    {
                        formViewCreator = (form.Action.ToString() + "Form").InstanceByPage <AtawBaseFormViewCreator>(form.Name);
                    }
                }
                formViewCreator.Initialize(ModuleConfig, form, BasePageView);
                var formViews = formViewCreator.Create();
                formViews.ToList().ForEach(view =>
                {
                    formViewDict.Add(view.Name, view);
                });
                //viewDict.Add(formView.Name, formView);
                //var info = new FormConfigInfo();
                //info.DataForm = dataForm;
                //info.FormConfig = a;
                //info.FormView = formView;
                //infoList.Add(info);
            });

            Dictionary <string, AtawMvcFormConfigView> mvcFormViewDict = new Dictionary <string, AtawMvcFormConfigView>();
            //创建MvcForm
            if (MvcFormConfigs != null)
            {
                MvcFormConfigs.Cast <MvcFormConfig>().ToList().ForEach(a =>
                {
                    AtawMvcFormConfigView mvcFormView = new AtawMvcFormConfigView();
                    mvcFormView.Title     = a.Title;
                    mvcFormView.Name      = a.Name;
                    mvcFormView.ShowType  = a.ShowType;
                    mvcFormView.ShowKind  = a.ShowKind;
                    mvcFormView.DataRoute = a.DataRoute;
                    mvcFormViewDict.Add(mvcFormView.Name, mvcFormView);
                });
            }

            Dictionary <string, AtawSeaFormConfigView> seaFormViewDict = new Dictionary <string, AtawSeaFormConfigView>();
            //创建MvcForm
            if (SeaFormConfigs != null)
            {
                SeaFormConfigs.Cast <SeaFormConfig>().ToList().ForEach(a =>
                {
                    AtawSeaFormConfigView seaFormView = new AtawSeaFormConfigView();
                    seaFormView.Title          = a.Title;
                    seaFormView.Name           = a.Name;
                    seaFormView.ShowType       = a.ShowType;
                    seaFormView.ShowKind       = a.ShowKind;
                    seaFormView.SeaInformation = a.SeaInformation;
                    seaFormViewDict.Add(seaFormView.Name, seaFormView);
                });
            }


            Dictionary <string, AtawScriptFormConfigView> scriptFormViewDict = new Dictionary <string, AtawScriptFormConfigView>();
            //创建MvcForm
            if (ScriptFormConfigs != null)
            {
                ScriptFormConfigs.Cast <ScriptFormConfig>().ToList().ForEach(a =>
                {
                    AtawScriptFormConfigView scriptFormView = new AtawScriptFormConfigView();
                    scriptFormView.Title    = a.Title;
                    scriptFormView.Name     = a.Name;
                    scriptFormView.ShowKind = a.ShowKind;
                    if (a.ScriptFunName.IsEmpty())
                    {
                        scriptFormView.ScriptFormFunName = a.Name;
                    }
                    else
                    {
                        scriptFormView.ScriptFormFunName = a.ScriptFunName;
                    }
                    scriptFormViewDict.Add(scriptFormView.Name, scriptFormView);
                });
            }



            //设置布局:当form不以tab连续布局时,则默认tile布局
            #region Layout
            BasePageView.Layout = new List <PanelList>();
            var previousKind = ShowKind.None;
            int i            = 0;
            //int count = 0;
            ModuleConfig.Forms.ForEach(a =>
            {
                PanelList panelList = null;
                if (ModuleConfig.Forms.Count > 1)
                {
                    if (i == 0)
                    {
                        if (a.ShowKind == ShowKind.Tab && ModuleConfig.Forms[i + 1].ShowKind == ShowKind.Tile)
                        {
                            a.ShowKind = ShowKind.Tile;
                        }
                    }
                    else if (i == ModuleConfig.Forms.Count - 1)
                    {
                        if (a.ShowKind == ShowKind.Tab && ModuleConfig.Forms[i - 1].ShowKind == ShowKind.Tile)
                        {
                            a.ShowKind = ShowKind.Tile;
                        }
                    }
                    else if (a.ShowKind == ShowKind.Tab && ModuleConfig.Forms[i - 1].ShowKind == ShowKind.Tile &&
                             ModuleConfig.Forms[i + 1].ShowKind == ShowKind.Tile)
                    {
                        a.ShowKind = ShowKind.Tile;
                    }
                    i++;
                }
                else
                {
                    a.ShowKind = ShowKind.Tile;
                }

                if (previousKind != a.ShowKind)
                {
                    panelList = new PanelList();

                    //panelList.VerticalTab = a.VerticalTab;
                    //if (panelList.VerticalTab)
                    //{
                    //    count++;

                    //}
                    //else if (count > 0)
                    //{
                    //    panelList.VerticalTab = false ? true : true;
                    //}
                    panelList.ShowKind  = a.ShowKind;
                    previousKind        = a.ShowKind;
                    List <Panel> panels = new List <Panel>();
                    Panel panel         = new Panel();
                    panel.FormName      = a.Name;
                    panels.Add(panel);
                    panelList.Panels = panels;
                    BasePageView.Layout.Add(panelList);
                }
                else
                {
                    Panel panel    = new Panel();
                    panel.FormName = a.Name;
                    //BasePageView.Layout[BasePageView.Layout.Count - 1].VerticalTab = a.VerticalTab;
                    //if (BasePageView.Layout[BasePageView.Layout.Count - 1].VerticalTab)
                    //{
                    //    count++;
                    //}
                    //if (count > 0)
                    //{
                    //    BasePageView.Layout[BasePageView.Layout.Count - 1].VerticalTab = false ? true : true;
                    //}

                    BasePageView.Layout[BasePageView.Layout.Count - 1].Panels.Add(panel);
                }
            });

            BasePageView.Layout.ForEach(a =>
            {
                if (a.ShowKind == ShowKind.Tab)
                {
                    var form = ModuleConfig.Forms.FirstOrDefault(b => b.VerticalTab);
                    if (form != null)
                    {
                        a.VerticalTab = true;
                    }
                }
            });
            #endregion

            //FormViews = viewDict;
            //FormInfoList = infoList;
            BasePageView.Title      = ModuleConfig.Title;
            BasePageView.PageLayout = ModuleConfig.Layout;
            BasePageView.Route      = ModuleConfig.Route;
            BasePageView.IsPart     = ModuleConfig.IsPart;

            BasePageView.BeforeHook = ModuleConfig.BeforeHook;
            BasePageView.AfterHook  = ModuleConfig.AfterHook;
            BasePageView.TsHook     = ModuleConfig.TsHook;

            //BasePageView.Forms = FormViews;
            SetReturnUrl();
            BasePageView.Forms       = formViewDict;
            BasePageView.MvcForms    = mvcFormViewDict;
            BasePageView.SeaForms    = seaFormViewDict;
            BasePageView.ScriptForms = scriptFormViewDict;
            //动态加载的js赋值
            if (ModuleConfig.Mode == ModuleMode.None)
            {
                BasePageView.Scripts = ModuleConfig.Scripts.Where(a => a.Style == Core.PageStyle.All || a.Style == Core.PageStyle.None).ToList();
            }
            else
            {
                var scripts = ModuleConfig.Scripts.Where(a => a.Style == Core.PageStyle.All || a.Style == Core.PageStyle.None || a.Style == PageStyle).ToList();
                //FirstOrDefault(a => (a.Style & PageStyle) == PageStyle);
                BasePageView.Scripts = scripts;
            }
            BasePageView.Scripts.ForEach(a =>
            {
                if (a != null && !a.Path.IsEmpty() && a.Path.IndexOf("/") != 0) //相对路径
                {
                    a.Path = string.Format("/Scripts/{0}", a);
                }
            });

            BasePageView.PageSourceData = AtawAppContext.Current.PageFlyweight.PageItems["PageSourceData"].Value <string>();

            return(BasePageView);
        }