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
878b60ad
Commit
878b60ad
authored
May 28, 2020
by
tr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、增加复制相同列通用方法及非法行判断方法
parent
62332030
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
.gitignore
.gitignore
+1
-0
EasyDataTable.cs
FunnyPick/FunnyPick/EasyDataTable.cs
+51
-0
No files found.
.gitignore
View file @
878b60ad
...
...
@@ -4,3 +4,4 @@
/FunnyPick/.vs/FunnyPick/v16/Server/sqlite3
/FunnyPick/.vs/FunnyPick/v16/.suo
/FunnyPick/.vs/FunnyPick/DesignTimeBuild/.dtbcache
FunnyPick/FunnyPick/EasyDataTable.cs
View file @
878b60ad
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Linq
;
...
...
@@ -60,5 +61,55 @@ namespace FunnyPick
// result : "name1,name2,name3"
}
/// <summary>
/// 复制相同列
/// </summary>
/// <param name="dtFrom">源表</param>
/// <param name="dtTarget">目标表</param>
/// <param name="distinctCol">去重列</param>
/// <param name="ExceptColList">去除列(即包含在此列表中的列不复制)</param>
public
void
CopySameCol2Table
(
DataTable
dtFrom
,
DataTable
dtTarget
,
string
distinctCol
,
List
<
string
>
ExceptColList
=
null
)
{
foreach
(
DataRow
r
in
dtFrom
.
Rows
)
{
if
(
IsIllegalDataRow
(
r
))
continue
;
//如果去重列不为空,并且两表都包含该列,则取出重复值
if
(!
string
.
IsNullOrEmpty
(
distinctCol
)
&&
dtFrom
.
Columns
.
Contains
(
distinctCol
)
&&
dtTarget
.
Columns
.
Contains
(
distinctCol
))
{
if
(
dtTarget
.
Select
(
$"
{
distinctCol
}
='
{
r
[
distinctCol
]}
'"
).
Length
>
0
)
continue
;
}
//创建目标新行
DataRow
drNew
=
dtTarget
.
NewRow
();
foreach
(
DataColumn
c
in
dtFrom
.
Columns
)
{
string
ColName
=
c
.
ColumnName
;
//ID和指定忽略的列,不复制
if
(
ColName
.
Equals
(
"ID"
)
||
ExceptColList
?.
IndexOf
(
ColName
)
>=
0
)
continue
;
if
(
dtTarget
.
Columns
.
Contains
(
ColName
))
{
drNew
[
ColName
]
=
r
[
ColName
];
}
}
drNew
.
EndEdit
();
dtTarget
.
Rows
.
Add
(
drNew
);
}
}
/// <summary>
/// 是否无效行
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
public
bool
IsIllegalDataRow
(
DataRow
dr
)
{
return
dr
==
null
||
dr
.
RowState
==
DataRowState
.
Deleted
||
dr
.
RowState
==
DataRowState
.
Detached
;
}
}
}
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