You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
7.2 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using SlnMesnac.RfidUpload.Model;
using SlnMesnac.RfidUpload.NLog;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
#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 readonly LogHelper logger = LogHelper.Instance;
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
});
}
#region 数据重传表相关操作
/// <summary>
/// 插入记录
/// </summary>
/// <param name="printRecord"></param>
/// <returns></returns>
public int InsertRecord(UploadRecord record)
{
int result = db.Insertable(record).ExecuteCommand();
return result;
}
/// <summary>
/// 查询记录列表--不包含strList字段
/// </summary>
/// <param name="printRecord"></param>
/// <returns></returns>
public List<UploadRecord> GetRecordList()
{
List<UploadRecord> list;
list = db.SqlQueryable<UploadRecord>("select id,UPLOAD_RECORD.ffjhNo,opBatch,ffjhscrq,stationOrgCode,stationOrgName,strList,isSuccess from UPLOAD_RECORD").ToList();
return list;
}
/// <summary>
/// 根据封发计划编号查询记录
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public UploadRecord GetRecordByFfjhNo(string ffjhNo)
{
UploadRecord record = db.SqlQueryable<UploadRecord>($"select * from UPLOAD_RECORD where ffjhNo='{ffjhNo}'").ToList().FirstOrDefault();
return record;
}
/// <summary>
/// 插入记录
/// </summary>
/// <param name="printRecord"></param>
/// <returns></returns>
public int InsertPrintCode(UploadRecord record)
{
int result = db.Insertable<UploadRecord>(record).ExecuteCommand();
return result;
}
/// <summary>
/// 根据封发计划编号改变上传记录上传结果
/// </summary>
/// <param name="printRecord"></param>
/// <returns></returns>
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<UploadRecord>(sql).ExecuteCommand();
return result;
}
#endregion
#region RFID数据表相关操作
/// <summary>
/// 根据调拨单号、送货单号、分发计划编号获取批次号
/// </summary>
/// <param name="printRecord"></param>
/// <returns></returns>
public int GetBatchNo(string code)
{
try
{
BatchNoInfo? batchNoInfo = db.Queryable<BatchNoInfo>().First(x => x.code == code);
if (batchNoInfo == null)
{
batchNoInfo = new BatchNoInfo();
batchNoInfo.Id = Guid.NewGuid().ToString();
batchNoInfo.code = code;
batchNoInfo.batchNo = 1;
batchNoInfo.RecordTime = DateTime.Now.ToString();
int result = db.Insertable(batchNoInfo).ExecuteCommand();
}
return batchNoInfo.batchNo;
}catch(Exception ex)
{
return 1;
}
}
public void AddBatchNo(string code)
{
try
{
BatchNoInfo? batchNoInfo = db.Queryable<BatchNoInfo>().First(x => x.code == code);
if (batchNoInfo != null)
{
batchNoInfo.batchNo += 1;
batchNoInfo.RecordTime = DateTime.Now.ToString();
db.Updateable(batchNoInfo).ExecuteCommand();
}
}catch(Exception ex)
{
}
}
/// <summary>
/// 查询记录列表--不包含strList字段
/// </summary>
/// <param name="printRecord"></param>
/// <returns></returns>
public List<RfidInfo> GetRFIDList()
{
List<RfidInfo> list;
list = db.Queryable<RfidInfo>().ToList();
return list;
}
/// <summary>
/// 删除所有RFID
/// </summary>
/// <param name="printRecord"></param>
/// <returns></returns>
public bool DeleteRFIDList()
{
int count = db.Deleteable<RfidInfo>().ExecuteCommand();
return count>0? true : false;
}
/// <summary>
/// 插入一条RFID
/// </summary>
/// <param name="printRecord"></param>
/// <returns></returns>
public int InsertRFID(RfidInfo record)
{
int result = db.Insertable<RfidInfo>(record).ExecuteCommand();
return result;
}
/// <summary>
/// 插入RFID集合
/// </summary>
/// <param name="printRecord"></param>
/// <returns></returns>
public int InsertRFIDList(List<RfidInfo> list)
{
int result = db.Insertable<RfidInfo>(list).ExecuteCommand();
return result;
}
#endregion
}
}