コード例 #1
0
        public void ReadFormConfig_Test()
        {
            var services = new ServiceCollection();

            services.AddCodePlugService();
            services.AddScoped <IUnitOfDapper>(p =>
            {
                return(new DapperContext("server=118.24.146.107;port=3306;uid=root;pwd=mypassword;database=Spoondrift;Min Pool Size=0;Pooling=true;connect timeout=120;CharSet=utf8mb4;SslMode=none;"));
            });
            services.AddScoped <Xml2DB>();
            var provide  = services.BuildServiceProvider();
            var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "modules", "RC_Role.xml");
            var config   = XmlUtil.ReadFromFile <ModuleConfig>(filePath);

            config.Forms.Cast <FormConfig>().ToList().ForEach(a =>
            {
                IListDataTable dt = provide.GetCodePlugService <IListDataTable>(a.DataPlug);
                var formPath      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "forms", a.File);
                var dataForm      = XmlUtil.ReadFromFile <DataFormConfig>(formPath);
                var xml2Db        = services.BuildServiceProvider().GetService <Xml2DB>();
                xml2Db.Migrations(dataForm);    //创建表               //dt.Initialize();
                var postDataSet = new DataSet();
                dt.Initialize(new ModuleFormInfo(postDataSet, 10, "", "",
                                                 a.TableName, dataForm.PrimaryKey, "", false, dataForm, a.OrderSql, a));
                var list = dt.List;
                var data = new DataSet();
                dt.AppendTo(data);    //数据获取
                var dataTable = data.Tables[a.Name];

                //Console.WriteLine(dataForm.Name);
            });

            BasePageViewCreator pageCreator = provide.GetCodePlugService <BasePageViewCreator>("ListPageView");

            pageCreator.Initialize(config, JsonConvert.DeserializeObject <DataSet>(""), null, "", false);
            var apcv = pageCreator.Create();
            var json = JsonConvert.SerializeObject(apcv);

            Assert.AreEqual("角色", config.Title);
        }
コード例 #2
0
        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();
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        protected void Merge(string ds, string xml, string pageStyle, out IPageViewTool toolOut, List <Func <SubmitData, SubmitData> > resultFunList)
        {
            xml = Xml(xml);
            ModuleConfig config = xml.SingletonByPage <ModuleConfig>();

            var tool = GetPageViewTool(config);

            toolOut = tool;
            tool.BeginModuleMergeInterceptor(ref ds, ref xml, ref pageStyle, ref config);
            config = xml.SingletonByPage <ModuleConfig>();
            //FormConfig fc = config.Forms[0];
            //string plugName = fc.DataPlug;
            //IListDataTable source = plugName.PlugInPageGet<IListDataTable>();
            if (config.DataBase != null)
            {
                var app = AtawAppContext.Current;

                app.UnitOfData = config.DataBase.FetchUnitofData();
            }
            SetPostDataSet(ds);
            var forms = config.Forms;
            //int result = 0;
            //AtawDbContext dbContext = null;
            string foreignKey = "";

            forms.Where(a => a is FormConfig).Cast <FormConfig>().ToList().ForEach(form =>
            {
                //if (form.Action == PageStyle.Insert || form.Action == PageStyle.Update)
                //{
                IListDataTable source = form.DataPlug.InstanceByPage <IListDataTable>(form.Name);
                if (config.Mode == ModuleMode.MasterDetail)
                {
                    var relation = config.Relations.FirstOrDefault(a => a.DetailForm == form.Name);
                    foreignKey   = relation == null ? "" : relation.DetailField;
                }

                var dataForm = form.File.InstanceByPage <DataFormConfig>(form.Name);
                if (dataForm.PrimaryKey.IsEmpty())
                {
                    dataForm.PrimaryKey = dataForm.Columns.First(col => col.IsKey).Name;
                }
                if (pageStyle.IsEmpty())
                {
                    pageStyle = form.Action.ToString();
                }

                List <ColumnConfig> _fullColumns = null;


                AtawBaseFormViewCreator.MergeColumns(form, dataForm, config, pageStyle.Value <PageStyle>(), out _fullColumns);

                source.Initialize(new ModuleFormInfo(this.PostDataSet, 0, "", "", form.TableName, "", foreignKey,
                                                     false, dataForm, form.OrderSql, config.DataBase, form)
                {
                    FullColumns = _fullColumns
                }
                                  );
                source.Merge(true);
                resultFunList.Add(source.SubmitFilterFun);
                // source.SubmitFilterEvent(null);
                //}
                //if (dbContext == null && source is BaseDataTableSource)
                //{
                //    dbContext = ((BaseDataTableSource)source).DbContext;
                //}
            });
        }