EquipmentService.cs
1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using CNCFanucDataReading;
using FreeSql;
using FreeSql.Internal;
using System;
using System.Threading.Tasks;
namespace CNCFanucDataReading
{
public class EquipmentService : IDisposable
{
private readonly IFreeSql _fsql;
private bool _disposed = false;
public EquipmentService(string connectionString)
{
if (string.IsNullOrEmpty(connectionString))
throw new ArgumentException("数据库连接字符串不能为空", nameof(connectionString));
_fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.SqlServer, connectionString)
.UseAutoSyncStructure(false) // 自动同步实体结构到数据库
.Build();
}
/// <summary>
/// 获取设备列表
/// </summary>
public async Task<List<BaseEquipment>> GetList()
{
try
{
var projectGuid = Guid.Parse(AppConfig.ProjectKeys);
return await _fsql.Select<BaseEquipment>()
.Where(a => a.ProjectKeys == projectGuid //长沙项目
&& a.FactoryCode == AppConfig.FactoryCode//3厂房
&& a.EquipmentTypeCode == AppConfig.EquipmentTypeCode)//CNC机床
.OrderBy(e => e.EquipmentCode)
.ToListAsync();
}
catch (Exception ex)
{
throw;
}
}
public void Dispose()
{
if (!_disposed)
{
_fsql?.Dispose();
_disposed = true;
}
}
}
}