SVN r1061
SVN-Revision: r1061
This commit is contained in:
+18
-27
@@ -20,6 +20,7 @@ using System.Net.Sockets;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Data.Common;
|
||||||
|
|
||||||
namespace Lskj.Core
|
namespace Lskj.Core
|
||||||
{
|
{
|
||||||
@@ -383,37 +384,27 @@ namespace Lskj.Core
|
|||||||
/// <para>版本:1.0</para>
|
/// <para>版本:1.0</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||||||
public bool CreateConnection(string Connection = "")
|
public bool CreateConnection(string Connection = "", ConnectionType connectionType = ConnectionType.SqlServer)
|
||||||
|
{
|
||||||
|
bool isConnect = false;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
string connStr = GetConnection(Connection);
|
string connStr = GetConnection(Connection);
|
||||||
if (SqlHelper._connection != null)
|
//connectionType = ConnectionType.KdbnServer;
|
||||||
|
//connStr = "host=192.168.0.55;port=54321;database=test3;username=lserpAdmin;password=lserp110;";
|
||||||
|
//connectionType = ConnectionType.DmServer;
|
||||||
|
//connStr = "Server=192.168.0.55:5236; schema=DBO; UserId=LSERPADMIN; PWD=Lserp110";
|
||||||
|
string providerName = "System.Data.SqlClient";
|
||||||
|
SqlHelper.ConnectionType = ConnectionType.SqlServer;
|
||||||
|
if (connectionType == ConnectionType.KdbnServer)
|
||||||
{
|
{
|
||||||
try
|
providerName = "Kdbndp";
|
||||||
{
|
SqlHelper.ConnectionType = ConnectionType.KdbnServer;
|
||||||
SqlHelper._connection.Close();
|
|
||||||
SqlHelper._connection.Dispose();
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
else if (connectionType == ConnectionType.DmServer)
|
||||||
{
|
{
|
||||||
|
providerName = "Dm";
|
||||||
|
SqlHelper.ConnectionType = ConnectionType.DmServer;
|
||||||
}
|
}
|
||||||
SqlHelper._connection = null;
|
SqlHelper.dbFactory = DbProviderFactories.GetFactory(providerName);
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SqlHelper._connection = new SqlConnection(connStr);
|
|
||||||
SqlHelper._connection.Open();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
LogHelper.Instance.WriteLog(ex.Message);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+395
-220
@@ -1,58 +1,77 @@
|
|||||||
/******************************
|
using Kdbndp;
|
||||||
* 说明:数据库操作类
|
using KdbndpTypes;
|
||||||
* 创建人:龚宇超
|
|
||||||
* 创建日期:2017-07-24
|
|
||||||
* 修改人:
|
|
||||||
* 修改日期:
|
|
||||||
* 修改备注:
|
|
||||||
* 版本:1.0.0.0
|
|
||||||
******************************/
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Data.SqlClient;
|
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Lskj.Core
|
namespace Lskj.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据库操作类
|
/// 数据库连接类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
public enum ConnectionType
|
||||||
|
{
|
||||||
|
SqlServer = 0,
|
||||||
|
KdbnServer = 1,
|
||||||
|
DmServer = 2
|
||||||
|
}
|
||||||
public static class SqlHelper
|
public static class SqlHelper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 连接类型
|
||||||
|
/// </summary>
|
||||||
|
private static ConnectionType connectionType = ConnectionType.SqlServer;
|
||||||
|
public static ConnectionType ConnectionType
|
||||||
|
{
|
||||||
|
get { return connectionType; }
|
||||||
|
set { connectionType = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 数据连接工厂
|
||||||
|
/// </summary>
|
||||||
|
public static DbProviderFactory dbFactory;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据连接
|
/// 数据连接
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static SqlConnection _connection;
|
public static DbConnection _connection;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求超时时间
|
/// 请求超时时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static int CommandTimeout;
|
public static int CommandTimeout;
|
||||||
|
/// <summary>
|
||||||
|
/// <para>说明:是否已经连接数据库</para>
|
||||||
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
|
/// <para>创建日期:2024-3-5 </para>
|
||||||
|
/// <para>功能关联:公版方法</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsConnect()
|
||||||
|
{
|
||||||
|
bool isConnect = _connection.State == ConnectionState.Open;
|
||||||
|
return isConnect;
|
||||||
|
}
|
||||||
#region ExecuteAdapter
|
#region ExecuteAdapter
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:获取适配器</para>
|
/// <para>说明:获取适配器</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType">Type of the command.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="commandParameters">The command parameters.</param>
|
||||||
/// <returns>SqlDataAdapter.</returns>
|
/// <returns>SqlDataAdapter.</returns>
|
||||||
public static SqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
public static DbDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
SqlDataAdapter adapter;
|
DbDataAdapter adapter = dbFactory.CreateDataAdapter();
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||||
adapter = new SqlDataAdapter(cmd);
|
adapter.SelectCommand = cmd;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -60,28 +79,23 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
return adapter;
|
return adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:获取适配器</para>
|
/// <para>说明:获取适配器</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType">Type of the command.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <returns>SqlDataAdapter.</returns>
|
/// <returns>SqlDataAdapter.</returns>
|
||||||
public static SqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText)
|
public static DbDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText)
|
||||||
{
|
{
|
||||||
SqlDataAdapter adapter;
|
DbDataAdapter adapter = dbFactory.CreateDataAdapter();
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
|
||||||
adapter = new SqlDataAdapter(cmd);
|
adapter.SelectCommand = cmd;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -90,16 +104,12 @@ namespace Lskj.Core
|
|||||||
return adapter;
|
return adapter;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ExecuteDataTable
|
#region ExecuteDataTable
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql返回DataTable</para>
|
/// <para>说明:执行sql返回DataTable</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <returns>DataTable.</returns>
|
/// <returns>DataTable.</returns>
|
||||||
@@ -109,28 +119,21 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql返回DataTable</para>
|
/// <para>说明:执行sql返回DataTable</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <returns>DataTable.</returns>
|
/// <returns>DataTable.</returns>
|
||||||
public static DataTable ExecuteDataTable(string cmdText, params SqlParameter[] commandParameters)
|
public static DataTable ExecuteDataTable(string cmdText, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
return ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0];
|
return ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql返回指定字段值</para>
|
/// <para>说明:执行sql返回指定字段值</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-08-15 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fieldName">Name of the field.</param>
|
/// <param name="fieldName">Name of the field.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
@@ -150,18 +153,15 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql返回指定字段值</para>
|
/// <para>说明:执行sql返回指定字段值</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-11-27 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fieldName">Name of the field.</param>
|
/// <param name="fieldName">Name of the field.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="commandParameters">The command parameters.</param>
|
||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public static object ExecuteObject(string fieldName, string cmdText, params SqlParameter[] commandParameters)
|
public static object ExecuteObject(string fieldName, string cmdText, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
object result = null;
|
object result = null;
|
||||||
try
|
try
|
||||||
@@ -176,12 +176,9 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql返回指定字段值</para>
|
/// <para>说明:执行sql返回指定字段值</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-08-15 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fieldName">Name of the field.</param>
|
/// <param name="fieldName">Name of the field.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
@@ -193,26 +190,21 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql返回指定字段值</para>
|
/// <para>说明:执行sql返回指定字段值</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-11-27 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fieldName">Name of the field.</param>
|
/// <param name="fieldName">Name of the field.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="commandParameters">The command parameters.</param>
|
||||||
/// <returns>System.String.</returns>
|
/// <returns>System.String.</returns>
|
||||||
public static string ExecuteString(string fieldName, string cmdText, params SqlParameter[] commandParameters)
|
public static string ExecuteString(string fieldName, string cmdText, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
object obj = ExecuteObject(fieldName, cmdText, commandParameters);
|
object obj = ExecuteObject(fieldName, cmdText, commandParameters);
|
||||||
return obj == null ? "" : obj.ToString();
|
return obj == null ? "" : obj.ToString();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ExecuteDataSet
|
#region ExecuteDataSet
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:查询结果集</para>
|
/// <para>说明:查询结果集</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建人:龚宇超</para>
|
||||||
@@ -227,7 +219,7 @@ namespace Lskj.Core
|
|||||||
/// <param name="tabName">Name of the tab.</param>
|
/// <param name="tabName">Name of the tab.</param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="commandParameters">The command parameters.</param>
|
||||||
/// <returns>DataSet.</returns>
|
/// <returns>DataSet.</returns>
|
||||||
public static DataSet ExecuteDataSet(int cmdType, string cmdText, string tabName, params SqlParameter[] commandParameters)
|
public static DataSet ExecuteDataSet(int cmdType, string cmdText, string tabName, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
CommandType _cmdType = CommandType.Text;
|
CommandType _cmdType = CommandType.Text;
|
||||||
switch (cmdType)
|
switch (cmdType)
|
||||||
@@ -255,14 +247,15 @@ namespace Lskj.Core
|
|||||||
/// <param name="tabName">表名</param>
|
/// <param name="tabName">表名</param>
|
||||||
/// <param name="commandParameters">参数</param>
|
/// <param name="commandParameters">参数</param>
|
||||||
/// <returns>DataSet.</returns>
|
/// <returns>DataSet.</returns>
|
||||||
public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName, params SqlParameter[] commandParameters)
|
public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
DataSet set2;
|
DataSet set2;
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);//sql参数处理
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);//sql参数处理
|
||||||
SqlDataAdapter adapter = new SqlDataAdapter(cmd);//创建对象,与sql命令对象绑定
|
DbDataAdapter adapter = dbFactory.CreateDataAdapter();
|
||||||
|
adapter.SelectCommand = cmd;//创建对象,与sql命令对象绑定
|
||||||
DataSet dataSet = new DataSet();
|
DataSet dataSet = new DataSet();
|
||||||
adapter.Fill(dataSet, tabName);//填充数据。第二个参数是数据集中内存表的名字,可以与数据库中的不同
|
adapter.Fill(dataSet, tabName);//填充数据。第二个参数是数据集中内存表的名字,可以与数据库中的不同
|
||||||
//adapter.FillSchema(dataSet, SchemaType.Mapped, tabName);
|
//adapter.FillSchema(dataSet, SchemaType.Mapped, tabName);
|
||||||
@@ -286,17 +279,13 @@ namespace Lskj.Core
|
|||||||
{
|
{
|
||||||
cmd.Dispose();
|
cmd.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
return set2;
|
return set2;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:查询结果集</para>
|
/// <para>说明:查询结果集</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
|
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
|
||||||
/// <param name="cmdText">执行内容</param>
|
/// <param name="cmdText">执行内容</param>
|
||||||
@@ -308,12 +297,9 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:查询结果集</para>
|
/// <para>说明:查询结果集</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdText">执行内容</param>
|
/// <param name="cmdText">执行内容</param>
|
||||||
/// <returns>DataSet.</returns>
|
/// <returns>DataSet.</returns>
|
||||||
@@ -323,34 +309,35 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:查询结果集</para>
|
/// <para>说明:查询结果集</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="procedureName">Name of the procedure.</param>
|
/// <param name="procedureName">Name of the procedure.</param>
|
||||||
/// <param name="tabName">表名</param>
|
/// <param name="tabName">表名</param>
|
||||||
/// <param name="parameterNames">The parameter names.</param>
|
/// <param name="parameterNames">The parameter names.</param>
|
||||||
/// <param name="parameterValues">The parameter values.</param>
|
/// <param name="parameterValues">The parameter values.</param>
|
||||||
/// <returns>DataSet.</returns>
|
/// <returns>DataSet.</returns>
|
||||||
public static DataSet ExecuteDataSet(string procedureName, string tabName, string[] parameterNames, object[] parameterValues)
|
public static DataSet ExecuteDataSet(string procedureName, string tabName, string[] parameterNames, DbParameter[] parameterValues)
|
||||||
{
|
{
|
||||||
DataSet set2;
|
DataSet set2;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SqlCommand cmd = new SqlCommand(procedureName, _connection);
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
|
cmd.CommandText = procedureName;
|
||||||
cmd.CommandType = CommandType.StoredProcedure;
|
cmd.CommandType = CommandType.StoredProcedure;
|
||||||
|
|
||||||
if (parameterNames != null && parameterValues != null)
|
if (parameterNames != null && parameterValues != null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < parameterNames.Length && i < parameterValues.Length; i++)
|
for (int i = 0; i < parameterNames.Length && i < parameterValues.Length; i++)
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue(parameterNames[i], parameterValues[i]);
|
DbParameter dbParameter = dbFactory.CreateParameter();
|
||||||
|
dbParameter.ParameterName = parameterNames[i];
|
||||||
|
dbParameter.Value = parameterValues[i];
|
||||||
|
cmd.Parameters.Add(dbParameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
|
DbDataAdapter adapter = dbFactory.CreateDataAdapter();
|
||||||
|
adapter.SelectCommand = cmd;
|
||||||
DataSet dataSet = new DataSet();
|
DataSet dataSet = new DataSet();
|
||||||
adapter.Fill(dataSet, tabName);
|
adapter.Fill(dataSet, tabName);
|
||||||
set2 = dataSet;
|
set2 = dataSet;
|
||||||
@@ -362,30 +349,63 @@ namespace Lskj.Core
|
|||||||
return set2;
|
return set2;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ExecuteNonQuery
|
#region ExecuteNonQuery
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程</para>
|
/// <para>说明:执行sql语句或者存储过程</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType">Type of the command.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="commandParameters">The command parameters.</param>
|
||||||
/// <returns>System.Int32.</returns>
|
/// <returns>System.Int32.</returns>
|
||||||
public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
int num = 0;
|
int num = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (_connection is KdbndpConnection)
|
||||||
|
{
|
||||||
|
if (cmdType == CommandType.StoredProcedure)
|
||||||
|
{
|
||||||
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||||
|
DbDataAdapter adapter = dbFactory.CreateDataAdapter();
|
||||||
|
adapter.SelectCommand = cmd;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
adapter.Fill(dataSet);
|
||||||
|
if (dataSet.Tables.Count > 0)
|
||||||
|
{
|
||||||
|
DataTable resultTable = dataSet.Tables[dataSet.Tables.Count - 1];
|
||||||
|
int.TryParse(resultTable.Rows[0]["execcount"] + "", out num);
|
||||||
|
string returnValue = resultTable.Rows[0]["returnValue"] + "";
|
||||||
|
string outputValue = resultTable.Rows[0]["outputValue"] + "";
|
||||||
|
for (int i = 0; i < commandParameters.Length; i++)
|
||||||
|
{
|
||||||
|
DbParameter sqlParameter = commandParameters[i];
|
||||||
|
if (sqlParameter.Direction == ParameterDirection.ReturnValue)
|
||||||
|
{
|
||||||
|
sqlParameter.Value = returnValue;
|
||||||
|
}
|
||||||
|
if (sqlParameter.Direction == ParameterDirection.Output)
|
||||||
|
{
|
||||||
|
sqlParameter.Value = outputValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||||
num = cmd.ExecuteNonQuery();
|
num = cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_connection is SqlConnection)
|
||||||
|
{
|
||||||
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||||
|
num = cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -408,29 +428,63 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程,带事务</para>
|
/// <para>说明:执行sql语句或者存储过程,带事务</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType"></param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText"></param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="Trans"></param>
|
||||||
/// <returns>System.Int32.</returns>
|
/// <param name="commandParameters"></param>
|
||||||
public static int ExecuteNonQuery(CommandType cmdType, string cmdText, SqlTransaction Trans,int a ,params SqlParameter[] commandParameters)
|
/// <returns></returns>
|
||||||
|
public static int ExecuteNonQuery(CommandType cmdType, string cmdText, DbTransaction Trans, int a, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
int num = 0;
|
int num = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (_connection is KdbndpConnection)
|
||||||
|
{
|
||||||
|
if (cmdType == CommandType.StoredProcedure)
|
||||||
|
{
|
||||||
|
PrepareCommand(cmd, _connection, Trans, cmdType, cmdText, commandParameters);
|
||||||
|
DbDataAdapter adapter = dbFactory.CreateDataAdapter();
|
||||||
|
adapter.SelectCommand = cmd;
|
||||||
|
DataSet dataSet = new DataSet();
|
||||||
|
adapter.Fill(dataSet);
|
||||||
|
if (dataSet.Tables.Count > 0)
|
||||||
|
{
|
||||||
|
DataTable resultTable = dataSet.Tables[dataSet.Tables.Count - 1];
|
||||||
|
int.TryParse(resultTable.Rows[0]["execcount"] + "", out num);
|
||||||
|
string returnValue = resultTable.Rows[0]["returnValue"] + "";
|
||||||
|
string outputValue = resultTable.Rows[0]["outputValue"] + "";
|
||||||
|
for (int i = 0; i < commandParameters.Length; i++)
|
||||||
|
{
|
||||||
|
DbParameter sqlParameter = commandParameters[i];
|
||||||
|
if (sqlParameter.Direction == ParameterDirection.ReturnValue)
|
||||||
|
{
|
||||||
|
sqlParameter.Value = returnValue;
|
||||||
|
}
|
||||||
|
if (sqlParameter.Direction == ParameterDirection.Output)
|
||||||
|
{
|
||||||
|
sqlParameter.Value = outputValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
PrepareCommand(cmd, _connection, Trans, cmdType, cmdText, commandParameters);
|
PrepareCommand(cmd, _connection, Trans, cmdType, cmdText, commandParameters);
|
||||||
num = cmd.ExecuteNonQuery();
|
num = cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_connection is SqlConnection)
|
||||||
|
{
|
||||||
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||||
|
num = cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -453,15 +507,11 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程</para>
|
/// <para>说明:执行sql语句或者存储过程</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType">Type of the command.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
@@ -472,12 +522,9 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程</para>
|
/// <para>说明:执行sql语句或者存储过程</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <returns>System.Int32.</returns>
|
/// <returns>System.Int32.</returns>
|
||||||
@@ -486,29 +533,25 @@ namespace Lskj.Core
|
|||||||
return ExecuteNonQuery(CommandType.Text, cmdText);
|
return ExecuteNonQuery(CommandType.Text, cmdText);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ExecuteReader
|
#region ExecuteReader
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程并返回结果集(只读、只进)</para>
|
/// <para>说明:执行sql语句或者存储过程并返回结果集(只读、只进)</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType">Type of the command.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="commandParameters">The command parameters.</param>
|
||||||
/// <returns>SqlDataReader.</returns>
|
/// <returns>SqlDataReader.</returns>
|
||||||
public static SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
public static DbDataReader ExecuteReader(CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
SqlDataReader reader2;
|
DbDataReader reader2;
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||||
SqlDataReader reader = cmd.ExecuteReader();
|
DbDataReader reader = cmd.ExecuteReader();
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
reader2 = reader;
|
reader2 = reader;
|
||||||
}
|
}
|
||||||
@@ -519,7 +562,6 @@ namespace Lskj.Core
|
|||||||
return reader2;
|
return reader2;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ExecuteCommand
|
#region ExecuteCommand
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程并返回SqlCommand(只读、只进)</para>
|
/// <para>说明:执行sql语句或者存储过程并返回SqlCommand(只读、只进)</para>
|
||||||
@@ -534,9 +576,9 @@ namespace Lskj.Core
|
|||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="commandParameters">The command parameters.</param>
|
||||||
/// <returns>SqlDataReader.</returns>
|
/// <returns>SqlDataReader.</returns>
|
||||||
public static SqlCommand ExecuteCommand(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
public static DbCommand ExecuteCommand(CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||||
@@ -549,25 +591,21 @@ namespace Lskj.Core
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ExecuteScalar
|
#region ExecuteScalar
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Connectionection">The connectionection.</param>
|
/// <param name="Connectionection">The connectionection.</param>
|
||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType">Type of the command.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="commandParameters">The command parameters.</param>
|
||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public static object ExecuteScalar(SqlConnection Connectionection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
public static object ExecuteScalar(DbConnection Connectionection, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
PrepareCommand(cmd, Connectionection, null, cmdType, cmdText, commandParameters);
|
PrepareCommand(cmd, Connectionection, null, cmdType, cmdText, commandParameters);
|
||||||
object obj2 = cmd.ExecuteScalar();
|
object obj2 = cmd.ExecuteScalar();
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
@@ -575,29 +613,24 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType">Type of the command.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <param name="commandParameters">The command parameters.</param>
|
/// <param name="commandParameters">The command parameters.</param>
|
||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public static object ExecuteScalar(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
|
public static object ExecuteScalar(CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
{
|
|
||||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
|
||||||
object obj2 = cmd.ExecuteScalar();
|
object obj2 = cmd.ExecuteScalar();
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
return obj2;
|
return obj2;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
|
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
|
||||||
@@ -612,85 +645,66 @@ namespace Lskj.Core
|
|||||||
//throw;
|
//throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType">Type of the command.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public static object ExecuteScalar(CommandType cmdType, string cmdText)
|
public static object ExecuteScalar(CommandType cmdType, string cmdText)
|
||||||
{
|
{
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
{
|
|
||||||
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
|
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
|
||||||
object obj2 = cmd.ExecuteScalar();
|
object obj2 = cmd.ExecuteScalar();
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
return obj2;
|
return obj2;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-08-21 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public static object ExecuteScalar(string cmdText)
|
public static object ExecuteScalar(string cmdText)
|
||||||
{
|
{
|
||||||
SqlCommand cmd = new SqlCommand();
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
{
|
|
||||||
PrepareCommand(cmd, _connection, null, CommandType.Text, cmdText, null);
|
PrepareCommand(cmd, _connection, null, CommandType.Text, cmdText, null);
|
||||||
object obj2 = cmd.ExecuteScalar();
|
object obj2 = cmd.ExecuteScalar();
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
return obj2;
|
return obj2;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列,带事务</para>
|
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列,带事务</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-08-21 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText"></param>
|
||||||
/// <returns>System.Object.</returns>
|
/// <param name="Trans"></param>
|
||||||
public static object ExecuteScalar(string cmdText,SqlTransaction Trans,int a,int b)
|
/// <param name="a"></param>
|
||||||
{
|
/// <param name="b"></param>
|
||||||
SqlCommand cmd = new SqlCommand();
|
/// <returns></returns>
|
||||||
|
public static object ExecuteScalar(string cmdText, DbTransaction Trans)
|
||||||
{
|
{
|
||||||
|
DbCommand cmd = dbFactory.CreateCommand();
|
||||||
PrepareCommand(cmd, _connection, Trans, CommandType.Text, cmdText, null);
|
PrepareCommand(cmd, _connection, Trans, CommandType.Text, cmdText, null);
|
||||||
object obj2 = cmd.ExecuteScalar();
|
object obj2 = cmd.ExecuteScalar();
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
return obj2;
|
return obj2;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region PrepareCommand
|
#region PrepareCommand
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>说明:sql参数处理</para>
|
/// <para>说明:sql参数处理</para>
|
||||||
/// <para>创建人:龚宇超</para>
|
/// <para>创建者:朗速科技有限公司</para>
|
||||||
/// <para>创建日期:2017-07-24 </para>
|
/// <para>创建日期:2023-12-28 </para>
|
||||||
/// <para>修改人:</para>
|
/// <para>功能关联:公版方法</para>
|
||||||
/// <para>修改日期:</para>
|
|
||||||
/// <para>修改备注:</para>
|
|
||||||
/// <para>版本:1.0</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmd">The command.</param>
|
/// <param name="cmd">The command.</param>
|
||||||
/// <param name="Connection">The connection.</param>
|
/// <param name="Connection">The connection.</param>
|
||||||
@@ -698,7 +712,68 @@ namespace Lskj.Core
|
|||||||
/// <param name="cmdType">Type of the command.</param>
|
/// <param name="cmdType">Type of the command.</param>
|
||||||
/// <param name="cmdText">The command text.</param>
|
/// <param name="cmdText">The command text.</param>
|
||||||
/// <param name="cmdParms">The command parms.</param>
|
/// <param name="cmdParms">The command parms.</param>
|
||||||
private static void PrepareCommand(SqlCommand cmd, SqlConnection Connection, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
|
private static void PrepareCommand(DbCommand cmd, DbConnection Connection, DbTransaction trans, CommandType cmdType, string cmdText, DbParameter[] cmdParms)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (connectionType == ConnectionType.KdbnServer)
|
||||||
|
{
|
||||||
|
if (Connection.State == ConnectionState.Open)
|
||||||
|
{
|
||||||
|
Connection.Close();
|
||||||
|
}
|
||||||
|
Connection.Open();
|
||||||
|
cmd.Connection = Connection;
|
||||||
|
cmd.CommandTimeout = CommandTimeout;
|
||||||
|
cmd.CommandText = cmdText;
|
||||||
|
if (trans != null)
|
||||||
|
{
|
||||||
|
cmd.Transaction = trans;
|
||||||
|
}
|
||||||
|
DbParameter[] kdbndpParameters = CastKdbndpParameterArray(cmdParms);
|
||||||
|
if (cmdType == CommandType.StoredProcedure)
|
||||||
|
{
|
||||||
|
string execSqlParas = "";
|
||||||
|
if (cmdParms != null)
|
||||||
|
{
|
||||||
|
foreach (KdbndpParameter parameter in kdbndpParameters)
|
||||||
|
{
|
||||||
|
if (parameter.Direction == ParameterDirection.ReturnValue)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
string value = (parameter.Value + "").Replace("'", "''");
|
||||||
|
if (parameter.Direction == ParameterDirection.Output)
|
||||||
|
{
|
||||||
|
execSqlParas += $"@outputValue output,";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
execSqlParas += $"'{value}',";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.AppendLine("declare @returnValue varchar(max)");
|
||||||
|
stringBuilder.AppendLine("declare @outputValue varchar(max)");
|
||||||
|
stringBuilder.AppendLine($"exec @returnValue = {cmdText} {execSqlParas.TrimEnd(',')}");
|
||||||
|
stringBuilder.AppendLine("select @@ROWCOUNT execcount,@returnValue returnValue,@outputValue outputValue");
|
||||||
|
cmd.CommandType = CommandType.Text;
|
||||||
|
cmd.CommandText = stringBuilder.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cmd.CommandText = cmdText;
|
||||||
|
if (cmdParms != null)
|
||||||
|
{
|
||||||
|
foreach (KdbndpParameter parameter in kdbndpParameters)
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (connectionType == ConnectionType.SqlServer || connectionType == ConnectionType.DmServer)
|
||||||
{
|
{
|
||||||
if (Connection.State != ConnectionState.Open)
|
if (Connection.State != ConnectionState.Open)
|
||||||
{
|
{
|
||||||
@@ -720,6 +795,106 @@ namespace Lskj.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
/// <summary>
|
||||||
|
/// 转换为人大金仓参数集合
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="commandParameters"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DbParameter[] CastKdbndpParameterArray(DbParameter[] commandParameters)
|
||||||
|
{
|
||||||
|
if (commandParameters == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
DbParameter[] kdbndpParameters = new DbParameter[commandParameters.Length];
|
||||||
|
for (int i = 0; i < commandParameters.Length; i++)
|
||||||
|
{
|
||||||
|
DbParameter sqlParameter = commandParameters[i];
|
||||||
|
kdbndpParameters[i] = CastKdbndpParameter(sqlParameter);
|
||||||
}
|
}
|
||||||
|
return kdbndpParameters;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 转换为人大金仓参数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sqlParameter"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DbParameter CastKdbndpParameter(DbParameter parameter)
|
||||||
|
{
|
||||||
|
KdbndpParameter kdbndpParameter = new KdbndpParameter();
|
||||||
|
KdbndpDbType kdbndpDbType = KdbndpDbType.Text;
|
||||||
|
if (parameter is SqlParameter sqlParameter)
|
||||||
|
{
|
||||||
|
switch (sqlParameter.SqlDbType)
|
||||||
|
{
|
||||||
|
case SqlDbType.BigInt:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_Bigint;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Binary:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_Binary;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Bit:
|
||||||
|
kdbndpDbType = KdbndpDbType.Bit;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Char:
|
||||||
|
kdbndpDbType = KdbndpDbType.Char;
|
||||||
|
break;
|
||||||
|
case SqlDbType.DateTime:
|
||||||
|
kdbndpDbType = KdbndpDbType.DateTime;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Decimal:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_Numeric;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Float:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_Float;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Image:
|
||||||
|
kdbndpDbType = KdbndpDbType.Image;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Int:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_Int;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Money:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_Money;
|
||||||
|
break;
|
||||||
|
case SqlDbType.NChar:
|
||||||
|
kdbndpDbType = KdbndpDbType.NChar;
|
||||||
|
break;
|
||||||
|
case SqlDbType.NText:
|
||||||
|
kdbndpDbType = KdbndpDbType.Ntext;
|
||||||
|
break;
|
||||||
|
case SqlDbType.NVarChar:
|
||||||
|
kdbndpDbType = KdbndpDbType.Text;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Real:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_Real;
|
||||||
|
break;
|
||||||
|
case SqlDbType.SmallDateTime:
|
||||||
|
kdbndpDbType = KdbndpDbType.SmallDateTime;
|
||||||
|
break;
|
||||||
|
case SqlDbType.SmallInt:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_Smallint;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Text:
|
||||||
|
kdbndpDbType = KdbndpDbType.Text;
|
||||||
|
break;
|
||||||
|
case SqlDbType.Timestamp:
|
||||||
|
kdbndpDbType = KdbndpDbType.Timestamp;
|
||||||
|
break;
|
||||||
|
case SqlDbType.TinyInt:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_Tinyint;
|
||||||
|
break;
|
||||||
|
case SqlDbType.VarBinary:
|
||||||
|
kdbndpDbType = KdbndpDbType.SqlServer_VarBinary;
|
||||||
|
break;
|
||||||
|
case SqlDbType.VarChar:
|
||||||
|
kdbndp
|
||||||
Reference in New Issue
Block a user