private static ColumnRightConfig GetColumnRight(FormConfig form, DataFormConfig dataForm, ModuleConfig moduleConfig)
        {
            ColumnRightConfig columnRight     = null;
            string            columnRightname = form.FormColumnRight.Name;

            if (form.FormColumnRight.RegName.IsEmpty())
            {
                AtawDebug.AssertArgumentNullOrEmpty(columnRightname, "FormColumnRight中若没指定RegName,Name属性不能为空", moduleConfig);
                columnRight = moduleConfig.Right.ColumnRights.FirstOrDefault(a => a.Name == columnRightname);
                AtawDebug.AssertArgumentNull(columnRight, string.Format("ModuleXml中必须配置名为'{0}'的ColumnRight", columnRightname), moduleConfig);
            }
            else
            {
                IColumnRight columnRightPlug = form.FormColumnRight.RegName.CodePlugIn <IColumnRight>();
                columnRightname = columnRightPlug.GetColumnRightName();
                columnRight     = moduleConfig.Right.ColumnRights.FirstOrDefault(a => a.Name == columnRightname);
                AtawDebug.AssertArgumentNull(columnRight, string.Format("ModuleXml中必须配置名为'{0}'的ColumnRight", columnRightname), moduleConfig);
            }
            return(columnRight);
        }
        public static void MergeColumns(FormConfig form, DataFormConfig dataForm, ModuleConfig moduleConfig, PageStyle pagestyle, out List <ColumnConfig> fullColumns)
        {
            if (form.FormColumnRight != null)
            {
                ColumnRightConfig columnRight = GetColumnRight(form, dataForm, moduleConfig);
                if (columnRight.Delete != null)
                {
                    columnRight.Delete.ForEach(dCol =>
                    {
                        var col = dataForm.Columns.FirstOrDefault(baseCol => baseCol.Name.Equals(dCol.Name, StringComparison.OrdinalIgnoreCase));
                        if (col != null)
                        {
                            dataForm.Columns.Remove(col);
                        }
                    });
                }
                if (columnRight.Override != null)
                {
                    columnRight.Override.ForEach(oCol =>
                    {
                        var col = dataForm.Columns.FirstOrDefault(baseCol => baseCol.Name.Equals(oCol.BaseColumnName, StringComparison.OrdinalIgnoreCase));
                        if (col != null)
                        {
                            AssignColumn(oCol, col);
                        }
                    });
                }
                if (columnRight.Add != null)
                {
                    dataForm.Columns.AddRange(columnRight.Add);
                }
            }
            fullColumns = new List <ColumnConfig>();

            fullColumns = dataForm.Columns;

            dataForm.Columns = dataForm.Columns.Where(a => a.ShowPage.HasFlag(pagestyle)).ToList();
        }
        protected virtual void FillDataSet(FormConfig fc)
        {
            IListDataTable dt = fc.DataPlug.InstanceByPage <IListDataTable>(fc.Name);

            dt.PageStyle = PageStyle;
            var dataForm = fc.File.InstanceByPage <DataFormConfig>(fc.Name);
            var keyCols  = dataForm.Columns.Where(a => a.IsKey);

            if (keyCols != null)
            {
                AtawDebug.Assert(keyCols.ToList().Count == 1, string.Format("{0}只能指定一个主键", fc.File), dataForm);
            }
            if (dataForm.PrimaryKey.IsEmpty())
            {
                dataForm.PrimaryKey = dataForm.Columns.First(col => col.IsKey).Name;
            }
            MergeColumns(fc, dataForm, ModuleConfig);
            //dt.Initialize(this.PostDataSet, ModuleConfig.PageSize, KeyValue, ForeignKeyValue, fc.TableName, dataForm.PrimaryKey);
            int pageSize = 0;

            if (fc.Pager != null)
            {
                pageSize = fc.Pager.PageSize;
            }
            string foreignKey = GetForeignKey(fc);

            if (!foreignKey.IsEmpty())
            {
                string _foreignKeyValue = KeyValue;
                var    _relations1      = this.ModuleConfig.Relations.Where(a => a.DetailForm == fc.Name).ToList();
                if (_relations1.Count > 0)
                {
                    var    _ra           = _relations1.First();
                    string __relationKey = "_foreignkey_{0}_{1}".AkFormat(_ra.MasterForm, _ra.MasterField);
                    if (AtawAppContext.Current.GetItem(__relationKey) != null)
                    {
                        _foreignKeyValue = AtawAppContext.Current.GetItem(__relationKey).ToString();
                    }
                    else
                    {
                        _foreignKeyValue = KeyValue;
                    }
                }

                dt.Initialize(new ModuleFormInfo(this.PostDataSet, pageSize, KeyValue, _foreignKeyValue,
                                                 fc.TableName, dataForm.PrimaryKey, foreignKey, IsFillEmpty, dataForm, fc.OrderSql, ModuleConfig.DataBase, fc));
            }
            else
            {
                dt.Initialize(new ModuleFormInfo(this.PostDataSet, pageSize, KeyValue, "", fc.TableName,
                                                 dataForm.PrimaryKey, "", IsFillEmpty, dataForm, fc.OrderSql, ModuleConfig.DataBase, fc));
            }

            //  if(this.ModuleConfig.Relations.Find(a=>a.MasterForm == fc.Name))
            var _relations = this.ModuleConfig.Relations.Where(a => a.MasterForm == fc.Name).ToList();

            if (dt.List.Count() > 0)
            {
                var row = dt.List.ToList()[0];
                if (_relations.Count > 0)
                {
                    _relations.ForEach((_relation) => {
                        string _key          = _relation.MasterField;
                        object _value        = row.Row[_key];
                        string __relationKey = "_foreignkey_{0}_{1}".AkFormat(_relation.MasterForm, _relation.MasterField);
                        AtawAppContext.Current.SetItem(__relationKey, _value);
                    });
                }
            }

            if (PageStyle != PageStyle.Insert)
            {
                var _list  = dt.List;
                var __list = _list.ToList();
                __list.ForEach(a =>
                {
                    if (!fc.ButtonRightPlug.IsEmpty())
                    {
                        var gh         = fc.ButtonRightPlug.CodePlugIn <IButtonRight>();
                        var buttons    = gh.GetButtons(a, dt.List);
                        a.BUTTON_RIGHT = SetDataBtnFilterButtonConfig(buttons);
                    }
                    if (fc.HasReview)
                    {
                        a.BUTTON_RIGHT = a.BUTTON_RIGHT + "|Review";
                    }
                });

                dt.AppendTo(this.BasePageView.Data);
                //给数据源添加虚拟字段
                var dataTable = this.BasePageView.Data.Tables[dt.RegName];
                if (dataTable != null)
                {
                    var virtualCols = dataForm.Columns.Where(a => a.Kind == ColumnKind.Virtual && !a.SourceName.IsEmpty());
                    if (virtualCols != null)
                    {
                        foreach (var col in virtualCols)
                        {
                            dataTable.Columns.Add(col.Name);
                            foreach (DataRow row in dataTable.Rows)
                            {
                                row[col.Name] = row[col.SourceName].ToString();
                            }
                        }
                    }
                }
            }
        }
        protected virtual void CreateColumns(AtawFormConfigView formView, DataFormConfig dataformConfig, FormConfig formConfig)
        {
            foreach (var column in dataformConfig.Columns)
            {
                if ((column.ShowPage & PageStyle) != PageStyle)
                {
                    continue;
                }
                else
                {
                    //var col = CreateColumn(formView, column);
                    ////列表和明细页面的所有字段控件类型为Detail
                    //if (!column.IsKey && (PageStyle == PageStyle.Detail || PageStyle == PageStyle.List))
                    //    col.ControlType = ControlType.Detail;
                    //formView.Columns.Add(col);
                    formView.Columns.Add(CreateColumn(formView, column));

                    //if (column.Navigation != null && column.Navigation.IsAvailable == true)
                    //{
                    //    formView.NavigationColumns.Add(CreateColumnNavigation(formView, column));
                    //}
                }
            }
        }
        protected AtawFormConfigView CreateFormView(DataFormConfig dataForm, FormConfig formConfig)
        {
            AtawFormConfigView formView = new AtawFormConfigView();

            formView.FormType           = formConfig.FormType;
            formView.ShowKind           = formConfig.ShowKind;
            formView.AfterInitFunName   = formConfig.AfterInitFunName;
            formView.VerticalTab        = formConfig.VerticalTab; //布局方式
            formView.HasBatchInsert     = false;
            formView.HasPager           = false;
            formView.HasSearch          = false;
            formView.ParentFieldName    = formConfig.ParentFieldName;
            formView.TextFieldName      = formConfig.TextFieldName;
            formView.IsParentFieldName  = formConfig.IsParentFieldName;
            formView.IsSafeMode         = formConfig.IsSafeMode;
            formView.HasReview          = formConfig.HasReview;
            formView.Calendar           = formConfig.Calendar;
            formView.ExpandDetailPlug   = formConfig.ExpandDetailPlug;
            formView.RowTpl             = formConfig.RowTpl;
            formView.ContentTpl         = formConfig.ContentTpl;
            formView.DisableColumnGroup = formConfig.Group.IsDisabled.ToLower() == "true" || formConfig.Group.IsDisabled == "1" ? true : false;
            // formView.Tpl = formConfig.Tpl;
            var _bean = formConfig.Tpls.FirstOrDefault(a => a.PageStyle == PageStyle);

            if (_bean != null)
            {
                formView.Tpl = _bean.Item;
            }


            formView.IsInner          = formConfig.IsInner;
            formView.HaveNoSwitchForm = formConfig.HaveNoSwitchForm;
            formView.HaveNoSortBar    = formConfig.HaveNoSortBar;
            //var NavigationList = dataForm.Columns.Where(a => a.Navigation != null);
            //if (NavigationList.Count() > 0)
            //{
            //    formView.HasNavigation = true;
            //     List<ColumnConfig> columns = NavigationList.ToList();
            //     foreach (var column in columns)
            //     {
            //         AtawColumnConfigView colView = new AtawColumnConfigView();
            //         if (column.Navigation != null && column.Navigation.IsAvailable == true && (column.ControlType == ControlType.CheckBox || column.ControlType == ControlType.Combo || column.ControlType == ControlType.Radio || column.ControlType == ControlType.TreeSingleSelector || column.ControlType == ControlType.TreeMultiSelector))
            //         {
            //             if (column.ControlType == ControlType.CheckBox)
            //             {
            //                 colView.ControlType = ControlType.CheckBoxNavi;
            //             }
            //             else if (column.ControlType == ControlType.Radio || column.ControlType == ControlType.Combo)
            //             {
            //                 colView.ControlType = ControlType.RadioNavi;
            //             }
            //             else if (column.ControlType == ControlType.TreeSingleSelector)
            //             {
            //                 colView.ControlType = ControlType.TreeSingleNavi;
            //             }
            //             else
            //             {
            //                 colView.ControlType = ControlType.TreeMultiNavi;
            //             }
            //         }
            //     }
            //}
            formView.TableName = formConfig.TableName;
            //if (formView.TableName.IsEmpty())
            //    formView.TableName = dataForm.TableName;
            //if (formView.TableName.IsEmpty())
            //    formView.TableName = formConfig.DataPlug.PlugInPageGet<IListDataTable>().RegName;

            formView.Title = formConfig.Title;
            //if (formView.Title.IsEmpty())
            //    formView.Title = dataForm.Title;
            //if (formView.Title.IsEmpty())
            //    formView.Title = ModuleConfig.Title;
            if (ModuleConfig.Mode == ModuleMode.None)
            {
                formView.Title = formView.Title;
            }
            else
            {
                switch (PageStyle)
                {
                case PageStyle.List:
                    formView.Title = formView.Title + "列表";
                    break;

                case PageStyle.Detail:
                    formView.Title = formView.Title + "明细";
                    break;

                case PageStyle.Update:
                    formView.Title = formView.Title + "修改";
                    break;

                case PageStyle.Insert:
                    formView.Title = formView.Title + "新增";
                    break;
                }
            }

            formView.Name = formConfig.Name;
            //if (formView.Name.IsEmpty())
            //    formView.Name = dataForm.Name;
            //if (formView.Name.IsEmpty())
            //    formView.Name = formView.TableName;
            //string msg = string.Format("数据源为{0}插件的form的名称不能为空", formConfig.DataPlug);
            //AtawDebug.AssertNotNullOrEmpty(formView.Name, msg, this);
            formView.Columns = new List <AtawColumnConfigView>();
            CreateColumns(formView, dataForm, formConfig);

            formView.ColumnGroups = new List <AtawColumnGroupConfigView>();
            CreateGroupColumns(formView, dataForm);

            formView.NavigationColumns = new List <AtawNaviColumnConfigView>(); //可能有多个navi(目前只有一个)
            if (PageStyle == Core.PageStyle.List)
            {
                var navigation = dataForm.Columns.FindAll(a => a.Navigation != null && a.Navigation.IsAvailable);
                foreach (var navi in navigation)
                {
                    if (navigation != null)
                    {
                        var viewColumn = formView.Columns.FirstOrDefault(a => a.Name == navi.Name);
                        var viewNavi   = CreateColumnNavigation(viewColumn, navi);
                        if (viewNavi != null)
                        {
                            formView.NavigationColumns.Add(viewNavi);
                        }
                    }
                }
            }
            return(formView);
        }