Lith 7 months ago
parent
commit
8d68c2bd4c

+ 52 - 5
doc/AutoTemp.README.md

@@ -28,13 +28,60 @@
 
 # 可通过修改数据库字段的注释或者数据模型实体的注释来配置字段控件属性。如:
 
-
- 
+``` csharp
+
+
+[[AutoTemp: {...} ]] 
+[[AutoTemp_Field:Ignore]]     
+[[AutoTemp_Field: {...} ]]   
+
+
+// Example:
+
+
+
+/// [[AutoTemp: {
+///     "permit": {"delete":false},
+///     "idField": "id",
+///     "pidField": "pid",
+///     "treeField": 'title',
+///     "rootPidValue": 0 ,
+/// 
+///     "listConfig": {
+///         "title": "autoTemp-demo",
+///         "listButtons": [
+///             {
+///                 "title": "执行js",
+///                 "jsHandler": "(sender)=>{ sender.progressStart(sender.title); setTimeout(sender.progressStop,5000); }" // sender: { ...button,  progressStart,progressStop }
+///             }
+///         ],
+///         "rowButtons": [
+///             {
+///                 "title": "查看id",
+///                 "jsHandler": "(sender,id,row)=>{ sender.progressStart(sender.title); setTimeout(sender.progressStop,5000); }" // sender: { ...button,  progressStart,progressStop }
+///             }
+///         ]
+///     }
+/// } ]]
+
+
+/// [[AutoTemp: { "permit": {"delete":false}   } ]]
+
+/// [[AutoTemp_Field: {
+///     "visible":false,
+///     "list_config": {"width":250},
+///     "ig_attr": {"ig_class":"TextArea", "ig_param":{"height":250} }
+/// } ]]
+
+/// [[AutoTemp_Field:Ignore]] 
+/// [[AutoTemp_Field: {   "visible":false  } ]]
+/// [[AutoTemp_Field: {   "editable":false  } ]]
+/// [[AutoTemp_Field: { "list_config": {"width":100}   } ]]
  
-    [[AutoTemp: {...} ]] 
-    [[AutoTemp_Field:Ignore]]     
-    [[AutoTemp_Field: {...} ]]   
+/// <span title='数据库连接字符串'>连接字符串</span>
+/// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea"} } ]]
 
+```
 
 
  注释:

+ 9 - 9
doc/controllerConfig.js

@@ -6,12 +6,12 @@ var controllerConfig = {
     //},
 
     ///* 添加、修改、查看、删除 等权限,可不指定。 默认值均为true  */
-    //"//permit": {
-    //    "insert": false,
-    //    "update": false,
-    //    "show": false,
-    //    "delete": false
-    //},
+    "permit": {
+        "insert": false,
+        "update": false,
+        "show": false,
+        "delete": false
+    },
 
     "idField": "id",
     "pidField": "pid",
@@ -54,17 +54,17 @@ var controllerConfig = {
             "field": "name",   // db field
             "title": "装修商",  // [optional] defaultValue is column.field
 
-            "visiable": false,
+            "visible": false,
             "editable": false,
 
             "list_config": { 
                 "title": "<span title=\"装修商名称\">装修商</span>", // [optional] defaultValue is field.title
                 "width": 200,
-                "visiable": true,
+                "visible": true,
             },
 
             "ig_attr": {
-                "ig_class": "Text",
+                "ig_class": "Text",  // Text TextArea
                 "ig_param": { "width": 300 }
             },
 

+ 53 - 56
src/Sqler/Data/SqlVersion/Demo.json

@@ -1,56 +1,53 @@
-{
-  "data": [
-    {
-      "version": 1,
-      "author": "Lith",
-      "code": "/* v1.407 创建表SysData\n    2020-10-09 16:01 Lith\n*/\n\n--(x.1)创建表\nif   object_id('SysData_Data') is null\ncreate table [SysData_Data] (\n    [id] int NOT NULL IDENTITY,\n    [pId] int NULL,\n    [name] nvarchar(1000) NULL,\n    [value] nvarchar(1000) NULL,\n    [dataCode] nvarchar(100) NULL,\n    [dataGroup] nvarchar(100) NULL,\n    [sortCode] nvarchar(100) NULL,\n    [remarks] nvarchar(1000) NULL,\n    [ext1] nvarchar(1000) NULL,\n    [ext2] nvarchar(1000) NULL,\n    [ext3] nvarchar(1000) NULL,\n    [ext4] nvarchar(1000) NULL,\n    [ext5] nvarchar(1000) NULL,\n    CONSTRAINT [PK_SysData_Data] PRIMARY KEY ([id])\n);\n\n\n\n--(x.2)创建索引\nif not exists (SELECT 1 FROM sys.indexes WHERE object_id=OBJECT_ID('SysData_Data', N'U') and NAME='Index_SysData_Data_pId_dataCode_dataGroup')\n\tcreate index Index_SysData_Data_pId_dataCode on SysData_Data(pId,dataCode,dataGroup) ;\n",
-      "comment": "创建表SysData",
-      "time": "2020-10-30 17:04:56",
-      "attr_type": "",
-      "attr_Opt": "",
-      "attr_obj": "",
-      "attr_obj2": "",
-      "attr_isSys": "",
-      "attr_ext": ""
-    },
-    {
-      "version": 2,
-      "author": "Lith",
-      "code": "/* v1.407 添加字段(SysData_Data.sortCode)\n2020-08-31 15:12 Lith\n*/ \nif col_length('SysData_Data', 'sortCode') is null\n\talter table SysData_Data add sortCode varchar(100);",
-      "comment": "添加字段(Tileset_File.sortCode)",
-      "time": "2024-06-30T18:27:58",
-      "attr_type": "",
-      "attr_Opt": "",
-      "attr_obj": "",
-      "attr_obj2": "",
-      "attr_isSys": "",
-      "attr_ext": ""
-    },
-    {
-      "version": 3,
-      "author": "Lith",
-      "code": "/* v1.407 删除字段(SysData_Data.sortCode)\n2020-10-30 15:28 Lith \n*/ \n\ndeclare @tableName varchar(50),@columnName varchar(50);\nset @tableName='SysData_Data'; set @columnName='sortCode';\n\nif col_length(@tableName, @columnName) is not null\nbegin\n\t--(x.1)删除约束(若存在)\n\tdeclare @constraintName varchar(50)\n\tselect  @constraintName =obj.name from sysobjects obj join syscolumns col on obj.id = col.cdefault\n\twhere col.id = object_id(@tableName) and col.name =@columnName;\n\n\tif(@constraintName is not null)\n\texec('alter table '+@tableName+' drop constraint ' + @constraintName);\n\n\n\t--(x.2)删除字段\n\texec('alter table '+@tableName+' drop column ' + @columnName); \n \n end\n",
-      "comment": "删除字段(SYS_User.suppliermcode)",
-      "time": "2024-06-30T18:25:03",
-      "attr_type": "",
-      "attr_Opt": "",
-      "attr_obj": "",
-      "attr_obj2": "",
-      "attr_isSys": "",
-      "attr_ext": ""
-    },
-    {
-      "version": 4,
-      "author": "Lith",
-      "code": "/* v1.407 删除表SysData_Data\n    2020-10-09 16:01 Lith\n*/\nif object_id('SysData_Data') is not null\n    drop table SysData_Data;\n \n\n \n\n\n\n\n\n\n\n ",
-      "comment": "删除表SysData_Data",
-      "time": "2020-10-30 17:04:26",
-      "attr_type": "",
-      "attr_Opt": "",
-      "attr_obj": "",
-      "attr_obj2": "",
-      "attr_isSys": "",
-      "attr_ext": ""
-    }
-  ]
-}
+[
+  {
+    "version": 1,
+    "author": "Lith",
+    "code": "/* v1\n    2020-10-09 16:01 Lith\n*/\n\nselect 1 ;\n",
+    "comment": "创建表SysData",
+    "time": "2020-10-30 17:04:56",
+    "attr_type": "",
+    "attr_Opt": "",
+    "attr_obj": "",
+    "attr_obj2": "",
+    "attr_isSys": "",
+    "attr_ext": ""
+  },
+  {
+    "version": 2,
+    "author": "Lith",
+    "code": "/* v2\n    2020-10-09 16:01 Lith\n*/\n\nselect 2 ;\n",
+    "comment": "添加字段(Tileset_File.sortCode)",
+    "time": "2024-06-30T18:27:58",
+    "attr_type": "",
+    "attr_Opt": "",
+    "attr_obj": "",
+    "attr_obj2": "",
+    "attr_isSys": "",
+    "attr_ext": ""
+  },
+  {
+    "version": 3,
+    "author": "Lith",
+    "code": "/* v3\n    2020-10-09 16:01 Lith\n*/\n\nselect 3 ;\n",
+    "time": "2024-06-30T18:25:03",
+    "attr_type": "",
+    "attr_Opt": "",
+    "attr_obj": "",
+    "attr_obj2": "",
+    "attr_isSys": "",
+    "attr_ext": ""
+  },
+  {
+    "version": 4,
+    "author": "Lith",
+    "code": "/* v4\n    2020-10-09 16:01 Lith\n*/\n\nselect 4 ;\n",
+    "comment": "删除表SysData_Data",
+    "time": "2020-10-30 17:04:26",
+    "attr_type": "",
+    "attr_Opt": "",
+    "attr_obj": "",
+    "attr_obj2": "",
+    "attr_isSys": "",
+    "attr_ext": ""
+  }
+]

+ 1 - 7
src/Sqler/Data/Sqler_DefaultMenu.json

@@ -130,12 +130,6 @@
     "title": "DataEditor",
     "extra": "{\"iconCls\":\"icon-man\"}"
   },
-  {
-    "id": 161,
-    "pid": 160,
-    "title": "DataEditor Config",
-    "url": "/Scripts/autoTemp/item.html?template=Sqler_DataEditor_Config&mode=update&id=1"
-  },
   {
     "id": 162,
     "pid": 160,
@@ -147,7 +141,7 @@
     "pid": 160,
     "title": "DataEditor List",
     "url": "/sqler/DataEditor/index.html",
-    "extra": "{\"iconCls\":\"icon-more\",\"target\":\"blank\"}"
+    "extra": "{\"iconCls\":\"icon-more\"}"
   },
 
   {

+ 29 - 6
src/Sqler/Data/sqler.json

@@ -42,16 +42,39 @@
 
 
 
-
   "SqlVersion": {
-
     "Config": {
       "provider": "Sqlite",
-      "connectionString": "data source=Data\\db.sqlite",
-      "sqlCodeEditable": "true"
+      "connectionString": "data source=Data\\SqlVersion.test.db",
+      "sqlVersionEditable": "true"
     }
-
-  }
+  },
 
 
+  "Vitorm": {
+    "Data": [
+      {
+        "provider": "Sqlite",
+        "namespace": "Sqler.DataEditor.Entity",
+        "connectionString": "data source=Data\\Sqler.DataEditor.db"
+      },
+      {
+        "provider": "Sqlite",
+        "namespace": "Sqler.DataEditor.Config",
+        "connectionString": "data source=Data\\Sqler.DataEditor.Config.db"
+      },
+      {
+        "provider": "Sqlite",
+        "namespace": "Sqler.Config,Sqler.Menu",
+        "connectionString": "data source=Data\\Sqler.Config.db"
+      },
+
+      {
+        "name": "SqlVersion_SqlCode",
+        "provider": "File",
+        "namespace": "Sqler.SqlVersion.Entity",
+        "connectionString": "Data\\SqlVersion"
+      }
+    ]
+  }
 }

+ 8 - 8
src/Sqler/Module/Sqler/ConsoleCommand/SqlVersionCommand.cs

@@ -27,9 +27,9 @@ namespace App.Module.Sqler.ConsoleCommand
 
             ApiReturn<int> apiRet = new ApiReturn<int>(0);
 
-            foreach (var sqlCodeRes in SqlVersionHelp.sqlCodeRepositorys)
+            foreach (var dataProvider in SqlVersionHelp.sqlCode_DataProviders)
             {
-                var curRet = VersionManage.UpgradeToVersion(sqlCodeRes.moduleName, sendMsg);
+                var curRet = SqlVersionService.UpgradeToVersion(dataProvider.template, sendMsg);
 
                 apiRet.data += curRet.data;
                 if (!curRet.success)
@@ -53,10 +53,10 @@ namespace App.Module.Sqler.ConsoleCommand
         {
             ConsoleHelp.Log("---------------");
             ConsoleHelp.Log("数据库版本信息: ");
-            foreach (var sqlCodeRes in SqlVersionHelp.sqlCodeRepositorys)
+            foreach (var sqlCodeRes in SqlVersionHelp.sqlCode_DataProviders)
             {
-                var moduleName = sqlCodeRes.moduleName;
-                int curVersion = VersionManage.GetDbCurVersion(moduleName);
+                var moduleName = sqlCodeRes.module;
+                int curVersion = SqlVersionService.GetDbCurVersion(moduleName);
                 int lastVersion = sqlCodeRes.lastVersion;
 
                 ConsoleHelp.Out("模块: " + moduleName + "\t当前版本: " + curVersion + "\t最新版本: " + lastVersion);
@@ -77,10 +77,10 @@ namespace App.Module.Sqler.ConsoleCommand
         public static void NewVersionCount(string[] args)
         {
             int newVersionCount = 0;
-            foreach (var sqlCodeRes in SqlVersionHelp.sqlCodeRepositorys)
+            foreach (var sqlCodeRes in SqlVersionHelp.sqlCode_DataProviders)
             {
-                var moduleName = sqlCodeRes.moduleName;
-                int curVersion = VersionManage.GetDbCurVersion(moduleName);
+                var moduleName = sqlCodeRes.module;
+                int curVersion = SqlVersionService.GetDbCurVersion(moduleName);
                 int lastVersion = sqlCodeRes.lastVersion;
                 if (lastVersion > curVersion)
                     newVersionCount += lastVersion - curVersion;

+ 10 - 10
src/Sqler/Module/Sqler/Controllers/SqlVersion/SqlVersionController.cs

@@ -27,12 +27,12 @@ namespace App.Module.Sqler.Controllers.SqlVersion
         /// </summary>
         /// <returns></returns>
         [HttpGet("upgrade")]
-        public void Upgrade([FromQuery] string module, [FromQuery] int version)
+        public void Upgrade([FromQuery] string template, [FromQuery] int version)
         {
 
             Response.ContentType = "text/html;charset=utf-8";
 
-            VersionManage.UpgradeToVersion(module, SendMsg, version);
+            SqlVersionService.UpgradeToVersion(template, SendMsg, version);
         }
 
 
@@ -48,9 +48,9 @@ namespace App.Module.Sqler.Controllers.SqlVersion
             Response.ContentType = "text/html;charset=utf-8";
 
 
-            foreach (var sqlCodeRes in SqlVersionHelp.sqlCodeRepositorys)
+            foreach (var dataProvider in SqlVersionHelp.sqlCode_DataProviders)
             {
-                VersionManage.UpgradeToVersion(sqlCodeRes.moduleName, SendMsg);
+                SqlVersionService.UpgradeToVersion(dataProvider.template, SendMsg);
             }
         }
 
@@ -79,22 +79,22 @@ namespace App.Module.Sqler.Controllers.SqlVersion
                 Response.WriteAsync(msg + "\r\n");
             }
 
-            var query = SqlVersionHelp.sqlCodeRepositorys.AsQueryable();
+            var query = SqlVersionHelp.sqlCode_DataProviders.AsQueryable();
 
             if (!string.IsNullOrEmpty(module))
             {
-                query = query.Where(m => m.moduleName == module);
+                query = query.Where(m => m.module == module);
             }
 
-            var repositorys = query.ToList();
+            var dataProviders = query.ToList();
 
-            foreach (var repository in repositorys)
+            foreach (var repository in dataProviders)
             {
                 sendMsg("---------------------------------------------------------------------------");
 
-                sendMsg("-- module: " + repository.moduleName);
+                sendMsg("-- module: " + repository.module);
 
-                var codes = (repository.dataSource.GetByPath<List<SqlCodeModel>>("data"));
+                var codes = repository.GetList().items.OrderBy(m => m.version);
                 if (codes == null) continue;
 
                 #region foreach

+ 6 - 8
src/Sqler/Module/Sqler/Logical/SqlBackup/MySqlBackup/ConfigRepository.cs

@@ -57,8 +57,8 @@ namespace App.Module.Sqler.Logical.SqlBackup.MySqlBackup
     {
 
         /// <summary>
-        /// [field:visible=false]
-        /// [controller:permit.delete=false] 
+        /// [[AutoTemp: { "permit": {"delete":false}   } ]]
+        /// [[AutoTemp_Field: {   "visible":false  } ]]
         /// </summary>
         [Key]
         [JsonIgnore]
@@ -66,17 +66,15 @@ namespace App.Module.Sqler.Logical.SqlBackup.MySqlBackup
 
 
         /// <summary>
-        /// 连接字符串
-        /// [field:title=&lt;span title='数据库连接字符串'&gt;连接字符串&lt;/span&gt;]       
-        /// [field:ig_class=TextArea]
+        /// &lt;span title='数据库连接字符串'&gt;连接字符串&lt;/span&gt;
+        /// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea"} } ]]
         /// </summary>
         public String ConnectionString { get; set; }
 
 
         /// <summary>
-        /// 数据库备份还原文件的所在文件夹。例:@"F:\\db"。若不指定则为 /Data/MySqlBackup
-        /// [field:title=&lt;span title='数据库备份还原文件的文件夹路径。例:@"F:\\db"。若不指定则为 Data/MySqlBackup'&gt;备份路径&lt;/span&gt;]
-        /// [field:ig_class=TextArea]
+        /// &lt;span title='数据库备份还原文件的文件夹路径。例:@"F:\\db"。若不指定则为 Data/MySqlBackup'&gt;备份路径&lt;/span&gt;
+        /// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea"} } ]]
         /// </summary>
         public String BackupPath { get; set; }
 

+ 8 - 12
src/Sqler/Module/Sqler/Logical/SqlBackup/SqlServerBackup/ConfigRepository.cs

@@ -57,8 +57,8 @@ namespace App.Module.Sqler.Logical.SqlBackup.SqlServerBackup
     {
 
         /// <summary>
-        /// [field:visible=false]
-        /// [controller:permit.delete=false] 
+        /// [[AutoTemp: { "permit": {"delete":false}   } ]]
+        /// [[AutoTemp_Field: {   "visible":false  } ]]
         /// </summary>
         [Key]
         [JsonIgnore]
@@ -66,26 +66,22 @@ namespace App.Module.Sqler.Logical.SqlBackup.SqlServerBackup
 
 
         /// <summary>
-        /// Ms连接字符串
-        /// [field:title=&lt;span title='SqlServer数据库连接字符串'&gt;Ms连接字符串&lt;/span&gt;]       
-        /// [field:ig_class=TextArea]
+        /// &lt;span title='数据库连接字符串'&gt;Ms连接字符串&lt;/span&gt;
+        /// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea"} } ]]
         /// </summary>
         public String ConnectionString { get; set; }
 
 
         /// <summary>
-        /// SqlServer数据库备份还原文件的所在文件夹。例:@"F:\\db"。若不指定则为 /Data/SqlServerBackup
-        /// [field:title=&lt;span title='SqlServer数据库备份还原文件的文件夹路径。例:@"F:\\db"。若不指定则为 Data/SqlServerBackup'&gt;Ms备份路径&lt;/span&gt;]
-        /// [field:ig_class=TextArea]
+        /// &lt;span title='SqlServer数据库备份还原文件的文件夹路径。例:@"F:\\db"。若不指定则为 Data/SqlServerBackup'&gt;Ms备份路径&lt;/span&gt;
+        /// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea"} } ]]
         /// </summary>
         public String BackupPath { get; set; }
 
 
         /// <summary>
-        /// SqlServer数据库文件所在文件夹。例:"..\DataBaseFile" 、 "C:\Program Files (x86)\Microsoft SQL Server\MSSQL\data"。若不指定则为系统默认路径
-        /// 
-        /// [field:title=&lt;span title='SqlServer数据库文件所在文件夹。例:"..\DataBaseFile" 、 "C:\Program Files (x86)\Microsoft SQL Server\MSSQL\data"。若不指定则为系统默认路径'&gt;Ms数据库路径&lt;/span&gt;]
-        /// [field:ig_class=TextArea]
+        /// &lt;span title='SqlServer数据库文件所在文件夹。例:"..\DataBaseFile" 、 "C:\Program Files (x86)\Microsoft SQL Server\MSSQL\data"。若不指定则为系统默认路径'&gt;Ms数据库路径&lt;/span&gt;
+        /// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea"} } ]]
         /// </summary>
         public String MdfPath { get; set; }
 

+ 5 - 3
src/Sqler/Module/Sqler/Logical/SqlRun/ConfigRepository.cs

@@ -57,8 +57,9 @@ namespace App.Module.Sqler.Logical.SqlRun
     {
 
         /// <summary>
-        /// [field:visible=false]
-        /// [controller:permit.delete=false] 
+        /// [[AutoTemp: { "permit": {"delete":false}   } ]]
+        /// 
+        /// [[AutoTemp_Field: {   "visible":false  } ]]
         /// </summary>
         [Key]
         [JsonIgnore]
@@ -72,7 +73,8 @@ namespace App.Module.Sqler.Logical.SqlRun
 
 
         /// <summary>
-        /// 连接字符串[field:ig_class=TextArea]
+        /// 连接字符串
+        /// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea"} } ]]
         /// </summary>
         public String ConnectionString { get; set; }
 

+ 5 - 4
src/Sqler/Module/Sqler/Logical/SqlVersion/ConfigRepository.cs

@@ -45,8 +45,8 @@ namespace App.Module.Sqler.Logical.SqlVersion
     {
 
         /// <summary>
-        /// [field:visible=false]
-        /// [controller:permit.delete=false] 
+        /// [[AutoTemp: { "permit": {"delete":false}   } ]]
+        /// [[AutoTemp_Field: {   "visible":false  } ]]
         /// </summary>
         [Key]
         [JsonIgnore]
@@ -66,7 +66,8 @@ namespace App.Module.Sqler.Logical.SqlVersion
 
 
         /// <summary>
-        /// 连接字符串[field:ig_class=TextArea]
+        /// 连接字符串
+        /// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea"} } ]]
         /// </summary>
         public String connectionString { get; set; }
 
@@ -74,7 +75,7 @@ namespace App.Module.Sqler.Logical.SqlVersion
         /// <summary>
         /// 是否可修改sql
         /// </summary>
-        public String sqlCodeEditable { get; set; }
+        public String sqlVersionEditable { get; set; }
 
 
     }

+ 95 - 0
src/Sqler/Module/Sqler/Logical/SqlVersion/Entity/SqlVersion_Code.cs

@@ -0,0 +1,95 @@
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace Sqler.SqlVersion.Entity
+{
+    public class SqlVersion_Code
+    {
+
+        /// <summary>
+        /// 版本号
+        /// 
+        /// 
+        /// [[AutoTemp: {
+        ///     "permit": {"delete":false},
+        /// 
+        ///     "listConfig": {
+        ///         "rowButtons": [
+        ///             {
+        ///                 "title": "升级至此版本",
+        ///                 "jsHandler": "(sender,id,row)=>{ window.open('/sqler/SqlVersion/upgrade?version='+id+'&amp;template='+document.url_GetCurArg('template')); }"
+        ///             }
+        ///         ]
+        ///     }
+        /// } ]]
+        /// 
+        /// 
+        /// [[AutoTemp_Field: {
+        ///     "visible":false,
+        ///     "list_config": {"width":80},
+        ///     "ig_attr": {"ig_class":"TextArea", "ig_param":{"height":250} }
+        /// } ]]
+        /// 
+        /// </summary>
+        [Key]
+        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
+        public int version { get; set; }
+
+
+        /// <summary>
+        /// [[AutoTemp_Field: { "list_config": {"width":80}   } ]]
+        /// </summary>
+        public String author { get; set; }
+
+        /// <summary>
+        /// sql script
+        /// [[AutoTemp_Field:{  "ig_attr": {"ig_class":"TextArea", "ig_param":{"height":200}} } ]]
+        /// </summary>
+        public String code { get; set; }
+
+        /// <summary>
+        /// [[AutoTemp_Field:{  "ig_attr": {"ig_class":"TextArea", "ig_param":{"height":50}} } ]]
+        /// </summary>
+        public String comment { get; set; }
+
+
+        /// <summary>
+        /// operate time
+        /// [[AutoTemp_Field: {   "editable":false  } ]]
+        /// </summary>
+        public DateTime time { get; set; } = DateTime.Now;
+
+
+        /// <summary>
+        /// &lt;span title='表结构、表字段、函数、存储过程、视图、触发器、表数据'&gt;类型&lt;/span&gt;
+        /// </summary>
+        public String attr_type { get; set; }
+        /// <summary>
+        /// &lt;span title='语句所做操作。(增加、删除、修改、重命名)'&gt;操作&lt;/span&gt;
+        /// </summary>
+        public String attr_Opt { get; set; }
+
+        /// <summary>
+        /// &lt;span title='例如:T_TreeData'&gt;处理对象&lt;/span&gt;
+        /// </summary>
+        public String attr_obj { get; set; }
+        /// <summary>
+        /// &lt;span title='例如: T_TreeData'&gt;处理对象2&lt;/span&gt;
+        /// </summary>
+        public String attr_obj2 { get; set; }
+
+        /// <summary>
+        /// &lt;span title='"true": true。others: false'&gt;is system script&lt;/span&gt;
+        /// </summary>
+        public String attr_isSys { get; set; }
+
+        /// <summary>
+        /// 额外说明
+        /// </summary>
+        public String attr_ext { get; set; }
+    }
+
+  
+
+
+}

+ 4 - 9
src/Sqler/Module/Sqler/Logical/SqlVersion/Entity/sqler_version.cs

@@ -1,7 +1,7 @@
 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations.Schema;
 
-namespace App.Module.Sqler.Logical.SqlVersion.Entity
+namespace Sqler.SqlVersion.DataSource
 {
 
     [Table("sqler_version")]
@@ -13,28 +13,24 @@ namespace App.Module.Sqler.Logical.SqlVersion.Entity
 
         /// <summary>
         /// 模块
-        /// [controller:permit.delete=false]
-        /// [filter:,=]
+        /// [[AutoTemp: { "permit": {"delete":false}   } ]]
         /// </summary>
         [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "nvarchar(1000)")]
         public string module { get; set; }
 
         /// <summary>
         /// 版本
-        /// [filter:,=]
         /// </summary>
         public int? version { get; set; }
 
         /// <summary>
         /// 是否成功
-        /// [filter:,=]
         /// </summary>
         public int success { get; set; }
 
         /// <summary>
         /// 语句执行结果
-        /// [field:ig_class=TextArea]
-        /// [field:ig_param={height:250}]
+        /// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea", "ig_param":{"height":250} } } ]]
         /// </summary>
         [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "ntext")]
         public string result { get; set; }
@@ -42,8 +38,7 @@ namespace App.Module.Sqler.Logical.SqlVersion.Entity
 
         /// <summary>
         /// sql语句
-        /// [field:ig_class=TextArea]
-        /// [field:ig_param={height:50}]
+        /// [[AutoTemp_Field:{   "ig_attr": {"ig_class":"TextArea", "ig_param":{"height":50} } } ]]
         /// </summary>
         [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "ntext")]
         public string code { get; set; }

+ 71 - 34
src/Sqler/Module/Sqler/Logical/SqlVersion/ModuleRepository.cs

@@ -1,4 +1,5 @@
 using System.ComponentModel.DataAnnotations;
+ 
 
 using Vit.AutoTemp.Repository;
 using Vit.Core.Util.ComponentModel.Data;
@@ -13,16 +14,37 @@ namespace App.Module.Sqler.Logical.SqlVersion
     #region SqlVersionModuleRepository
     public class ModuleRepository : IRepository<SqlVersionModuleModel>
     {
+
+        public static List<string> GetAllModules()
+        {
+            DirectoryInfo dir = new DirectoryInfo(SqlerHelp.GetDataFilePath("SqlVersion"));
+            if (dir.Exists)
+            {
+                return dir.GetFiles("*.json").Select(file => Path.GetFileNameWithoutExtension(file.Name)).ToList();
+            }
+
+            return new();
+        }
+
+        public SqlCode_DataProvider[] sqlCode_DataProviders { get; private set; }
         readonly SqlVersionModuleModel[] moduleModels;
-        public ModuleRepository(SqlVersionModuleModel[] moduleModels)
+        public ModuleRepository()
         {
-            this.moduleModels = moduleModels;
+            sqlCode_DataProviders = GetAllModules()
+                    .Select(moduleName => new SqlCode_DataProvider("Sqler_SqlVersion_Module_" + moduleName, moduleName))
+                   .ToArray();
+
+
+            moduleModels = sqlCode_DataProviders.AsQueryable()
+                    .Select(dataProvider => new SqlVersionModuleModel(dataProvider)).ToArray();
+
+
         }
 
 
         public ApiReturn Delete(SqlVersionModuleModel m)
         {
-            File.Delete(SqlerHelp.GetDataFilePath("SqlVersion", m.fileName));
+            File.Delete(SqlerHelp.GetDataFilePath("SqlVersion", m.moduleName+".json"));
             SqlVersionHelp.InitEnvironmentAndAutoTemp();
             return true;
         }
@@ -43,21 +65,22 @@ namespace App.Module.Sqler.Logical.SqlVersion
 
         public ApiReturn<SqlVersionModuleModel> Insert(SqlVersionModuleModel m)
         {
-            new JsonFile(SqlerHelp.GetDataFilePath("SqlVersion", m.fileName)).SaveToFile();
+            var fileName = m.moduleName + ".json";
+            new JsonFile(SqlerHelp.GetDataFilePath("SqlVersion", fileName)).SaveToFile();
 
             SqlVersionHelp.InitEnvironmentAndAutoTemp();
             return m;
         }
 
         public ApiReturn<SqlVersionModuleModel> Update(SqlVersionModuleModel m, string id)
-        {
+        { 
             var query = moduleModels.AsQueryable();
 
             var mFromDb = query.FirstOrDefault(m_ => m_.id == m.id);
 
 
-            FileInfo fi = new FileInfo(SqlerHelp.GetDataFilePath("SqlVersion", mFromDb.fileName));
-            fi.MoveTo(SqlerHelp.GetDataFilePath("SqlVersion", m.fileName));
+            FileInfo fi = new FileInfo(SqlerHelp.GetDataFilePath("SqlVersion", mFromDb.moduleName + ".json"));
+            fi.MoveTo(SqlerHelp.GetDataFilePath("SqlVersion", m.moduleName + ".json"));
 
             SqlVersionHelp.InitEnvironmentAndAutoTemp();
             return m;
@@ -76,36 +99,48 @@ namespace App.Module.Sqler.Logical.SqlVersion
         {
         }
 
-        public SqlVersionModuleModel(SqlCodeRepository rep)
+        public SqlVersionModuleModel(SqlCode_DataProvider dataProvider)
         {
-            this.repository = rep;
-            //id = ""+this.GetHashCode();
-            fileName = rep.fileName;
+            this.dataProvider = dataProvider;
+            moduleName = dataProvider.module;
+            id = moduleName;
         }
 
         /// <summary>
-        /// [fieldIgnore]
+        /// [[AutoTemp_Field:Ignore]] 
         /// </summary>
-        public SqlCodeRepository repository { get; private set; }
+        [System.Text.Json.Serialization.JsonIgnore]
+        [Newtonsoft.Json.JsonIgnore]
+        public SqlCode_DataProvider dataProvider { get; private set; }
 
         /// <summary>
-        /// [field:visible=false]
-        /// 
-        /// [controller:permit.update=false]
-        /// [controller:permit.delete=false]
-        /// [controller:permit.show=false]
-        /// 
-        /// [controller:list.buttons=\x5B
-        /// {text:'一键升级',handler:'function(callback){  callback();window.open("/sqler/SqlVersion/oneKeyUpgrade"); }' }  
-        /// \x5D]
-        /// 
-        /// [controller:list.rowButtons=\x5B
-        /// {text:'管理',handler:'function(callback,id){  callback();theme.addTab("/autoTemp/Scripts/autoTemp/list.html?apiRoute=/autoTemp/data/Sqler_SqlVersion_Module_"+id+"/{action}","SqlVersion_"+id); }' } 
-        /// ,{text:'升级至最新',handler:'function(callback,id){  callback();window.open("/sqler/SqlVersion/upgrade?version=-1&amp;module="+id); }' }  
-        /// ,{text:'下载sql',handler:'function(callback,id){  callback();window.open("/sqler/SqlVersion/download?module="+id); }' }  
-        /// \x5D]
-        /// 
+        /// [[AutoTemp: { 
+        ///     "permit": { "update":false, "delete":false, "show":false},
+        ///     "listConfig": {
+        ///         "listButtons": [
+        ///             {
+        ///                 "title": "一键升级",
+        ///                 "jsHandler": "(sender)=>{ window.open('/sqler/SqlVersion/oneKeyUpgrade'); }"
+        ///             }
+        ///         ],
+        ///         "rowButtons": [
+        ///             {
+        ///                 "title": "管理",
+        ///                 "jsHandler": "(sender,id,row)=>{ theme.addTab('/Scripts/autoTemp/list.html?template=Sqler_SqlVersion_Module_'+id,'SqlVersion_'+id); }" 
+        ///             },
+        ///             {
+        ///                 "title": "升级至最新",
+        ///                 "jsHandler": "(sender,id,row)=>{ window.open('/sqler/SqlVersion/upgrade?version=-1&amp;template=Sqler_SqlVersion_Module_'+id); }" 
+        ///             },
+        ///             {
+        ///                 "title": "下载sql",
+        ///                 "jsHandler": "(sender,id,row)=>{ window.open('/sqler/SqlVersion/download?module='+id); }" 
+        ///             }
+        ///         ]
+        ///     }
+        /// } ]]
         /// 
+        /// [[AutoTemp_Field: {   "editable":false  } ]]
         /// </summary>
         [Key]
         public string id { get; set; }
@@ -114,18 +149,20 @@ namespace App.Module.Sqler.Logical.SqlVersion
         /// <summary>
         /// 文件名称 
         /// </summary> 
-        public string fileName { get; set; }
+        public string moduleName { get; set; }
 
         /// <summary>
-        /// 最高版本[field:editable=false]
+        /// 最高版本
+        /// [[AutoTemp_Field: {   "editable":false  } ]]
         /// </summary>
-        public int lastVersion { get => repository?.lastVersion ?? -1; }
+        public int lastVersion { get => dataProvider?.lastVersion ?? -1; }
 
 
         /// <summary>
-        /// 当前版本[field:editable=false]
+        /// 当前版本
+        /// [[AutoTemp_Field: {   "editable":false  } ]]
         /// </summary>
-        public int? curDbVersion { get => repository?.curDbVersion; }
+        public int? curDbVersion { get => SqlVersionService.GetDbCurVersion(dataProvider.module); }
 
     }
 

+ 0 - 190
src/Sqler/Module/Sqler/Logical/SqlVersion/SqlCodeRepository.cs

@@ -1,190 +0,0 @@
-using System.ComponentModel.DataAnnotations;
-
-using Newtonsoft.Json.Linq;
-
-using Vit.AutoTemp.Repository;
-using Vit.Core.Util.ComponentModel.Data;
-using Vit.Core.Util.ConfigurationManager;
-using Vit.Extensions.Newtonsoft_Extensions;
-using Vit.Extensions.Serialize_Extensions;
-using Vit.Linq;
-using Vit.Linq.ComponentModel;
-using Vit.Linq.FilterRules.ComponentModel;
-
-namespace App.Module.Sqler.Logical.SqlVersion
-{
-
-    #region SqlVersionRepository
-    public class SqlCodeRepository : IRepository<SqlCodeModel>
-    {
-        public readonly string moduleName;
-        public readonly string fileName;
-        public JsonFile dataSource { get; private set; }
-        public SqlCodeRepository(string moduleName)
-        {
-            this.moduleName = moduleName;
-            fileName = moduleName + ".json";
-            dataSource = new JsonFile(SqlerHelp.GetDataFilePath("SqlVersion", fileName));
-        }
-
-        /// <summary>
-        /// 最高版本
-        /// </summary>
-        public int lastVersion
-        {
-            get
-            {
-                return dataSource.root["data"]?.Value<JArray>()?.Count ?? -1;
-            }
-        }
-
-        /// <summary>
-        /// 数据库当前版本
-        /// </summary>
-        public int curDbVersion { get => VersionManage.GetDbCurVersion(moduleName); }
-
-
-        public ApiReturn Delete(SqlCodeModel m)
-        {
-            throw new Exception("不可删除sql语句");
-        }
-
-        public ApiReturn<PageData<SqlCodeModel>> GetList(FilterRule filter, IEnumerable<OrderField> sort, PageInfo page)
-        {
-            var queryable = (dataSource.GetByPath<List<SqlCodeModel>>("data") ?? new List<SqlCodeModel>()).AsQueryable();
-            return queryable.ToPageData(filter, sort, page);
-        }
-
-        public ApiReturn<SqlCodeModel> GetModel(string id)
-        {
-            var data = dataSource.root["data"].Value<JArray>();
-            var m = data[int.Parse(id) - 1].Deserialize<SqlCodeModel>();
-            return m;
-        }
-
-        public ApiReturn<SqlCodeModel> Insert(SqlCodeModel m)
-        {
-            var data = dataSource.root["data"]?.Value<JArray>();
-            if (data == null)
-            {
-                dataSource.root["data"] = data = new JArray();
-            }
-
-            m.version = data.Count + 1;
-            m.time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
-
-            data.Add(m.ConvertBySerialize<JToken>());
-            dataSource.SaveToFile();
-            return m;
-        }
-
-
-
-
-        public ApiReturn<SqlCodeModel> Update(SqlCodeModel m, string id)
-        {
-
-            if (SqlerHelp.sqlerConfig.GetByPath<bool?>("SqlVersion.Config.SqlCodeEditable") == false)
-            {
-                throw new Exception("不可修改sql语句");
-            }
-
-
-            m.time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
-
-            var data = dataSource.root["data"].Value<JArray>();
-            var modelFromDb = data[m.version.Value - 1];
-
-            modelFromDb.Replace(m.ConvertBySerialize<JToken>());
-
-            dataSource.SaveToFile();
-
-            return m;
-        }
-    }
-    #endregion
-
-
-    #region Model
-    public class SqlCodeModel
-    {
-
-        /// <summary>
-        /// 版本号[field:list_width=80] 
-        /// [controller:permit.delete=false]    
-        /// 
-        /// [controller:list.rowButtons=\x5B
-        ///   {text:'升级至此版本',handler:'function(callback,id){  callback();window.open("/sqler/SqlVersion/upgrade?version="+id+"&amp;module="+document.url_GetCurArg("apiRoute").slice(39,-9)); }' }  
-        /// \x5D]
-        /// 
-        /// 
-        /// 
-        /// </summary>
-        [Key]
-        public int? version { get; set; }
-
-
-        /// <summary>
-        /// 作者[field:list_width=80] 
-        /// </summary>
-        public String author { get; set; }
-
-        /// <summary>
-        /// sql语句
-        /// [field:ig_class=TextArea] 
-        /// [field:ig_param={height:200}]
-        /// </summary>
-        public String code { get; set; }
-
-        /// <summary>
-        /// 说明
-        /// [field:ig_class=TextArea]       
-        /// [field:ig_param={height:50}]
-        /// </summary>
-        public String comment { get; set; }
-
-
-        /// <summary>
-        /// 操作时间[field:editable=false]
-        /// </summary>
-        public string time { get; set; }
-
-
-        /// <summary>
-        /// 类型。(表结构、表字段、函数、存储过程、视图、触发器、表数据)
-        /// [field:title=类型]
-        /// </summary>
-        public String attr_type { get; set; }
-        /// <summary>
-        /// 操作。语句所做操作。(增加、删除、修改、重命名) 
-        /// [field:title=操作]
-        /// </summary>
-        public String attr_Opt { get; set; }
-
-        /// <summary>
-        /// 处理对象。例如: T_TreeData
-        /// [field:title=处理对象]
-        /// </summary>
-        public String attr_obj { get; set; }
-        /// <summary>
-        /// 处理对象2。例如: T_TreeData
-        /// [field:title=处理对象2]
-        /// </summary>
-        public String attr_obj2 { get; set; }
-
-        /// <summary>
-        /// 是否为系统语句。"是":是。其他(尤指"否"):否。
-        /// [field:title=系统语句]
-        /// </summary>
-        public String attr_isSys { get; set; }
-
-        /// <summary>
-        /// 额外说明
-        /// </summary>
-        public String attr_ext { get; set; }
-    }
-
-    #endregion
-
-
-}

+ 70 - 0
src/Sqler/Module/Sqler/Logical/SqlVersion/SqlCode_DataProvider.cs

@@ -0,0 +1,70 @@
+using Newtonsoft.Json.Linq;
+
+using Sqler.SqlVersion.Entity;
+
+using Vit.AutoTemp.DataProvider;
+using Vit.Core.Util.ComponentModel.Data;
+
+using Vitorm;
+
+namespace App.Module.Sqler.Logical.SqlVersion
+{
+
+    public class SqlCode_DataProvider : DataProvider_Vitorm<SqlVersion_Code, DbContext>
+    {
+        public readonly string module;
+
+
+        static DbContext CreateDbContext()
+        {
+            return Data.DataProvider<SqlVersion_Code>().CreateDbContext();
+        }
+
+        static Func<DbContext, IDbSet<SqlVersion_Code>> DbSetGenerator(string module)
+        {
+            return (dbContext) =>
+            {
+                var dbSet = dbContext.DbSet<SqlVersion_Code>();
+                dbSet.ChangeTable(module);
+                return dbSet;
+            };
+        }
+
+        public SqlCode_DataProvider(string template, string module) : base(template, CreateDbContext, GetDbSet: DbSetGenerator(module))
+        {
+            this.module = module;
+        }
+
+
+        public int lastVersion
+        {
+            get
+            {
+                using var dbContext = CreateDbContext();
+                var dbSet = GetDbSet(dbContext);
+                return dbSet.Query().Max(m => m.version);
+            }
+        }
+
+
+        public override ApiReturn delete(object sender, JObject arg)
+        {
+            throw new Exception("不可删除sql语句");
+            return base.delete(sender, arg);
+        }
+
+        public override ApiReturn update(object sender, JObject model, string id)
+        {
+            if (SqlerHelp.sqlerConfig.GetByPath<bool?>("SqlVersion.Config.SqlCodeEditable") == false)
+            {
+                throw new Exception("不可修改sql语句");
+            }
+
+            return base.update(sender, model, id);
+        }
+    }
+
+
+
+
+}

+ 22 - 44
src/Sqler/Module/Sqler/Logical/SqlVersion/SqlVersionHelp.cs

@@ -1,6 +1,6 @@
 using System.Data;
 
-using App.Module.Sqler.Logical.SqlVersion.Entity;
+using Sqler.SqlVersion.DataSource;
 
 using Vit.AutoTemp;
 using Vit.AutoTemp.DataProvider;
@@ -13,7 +13,8 @@ namespace App.Module.Sqler.Logical.SqlVersion
 {
     public class SqlVersionHelp
     {
-        public static SqlCodeRepository[] sqlCodeRepositorys { get; private set; }
+        static ModuleRepository moduleRepository;
+        public static SqlCode_DataProvider[] sqlCode_DataProviders => moduleRepository.sqlCode_DataProviders;
 
 
         static readonly List<IDataProvider> dataProviders = new List<IDataProvider>();
@@ -36,7 +37,7 @@ namespace App.Module.Sqler.Logical.SqlVersion
         public static void InitEnvironment()
         {
 
-            #region (x.1) init dataSource
+            #region #1 init dataSource
             {
                 var dataSourceConfig = SqlerHelp.sqlerConfig.GetByPath<Dictionary<string, object>>("SqlVersion.Config");
                 dataSourceConfig["namespace"] = typeof(sqler_version).Namespace;
@@ -49,69 +50,46 @@ namespace App.Module.Sqler.Logical.SqlVersion
             }
             #endregion
 
-
-            #region (x.2)初始化 moduleNames
-            DirectoryInfo dir = new DirectoryInfo(SqlerHelp.GetDataFilePath("SqlVersion"));
-            if (dir.Exists)
-            {
-                sqlCodeRepositorys = dir.GetFiles("*.json")
-                    .Select(file => Path.GetFileNameWithoutExtension(file.Name))
-                    .Select(name => new SqlCodeRepository(name))
-                    .ToArray();
-            }
-            else
-            {
-                sqlCodeRepositorys = Array.Empty<SqlCodeRepository>();
-            }
-            #endregion
-
         }
 
 
 
         public static void InitAutoTemp()
         {
-            //(x.1)取消注册
+            // #1 unregister AutoTemp
             if (dataProviders.Count > 0)
             {
                 Vit.AutoTemp.AutoTempHelp.UnRegisterDataProvider(dataProviders.ToArray());
                 dataProviders.Clear();
             }
+            IDataProvider dataProvider;
 
-            //(x.2)注册 SqlVersion Config
-            Vit.AutoTemp.AutoTempHelp.RegisterDataProvider(
-                new global::App.Module.Sqler.Logical.SqlVersion.ConfigRepository().ToDataProvider("Sqler_SqlVersion_Config"));
+            // #2 register SqlVersion Config
+            dataProvider = new global::App.Module.Sqler.Logical.SqlVersion.ConfigRepository().ToDataProvider("Sqler_SqlVersion_Config");
+            dataProviders.Add(dataProvider);
+      
 
-            //(x.3)注册 ModuleMng
-            SqlVersionModuleModel[] moduleModels = sqlCodeRepositorys.AsQueryable()
-                    .Select(rep => new SqlVersionModuleModel(rep) { id = Path.GetFileNameWithoutExtension(rep.fileName) }).ToArray();
+            // #3 register ModuleMng
+            moduleRepository = new ModuleRepository();
+            dataProvider = moduleRepository.ToDataProvider("Sqler_SqlVersion_Module");
+            dataProviders.Add(dataProvider);
 
-            Vit.AutoTemp.AutoTempHelp.RegisterDataProvider(
-                                new ModuleRepository(moduleModels).ToDataProvider("Sqler_SqlVersion_Module"));
 
+            // #4 register sqlCode_DataProviders
+            dataProviders.AddRange(sqlCode_DataProviders);
 
-            #region (x.4)创建并注册 sqlCodeDataProviders(VersionMng list)
-            {
-                var sqlCodeDataProviders = sqlCodeRepositorys.Select(repository =>
-                           repository.ToDataProvider("Sqler_SqlVersion_Module_" + repository.moduleName))
-                            .ToArray();
 
-                dataProviders.AddRange(sqlCodeDataProviders);
+            // #5 register VersionResult(from database)
+            dataProvider = AutoTempHelp.CreateDataProvider<sqler_version>("Sqler_SqlVersion_VersionInfo", CreateDbContext);
+            dataProviders.Add(dataProvider);
 
-                Vit.AutoTemp.AutoTempHelp.RegisterDataProvider(sqlCodeDataProviders);
-            }
-            #endregion
 
 
+            Vit.AutoTemp.AutoTempHelp.RegisterDataProvider(dataProviders.ToArray());
 
-            #region (x.6)注册 VersionResult( from database)
-            {
-                var template = "Sqler_SqlVersion_VersionInfo";
-                var dataProvider = AutoTempHelp.CreateDataProvider<sqler_version>(template, CreateDbContext);
 
-                Vit.AutoTemp.AutoTempHelp.RegisterDataProvider(dataProvider);
-            }
-            #endregion
+            // #6 ensure table sqler_version exist
+            SqlVersionService.EnsureTableCreate();
 
         }
 

+ 294 - 293
src/Sqler/Module/Sqler/Logical/SqlVersion/VersionManage.cs → src/Sqler/Module/Sqler/Logical/SqlVersion/SqlVersionService.cs

@@ -1,293 +1,294 @@
-using System.Text;
-using System.Text.RegularExpressions;
-
-using App.Module.Sqler.Logical.SqlVersion.Entity;
-
-using Sqler.Module.Sqler.Logical.Message;
-
-using Vit.Core.Module.Log;
-using Vit.Core.Util.ComponentModel.Data;
-using Vit.Core.Util.ConfigurationManager;
-using Vit.Extensions;
-using Vit.Extensions.Db_Extensions;
-
-using Vitorm;
-
-namespace App.Module.Sqler.Logical.SqlVersion
-{
-    public class VersionManage
-    {
-        static bool EnsureTableCreate()
-        {
-            using (var conn = SqlVersionHelp.CreateOpenedDbConnection())
-            {
-                var dbType = conn.GetDbType();
-
-                var sql = new JsonFile(SqlerHelp.GetDataFilePath("sqler.SqlVersion.table.json")).GetStringByPath("initDb." + dbType);
-
-                if (!string.IsNullOrWhiteSpace(sql))
-                {
-                    conn.Execute(sql);
-                    return true;
-                }
-            }
-
-            Data.TryCreateTable<sqler_version>();
-
-            return true;
-        }
-
-
-
-        public static int GetDbCurVersion(string module)
-        {
-            try
-            {
-                var versionResult = (from v in Data.Query<sqler_version>()
-                                     where v.module == module && v.success == 1
-                                     orderby v.version descending
-                                     select v)
-                                   .FirstOrDefault();
-
-                return versionResult?.version ?? 0;
-            }
-            catch (Exception ex)
-            {
-                Logger.Error(ex);
-            }
-            return 0;
-        }
-
-
-
-
-
-        static void ExecVersion(string module, SqlCodeModel versionData, Action<EMsgType, String> sendMsg)
-        {
-            #region (x.1)版本检验
-            //int? dbVersioin = GetDbCurVersion(module);
-            //if (
-            //    (dbVersioin == null && versionData.version.Value != 1)
-            //    || (dbVersioin != null && versionData.version.Value != dbVersioin.Value + 1)
-            //    ) 
-            //{
-            //    return new SsError { errorMessage= "无法跨版本执行。" };
-            //}
-            #endregion
-
-            sendMsg(EMsgType.Title, "执行版本" + versionData.version + "升级语句。");
-            sendMsg(EMsgType.Nomal, "comment:" + versionData.comment);
-
-            #region (x.2)对象构建
-            sqler_version versionResult = new sqler_version();
-
-            versionResult.module = module;
-            versionResult.version = versionData.version;
-            versionResult.code = versionData.code;
-            versionResult.exec_time = DateTime.Now;
-
-            versionResult.result = "";
-            versionResult.remarks = "";
-            #endregion
-
-
-            StringBuilder execResult = new StringBuilder();
-
-            #region (x.3)执行语句函数
-            void ExecSql()
-            {
-                using var conn = SqlVersionHelp.CreateOpenedDbConnection();
-                conn.RunInTransaction((tran) =>
-                {
-
-                    int index = 1;
-                    //  /*GO*/GO 中间可出现多个空白字符,包括空格、制表符、换页符等
-                    //Regex reg = new Regex("/\\*GO\\*/\\s*GO");
-                    Regex reg = new Regex("\\sGO\\s");
-                    var sqls = reg.Split(versionResult.code);
-                    foreach (String sql in sqls)
-                    {
-                        if (String.IsNullOrEmpty(sql.Trim()))
-                        {
-                            sendMsg(EMsgType.Title, $"[{(index++)}/{sqls.Length}]空语句,无需执行.");
-                        }
-                        else
-                        {
-                            sendMsg(EMsgType.Title, $"[{(index++)}/{sqls.Length}]执行sql语句:");
-                            sendMsg(EMsgType.Nomal, sql);
-                            var result = "执行结果:" + conn.Execute(sql, null, tran) + " Lines effected.";
-                            execResult.AppendLine(result);
-                            sendMsg(EMsgType.Title, result);
-                        }
-                    }
-
-                }, onException: Logger.Error);
-            }
-            #endregion
-
-
-            #region (x.4)执行并入库结果
-
-            try
-            {
-                versionResult.success = 0;
-                ExecSql();
-                versionResult.success = 1;
-            }
-            catch (Exception ex)
-            {
-                Logger.Error(ex);
-                execResult.AppendLine(ex.GetBaseException().Message);
-                throw;
-            }
-            finally
-            {
-                try
-                {
-                    versionResult.result = execResult.ToString();
-                    Data.Add(versionResult);
-                }
-                catch (Exception ex)
-                {
-                    Logger.Error(ex);
-                }
-            }
-
-            #endregion
-
-
-
-            sendMsg(EMsgType.Title, "版本" + versionData.version + " 升级成功。");
-            sendMsg(EMsgType.Nomal, "");
-            sendMsg(EMsgType.Nomal, "");
-
-        }
-
-
-
-
-        #region 升级
-
-        /// <summary>
-        /// 返回已经升级的版本数量
-        /// </summary>
-        /// <param name="module"></param>
-        /// <param name="sendMsg"></param>
-        /// <param name="descVersion"></param>
-        /// <returns></returns>
-        public static ApiReturn<int> UpgradeToVersion(string module, Action<EMsgType, String> sendMsg, int descVersion = -1)
-        {
-
-            ApiReturn<int> apiRet = new ApiReturn<int>(0);
-
-
-            var repository = SqlVersionHelp.sqlCodeRepositorys.AsQueryable().FirstOrDefault(m => m.moduleName == module);
-
-            sendMsg =
-                ((EMsgType type, String msg) =>
-            {
-                Logger.log.Log(Level.ApiTrace, msg);
-            })
-            + sendMsg;
-
-            int oriVersion = GetDbCurVersion(module);
-            int curVersion = oriVersion;
-            int lastVersion = repository.lastVersion;
-
-            if (descVersion < 0)
-            {
-                descVersion = lastVersion;
-            }
-
-            try
-            {
-
-                if (lastVersion < descVersion) descVersion = lastVersion;
-
-
-                sendMsg(EMsgType.Title, "升级模块:   " + module);
-                sendMsg(EMsgType.Title, "当前版本:   " + curVersion);
-                sendMsg(EMsgType.Title, "目标版本:   " + descVersion);
-                sendMsg(EMsgType.Title, "最新版本:   " + lastVersion);
-
-
-
-                if (descVersion < curVersion)
-                {
-                    sendMsg(EMsgType.Title, "无需执行,当前版本已经比目标版本高。");
-                    return apiRet;
-                }
-
-                if (descVersion == curVersion)
-                {
-                    sendMsg(EMsgType.Title, "无需执行,当前版本已经为目标版本。");
-                    return apiRet;
-                }
-
-
-
-
-                sendMsg(EMsgType.Title, "执行数据库升级语句...");
-                sendMsg(EMsgType.Nomal, "");
-                sendMsg(EMsgType.Nomal, "");
-
-
-
-                // ensure table sqler_version exist
-                EnsureTableCreate();
-
-
-                while (curVersion < descVersion)
-                {
-                    var sqlCode = repository.GetModel("" + (curVersion + 1));
-                    ExecVersion(module, sqlCode.data, sendMsg);
-                    curVersion++;
-                }
-
-
-                sendMsg(EMsgType.Nomal, "");
-                sendMsg(EMsgType.Nomal, "");
-                sendMsg(EMsgType.Nomal, "");
-                sendMsg(EMsgType.Title, "升级成功。");
-                sendMsg(EMsgType.Title, "数据库当前版本:   " + curVersion);
-                sendMsg(EMsgType.Title, "数据库目标版本:   " + descVersion);
-            }
-            catch (Exception e)
-            {
-                sendMsg(EMsgType.Err, "执行出错,原因:");
-                sendMsg(EMsgType.Err, e.GetBaseException().Message);
-                try
-                {
-                    curVersion = GetDbCurVersion(module);
-                }
-                catch { }
-
-                sendMsg(EMsgType.Title, "数据库当前版本:   " + curVersion);
-                sendMsg(EMsgType.Title, "数据库目标版本:   " + descVersion);
-
-                Logger.Error("SqlRun执行sql语句出错.出错版本:" + (curVersion + 1), e);
-
-                apiRet.success = false;
-                apiRet.error = e.GetBaseException();
-
-            }
-
-            sendMsg(EMsgType.Nomal, "");
-            sendMsg(EMsgType.Nomal, "");
-            sendMsg(EMsgType.Nomal, "");
-
-
-            apiRet.data = curVersion - oriVersion;
-            return apiRet;
-
-        }
-
-        #endregion
-
-
-
-
-
-
-    }
-}
+using System.Text;
+using System.Text.RegularExpressions;
+
+using Sqler.Module.Sqler.Logical.Message;
+using Sqler.SqlVersion.DataSource;
+using Sqler.SqlVersion.Entity;
+
+using Vit.Core.Module.Log;
+using Vit.Core.Util.ComponentModel.Data;
+using Vit.Core.Util.ConfigurationManager;
+using Vit.Extensions;
+using Vit.Extensions.Db_Extensions;
+
+using Vitorm;
+
+namespace App.Module.Sqler.Logical.SqlVersion
+{
+    public class SqlVersionService
+    {
+        public static bool EnsureTableCreate()
+        {
+            using (var conn = SqlVersionHelp.CreateOpenedDbConnection())
+            {
+                var dbType = conn.GetDbType()?.ToString()?.ToLower();
+
+                var sql = new JsonFile(SqlerHelp.GetDataFilePath("sqler.SqlVersion.table.json")).GetStringByPath("initDb." + dbType);
+
+                if (!string.IsNullOrWhiteSpace(sql))
+                {
+                    conn.Execute(sql);
+                    return true;
+                }
+            }
+
+            Data.TryCreateTable<sqler_version>();
+
+            return true;
+        }
+
+
+
+        public static int GetDbCurVersion(string module)
+        {
+            try
+            {
+                var versionResult = (from v in Data.Query<sqler_version>()
+                                     where v.module == module && v.success == 1
+                                     orderby v.version descending
+                                     select v)
+                                   .FirstOrDefault();
+
+                return versionResult?.version ?? 0;
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex);
+            }
+            return 0;
+        }
+
+
+
+
+
+        static void ExecVersion(string module, SqlVersion_Code versionData, Action<EMsgType, String> sendMsg)
+        {
+            #region (x.1)版本检验
+            //int? dbVersioin = GetDbCurVersion(module);
+            //if (
+            //    (dbVersioin == null && versionData.version.Value != 1)
+            //    || (dbVersioin != null && versionData.version.Value != dbVersioin.Value + 1)
+            //    ) 
+            //{
+            //    return new SsError { errorMessage= "无法跨版本执行。" };
+            //}
+            #endregion
+
+            sendMsg(EMsgType.Title, "执行版本" + versionData.version + "升级语句。");
+            sendMsg(EMsgType.Nomal, "comment:" + versionData.comment);
+
+            #region (x.2)对象构建
+            sqler_version versionResult = new sqler_version();
+
+            versionResult.module = module;
+            versionResult.version = versionData.version;
+            versionResult.code = versionData.code;
+            versionResult.exec_time = DateTime.Now;
+
+            versionResult.result = "";
+            versionResult.remarks = "";
+            #endregion
+
+
+            StringBuilder execResult = new StringBuilder();
+
+            #region (x.3)执行语句函数
+            void ExecSql()
+            {
+                using var conn = SqlVersionHelp.CreateOpenedDbConnection();
+                conn.RunInTransaction((tran) =>
+                {
+
+                    int index = 1;
+                    //  /*GO*/GO 中间可出现多个空白字符,包括空格、制表符、换页符等
+                    //Regex reg = new Regex("/\\*GO\\*/\\s*GO");
+                    Regex reg = new Regex("\\sGO\\s");
+                    var sqls = reg.Split(versionResult.code);
+                    foreach (String sql in sqls)
+                    {
+                        if (String.IsNullOrEmpty(sql.Trim()))
+                        {
+                            sendMsg(EMsgType.Title, $"[{(index++)}/{sqls.Length}]空语句,无需执行.");
+                        }
+                        else
+                        {
+                            sendMsg(EMsgType.Title, $"[{(index++)}/{sqls.Length}]执行sql语句:");
+                            sendMsg(EMsgType.Nomal, sql);
+                            var result = "执行结果:" + conn.Execute(sql, null, tran) + " Lines effected.";
+                            execResult.AppendLine(result);
+                            sendMsg(EMsgType.Title, result);
+                        }
+                    }
+
+                }, onException: Logger.Error);
+            }
+            #endregion
+
+
+            #region (x.4)执行并入库结果
+
+            try
+            {
+                versionResult.success = 0;
+                ExecSql();
+                versionResult.success = 1;
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex);
+                execResult.AppendLine(ex.GetBaseException().Message);
+                throw;
+            }
+            finally
+            {
+                try
+                {
+                    versionResult.result = execResult.ToString();
+                    Data.Add(versionResult);
+                }
+                catch (Exception ex)
+                {
+                    Logger.Error(ex);
+                }
+            }
+
+            #endregion
+
+
+
+            sendMsg(EMsgType.Title, "版本" + versionData.version + " 升级成功。");
+            sendMsg(EMsgType.Nomal, "");
+            sendMsg(EMsgType.Nomal, "");
+
+        }
+
+
+
+
+        #region 升级
+
+        /// <summary>
+        /// 返回已经升级的版本数量
+        /// </summary>
+        /// <param name="template"></param>
+        /// <param name="sendMsg"></param>
+        /// <param name="targetVersion"></param>
+        /// <returns></returns>
+        public static ApiReturn<int> UpgradeToVersion(string template, Action<EMsgType, String> sendMsg, int targetVersion = -1)
+        {
+
+            ApiReturn<int> apiRet = new ApiReturn<int>(0);
+
+
+            var dataProvider = SqlVersionHelp.sqlCode_DataProviders.AsQueryable().FirstOrDefault(m => m.template == template);
+            var module = dataProvider.module;
+
+            sendMsg =
+                ((EMsgType type, String msg) =>
+            {
+                Logger.log.Log(Level.ApiTrace, msg);
+            })
+            + sendMsg;
+
+            int oriVersion = GetDbCurVersion(module);
+            int curVersion = oriVersion;
+            int lastVersion = dataProvider.lastVersion;
+
+            if (targetVersion < 0)
+            {
+                targetVersion = lastVersion;
+            }
+
+            try
+            {
+
+                if (lastVersion < targetVersion) targetVersion = lastVersion;
+
+
+                sendMsg(EMsgType.Title, "升级模块:   " + module);
+                sendMsg(EMsgType.Title, "当前版本:   " + curVersion);
+                sendMsg(EMsgType.Title, "目标版本:   " + targetVersion);
+                sendMsg(EMsgType.Title, "最新版本:   " + lastVersion);
+
+
+
+                if (targetVersion < curVersion)
+                {
+                    sendMsg(EMsgType.Title, "无需执行,当前版本已经比目标版本高。");
+                    return apiRet;
+                }
+
+                if (targetVersion == curVersion)
+                {
+                    sendMsg(EMsgType.Title, "无需执行,当前版本已经为目标版本。");
+                    return apiRet;
+                }
+
+
+
+
+                sendMsg(EMsgType.Title, "执行数据库升级语句...");
+                sendMsg(EMsgType.Nomal, "");
+                sendMsg(EMsgType.Nomal, "");
+
+
+
+                // ensure table sqler_version exist
+                EnsureTableCreate();
+
+
+                while (curVersion < targetVersion)
+                {
+                    var sqlCode = dataProvider.getModel(null,"" + (curVersion + 1));
+                    ExecVersion(module, sqlCode.data, sendMsg);
+                    curVersion++;
+                }
+
+
+                sendMsg(EMsgType.Nomal, "");
+                sendMsg(EMsgType.Nomal, "");
+                sendMsg(EMsgType.Nomal, "");
+                sendMsg(EMsgType.Title, "升级成功。");
+                sendMsg(EMsgType.Title, "数据库当前版本:   " + curVersion);
+                sendMsg(EMsgType.Title, "数据库目标版本:   " + targetVersion);
+            }
+            catch (Exception e)
+            {
+                sendMsg(EMsgType.Err, "执行出错,原因:");
+                sendMsg(EMsgType.Err, e.GetBaseException().Message);
+                try
+                {
+                    curVersion = GetDbCurVersion(module);
+                }
+                catch { }
+
+                sendMsg(EMsgType.Title, "数据库当前版本:   " + curVersion);
+                sendMsg(EMsgType.Title, "数据库目标版本:   " + targetVersion);
+
+                Logger.Error("SqlRun执行sql语句出错.出错版本:" + (curVersion + 1), e);
+
+                apiRet.success = false;
+                apiRet.error = e.GetBaseException();
+
+            }
+
+            sendMsg(EMsgType.Nomal, "");
+            sendMsg(EMsgType.Nomal, "");
+            sendMsg(EMsgType.Nomal, "");
+
+
+            apiRet.data = curVersion - oriVersion;
+            return apiRet;
+
+        }
+
+        #endregion
+
+
+
+
+
+
+    }
+}

+ 7 - 11
src/Sqler/Sqler.csproj

@@ -18,16 +18,17 @@
         <PackageReference Include="Vit.WebHost" Version="6.1.1" />
         <PackageReference Include="Vit.Db.DbMng" Version="3.0.1" />
         <PackageReference Include="Sers.Core" Version="2.1.28" />
-        <PackageReference Include="Vitorm.Data" Version="2.2.0-preview3" />
-        <PackageReference Include="Vitorm.MySql" Version="2.2.0-preview3-ki16" />
-        <PackageReference Include="Vitorm.Sqlite" Version="2.2.0-preview3" />
-        <PackageReference Include="Vitorm.SqlServer" Version="2.2.0-preview3" />
-        <PackageReference Include="Vitorm.EntityGenerate" Version="2.2.0-preview3" />
+        <PackageReference Include="Vitorm.Data" Version="2.2.0-preview4-ki22" />
+        <PackageReference Include="Vitorm.File" Version="2.2.0-preview2-ki8" />
+        <PackageReference Include="Vitorm.MySql" Version="2.2.0-preview4-ki22" />
+        <PackageReference Include="Vitorm.Sqlite" Version="2.2.0-preview4-ki22" />
+        <PackageReference Include="Vitorm.SqlServer" Version="2.2.0-preview4-ki22" />
+        <PackageReference Include="Vitorm.EntityGenerate" Version="2.2.0-preview4-ki22" />
     </ItemGroup>
 
 
     <ItemGroup>
-      <ProjectReference Include="..\..\..\VitormLib\Vitorm\src\Vitorm.Data\Vitorm.Data.csproj" />
+      <ProjectReference Include="..\..\..\Vit.Db\src\Vit.Db\Vit.Db\Vit.Db.csproj" />
       <ProjectReference Include="..\Vit.AutoTemp\Vit.AutoTemp.csproj" />
     </ItemGroup>
 
@@ -76,9 +77,4 @@
         </None>
     </ItemGroup>
 
-
-    <ItemGroup>
-      <Folder Include="Module\Sqler\Logical\Menu\" />
-    </ItemGroup>
-
 </Project>

+ 4 - 4
src/Sqler/wwwroot/Scripts/autoTemp/autoTemp.Controller.js

@@ -74,7 +74,7 @@
                             if (typeof (button.jsHandler) == 'string') {
                                 button.handler = eval('(' + button.jsHandler + ')');
                             }
-                            theme.progressStart(button.title);
+                            //theme.progressStart(button.title);
 
                             let arg = { ...button, progressStart: theme.progressStart, progressStop: theme.progressStop };
                             button.handler(arg, null);
@@ -112,18 +112,18 @@
 
         // #4 row buttons
         if (controllerConfig.listConfig?.rowButtons) {
-            var rowButtons = controllerConfig.rowButtons.rowButtons;
+            var rowButtons = controllerConfig.listConfig.rowButtons;
             $.each(rowButtons, function (i, button) {
 
                 controller.addRowButton({
-                    text: button.text,
+                    text: button.title,
                     onclick: function (id) {
                         // ##1 jsHandler
                         if (button.jsHandler) {
                             if (typeof (button.jsHandler) == 'string') {
                                 button.handler = eval('(' + button.jsHandler + ')');
                             }
-                            theme.progressStart(button.title);
+                            //theme.progressStart(button.title);
 
                             let arg = { ...button, progressStart: theme.progressStart, progressStop:theme.progressStop };
                             button.handler(arg, id, null);

+ 11 - 0
src/Vit.AutoTemp/AutoTempControllerConfig.cs

@@ -13,8 +13,19 @@ namespace Vit.AutoTemp
         public string treeField;
         public string rootPidValue;
 
+        public Permit permit;
         public ListConfig listConfig;
 
         public List<FieldConfig> fields;
+
+
+        public class Permit 
+        {
+            public bool? insert;
+            public bool? update;
+            public bool? show;
+            public bool? delete;
+
+        }
     }
 }

+ 16 - 10
src/Vit.AutoTemp/AutoTempHelp.cs

@@ -1,21 +1,14 @@
 using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
-using System.Data.Common;
 using System.Linq;
 using System.Reflection;
 using System.Text.RegularExpressions;
 
-using Newtonsoft.Json.Linq;
-
 using Vit.AutoTemp.DataProvider;
-using Vit.Core.Module.Log;
 using Vit.Core.Module.Serialization;
 using Vit.Core.Util.XmlComment;
 using Vit.Db.Module.Schema;
-using Vit.Extensions;
-using Vit.Extensions.Newtonsoft_Extensions;
-using Vit.Extensions.Serialize_Extensions;
 
 using static Vit.AutoTemp.AutoTempControllerConfig;
 
@@ -34,8 +27,9 @@ namespace Vit.AutoTemp
             (string template, Func<global::Vitorm.DbContext> CreateDbContext, TableSchema tableSchema = null, AutoTempControllerConfig controllerConfig = null)
             where Model : class
         {
-            return new DataProvider_Vitorm<Model, global::Vitorm.DbContext>(template, CreateDbContext, tableSchema, controllerConfig);
+            return new DataProvider_Vitorm<Model, global::Vitorm.DbContext>(template, CreateDbContext: CreateDbContext, tableSchema: tableSchema, controllerConfig: controllerConfig);
         }
+
         static readonly System.Reflection.MethodInfo CreateDataProviderMethod =
             new Func<string, Func<global::Vitorm.DbContext>, TableSchema, AutoTempControllerConfig, DataProvider_Vitorm<object, global::Vitorm.DbContext>>
             (CreateDataProvider<object>)
@@ -145,11 +139,23 @@ namespace Vit.AutoTemp
                     field.list_config ??= new();
                     field.ig_attr ??= new();
 
+                    var title = field.title;
+                    if (string.IsNullOrWhiteSpace(title))
+                    {
+                        if (!string.IsNullOrWhiteSpace(comment))
+                        {
+                            title = comment;
+                            title = autoTempReg.Replace(title, "");
+                            title = autoTempFieldReg.Replace(title, "")?.Trim();
+                        }
+
+                        if (string.IsNullOrWhiteSpace(title)) title = column.column_name;
+                    }
 
-                    field.title ??= column.column_name;
+                    field.title ??= title;
                     field.field ??= column.column_name;
 
-                    field.list_config.title ??= column.column_name;
+                    field.list_config.title ??= title;
                     field.list_config.width ??= 200;
                     field.list_config.visible ??= true;
 

+ 54 - 24
src/Vit.AutoTemp/DataProvider/DataProvider_Vitorm.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 
@@ -15,6 +16,8 @@ using Vit.Linq;
 using Vit.Linq.ComponentModel;
 using Vit.Linq.FilterRules.ComponentModel;
 
+using Vitorm;
+
 namespace Vit.AutoTemp.DataProvider
 {
     public class DataProvider_Vitorm<Model, DbContext> : IDataProvider_Vitorm
@@ -27,19 +30,23 @@ namespace Vit.AutoTemp.DataProvider
         public TableSchema tableSchema { get; private set; }
 
 
-        string idField => controllerConfig?.idField;
-        string pidField => controllerConfig?.pidField;
-        readonly Type entityType;
-        AutoTempControllerConfig controllerConfig;
-        readonly Func<DbContext> CreateDbContext;
+        protected string idField => controllerConfig?.idField;
+        protected string pidField => controllerConfig?.pidField;
+        protected readonly Type entityType;
+        protected AutoTempControllerConfig controllerConfig;
+        protected readonly Func<DbContext> CreateDbContext;
+        protected readonly Func<DbContext, IDbSet<Model>> GetDbSet = (dbContext => dbContext.DbSet<Model>());
 
 
-        public DataProvider_Vitorm(string template, Func<DbContext> CreateDbContext, TableSchema tableSchema = null, AutoTempControllerConfig controllerConfig = null)
+        public DataProvider_Vitorm(string template, Func<DbContext> CreateDbContext, TableSchema tableSchema = null, Func<DbContext, IDbSet<Model>> GetDbSet = null, AutoTempControllerConfig controllerConfig = null)
         {
             this.template = template;
 
             this.CreateDbContext = CreateDbContext;
 
+            if (GetDbSet != null)
+                this.GetDbSet = GetDbSet;
+
             entityType = typeof(Model);
 
             tableSchema ??= AutoTempHelp.EntityTypeToTableSchema(entityType);
@@ -51,7 +58,7 @@ namespace Vit.AutoTemp.DataProvider
 
 
         #region getConfig
-        public ApiReturn<AutoTempControllerConfig> getControllerConfig(object sender)
+        public virtual ApiReturn<AutoTempControllerConfig> getControllerConfig(object sender)
         {
             var config = Json.ConvertBySerialize<AutoTempControllerConfig>(controllerConfig);
             return config;
@@ -61,13 +68,27 @@ namespace Vit.AutoTemp.DataProvider
 
 
         #region getList
-        public ApiReturn getList(object sender, FilterRule filter, IEnumerable<OrderField> sort, PageInfo page, JObject arg)
+        public virtual PageData<Model> GetList(FilterRule filter=null, IEnumerable<OrderField> sort = null, PageInfo page = null)
         {
             using var dbContext = CreateDbContext();
+            var dbSet = GetDbSet(dbContext);
 
-            var query = dbContext.Query<Model>();
+            var query = dbSet.Query();
 
             var data = query.ToPageData(filter, sort, page);
+
+            return data;
+        }
+
+        public virtual ApiReturn getList(object sender, FilterRule filter, IEnumerable<OrderField> sort, PageInfo page, JObject arg) 
+        {
+            using var dbContext = CreateDbContext();
+            var dbSet = GetDbSet(dbContext);
+
+            var query = dbSet.Query();
+
+            var data = query.ToPageData(filter, sort, page);
+
             var pageData = Json.Deserialize<PageData<JObject>>(Json.Serialize(data));
 
             #region _childrenCount
@@ -89,38 +110,45 @@ namespace Vit.AutoTemp.DataProvider
 
 
         #region getModel
-        public ApiReturn getModel(object sender, string id)
+        public virtual new ApiReturn<Model> getModel(object sender, string id)
         {
             using var dbContext = CreateDbContext();
-            var entity = dbContext.Get<Model>(id);
+            var dbSet = GetDbSet(dbContext);
 
-            return new ApiReturn<object> { data = entity };
+            var entity = dbSet.Get(id);
+
+            return entity;
         }
+
+        ApiReturn IDataProvider.getModel(object sender, string id) => getModel(sender, id);
+
         #endregion
 
         #region insert
-        public ApiReturn insert(object sender, JObject model)
+        public virtual ApiReturn insert(object sender, JObject model)
         {
+            using var dbContext = CreateDbContext();
+            var dbSet = GetDbSet(dbContext);
+
             var userModel = model.ConvertBySerialize<Model>();
 
-            using (var dbContext = CreateDbContext())
-            {
-                dbContext.Add(userModel);
-            }
+            dbSet.Add(userModel);
+
             return new ApiReturn<object>(userModel);
         }
         #endregion
 
 
         #region update
-        public ApiReturn update(object sender, JObject model, string id)
+        public virtual ApiReturn update(object sender, JObject model, string id)
         {
-            var userModel = model.ConvertBySerialize(entityType);
-
             using var dbContext = CreateDbContext();
+            var dbSet = GetDbSet(dbContext);
+
+            var userModel = model.ConvertBySerialize(entityType);
 
             var _id = model[idField].GetValue();
-            var entity = dbContext.Get<Model>(_id);
+            var entity = dbSet.Get(_id);
 
             if (entity == null)
             {
@@ -132,7 +160,7 @@ namespace Vit.AutoTemp.DataProvider
 
             entity.CopyNotNullProrertyFrom(userModel);
 
-            dbContext.Update(entity);
+            dbSet.Update(entity);
 
             return new ApiReturn<object> { data = entity };
 
@@ -141,11 +169,13 @@ namespace Vit.AutoTemp.DataProvider
 
 
         #region delete
-        public ApiReturn delete(object sender, JObject arg)
+        public virtual ApiReturn delete(object sender, JObject arg)
         {
             using var dbContext = CreateDbContext();
+            var dbSet = GetDbSet(dbContext);
+
             var id = arg["id"].GetValue();
-            var count = dbContext.DeleteByKey<Model>(id);
+            var count = dbSet.DeleteByKey(id);
 
             if (count == 0)
             {