店铺优化功能优化
This commit is contained in:
1 parent
5e0a54a8ba
commit
16342df70a
22 files changed
+1121
-442
No files matched your search
@@ -58,21 +58,21 @@ namespace KJD_Web.Utils
|
||||
/// </summary>
|
||||
public bool IsRunning = false;
|
||||
|
||||
public bool IsUseTrans { get; set; } = false;
|
||||
public MySqlTransaction Transaction { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化数据库链接
|
||||
/// </summary>
|
||||
/// <param name="connString">数据库链接</param>
|
||||
public MysqlUtils(string connString)
|
||||
public MysqlUtils(string connString, bool isUseTrans = false)
|
||||
{
|
||||
this.IsUseTrans = isUseTrans;
|
||||
|
||||
ConnString = connString;
|
||||
ConnTo();
|
||||
}
|
||||
|
||||
public void BeginTransaction()
|
||||
{
|
||||
Conn.BeginTransaction();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 去掉SQL中的特殊字符
|
||||
/// </summary>
|
||||
@@ -112,6 +112,15 @@ namespace KJD_Web.Utils
|
||||
return value;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 开放一个Conn获取路径,以便外部使用事务提交
|
||||
///// </summary>
|
||||
//public MySqlConnection GetConn()
|
||||
//{
|
||||
// //Transaction = Conn.BeginTransaction();
|
||||
// return Conn;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 插入数据
|
||||
/// </summary>
|
||||
@@ -662,24 +671,24 @@ namespace KJD_Web.Utils
|
||||
cmd.Connection = Conn;
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.CommandTimeout = TimeOut;
|
||||
}
|
||||
|
||||
public MySqlTransaction Transaction { get; set; } = null;
|
||||
if (Transaction != null)
|
||||
cmd.Transaction = Transaction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接数据库
|
||||
/// </summary>
|
||||
private void ConnTo(bool isTransaction = false)
|
||||
private void ConnTo()
|
||||
{
|
||||
Close();
|
||||
try
|
||||
{
|
||||
Conn = new MySqlConnection(ConnString);
|
||||
Conn.Open();
|
||||
if (isTransaction)
|
||||
{
|
||||
Conn.BeginTransaction();
|
||||
}
|
||||
|
||||
if (IsUseTrans)
|
||||
this.Transaction = Conn.BeginTransaction();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -711,6 +720,18 @@ namespace KJD_Web.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
if (Transaction != null)
|
||||
Transaction.Commit();
|
||||
}
|
||||
|
||||
public void RollBack()
|
||||
{
|
||||
if (Transaction != null)
|
||||
Transaction.Rollback();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭数据库链接
|
||||
/// </summary>
|
||||
@@ -720,7 +741,9 @@ namespace KJD_Web.Utils
|
||||
try
|
||||
{
|
||||
if (Conn != null && Conn.State == ConnectionState.Open)
|
||||
{
|
||||
Conn.Close();
|
||||
}
|
||||
Conn = null;
|
||||
|
||||
try
|
||||
@@ -732,6 +755,16 @@ namespace KJD_Web.Utils
|
||||
{
|
||||
}
|
||||
reader = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (Transaction != null)
|
||||
Transaction.Dispose();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
Transaction = null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user