diff --git a/Data/Entities/DbDevice.cs b/Data/Entities/DbDevice.cs new file mode 100644 index 0000000..4e755f5 --- /dev/null +++ b/Data/Entities/DbDevice.cs @@ -0,0 +1,11 @@ +namespace PMSWPF.Data.Entities; + +public class DbDevice +{ + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public bool IsActive { get; set; } + public bool IsRuning { get; set; } + +} \ No newline at end of file diff --git a/Data/Entities/PLC.cs b/Data/Entities/DbPLC.cs similarity index 91% rename from Data/Entities/PLC.cs rename to Data/Entities/DbPLC.cs index 405cac4..5b1cf42 100644 --- a/Data/Entities/PLC.cs +++ b/Data/Entities/DbPLC.cs @@ -4,7 +4,7 @@ using SqlSugar.DbConvert; namespace PMSWPF.Data.Entities { - public class PLC + public class DbPLC { [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增 public int id { get; set; } @@ -47,11 +47,11 @@ namespace PMSWPF.Data.Entities /// public bool IsEnable { get; set; } - public PLC() + public DbPLC() { } - public PLC(string name = "", string nodeID = "", string ip = "", string status = "", string connType = "") + public DbPLC(string name = "", string nodeID = "", string ip = "", string status = "", string connType = "") { this.Name = name; this.NodeID = nodeID; diff --git a/Data/Repositories/BaseRepositories.cs b/Data/Repositories/BaseRepositories.cs new file mode 100644 index 0000000..ccdc7da --- /dev/null +++ b/Data/Repositories/BaseRepositories.cs @@ -0,0 +1,13 @@ +using SqlSugar; + +namespace PMSWPF.Data.Repositories; + +public class BaseRepositories +{ + protected readonly SqlSugarClient _db; + + public BaseRepositories() + { + _db = DbContext.GetInstance(); + } +} \ No newline at end of file diff --git a/Data/Repositories/DevicesRepositories.cs b/Data/Repositories/DevicesRepositories.cs new file mode 100644 index 0000000..33fecca --- /dev/null +++ b/Data/Repositories/DevicesRepositories.cs @@ -0,0 +1,29 @@ +using PMSWPF.Data.Entities; + +namespace PMSWPF.Data.Repositories; + +public class DevicesRepositories:BaseRepositories +{ + public DevicesRepositories() + { + + } + + public async Task Add(DbPLC dbPLC) + { + return await _db.Insertable(dbPLC).ExecuteCommandAsync(); + } + + public async Task> GetAll() + { + return await _db.Queryable().ToListAsync(); + } + public async Task GetById(int id) + { + return await _db.Queryable().FirstAsync(p=>p.id == id); + } + public async Task DeleteById(int id) + { + return await _db.Deleteable(new DbPLC() { id = id }).ExecuteCommandAsync(); + } +} \ No newline at end of file diff --git a/Data/Repositories/PlcRepositories.cs b/Data/Repositories/PlcRepositories.cs index be755a9..29e2375 100644 --- a/Data/Repositories/PlcRepositories.cs +++ b/Data/Repositories/PlcRepositories.cs @@ -11,10 +11,10 @@ namespace PMSWPF.Data.Repositories { _db = DbContext.GetInstance(); - var tabExist = _db.DbMaintenance.IsAnyTable(nameof(PLC), false); + var tabExist = _db.DbMaintenance.IsAnyTable(nameof(DbPLC), false); if (tabExist) { - _db.CodeFirst.InitTables(); + _db.CodeFirst.InitTables(); } } } diff --git a/Models/Device.cs b/Models/Device.cs new file mode 100644 index 0000000..b35156d --- /dev/null +++ b/Models/Device.cs @@ -0,0 +1,6 @@ +namespace PMSWPF.Models; + +public class Device +{ + +} \ No newline at end of file diff --git a/PMSWPF.csproj b/PMSWPF.csproj index 5d0efd2..4fef5c5 100644 --- a/PMSWPF.csproj +++ b/PMSWPF.csproj @@ -18,7 +18,6 @@ - diff --git a/ViewModels/DevicesViewModel.cs b/ViewModels/DevicesViewModel.cs index 6301f9f..d8d3171 100644 --- a/ViewModels/DevicesViewModel.cs +++ b/ViewModels/DevicesViewModel.cs @@ -2,5 +2,11 @@ public class DevicesViewModel:ViewModelBase { + public DevicesViewModel() + { + + } + + } \ No newline at end of file diff --git a/Views/DevicesView.xaml b/Views/DevicesView.xaml index 3b405cc..4d01eb0 100644 --- a/Views/DevicesView.xaml +++ b/Views/DevicesView.xaml @@ -6,7 +6,10 @@ xmlns:local="clr-namespace:PMSWPF.Views" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> - + + +