using SlnMesnac.RfidUpload.Model;
using SlnMesnac.RfidUpload.NLog;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2024 WenJY 保留所有权利。
* CLR版本:4.0.30319.42000
* 机器名称:T14-GEN3-7895
* 命名空间:slnmesnac.rfidupload.Repository
* 唯一标识:af6b459e-40d9-4e83-97e6-0b17f28044e5
*
* 创建者:WenJY
* 电子邮箱:
* 创建时间:2024-12-06 9:01:34
* 版本:V1.0.0
* 描述:
*
*--------------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本:V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace slnmesnac.rfidupload.Repository
{
public class SqlSugarHelper
{
private static SqlSugarHelper instance = null;
private static readonly object padlock = new object();
private SqlSugarHelper() { }
public static SqlSugarHelper Instance
{
get
{
lock (padlock)
{
if (instance == null)
instance = new SqlSugarHelper();
return instance;
}
}
}
public static string url = System.Environment.CurrentDirectory + "/db/";
static string ConnectionString1 = $"Data Source={url}/hw.db";
public static SqlSugarClient db
{
get => new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = $"Data Source={url}/hw.db",
DbType = SqlSugar.DbType.Sqlite, //必填, 数据库类型
IsAutoCloseConnection = true, //默认false, 时候知道关闭数据库连接, 设置为true无需使用using或者Close操作
InitKeyType = InitKeyType.SystemTable //默认SystemTable, codefist需要使用Attribute
});
}
///
/// 插入记录
///
///
///
public int InsertRecord(UploadRecord record)
{
int result = db.Insertable(record).ExecuteCommand();
return result;
}
///
/// 查询记录列表--不包含strList字段
///
///
///
public List GetRecordList()
{
List list;
list = db.SqlQueryable("select id,UPLOAD_RECORD.ffjhNo,opBatch,ffjhscrq,stationOrgCode,stationOrgName,strList,isSuccess from UPLOAD_RECORD").ToList();
return list;
}
///
/// 根据封发计划编号查询记录
///
///
///
public UploadRecord GetRecordByFfjhNo(string ffjhNo)
{
UploadRecord record = db.SqlQueryable($"select * from UPLOAD_RECORD where ffjhNo='{ffjhNo}'").ToList().FirstOrDefault();
return record;
}
///
/// 插入记录
///
///
///
public int InsertPrintCode(UploadRecord record)
{
int result = db.Insertable(record).ExecuteCommand();
return result;
}
///
/// 根据封发计划编号改变上传记录上传结果
///
///
///
public int updateRecordByFfjhNo(string ffjhNo,bool uploadResult)
{
int flag = uploadResult ? 1 : 0;
string sql = $"UPDATE UPLOAD_RECORD SET isSuccess = {flag} WHERE ffjhNo = {ffjhNo}";
int result = db.Updateable(sql).ExecuteCommand();
return result;
}
}
}