@@ -24,7 +24,7 @@ public static TableInfo AnalyzeTable(DataTable dt, string tableName, out string
24
24
}
25
25
else
26
26
{
27
- // 解析出第一列,然后检查主键唯一性,如果是string型主键还要检查是否非空、是否符合变量名的规范 (只能由英文字母、数字、下划线组成)
27
+ // 解析出主键列,然后检查是否非空、唯一,如果是string型主键还要检查是否符合变量名的规范 (只能由英文字母、数字、下划线组成)
28
28
FieldInfo primaryKeyField = _AnalyzeOneField ( dt , tableInfo , 0 , null , out curColumnIndex , out errorString ) ;
29
29
if ( errorString != null )
30
30
{
@@ -43,7 +43,8 @@ public static TableInfo AnalyzeTable(DataTable dt, string tableName, out string
43
43
errorString = _GetTableAnalyzeErrorString ( tableName , 0 ) + "主键列存在重复错误\n " + errorString ;
44
44
return null ;
45
45
}
46
- // string型主键检查是否非空、是否符合变量名的规范
46
+
47
+ // string型主键检查是否符合变量名的规范
47
48
if ( primaryKeyColumnType == DataType . String )
48
49
{
49
50
StringBuilder errorStringBuilder = new StringBuilder ( ) ;
@@ -57,6 +58,21 @@ public static TableInfo AnalyzeTable(DataTable dt, string tableName, out string
57
58
if ( ! string . IsNullOrEmpty ( errorStringBuilder . ToString ( ) ) )
58
59
{
59
60
errorString = _GetTableAnalyzeErrorString ( tableName , 0 ) + "string型主键列存在非法数据\n " + errorStringBuilder . ToString ( ) ;
61
+ return null ;
62
+ }
63
+ }
64
+
65
+ // 非空检查(因为string型检查是否符合变量名规范时以及未声明数值型字段中允许空时,均已对主键列进行过非空检查,这里只需对数据值字段且声明数值型字段中允许空的情况下进行非空检查)
66
+ if ( AppValues . IsAllowedNullNumber == true && ( primaryKeyColumnType == DataType . Int || primaryKeyColumnType == DataType . Long ) )
67
+ {
68
+ FieldCheckRule notEmptyCheckRule = new FieldCheckRule ( ) ;
69
+ uniqueCheckRule . CheckType = TableCheckType . NotEmpty ;
70
+ uniqueCheckRule . CheckRuleString = "notEmpty" ;
71
+ TableCheckHelper . CheckNotEmpty ( primaryKeyField , notEmptyCheckRule , out errorString ) ;
72
+ if ( errorString != null )
73
+ {
74
+ errorString = _GetTableAnalyzeErrorString ( tableName , 0 ) + "主键列存在非空错误\n " + errorString ;
75
+ return null ;
60
76
}
61
77
}
62
78
@@ -1433,7 +1449,7 @@ private static TableStringFormatDefine _GetTableStringFormatDefine(string dataTy
1433
1449
Dictionary < string , int > tableKeys = new Dictionary < string , int > ( ) ;
1434
1450
for ( int i = 0 ; i < tableElementDefine . Length ; ++ i )
1435
1451
{
1436
- TableElementDefine oneTableElementDefine = _GetTablelementDefine ( tableElementDefine [ i ] . Trim ( ) , out errorString ) ;
1452
+ TableElementDefine oneTableElementDefine = _GetTableElementDefine ( tableElementDefine [ i ] . Trim ( ) , out errorString ) ;
1437
1453
if ( errorString != null )
1438
1454
{
1439
1455
errorString = string . Format ( "table类型值声明错误,无法解析{0}," , tableElementDefine [ i ] . Trim ( ) ) + errorString ;
@@ -1481,7 +1497,7 @@ private static TableStringFormatDefine _GetTableStringFormatDefine(string dataTy
1481
1497
/// <summary>
1482
1498
/// 将形如type=#1(int)的格式定义字符串转为TableElementDefine定义
1483
1499
/// </summary>
1484
- private static TableElementDefine _GetTablelementDefine ( string tableElementDefine , out string errorString )
1500
+ private static TableElementDefine _GetTableElementDefine ( string tableElementDefine , out string errorString )
1485
1501
{
1486
1502
TableElementDefine elementDefine = new TableElementDefine ( ) ;
1487
1503
0 commit comments