Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
Ftt_Common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Ftt_Common
Commits
ba337e9e
Commit
ba337e9e
authored
Dec 22, 2023
by
陈航
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
字段可为空的类型转换和生成类代码调整
parent
8353a772
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
37 deletions
+45
-37
wAutoClass.cs
Tools/UI/wAutoClass.cs
+45
-37
No files found.
Tools/UI/wAutoClass.cs
View file @
ba337e9e
...
...
@@ -94,16 +94,30 @@ namespace Tools.UI
{
GenerateEntity
();
}
private
string
GetCsharpTypeNameBySqlType
(
string
nSqlTypeName
)
private
string
GetCsharpTypeNameBySqlType
(
string
nSqlTypeName
,
bool
isnull
)
{
switch
(
nSqlTypeName
)
{
case
"image"
:
return
"Image"
;
case
"int"
:
return
"int"
;
case
"datetime"
:
return
"DateTime?"
;
case
"bit"
:
return
"bool"
;
case
"varchar"
:
return
"string"
;
case
"char"
:
return
"char"
;
case
"image"
:
return
isnull
?
"image?"
:
"image"
;
case
"int"
:
return
isnull
?
"int?"
:
"int"
;
case
"bigint"
:
return
isnull
?
"long?"
:
"long"
;
case
"float"
:
return
isnull
?
"float?"
:
"float"
;
case
"decimal"
:
return
isnull
?
"decimal?"
:
"decimal"
;
case
"datetime"
:
return
isnull
?
"DateTime?"
:
"DateTime"
;
case
"bit"
:
return
isnull
?
"bool?"
:
"bool"
;
case
"char"
:
case
"varchar"
:
case
"nvarchar"
:
case
"text"
:
case
"ntext"
:
return
"string"
;
case
"uniqueidentifier"
:
return
isnull
?
"Guid?"
:
"Guid"
;
default
:
return
"string"
;
}
}
...
...
@@ -118,11 +132,11 @@ namespace Tools.UI
/// </summary>
private
void
GenerateEntity
()
{
if
(
lsbTableInfo
.
SelectedItem
==
null
)
return
;
if
(
lsbTableInfo
.
SelectedItem
==
null
)
return
;
string
strTableName
=
lsbTableInfo
.
SelectedItem
.
ToString
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
AppendLine
(
$@"SELECT b.name, b.user_type_id, c.name AS TypeName, ISNULL(d.value, b.name) AS Description
sb
.
AppendLine
(
$@"SELECT b.name, b.user_type_id, c.name AS TypeName, ISNULL(d.value, b.name) AS Description
, b.is_nullable
FROM sys.objects a
INNER JOIN sys.columns b ON b.object_id = a.object_id
INNER JOIN sys.types c ON b.user_type_id = c.user_type_id
...
...
@@ -137,46 +151,40 @@ ORDER BY b.column_id;
//生成前端列名
if
(
chkFrontendcolumn
.
Checked
)
{
sb
.
Append
(
$@"
Colums:
[
"
);
sb
.
AppendLine
(
"Colums:"
);
sb
.
AppendLine
(
"["
);
foreach
(
DataRow
row
in
dataTable
.
Rows
)
{
sb
.
Append
(
$@"
{{
label
:
'
{
row
[
"Description"
]}
'
,
value
:
'
{
row
[
"name"
]}
'
,
show_overflow_tooltip
:
true
}}
,"
);
sb
.
AppendLine
(
" {"
);
sb
.
AppendLine
(
$" label: '
{
row
[
"Description"
]}
',"
);
sb
.
AppendLine
(
$" value: '
{
row
[
"name"
]}
',"
);
sb
.
AppendLine
(
$" show_overflow_tooltip: true"
);
sb
.
AppendLine
(
" },"
);
}
txtResult
.
Text
=
sb
.
ToString
().
Substring
(
0
,
sb
.
ToString
().
Length
-
1
)
+
@"
]"
;
}
else
//生成实体类
{
sb
.
Append
(
$@"
/// <summary>
///
{
strTableName
}
/// </summary>
public class
{
strTableName
}
{{
");
sb
.
AppendLine
(
" /// <summary>"
);
sb
.
AppendLine
(
$" ///
{
strTableName
}
"
);
sb
.
AppendLine
(
" /// </summary>"
);
sb
.
AppendLine
(
$" public class
{
strTableName
}
"
);
sb
.
AppendLine
(
" {"
);
foreach
(
DataRow
row
in
dataTable
.
Rows
)
{
sb
.
Append
(
$@"
/// <summary>
///
{
row
[
"Description"
]}
/// </summary>
public
{
GetCsharpTypeNameBySqlType
(
row
[
"TypeName"
].
ToString
())}
{
row
[
"name"
]}
{{
get
;
set
;
}}
"
);
}
sb
.
AppendLine
(
$@" /// <summary>"
);
sb
.
AppendLine
(
$@" ///
{
row
[
"Description"
]}
"
);
sb
.
AppendLine
(
$@" /// </summary>"
);
sb
.
Append
(
$@"
}}
"
);
sb
.
AppendLine
(
$" public
{
GetCsharpTypeNameBySqlType
(
row
[
"TypeName"
].
ToString
(),
(
bool
)
row
[
"is_nullable"
])}
{
row
[
"name"
]}
{{
get
;
set
;
}}
"
);
sb
.
AppendLine
();
}
sb
.
AppendLine
(
" }"
);
txtResult
.
Text
=
sb
.
ToString
();
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment