Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gis_dev
校园建筑物GIS
提交
bfd92fc5
校
校园建筑物GIS
项目概览
gis_dev
/
校园建筑物GIS
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
校
校园建筑物GIS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bfd92fc5
编写于
11月 27, 2023
作者:
lixilin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加数据库接口和SQLSERVER助手
上级
8f077eb2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
554 addition
and
0 deletion
+554
-0
Core/EnumDbType.cs
Core/EnumDbType.cs
+21
-0
Core/SketchStyleConfig.cs
Core/SketchStyleConfig.cs
+109
-0
DAL/IDBHelper.cs
DAL/IDBHelper.cs
+86
-0
DAL/SqlServerHelper.cs
DAL/SqlServerHelper.cs
+338
-0
未找到文件。
Core/EnumDbType.cs
0 → 100644
浏览文件 @
bfd92fc5
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
CSU.Ligq.Core
{
/// <summary>
/// 数据类型
/// </summary>
public
enum
DbType
{
/// <summary>
/// 未知数据库
/// </summary>
UNKNOW
=
0
,
POSTGIS
=
1
,
SQLSERVER
=
2
}
}
Core/SketchStyleConfig.cs
0 → 100644
浏览文件 @
bfd92fc5
using
ESRI.ArcGIS.Display
;
using
System
;
using
System.Collections.Generic
;
using
System.Configuration
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
CSU.Ligq.Core
{
/// <summary>
/// 草图风格配置
/// </summary>
public
class
SketchStyleConfig
{
IRgbColor
lineColor
=
new
RgbColor
();
int
lineWidth
=
1
;
IRgbColor
fillColor
=
new
RgbColor
();
esriSimpleLineStyle
lineStyle
;
/// <summary>
/// 线颜色
/// </summary>
public
IRgbColor
LineColor
{
get
=>
lineColor
;
set
=>
lineColor
=
value
;
}
/// <summary>
/// 线宽
/// </summary>
public
int
LineWidth
{
get
=>
lineWidth
;
set
=>
lineWidth
=
value
;
}
/// <summary>
/// 填充颜色
/// </summary>
public
IRgbColor
FillColor
{
get
=>
fillColor
;
set
=>
fillColor
=
value
;
}
/// <summary>
/// 线型
/// </summary>
public
esriSimpleLineStyle
LineStyle
{
get
=>
lineStyle
;
set
=>
lineStyle
=
value
;
}
static
SketchStyleConfig
instance
;
/// <summary>
/// 获取/创建实例
/// </summary>
/// <returns></returns>
public
static
SketchStyleConfig
GetInstance
()
{
if
(
instance
==
null
)
{
instance
=
new
SketchStyleConfig
();
instance
.
ReadConfig
();
}
return
instance
;
}
/// <summary>
/// 读取数据库配置
/// </summary>
public
void
ReadConfig
()
{
try
{
string
str
=
ConfigurationManager
.
AppSettings
[
"sketch-line-color"
].
Trim
();
string
[]
arr
=
str
.
Split
(
','
);
if
(
arr
.
Length
==
3
)
{
this
.
lineColor
.
Red
=
int
.
Parse
(
arr
[
0
]);
this
.
lineColor
.
Green
=
int
.
Parse
(
arr
[
1
]);
this
.
lineColor
.
Blue
=
int
.
Parse
(
arr
[
2
]);
}
str
=
ConfigurationManager
.
AppSettings
[
"sketch-fill-color"
].
Trim
();
arr
=
str
.
Split
(
','
);
if
(
arr
.
Length
==
3
)
{
this
.
fillColor
.
Red
=
int
.
Parse
(
arr
[
0
]);
this
.
fillColor
.
Green
=
int
.
Parse
(
arr
[
1
]);
this
.
fillColor
.
Blue
=
int
.
Parse
(
arr
[
2
]);
}
str
=
ConfigurationManager
.
AppSettings
[
"sketch-line-width"
].
Trim
();
int
.
TryParse
(
str
,
out
this
.
lineWidth
);
str
=
ConfigurationManager
.
AppSettings
[
"sketch-line-style"
].
Trim
();
int
i
=
0
;
int
.
TryParse
(
str
,
out
i
);
this
.
lineStyle
=
(
esriSimpleLineStyle
)
i
;
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
/// <summary>
/// 保存配置
/// </summary>
public
void
SaveConfig
()
{
Configuration
config
=
ConfigurationManager
.
OpenExeConfiguration
(
ConfigurationUserLevel
.
None
);
config
.
AppSettings
.
Settings
[
"sketch-line-color"
].
Value
=
$"
{
this
.
lineColor
.
Red
}
,
{
this
.
lineColor
.
Green
}
,
{
this
.
lineColor
.
Blue
}
"
;
config
.
AppSettings
.
Settings
[
"sketch-line-width"
].
Value
=
this
.
lineWidth
.
ToString
();
config
.
AppSettings
.
Settings
[
"sketch-line-style"
].
Value
=
((
int
)
this
.
lineStyle
).
ToString
();
config
.
AppSettings
.
Settings
[
"sketch-fill-color"
].
Value
=
$"
{
this
.
fillColor
.
Red
}
,
{
this
.
fillColor
.
Green
}
,
{
this
.
fillColor
.
Blue
}
"
;
;
config
.
Save
(
ConfigurationSaveMode
.
Modified
);
}
}
}
DAL/IDBHelper.cs
0 → 100644
浏览文件 @
bfd92fc5
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data.Common
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
CSU.Ligq.Dal
{
/// <summary>
/// 接口:数据库助手接口
/// 作者:李光强
/// 时间:2023.11.11
/// </summary>
/// <remarks></remarks>
public
interface
IDBHelper
{
Core
.
DbType
GetDbType
();
/// <summary>
/// 创建数据库助手实例
/// </summary>
/// <returns></returns>
IDBHelper
CreateInstance
();
/// <summary>
/// 获取数据库的版本,用于测试数据库连接是否成功
/// </summary>
/// <returns></returns>
string
GetVersion
();
/// <summary>
/// 获取记录数
/// </summary>
/// <param name="where">查询条件从句</param>
/// <param name="tblName">数据库名称,可以指定模式名称</param>
int
GetCount
(
string
tblName
,
string
where
);
/// <summary>
/// 执行查询SQL
/// </summary>
/// <param name="cmdParms">查询参数列表</param>
/// <param name="sql">sql语句</param>
/// <returns>DataTable</returns>
DataTable
ExecuteQuery
(
string
sql
,
params
DbParameter
[]
cmdParms
);
/// <summary>
/// 执行查询
/// </summary>
/// <param name="cmdParms">查询参数列表</param>
/// <param name="cmdText">查询命令</param>
/// <param name="cmdType">查询方式</param>
/// <returns>DataTable</returns>
DataTable
ExecuteQuery
(
CommandType
cmdType
,
string
cmdText
,
DbParameter
[]
cmdParms
=
null
);
/// <summary>
/// 执行SQL语句 语句并返回受影响的行数。
/// </summary>
/// <param name="cmdParms">参数列表</param>
/// <param name="cmdText">SQL语句</param>
/// <param name="cmdType">命令类型</param>
int
ExecuteNonQuery
(
string
cmdText
,
CommandType
cmdType
=
CommandType
.
Text
,
DbParameter
[]
cmdParms
=
null
);
/// <summary>
/// 执行查询,返回DataReader
/// </summary>
DbDataReader
ExecuteReader
(
CommandType
cmdType
,
string
cmdText
,
params
DbParameter
[]
cmdParms
);
/// <summary>
/// 执行查询,并返回查询所返回的结果集中第一行的第一列。忽略其他列或行。
/// </summary>
/// <param name="cmdParms">参数列表</param>
/// <param name="cmdText">SQL</param>
/// <param name="cmdType">命令类型</param>
object
ExecuteScalar
(
CommandType
cmdType
,
string
cmdText
,
params
DbParameter
[]
cmdParms
);
}
}
DAL/SqlServerHelper.cs
0 → 100644
浏览文件 @
bfd92fc5
using
System
;
using
System.Data
;
using
System.Data.OleDb
;
using
System.Data.SqlClient
;
using
System.Windows.Forms
;
using
System.IO
;
using
System.Drawing
;
using
System.Data.Common
;
using
CSU.Ligq.Core
;
using
System.Text
;
namespace
CSU.Ligq.Dal
{
/// <summary>
/// 类名:SQLSERVER数据库连接类
/// 作者:李光强
/// 时间:2009.11.18
/// 版本:V1.0
/// 修改:2023.11.12
/// 版本:V2.0
/// </summary>
/// <remarks></remarks>
public
class
SQLServerHelper
:
IDBHelper
{
#
region
私有变量
/// <summary>
/// 连接字符串
/// </summary>
/// <remarks>示例: "Host=localhost;Username=postgres;Password=s$cret;Database=testdb";</remarks>
string
connectionString
;
/// <summary>
/// 数据库连接
/// </summary>
protected
SqlConnection
connection
;
#
endregion
/// <summary>
/// 创建实例
/// </summary>
/// <returns></returns>
public
IDBHelper
CreateInstance
()
{
return
new
SQLServerHelper
();
}
/// <summary>
/// 构造函数
/// </summary>
/// <remarks></remarks>
public
SQLServerHelper
(
)
{
this
.
connectionString
=
string
.
Format
(
"Data Source={0},{4};persist security info=true;user id={1};password={2};Initial Catalog={3};"
,
DbConfig
.
GetInstance
().
Host
,
DbConfig
.
GetInstance
().
User
,
DbConfig
.
GetInstance
().
Password
,
DbConfig
.
GetInstance
().
Database
,
DbConfig
.
GetInstance
().
Port
);
}
/// <summary>
/// 构造函数
/// </summary>
/// <remarks></remarks>
public
SQLServerHelper
(
string
connStr
)
{
this
.
connectionString
=
connStr
;
}
/// <summary>
/// 构造函数
/// </summary>
/// <remarks></remarks>
public
SQLServerHelper
(
string
host
,
string
user
,
string
password
,
string
dataBase
,
int
port
)
{
this
.
connectionString
=
string
.
Format
(
"Data Source={0},{4};persist security info=true;user id={1};password={2};Initial Catalog={3};"
,
host
,
user
,
password
,
dataBase
,
port
);
}
/// <summary>
/// 返回数据类型
/// </summary>
/// <returns></returns>
public
Core
.
DbType
GetDbType
()
{
return
Core
.
DbType
.
SQLSERVER
;
}
/// <summary>
/// 获取数据库的版本,用于测试数据库连接是否成功
/// </summary>
/// <returns></returns>
public
string
GetVersion
()
{
try
{
string
sql
=
"select @@VERSION"
;
DataTable
dt
=
this
.
ExecuteQuery
(
sql
);
if
(
dt
!=
null
)
{
DataRow
row
=
dt
.
Rows
[
0
];
return
row
[
0
].
ToString
();
}
else
throw
new
Exception
(
"数据连接失败."
);
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
/// <summary>
/// 获取记录数
/// </summary>
/// <param name="condition">查询条件从句</param>
/// <param name="tblName">数据库名称,可以指定模式名称</param>
public
int
GetCount
(
string
tblName
,
string
condition
)
{
try
{
StringBuilder
sql
=
new
StringBuilder
(
$"select count(*) from
{
tblName
}
"
);
if
(!
string
.
IsNullOrEmpty
(
condition
))
sql
.
Append
(
$" where
{
condition
}
"
);
object
count
=
ExecuteScalar
(
CommandType
.
Text
,
sql
.
ToString
(),
null
);
return
int
.
Parse
(
count
.
ToString
());
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
/// <summary>
/// 执行查询SQL
/// </summary>
/// <param name="cmdParms">查询参数列表</param>
/// <param name="sql">sql语句</param>
/// <returns>DataTable</returns>
public
DataTable
ExecuteQuery
(
string
sql
,
params
DbParameter
[]
cmdParms
)
{
try
{
using
(
SqlConnection
conn
=
new
SqlConnection
(
connectionString
))
{
conn
.
Open
();
this
.
connection
=
conn
;
using
(
SqlCommand
cmd
=
new
SqlCommand
())
{
PrepareCommand
(
cmd
,
CommandType
.
Text
,
sql
,
cmdParms
);
using
(
SqlDataAdapter
da
=
new
SqlDataAdapter
(
cmd
))
{
DataSet
ds
=
new
DataSet
();
da
.
Fill
(
ds
,
"ds"
);
cmd
.
Parameters
.
Clear
();
if
(
ds
.
Tables
.
Count
>
0
)
return
ds
.
Tables
[
0
];
else
return
null
;
}
}
}
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
/// <summary>
/// 执行查询
/// </summary>
/// <param name="cmdParms">查询参数列表</param>
/// <param name="cmdText">查询命令</param>
/// <param name="cmdType">查询方式</param>
/// <returns>DataTable</returns>
public
DataTable
ExecuteQuery
(
CommandType
cmdType
,
string
cmdText
,
DbParameter
[]
cmdParms
=
null
)
{
try
{
using
(
SqlConnection
conn
=
new
SqlConnection
(
connectionString
))
{
conn
.
Open
();
this
.
connection
=
conn
;
using
(
SqlCommand
cmd
=
new
SqlCommand
())
{
PrepareCommand
(
cmd
,
cmdType
,
cmdText
,
cmdParms
);
using
(
SqlDataAdapter
da
=
new
SqlDataAdapter
(
cmd
))
{
DataSet
ds
=
new
DataSet
();
da
.
Fill
(
ds
,
"ds"
);
cmd
.
Parameters
.
Clear
();
if
(
ds
.
Tables
.
Count
>
0
)
return
ds
.
Tables
[
0
];
else
return
null
;
}
}
}
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
/// <summary>
/// 执行SQL语句 语句并返回受影响的行数。
/// </summary>
/// <param name="cmdParms">参数列表</param>
/// <param name="cmdText">SQL语句</param>
/// <param name="cmdType">命令类型</param>
public
int
ExecuteNonQuery
(
string
cmdText
,
CommandType
cmdType
=
CommandType
.
Text
,
DbParameter
[]
cmdParms
=
null
)
{
try
{
using
(
SqlConnection
conn
=
new
SqlConnection
(
connectionString
))
{
conn
.
Open
();
this
.
connection
=
conn
;
using
(
SqlCommand
cmd
=
new
SqlCommand
())
{
PrepareCommand
(
cmd
,
cmdType
,
cmdText
,
cmdParms
);
int
val
=
cmd
.
ExecuteNonQuery
();
cmd
.
Parameters
.
Clear
();
return
val
;
}
}
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
/// <summary>
/// 执行查询,返回DataReader
/// </summary>
public
DbDataReader
ExecuteReader
(
CommandType
cmdType
,
string
cmdText
,
params
DbParameter
[]
cmdParms
)
{
try
{
using
(
SqlConnection
conn
=
new
SqlConnection
(
connectionString
))
{
conn
.
Open
();
this
.
connection
=
conn
;
using
(
SqlCommand
cmd
=
new
SqlCommand
())
{
PrepareCommand
(
cmd
,
cmdType
,
cmdText
,
cmdParms
);
SqlDataReader
rdr
=
cmd
.
ExecuteReader
(
CommandBehavior
.
CloseConnection
);
cmd
.
Parameters
.
Clear
();
return
rdr
;
}
}
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
/// <summary>
/// 执行查询,并返回查询所返回的结果集中第一行的第一列。忽略其他列或行。
/// </summary>
/// <param name="cmdParms">参数列表</param>
/// <param name="cmdText">SQL</param>
/// <param name="cmdType">命令类型</param>
public
object
ExecuteScalar
(
CommandType
cmdType
,
string
cmdText
,
params
DbParameter
[]
cmdParms
)
{
try
{
using
(
SqlConnection
conn
=
new
SqlConnection
(
connectionString
))
{
conn
.
Open
();
this
.
connection
=
conn
;
using
(
SqlCommand
cmd
=
new
SqlCommand
())
{
PrepareCommand
(
cmd
,
cmdType
,
cmdText
,
cmdParms
);
object
val
=
cmd
.
ExecuteScalar
();
cmd
.
Parameters
.
Clear
();
return
val
;
}
}
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
/// <summary>
/// 生成要执行的命令
/// </summary>
/// <remarks>参数的格式:冒号+参数名</remarks>
private
void
PrepareCommand
(
DbCommand
cmd
,
CommandType
cmdType
,
string
cmdText
,
DbParameter
[]
cmdParms
)
{
try
{
cmd
.
Connection
=
this
.
connection
;
cmd
.
CommandText
=
cmdText
;
//.Replace(":", "@").Replace("?", "@");
cmd
.
CommandType
=
cmdType
;
if
(
cmdParms
!=
null
)
{
foreach
(
SqlParameter
parm
in
cmdParms
)
{
parm
.
ParameterName
=
parm
.
ParameterName
;
//.Replace(":", "@").Replace("?", "@");
cmd
.
Parameters
.
Add
(
parm
);
}
}
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录