diff --git a/JinYuan.ControlCenter/ControlCenter_Plc.cs b/JinYuan.ControlCenter/ControlCenter_Plc.cs
index 5860d4b..006032b 100644
--- a/JinYuan.ControlCenter/ControlCenter_Plc.cs
+++ b/JinYuan.ControlCenter/ControlCenter_Plc.cs
@@ -525,8 +525,6 @@ namespace JinYuan.ControlCenters
LogHelper.Instance.WriteLog($"[{logName}] 反馈PLC结果:{string.Join(",", listRes)}", logName);
-
-
bool writeResult = CommonMethods.plcDevices[pf.PlcNum - 1].WriteInt16(pf.VarList[0].VarAddress, 0);
LogHelper.Instance.WriteLog($"[{logName}] 清0结果:{writeResult}", logName);
#endregion
diff --git a/JinYuan.DAL/SQLSugarService.cs b/JinYuan.DAL/SQLSugarService.cs
index 573e3e2..6174c1d 100644
--- a/JinYuan.DAL/SQLSugarService.cs
+++ b/JinYuan.DAL/SQLSugarService.cs
@@ -356,21 +356,28 @@ namespace JinYuan.DAL
///
///
public Task QueryAsync(Expression> whereLambda = null) where T : class, new()
+ {
+ return QueryAsyncImpl(whereLambda);
+ }
+
+ private async Task QueryAsyncImpl(Expression> whereLambda = null) where T : class, new()
{
try
{
- ISugarQueryable up = SqlSugarDb.Queryable().With(SqlWith.NoLock);
- if (whereLambda != null)
+ var config = SqlSugarDb.CurrentConnectionConfig;
+ using (var db = new SqlSugarClient(new ConnectionConfig()
{
- up = up.Where(whereLambda);
+ ConnectionString = config.ConnectionString,
+ DbType = config.DbType,
+ IsAutoCloseConnection = true
+ }))
+ {
+ var up = db.Queryable().With(SqlWith.NoLock);
+ if (whereLambda != null) up = up.Where(whereLambda);
+ return await up.FirstAsync();
}
- return up.FirstAsync();
}
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
-
+ catch (Exception ex) { throw new Exception(ex.Message); }
}
///
@@ -505,7 +512,7 @@ namespace JinYuan.DAL
{
up = up.Where(whereLambda);
}
- if (sort != "")
+ if (!string.IsNullOrEmpty(sort))
{
var orderBys = ParseOrderBy(sort, byType);
up = up.OrderBy(orderBys).Take(Take);
@@ -537,7 +544,7 @@ namespace JinYuan.DAL
{
up = up.Where(whereLambda);
}
- if (sort != "")
+ if (!string.IsNullOrEmpty(sort))
{
var orderBys = ParseOrderBy(sort, byType);
up = up.OrderBy(orderBys);
@@ -876,14 +883,18 @@ namespace JinYuan.DAL
{
try
{
- var result = await SqlSugarDb.Insertable(entity).With(SqlWith.UpdLock).ExecuteCommandAsync() > 0;
- return result;
+ var config = SqlSugarDb.CurrentConnectionConfig;
+ using (var db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = config.ConnectionString,
+ DbType = config.DbType,
+ IsAutoCloseConnection = true
+ }))
+ {
+ return await db.Insertable(entity).With(SqlWith.UpdLock).ExecuteCommandAsync() > 0;
+ }
}
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
-
+ catch (Exception ex) { throw new Exception(ex.Message); }
}
///
@@ -912,15 +923,18 @@ namespace JinYuan.DAL
{
try
{
- //var result = await SqlSugarDb.Insertable(entitys).With(SqlWith.UpdLock).ExecuteCommandAsync() > 0;
- var result = await SqlSugarDb.Insertable(entitys).ExecuteCommandAsync() > 0;
- return result;
+ var config = SqlSugarDb.CurrentConnectionConfig;
+ using (var db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = config.ConnectionString,
+ DbType = config.DbType,
+ IsAutoCloseConnection = true
+ }))
+ {
+ return await db.Insertable(entitys).ExecuteCommandAsync() > 0;
+ }
}
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
-
+ catch (Exception ex) { throw new Exception(ex.Message); }
}
#endregion
@@ -1104,23 +1118,21 @@ namespace JinYuan.DAL
{
try
{
- IUpdateable up = SqlSugarDb.Updateable().SetColumns(update);
- if (where != null)
+ var config = SqlSugarDb.CurrentConnectionConfig;
+ using (var db = new SqlSugarClient(new ConnectionConfig()
{
- up = up.Where(where);
- }
- if (isLock)
+ ConnectionString = config.ConnectionString,
+ DbType = config.DbType,
+ IsAutoCloseConnection = true
+ }))
{
- up = up.With(SqlWith.UpdLock);
+ var up = db.Updateable().SetColumns(update);
+ if (where != null) up = up.Where(where);
+ if (isLock) up = up.With(SqlWith.UpdLock);
+ return await up.ExecuteCommandAsync();
}
- var result = await up.ExecuteCommandAsync();
- return result;
- }
- catch (Exception ex)
- {
-
- throw new Exception(ex.Message);
}
+ catch (Exception ex) { throw new Exception(ex.Message); }
}
@@ -1178,30 +1190,22 @@ namespace JinYuan.DAL
{
try
{
- // 每次获取新的 SqlSugarScope 实例,避免多线程冲突
- // IsAutoCloseConnection = true 已配置,无需using语句
-
- IUpdateable up = SqlSugarDb.Updateable(entity);
- if (IgnoreColumns != null)
+ var config = SqlSugarDb.CurrentConnectionConfig;
+ using (var db = new SqlSugarClient(new ConnectionConfig()
{
- up = up.UpdateColumns(IgnoreColumns);
- }
- if (where != null)
+ ConnectionString = config.ConnectionString,
+ DbType = config.DbType,
+ IsAutoCloseConnection = true
+ }))
{
- up = up.Where(where);
+ var up = db.Updateable(entity);
+ if (IgnoreColumns != null) up = up.UpdateColumns(IgnoreColumns);
+ if (where != null) up = up.Where(where);
+ if (isLock) up = up.With(SqlWith.UpdLock);
+ return await up.ExecuteCommandAsync();
}
- if (isLock)
- {
- up = up.With(SqlWith.UpdLock);
- }
- var result = await up.ExecuteCommandAsync();
- return result;
}
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
-
+ catch (Exception ex) { throw new Exception(ex.Message); }
}
@@ -1535,20 +1539,24 @@ namespace JinYuan.DAL
///
///
///
- public Task DeleteAsync(Expression> where, bool isLock = true) where T : class, new()
+ public async Task DeleteAsync(Expression> where, bool isLock = true) where T : class, new()
{
try
{
- var result = isLock ?
- SqlSugarDb.Deleteable().Where(where).With(SqlWith.RowLock).ExecuteCommandAsync()
- : SqlSugarDb.Deleteable().Where(where).ExecuteCommandAsync();
- return result;
- }
- catch (Exception ex)
- {
-
- throw new Exception(ex.Message);
+ var config = SqlSugarDb.CurrentConnectionConfig;
+ using (var db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = config.ConnectionString,
+ DbType = config.DbType,
+ IsAutoCloseConnection = true
+ }))
+ {
+ return isLock
+ ? await db.Deleteable().Where(where).With(SqlWith.RowLock).ExecuteCommandAsync()
+ : await db.Deleteable().Where(where).ExecuteCommandAsync();
+ }
}
+ catch (Exception ex) { throw new Exception(ex.Message); }
}
diff --git a/LargeSquareOne/FrmDataMonitor.cs b/LargeSquareOne/FrmDataMonitor.cs
index 45a1e23..c8ab1dd 100644
--- a/LargeSquareOne/FrmDataMonitor.cs
+++ b/LargeSquareOne/FrmDataMonitor.cs
@@ -965,31 +965,6 @@ namespace LargeSquareOne
{
new FrmMsgBoxWithAck("批量复投条码个数>8, 请单个复投", "提示").ShowDialog();
}
- //if (CommonMethods.isRepeat)
- //{
- // for (int i = 0; i < CommonMethods.repeatCodeList.Count; i++)
- // {
- // string code = CommonMethods.repeatCodeList[i];//取出队列数据
- // if (code.Length > 11) //手持扫码枪的条码格式结尾带字符,到时候根据那个结尾字符判断
- // {
- // if (counter > 8) counter = 1; // 循环计数(1-8)
- // // 将计数值写入PLC的D9050地址(16位整数)
- // CommonMethods.plcDevices[0]?.WriteValue("D9050", counter, PLC.DataType.Int);
- // // 写入条码到D9000
- // JYResult result1 = CommonMethods.plcDevices[0].WriteValue(
- // "D9000",
- // code,
- // PLC.DataType.String
- // );
- // Thread.Sleep(150);
- // if (result1 == null)
- // {
- // CommonMethods.AddDataMonitorLog(2, "条码复投失败".Translated() + ":" + code);
- // }
- // counter++; // 计数器递增
- // }
- // }
- //}
}
else if (checkBox4.Checked)//已包蓝膜
{