From 43fa85e6e8c8e8da94f18b67aad89cc109e30f63 Mon Sep 17 00:00:00 2001 From: gongxh Date: Thu, 5 May 2022 13:35:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Dapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CleanMachineHMI/frmMainNew.cs | 2 +- .../LeadDataBaseUtility.csproj | 1 + LeadDataBaseUtility/LeadDbHelperSQLite.cs | 44 ++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/CleanMachineHMI/frmMainNew.cs b/CleanMachineHMI/frmMainNew.cs index fe96b49..fa87713 100644 --- a/CleanMachineHMI/frmMainNew.cs +++ b/CleanMachineHMI/frmMainNew.cs @@ -486,7 +486,7 @@ namespace CleanMachineHMI long lastTick = DateTime.Now.Ticks; while (GlobalHelper.SysThIsRunFlag) { -#if RELEASE +#if !DEBUG try { #endif diff --git a/LeadDataBaseUtility/LeadDataBaseUtility.csproj b/LeadDataBaseUtility/LeadDataBaseUtility.csproj index 5b89e90..da1018c 100644 --- a/LeadDataBaseUtility/LeadDataBaseUtility.csproj +++ b/LeadDataBaseUtility/LeadDataBaseUtility.csproj @@ -11,6 +11,7 @@ + diff --git a/LeadDataBaseUtility/LeadDbHelperSQLite.cs b/LeadDataBaseUtility/LeadDbHelperSQLite.cs index f1e94c3..34d0530 100644 --- a/LeadDataBaseUtility/LeadDbHelperSQLite.cs +++ b/LeadDataBaseUtility/LeadDbHelperSQLite.cs @@ -7,7 +7,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; - +using Dapper; namespace LeadDataBaseUtility { /// @@ -16,9 +16,27 @@ namespace LeadDataBaseUtility /// 允许修改、添加满足自己项目的需要。 /// 添加、修改后请详细注释。违者会强制删除不予采用。 /// - public abstract class LeadDbHelperSQLite + public static class LeadDbHelperSQLite { public static string connectionString = LeadConfigureConnectionString.getConnectionString("LeadSQLite"); + static LeadDbHelperSQLite() + { + + Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true; + } + + + + + public static int ExecuteSql(string sql, object param = null) + { + using (SQLiteConnection conn = new SQLiteConnection(connectionString)) + { + return conn.Execute(sql, param); + + } + } + /// /// 对SQLite数据库执行增删改操作,返回受影响的行数。 @@ -52,6 +70,18 @@ namespace LeadDataBaseUtility #endif return affectedRows; } + + public static IEnumerable Query(string Strsql, object Param = null) + { + using (SQLiteConnection connection = new SQLiteConnection(connectionString)) + { + + return connection.Query(Strsql, Param); + } + + } + + /// /// 执行查询语句,返回DataSet /// @@ -80,6 +110,16 @@ namespace LeadDataBaseUtility return ds; } } + + public static T GetSingle(string SQLString, object Param = null) + { + using (SQLiteConnection connection = new SQLiteConnection(connectionString)) + { + return connection.QueryFirstOrDefault(SQLString, Param); + } + } + + /// /// 执行一条计算查询结果语句,返回查询结果(object)。 ///