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
abac8e37
Commit
abac8e37
authored
Jun 24, 2021
by
tr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、自动更新程序优化:剔除冗余方法和文件
parent
751936b2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
667 deletions
+88
-667
AutoUpdate.csproj
AutoUpdate/AutoUpdate.csproj
+0
-2
Form1.cs
AutoUpdate/Form1.cs
+88
-5
SmpDB.cs
AutoUpdate/SmpDB.cs
+0
-598
Utils.cs
AutoUpdate/Utils.cs
+0
-62
No files found.
AutoUpdate/AutoUpdate.csproj
View file @
abac8e37
...
@@ -59,8 +59,6 @@
...
@@ -59,8 +59,6 @@
</Compile>
</Compile>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"SmpDB.cs"
/>
<Compile
Include=
"Utils.cs"
/>
<EmbeddedResource
Include=
"Form1.resx"
>
<EmbeddedResource
Include=
"Form1.resx"
>
<DependentUpon>
Form1.cs
</DependentUpon>
<DependentUpon>
Form1.cs
</DependentUpon>
</EmbeddedResource>
</EmbeddedResource>
...
...
AutoUpdate/Form1.cs
View file @
abac8e37
using
System
;
using
ICSharpCode.SharpZipLib.Zip
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Data
;
using
System.Data
;
using
System.Data.SqlClient
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.Drawing
;
using
System.IO
;
using
System.IO
;
...
@@ -69,8 +71,8 @@ namespace AutoUpdate
...
@@ -69,8 +71,8 @@ namespace AutoUpdate
private
void
AppUpdate
()
private
void
AppUpdate
()
{
{
string
link
=
Util
s
.
GetDbLinkString204
(
"FTT_Work"
);
string
link
=
thi
s
.
GetDbLinkString204
(
"FTT_Work"
);
DataTable
dt
=
new
SmpDB
()
.
GetDataTable
(
link
,
"SELECT TOP 1 * FROM dbo.FTT_AutoUpdate ORDER BY UDate DESC"
,
"FTT_AutoUpdate"
);
DataTable
dt
=
this
.
GetDataTable
(
link
,
"SELECT TOP 1 * FROM dbo.FTT_AutoUpdate ORDER BY UDate DESC"
,
"FTT_AutoUpdate"
);
if
(
dt
.
DefaultView
.
Count
>
0
)
if
(
dt
.
DefaultView
.
Count
>
0
)
{
{
//结束原进程
//结束原进程
...
@@ -94,7 +96,7 @@ namespace AutoUpdate
...
@@ -94,7 +96,7 @@ namespace AutoUpdate
File
.
WriteAllBytes
(
fileFullName
,
bytes
);
File
.
WriteAllBytes
(
fileFullName
,
bytes
);
this
.
AddProcessText
(
60
);
this
.
AddProcessText
(
60
);
//解压更新包到指定目录
//解压更新包到指定目录
Util
s
.
ZipDecompress
(
fileFullName
,
this
.
_path
);
thi
s
.
ZipDecompress
(
fileFullName
,
this
.
_path
);
this
.
AddProcessText
(
90
);
this
.
AddProcessText
(
90
);
//删除更新包
//删除更新包
File
.
Delete
(
fileFullName
);
File
.
Delete
(
fileFullName
);
...
@@ -106,6 +108,87 @@ namespace AutoUpdate
...
@@ -106,6 +108,87 @@ namespace AutoUpdate
this
.
textBox1
.
Text
+=
$"进度完成
{
value
}
%\r\n"
;
this
.
textBox1
.
Text
+=
$"进度完成
{
value
}
%\r\n"
;
}
}
#
region
工具方法
/// <summary>
/// 获取数据表
/// </summary>
/// <param name="strLink">数据库连接字串</param>
/// <param name="strSql">SQL语句</param>
/// <param name="strTableName">表名</param>
/// <param name="Schema">是否获取结构信息</param>
/// <returns></returns>
public
DataTable
GetDataTable
(
string
strLink
,
string
strSql
,
string
strTableName
,
bool
Schema
=
true
)
{
DataTable
dt
=
new
DataTable
(
strTableName
);
SqlConnection
conn
=
null
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
var
ada
=
new
SqlDataAdapter
(
strSql
,
conn
);
if
(
Schema
)
ada
.
FillSchema
(
dt
,
SchemaType
.
Mapped
);
//取出数据结构
ada
.
Fill
(
dt
);
//填充数据
}
catch
(
Exception
ex
)
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
throw
(
new
Exception
(
"获取数据出错:\r\n"
+
ex
.
Message
));
}
return
dt
;
}
/// <summary>
/// 获取204的数据库链接
/// </summary>
/// <param name="dbName"></param>
/// <returns></returns>
public
string
GetDbLinkString204
(
string
dbName
)
{
return
$"Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=
{
dbName
}
;Data Source=jhdsoft.gicp.net,3204"
;
}
/// <summary>
/// Zip:解压文件
/// </summary>
/// <param name="zipFileName">压缩包路径</param>
/// <param name="outFilePath">解压文件路径(缺省时,默认为桌面路径)</param>
public
void
ZipDecompress
(
string
zipFileName
,
string
outFilePath
=
""
)
{
if
(!
File
.
Exists
(
zipFileName
))
{
MessageBox
.
Show
(
$"Cannot find file '
{
zipFileName
}
'"
);
return
;
}
if
(
string
.
IsNullOrEmpty
(
outFilePath
))
{
outFilePath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
Desktop
);
}
using
ZipInputStream
zip
=
new
ZipInputStream
(
File
.
OpenRead
(
zipFileName
));
//zip.Password = "123";
byte
[]
buffer
=
new
byte
[
1024
];
//缓冲区大小
ZipEntry
entry
;
while
((
entry
=
zip
.
GetNextEntry
())
!=
null
)
{
string
directoryName
=
Path
.
GetDirectoryName
(
entry
.
Name
);
string
fileName
=
Path
.
GetFileName
(
entry
.
Name
);
if
(
string
.
IsNullOrEmpty
(
directoryName
)
||
string
.
IsNullOrEmpty
(
fileName
))
continue
;
//创建解压文件路径(压缩只考虑相对路径,所以这里创建时要加上输出路径)
Directory
.
CreateDirectory
(
$@"
{
outFilePath
}
\
{
directoryName
}
"
);
using
FileStream
fs
=
File
.
Create
(
$@"
{
outFilePath
}
\
{
entry
.
Name
}
"
);
//entry.Name <=> directoryName + fileName
//写入解压流
int
size
=
0
;
while
((
size
=
zip
.
Read
(
buffer
,
0
,
buffer
.
Length
))
>
0
)
{
fs
.
Write
(
buffer
,
0
,
size
);
}
}
}
#
endregion
}
}
}
}
AutoUpdate/SmpDB.cs
deleted
100644 → 0
View file @
751936b2
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
//----------------------------------------------
using
System.Data
;
using
System.Data.SqlClient
;
namespace
AutoUpdate
{
/// <summary>
/// 数据库操作类
/// </summary>
public
class
SmpDB
:
IDisposable
{
#
region
实现接口:
IDisposable
public
void
Dispose
()
{
}
#
endregion
/// <summary>
/// 获取数据表
/// </summary>
/// <param name="strLink">数据库连接字串</param>
/// <param name="strSql">SQL语句</param>
/// <param name="strTableName">表名</param>
/// <param name="Schema">是否获取结构信息</param>
/// <returns></returns>
public
DataTable
GetDataTable
(
string
strLink
,
string
strSql
,
string
strTableName
,
bool
Schema
=
true
)
{
DataTable
dt
=
new
DataTable
(
strTableName
);
SqlConnection
conn
=
null
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
var
ada
=
new
SqlDataAdapter
(
strSql
,
conn
);
if
(
Schema
)
ada
.
FillSchema
(
dt
,
SchemaType
.
Mapped
);
//取出数据结构
ada
.
Fill
(
dt
);
//填充数据
}
catch
(
Exception
ex
)
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
throw
(
new
Exception
(
"获取数据出错:\r\n"
+
ex
.
Message
));
}
return
dt
;
}
/// <summary>
/// 获取数据集
/// </summary>
/// <param name="strLink">数据库连接字串</param>
/// <param name="strSql">SQL语句</param>
/// <param name="strTableName">表名</param>
/// <returns></returns>
public
DataSet
GetData
(
string
strLink
,
string
strSql
,
string
strTableName
)
{
DataSet
dsData
=
new
DataSet
();
SqlConnection
conn
=
null
;
SqlDataAdapter
ada
=
null
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
ada
=
new
SqlDataAdapter
(
strSql
,
conn
);
ada
.
FillSchema
(
dsData
,
SchemaType
.
Mapped
,
strTableName
);
//取出数据结构
ada
.
Fill
(
dsData
,
strTableName
);
//填充数据
}
catch
(
Exception
ex
)
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
throw
(
new
Exception
(
"获取数据出错:\r\n"
+
ex
.
Message
));
}
return
dsData
;
}
/// <summary>
/// 获取数据集
/// </summary>
/// <param name="strLink">数据库连接字串</param>
/// <param name="Tables">表的扩展集合</param>
/// <param name="Schema">是否获取结构信息</param>
/// <returns></returns>
public
DataSet
GetData
(
string
strLink
,
List
<
TQuery
>
Tables
,
bool
Schema
)
{
DataSet
ds
=
new
DataSet
();
SqlConnection
conn
=
null
;
SqlCommand
cmd
=
null
;
SqlDataAdapter
ada
=
null
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
foreach
(
TQuery
t
in
Tables
)
{
cmd
=
new
SqlCommand
(
t
.
QuerySQL
,
conn
);
if
(
t
.
QueryParameters
.
Count
>
0
)
{
foreach
(
SqlParameter
para
in
t
.
QueryParameters
)
{
cmd
.
Parameters
.
Add
(
para
);
}
}
ada
=
new
SqlDataAdapter
(
cmd
);
if
(
Schema
)
{
ada
.
FillSchema
(
ds
,
SchemaType
.
Mapped
,
t
.
TableName
);
//取出数据结构
}
ada
.
Fill
(
ds
,
t
.
TableName
);
//填充数据
}
}
catch
(
Exception
ex
)
{
throw
(
new
Exception
(
"获取数据出错:\r\n"
+
ex
.
Message
));
}
finally
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
}
return
ds
;
}
/// <summary>
/// 保存数据表
/// <para>单表效率测试:100行0.75秒;500行3.7秒;5000行36秒左右</para>
/// </summary>
/// <param name="strLink">数据库连接字串</param>
/// <param name="dt">待保存表</param>
/// <returns></returns>
public
bool
SaveDataTable
(
string
strLink
,
DataTable
dt
)
{
SqlConnection
conn
=
null
;
SqlTransaction
tran
=
null
;
//
string
cmdText
=
$"Select * from
{
dt
.
TableName
}
"
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
var
dataAdapter
=
new
SqlDataAdapter
(
cmdText
,
conn
);
var
commandBuilder
=
new
SqlCommandBuilder
(
dataAdapter
)
{
ConflictOption
=
ConflictOption
.
OverwriteChanges
,
};
if
(
dt
.
PrimaryKey
.
Length
>
0
)
//没有主键是不能自动生成删除和更新语句的
{
dataAdapter
.
DeleteCommand
=
commandBuilder
.
GetDeleteCommand
();
dataAdapter
.
UpdateCommand
=
commandBuilder
.
GetUpdateCommand
();
}
dataAdapter
.
InsertCommand
=
commandBuilder
.
GetInsertCommand
();
tran
=
conn
.
BeginTransaction
();
//开始事务,并设置回滚点
if
(
dataAdapter
.
DeleteCommand
!=
null
)
//删除和更新有可能为空
dataAdapter
.
DeleteCommand
.
Transaction
=
tran
;
if
(
dataAdapter
.
UpdateCommand
!=
null
)
dataAdapter
.
UpdateCommand
.
Transaction
=
tran
;
//
dataAdapter
.
InsertCommand
.
Transaction
=
tran
;
dataAdapter
.
Update
(
dt
);
tran
.
Commit
();
}
catch
(
Exception
ex
)
{
if
(
tran
!=
null
)
tran
.
Rollback
();
throw
(
new
Exception
(
"保存数据集出错:\r\n"
+
ex
.
Message
));
}
finally
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
}
return
true
;
}
/// <summary>
/// 保存数据集
/// <para>单表效率测试:100行0.75秒;500行3.7秒;5000行36秒左右</para>
/// </summary>
/// <param name="strLink">数据库连接字串</param>
/// <param name="ds">待保存的数据集</param>
/// <returns></returns>
public
bool
SaveData
(
string
strLink
,
DataSet
ds
,
string
strTableName
)
{
SqlConnection
conn
=
null
;
SqlDataAdapter
dataAdapter
=
null
;
SqlCommandBuilder
commandBuilder
=
null
;
SqlTransaction
tran
=
null
;
//
string
cmdText
=
$"Select * from
{
strTableName
}
"
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
dataAdapter
=
new
SqlDataAdapter
(
cmdText
,
conn
);
commandBuilder
=
new
SqlCommandBuilder
(
dataAdapter
)
{
ConflictOption
=
ConflictOption
.
OverwriteChanges
};
if
(
ds
.
Tables
[
strTableName
].
PrimaryKey
.
Length
>
0
)
//没有主键是不能自动生成删除和更新语句的
{
dataAdapter
.
DeleteCommand
=
commandBuilder
.
GetDeleteCommand
();
dataAdapter
.
UpdateCommand
=
commandBuilder
.
GetUpdateCommand
();
}
dataAdapter
.
InsertCommand
=
commandBuilder
.
GetInsertCommand
();
tran
=
conn
.
BeginTransaction
();
//开始事务,并设置回滚点
if
(
dataAdapter
.
DeleteCommand
!=
null
)
//删除和更新有可能为空
dataAdapter
.
DeleteCommand
.
Transaction
=
tran
;
if
(
dataAdapter
.
UpdateCommand
!=
null
)
dataAdapter
.
UpdateCommand
.
Transaction
=
tran
;
//
dataAdapter
.
InsertCommand
.
Transaction
=
tran
;
dataAdapter
.
Update
(
ds
,
strTableName
);
tran
.
Commit
();
}
catch
(
Exception
ex
)
{
if
(
tran
!=
null
)
tran
.
Rollback
();
throw
(
new
Exception
(
"保存数据集出错:\r\n"
+
ex
.
Message
));
}
finally
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
}
return
true
;
}
/// <summary>
/// 保存数据集
/// <para>单表效率测试:100行0.76秒;500行3.7秒;5000行37秒左右</para>
/// </summary>
/// <param name="strLink">数据库连接字串</param>
/// <param name="ds">数据集</param>
/// <param name="Tables">表的扩展集合</param>
/// <returns></returns>
public
bool
SaveData
(
string
strLink
,
DataSet
ds
,
List
<
TQuery
>
Tables
)
{
List
<
SqlDataAdapter
>
SqlDAList
=
new
List
<
SqlDataAdapter
>();
//
SqlConnection
conn
=
null
;
SqlDataAdapter
dataAdapter
=
null
;
SqlCommandBuilder
commandBuilder
=
null
;
SqlTransaction
tran
=
null
;
string
cmdText
=
string
.
Empty
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
//生成命令
foreach
(
TQuery
t
in
Tables
)
{
cmdText
=
$"Select * from
{
t
.
TableName
}
"
;
dataAdapter
=
new
SqlDataAdapter
(
cmdText
,
conn
);
commandBuilder
=
new
SqlCommandBuilder
(
dataAdapter
)
{
ConflictOption
=
ConflictOption
.
OverwriteChanges
};
dataAdapter
.
DeleteCommand
=
commandBuilder
.
GetDeleteCommand
();
dataAdapter
.
InsertCommand
=
commandBuilder
.
GetInsertCommand
();
dataAdapter
.
UpdateCommand
=
commandBuilder
.
GetUpdateCommand
();
SqlDAList
.
Add
(
dataAdapter
);
}
//开启事务,统一设置事务回滚点
tran
=
conn
.
BeginTransaction
();
foreach
(
var
a
in
SqlDAList
)
{
a
.
DeleteCommand
.
Transaction
=
tran
;
a
.
UpdateCommand
.
Transaction
=
tran
;
a
.
InsertCommand
.
Transaction
=
tran
;
}
//更新数据
for
(
int
i
=
0
;
i
<
SqlDAList
.
Count
;
i
++)
{
var
tn
=
Tables
[
i
].
TableName
;
SqlDAList
[
i
].
Update
(
ds
,
tn
);
}
//提交事务
tran
.
Commit
();
}
catch
(
Exception
ex
)
{
if
(
tran
!=
null
)
tran
.
Rollback
();
throw
(
new
Exception
(
"保存数据集出错:\r\n"
+
ex
.
Message
));
}
finally
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
}
return
true
;
}
/// <summary>
/// 数据库连接测试
/// </summary>
/// <param name="strLink">数据库连接字串</param>
/// <returns></returns>
public
bool
ConnectionTest
(
string
strLink
)
{
SqlConnection
conn
=
null
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
}
catch
(
Exception
)
{
return
false
;
}
finally
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
}
return
true
;
}
/// <summary>
/// 执行SQL语句:这里的多条语句采用同一事务处理,方便出错时回滚,保证数据统一
/// </summary>
/// <param name="strLink">数据库连接</param>
/// <param name="sqls">带执行的SQL列表</param>
/// <returns></returns>
public
bool
ExecNonSql
(
string
strLink
,
params
string
[]
sqls
)
{
SqlConnection
conn
=
null
;
SqlCommand
cmd
=
null
;
SqlTransaction
tran
=
null
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
tran
=
conn
.
BeginTransaction
();
//开始事务
cmd
=
new
SqlCommand
();
cmd
.
Connection
=
conn
;
//绑定连接
cmd
.
Transaction
=
tran
;
//绑定事务
//批量处理命令
foreach
(
string
cmdText
in
sqls
)
{
cmd
.
CommandText
=
cmdText
;
cmd
.
CommandType
=
CommandType
.
Text
;
int
ret
=
cmd
.
ExecuteNonQuery
();
}
//提交事务
tran
.
Commit
();
}
catch
(
Exception
ex
)
{
if
(
tran
!=
null
)
tran
.
Rollback
();
throw
(
new
Exception
(
"执行SQL出错:\r\n"
+
ex
.
Message
));
}
finally
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
}
return
true
;
}
/// <summary>
/// 是否存在
/// </summary>
/// <param name="strLink"></param>
/// <param name="strSql"></param>
/// <returns></returns>
public
bool
IsExist
(
string
strLink
,
string
strSql
)
{
SqlConnection
conn
=
null
;
SqlCommand
cmd
=
null
;
object
objCount
=
null
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
cmd
=
new
SqlCommand
(
strSql
,
conn
);
objCount
=
cmd
.
ExecuteScalar
();
}
catch
(
Exception
ex
)
{
throw
(
new
Exception
(
"是否存在执行出错:\r\n"
+
ex
.
Message
));
}
finally
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
}
int
iCount
=
-
1
;
if
(!
int
.
TryParse
(
objCount
.
ToString
(),
out
iCount
))
{
throw
(
new
Exception
(
"数据类型转换失败!"
));
}
return
iCount
>
0
;
}
#
region
async
methods
/*
* 异步方法使用演示:
*
* 1.同步调用:
* ConnectionTestAsync(link).GetAwaiter().GetResult();
* 2.异步调用:
* public async void SomeMethod()
* {
* DataSet ds = await ConnectionTestAsync(link);
* }
* 注意:
* 1、同步调动需通过GetAwaiter().GetResult()等待结果
* 2、异步需使用async修饰,才能在方法内部使用await关键字。
* 使用async修饰的异步方法,必须返回void或Task<T>
*/
/// <summary>
/// 单表取数(异步)
/// </summary>
/// <param name="strLink"></param>
/// <param name="strSql"></param>
/// <param name="strTableName"></param>
/// <returns></returns>
public
Task
<
DataTable
>
GetDataTableAsync
(
string
strLink
,
string
strSql
,
string
strTableName
)
{
return
Task
.
Run
(()
=>
GetDataTable
(
strLink
,
strSql
,
strTableName
));
}
/// <summary>
/// 单表取数(异步)
/// </summary>
/// <param name="strLink"></param>
/// <param name="strSql"></param>
/// <param name="strTableName"></param>
/// <returns></returns>
public
Task
<
DataSet
>
GetDataAsync
(
string
strLink
,
string
strSql
,
string
strTableName
)
{
return
Task
.
Run
(()
=>
GetData
(
strLink
,
strSql
,
strTableName
));
}
/// <summary>
/// 多表取数(异步)
/// </summary>
/// <param name="strLink"></param>
/// <param name="Tables"></param>
/// <param name="Schema"></param>
/// <returns></returns>
public
Task
<
DataSet
>
GetDataAsync
(
string
strLink
,
List
<
TQuery
>
Tables
,
bool
Schema
)
{
return
Task
.
Run
(()
=>
GetData
(
strLink
,
Tables
,
Schema
));
}
/// <summary>
/// 单表保存(异步)
/// </summary>
/// <param name="ds"></param>
/// <param name="strLink"></param>
/// <param name="strTableName"></param>
/// <returns></returns>
public
Task
<
bool
>
SaveDataTableAsync
(
string
strLink
,
DataTable
dt
,
string
strTableName
)
{
return
Task
.
Run
(()
=>
SaveDataTable
(
strLink
,
dt
));
}
/// <summary>
/// 单表保存(异步)
/// </summary>
/// <param name="ds"></param>
/// <param name="strLink"></param>
/// <param name="strTableName"></param>
/// <returns></returns>
public
Task
<
bool
>
SaveDataAsync
(
string
strLink
,
DataSet
ds
,
string
strTableName
)
{
return
Task
.
Run
(()
=>
SaveData
(
strLink
,
ds
,
strTableName
));
}
/// <summary>
/// 多表保存(异步)
/// </summary>
/// <param name="ds"></param>
/// <param name="strLink"></param>
/// <param name="Tables"></param>
/// <returns></returns>
public
Task
<
bool
>
SaveDataAsync
(
string
strLink
,
DataSet
ds
,
List
<
TQuery
>
Tables
)
{
return
Task
.
Run
(()
=>
SaveData
(
strLink
,
ds
,
Tables
));
}
/// <summary>
/// 数据库连接测试(异步)
/// </summary>
/// <param name="strLink"></param>
/// <returns></returns>
public
Task
<
bool
>
ConnectionTestAsync
(
string
strLink
)
{
return
Task
.
Run
(()
=>
ConnectionTest
(
strLink
));
}
/// <summary>
/// SQL批量执行(异步)
/// </summary>
/// <param name="strLink"></param>
/// <param name="sqls"></param>
/// <returns></returns>
public
Task
<
bool
>
ExecNonSqlAsync
(
string
strLink
,
params
string
[]
sqls
)
{
return
Task
.
Run
(()
=>
ExecNonSql
(
strLink
,
sqls
));
}
/// <summary>
/// 是否存在(异步)
/// </summary>
/// <param name="strLink"></param>
/// <param name="strSql"></param>
/// <returns></returns>
public
Task
<
bool
>
ISExistAsync
(
string
strLink
,
string
strSql
)
{
return
Task
.
Run
(()
=>
IsExist
(
strLink
,
strSql
));
}
#
endregion
}
/// <summary>
/// 表查询
/// </summary>
public
class
TQuery
{
/// <summary>
/// 构造器
/// </summary>
/// <param name="tableName">数据库表名</param>
public
TQuery
(
string
tableName
)
{
this
.
TableName
=
tableName
;
this
.
QuerySQL
=
$"SELECT * FROM
{
tableName
}
"
;
}
/// <summary>
/// 构造器
/// </summary>
/// <param name="Name">数据库表名</param>
/// <param name="querySQL">查询语句</param>
public
TQuery
(
string
tableName
,
string
querySQL
,
params
SqlParameter
[]
parameters
)
{
this
.
TableName
=
tableName
;
this
.
QuerySQL
=
querySQL
;
this
.
QueryParameters
=
parameters
.
ToList
();
}
/// <summary>
/// 数据库表名
/// </summary>
public
string
TableName
{
get
;
set
;
}
/// <summary>
/// Select语句
/// </summary>
public
string
QuerySQL
{
get
;
set
;
}
/// <summary>
/// 选择语句参数
/// </summary>
public
List
<
SqlParameter
>
QueryParameters
=
new
List
<
SqlParameter
>();
}
}
AutoUpdate/Utils.cs
deleted
100644 → 0
View file @
751936b2
using
ICSharpCode.SharpZipLib.Zip
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
namespace
AutoUpdate
{
public
class
Utils
{
/// <summary>
/// 获取204的数据库链接
/// </summary>
/// <param name="dbName"></param>
/// <returns></returns>
public
static
string
GetDbLinkString204
(
string
dbName
)
{
return
$"Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=
{
dbName
}
;Data Source=jhdsoft.gicp.net,3204"
;
}
/// <summary>
/// Zip:解压文件
/// </summary>
/// <param name="zipFileName">压缩包路径</param>
/// <param name="outFilePath">解压文件路径(缺省时,默认为桌面路径)</param>
public
static
void
ZipDecompress
(
string
zipFileName
,
string
outFilePath
=
""
)
{
if
(!
File
.
Exists
(
zipFileName
))
{
MessageBox
.
Show
(
$"Cannot find file '
{
zipFileName
}
'"
);
return
;
}
if
(
string
.
IsNullOrEmpty
(
outFilePath
))
{
outFilePath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
Desktop
);
}
using
ZipInputStream
zip
=
new
ZipInputStream
(
File
.
OpenRead
(
zipFileName
));
//zip.Password = "123";
byte
[]
buffer
=
new
byte
[
1024
];
//缓冲区大小
ZipEntry
entry
;
while
((
entry
=
zip
.
GetNextEntry
())
!=
null
)
{
string
directoryName
=
Path
.
GetDirectoryName
(
entry
.
Name
);
string
fileName
=
Path
.
GetFileName
(
entry
.
Name
);
if
(
string
.
IsNullOrEmpty
(
directoryName
)
||
string
.
IsNullOrEmpty
(
fileName
))
continue
;
//创建解压文件路径(压缩只考虑相对路径,所以这里创建时要加上输出路径)
Directory
.
CreateDirectory
(
$@"
{
outFilePath
}
\
{
directoryName
}
"
);
using
FileStream
fs
=
File
.
Create
(
$@"
{
outFilePath
}
\
{
entry
.
Name
}
"
);
//entry.Name <=> directoryName + fileName
//写入解压流
int
size
=
0
;
while
((
size
=
zip
.
Read
(
buffer
,
0
,
buffer
.
Length
))
>
0
)
{
fs
.
Write
(
buffer
,
0
,
size
);
}
}
}
}
}
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