Esempio n. 1
0
        /// <summary>
        /// Loads the shape definition file.
        /// </summary>
        /// <param name="name">Name of shape.</param>
        /// <param name="data">Data that is passed to the shape object (not the form, the
        /// object that aids the Form).</param>
        public void LoadDefinition(string name, object data)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            _filename = FormConfigs.GetShapeFile(name);

            _definition = new XmlDocument(FormsNamespace.NamespaceManager.NameTable);
            _definition.Load(_filename);

            XmlElement attributesElem = (XmlElement)_definition.SelectSingleNode("/shape/attributes", FormsNamespace.NamespaceManager);

            if (attributesElem == null)
            {
                throw new ArgumentException("Missing attributes element.", "doc");
            }

            XmlNode formSize = (XmlElement)_definition.SelectSingleNode("/shape/properties/size", FormsNamespace.NamespaceManager);

            if (formSize != null)
            {
                if (formSize.Attributes["width"] != null && formSize.Attributes["width"].Value != null && formSize.Attributes["width"].Value.ToString().Length > 0)
                {
                    _formWidth = int.Parse(formSize.Attributes["width"].Value.ToString());
                }
                if (formSize.Attributes["height"] != null && formSize.Attributes["height"].Value != null && formSize.Attributes["height"].Value.ToString().Length > 0)
                {
                    _formHeight = int.Parse(formSize.Attributes["height"].Value.ToString());
                }
                ManageShapeSize();
            }
            string moniker = attributesElem.Attributes["moniker"].Value;

            object[] ctorArgs = new object[] { data, this, attributesElem };

            this.Tag = TypeFactory.Create(moniker, ctorArgs);
        }
        /// <summary>
        /// 对ModuleConfig进行再处理,FormName不为空时则只对单个Form处理(例如,多表中对某张表进行查询)
        /// </summary>
        /// <param name="moduleConfig"></param>
        /// <returns></returns>
        private ModuleConfig AnalysisModule(ModuleConfig moduleConfig)
        {
            FormConfigs = moduleConfig.Forms.Where(a => a is FormConfig)
                          .Cast <FormConfig>()
                          .Where(a => IsSupportPage(a.SupportPage, this.PageStyle));
            MvcFormConfigs = moduleConfig.Forms.Where(a => a is MvcFormConfig) == null ? null :
                             moduleConfig.Forms.Where(a => a is MvcFormConfig).Cast <MvcFormConfig>();
            SeaFormConfigs = moduleConfig.Forms.Where(a => a is SeaFormConfig) == null ? null :
                             moduleConfig.Forms.Where(a => a is SeaFormConfig).Cast <SeaFormConfig>();

            ScriptFormConfigs = moduleConfig.Forms.Where(a => a is ScriptFormConfig) == null ? null :
                                moduleConfig.Forms.Where(a => a is ScriptFormConfig).Cast <ScriptFormConfig>();

            //if (moduleConfig.Mode == ModuleMode.MasterDetail)
            //{
            // AtawDebug.AssertArgumentNull(moduleConfig.Relations, "主从表必须配置Relation", this);
            //BasePageView.KeyValue = KeyValue;  //主从表修改时,主表主键需要传递给前台
            // }
            #region 非空属性赋值
            //Form配置中Name或TableName或Title可能没有值,此时需要赋值
            moduleConfig.Forms.ForEach(a =>
            {
                if (a is FormConfig)
                {
                    var form     = a as FormConfig;
                    var dataForm = form.File.InstanceByPage <DataFormConfig>(a.Name);

                    if (form.TableName.IsEmpty())
                    {
                        form.TableName = dataForm.TableName;
                    }
                    if (form.TableName.IsEmpty())
                    {
                        form.TableName = form.DataPlug.InstanceByPage <IListDataTable>(a.Name).RegName;
                    }
                    if (a.Name.IsEmpty())
                    {
                        a.Name = dataForm.Name;
                    }
                    if (a.Name.IsEmpty())
                    {
                        a.Name = form.TableName;
                    }
                    a.Width    = form.Width;
                    string msg = string.Format("数据源为{0}插件的form的名称不能为空", form.DataPlug);
                    AtawDebug.AssertNotNullOrEmpty(form.Name, msg, this);

                    if (a.Title.IsEmpty())
                    {
                        a.Title = dataForm.Title;
                    }
                    if (a.Title.IsEmpty())
                    {
                        a.Title = moduleConfig.Title;
                    }
                }
                if (a is MvcFormConfig)
                {
                    var mvcForm = a as MvcFormConfig;
                    AtawDebug.AssertNotNull(mvcForm.DataRoute, "MvcForm需要配置DataRoute", this);
                    var dataRoute = AtawAppContext.Current.MvcConfigXml.DataRoutes.FirstOrDefault(route => route.Name == mvcForm.DataRoute.Name);
                    if (dataRoute != null)
                    {
                        mvcForm.DataRoute.ActionName  = dataRoute.ActionName;
                        mvcForm.DataRoute.ControlName = dataRoute.ControlName;
                        mvcForm.DataRoute.AreaName    = dataRoute.AreaName;
                        mvcForm.DataRoute.NameSpace   = dataRoute.NameSpace;
                    }
                    else
                    {
                        if (mvcForm.DataRoute.ControlName.IsEmpty())
                        {
                            AtawDebug.AssertNotNullOrEmpty(mvcForm.DataRoute.ControlName, "DataRoute的ControlName不能为空", this);
                        }
                        if (mvcForm.DataRoute.ActionName.IsEmpty())
                        {
                            AtawDebug.AssertNotNullOrEmpty(mvcForm.DataRoute.ActionName, "DataRoute的ActionName不能为空", this);
                        }
                        if (mvcForm.DataRoute.AreaName.IsEmpty())
                        {
                            AtawDebug.AssertNotNullOrEmpty(mvcForm.DataRoute.AreaName, "DataRoute的AreaName不能为空", this);
                        }
                        if (mvcForm.DataRoute.NameSpace.IsEmpty())
                        {
                            AtawDebug.AssertNotNullOrEmpty(mvcForm.DataRoute.NameSpace, "DataRoute的NameSpace不能为空", this);
                        }
                    }
                }
            });
            #endregion

            #region 主从表批量修改或显示明细时,现只针对主表操作
            if (PostDataSet != null && PostDataSet.Tables.Count > 0)
            {
                DataTable dt = PostDataSet.Tables["_KEY"];
                if (dt != null)
                {
                    if (dt.Rows.Count > 1)
                    {
                        moduleConfig.Mode = ModuleMode.Single;
                    }
                    //else if (dt.Rows.Count == 1)
                    //    BasePageView.KeyValue = dt.Rows[0][0].ToString();


                    var keyValueList = new List <string>();
                    foreach (DataRow row in dt.Rows)
                    {
                        string _key = row["KeyValue"].ToString();
                        keyValueList.Add(_key);
                    }
                    BasePageView.KeyValue = String.Join <string>(",", keyValueList);
                }
            }
            #endregion

            if (FormName.IsEmpty())
            {
                if (moduleConfig.Mode == ModuleMode.Single || moduleConfig.Mode == ModuleMode.MasterDetail ||
                    moduleConfig.Mode == ModuleMode.SingleToSingle)
                {
                    var form     = FormConfigs.FirstOrDefault(a => a.IsMainTable);
                    var mainForm = form == null?FormConfigs.FirstOrDefault() : form;  //若没有配置主表,则指定第一个为主表

                    mainForm.IsMainTable = true;
                    switch (PageStyle)
                    {
                    case PageStyle.List:
                        moduleConfig.Forms.Clear();
                        mainForm.HasSearch = true;
                        moduleConfig.Forms.Add(mainForm);
                        moduleConfig.HasReview = mainForm.HasReview;
                        break;

                    case PageStyle.Insert:
                    case PageStyle.Update:
                    case PageStyle.Review:
                    case PageStyle.Detail:
                        mainForm.FormType = FormType.Normal;
                        if (moduleConfig.Mode == ModuleMode.Single)
                        {
                            moduleConfig.Forms.Clear();
                            moduleConfig.Forms.Add(mainForm);
                            moduleConfig.HasReview = mainForm.HasReview;
                        }
                        else
                        {
                            //var detailForms = FormConfigs.Where(a => !a.IsMainTable);
                            //foreach (FormConfig item in detailForms)
                            //{
                            //    item.FormType = FormType.Grid;
                            //}
                        }
                        break;
                    }
                }
            }
            else
            {
                var form = moduleConfig.Forms.Find(a => a.Name == FormName);
                AtawDebug.AssertNotNull(form, string.Format(ObjectUtil.SysCulture, "请求的formname:  {0}不存在,请检查xml文件是否有问题", FormName), this);
                //var mainForm = form == null ? moduleConfig.Forms.First() : form;//若没有配置主表,则指定第一个为主表
                //if (PageStyle == PageStyle.Insert || PageStyle == PageStyle.Detail || PageStyle == PageStyle.Update)
                //{
                //    mainForm.FormType = FormType.Normal;
                //}
                //if (moduleConfig.Mode == ModuleMode.Single)
                //{
                moduleConfig.Forms.Clear();
                moduleConfig.Forms.Add(form);
                // }
            }

            return(moduleConfig);
        }
        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);
        }