From 1294adfbfd465fe6321ccce04ed3e8a0e46fa19a Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Thu, 29 May 2025 21:46:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BA=86PLC=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml | 12 +++++- Data/DbContext.cs | 4 +- Data/Entities/PLC.cs | 64 ++++++++++++++++++++++++++++ Data/Repositories/PlcRepositories.cs | 21 +++++++++ Enums/Brand.cs | 18 ++++++++ Helper/SqlSugarHelper.cs | 26 +++++++++++ PMSWPF.csproj | 2 - ViewModels/MainViewModel.cs | 5 ++- ViewModels/PlcListViewModel.cs | 17 ++++++++ Views/MainView.xaml | 1 + Views/PlcListView.xaml | 29 +++++++++++++ Views/PlcListView.xaml.cs | 27 ++++++++++++ 12 files changed, 219 insertions(+), 7 deletions(-) create mode 100644 Data/Entities/PLC.cs create mode 100644 Data/Repositories/PlcRepositories.cs create mode 100644 Enums/Brand.cs create mode 100644 Helper/SqlSugarHelper.cs create mode 100644 ViewModels/PlcListViewModel.cs create mode 100644 Views/PlcListView.xaml create mode 100644 Views/PlcListView.xaml.cs diff --git a/App.xaml b/App.xaml index ff7637e..79923b4 100644 --- a/App.xaml +++ b/App.xaml @@ -2,6 +2,14 @@ x:Class="PMSWPF.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="clr-namespace:PMSWPF"> - + xmlns:local="clr-namespace:PMSWPF" + StartupUri="Views/PlcListView.xaml"> + + + + + + + + diff --git a/Data/DbContext.cs b/Data/DbContext.cs index a92acd2..b2b4caa 100644 --- a/Data/DbContext.cs +++ b/Data/DbContext.cs @@ -2,7 +2,7 @@ namespace PMSWPF.Data { - internal class DbContext + public class DbContext { private static SqlSugarClient _db; @@ -10,7 +10,7 @@ namespace PMSWPF.Data { if (_db == null) { - string connectionString = "server=127.0.0.1;port=3306;user=root;password=Pgw15221236646; database=PMS;"; + string connectionString = "server=127.0.0.1;port=3306;user=root;password=Pgw15221236646; database=pmswpf;"; _db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = connectionString, diff --git a/Data/Entities/PLC.cs b/Data/Entities/PLC.cs new file mode 100644 index 0000000..405cac4 --- /dev/null +++ b/Data/Entities/PLC.cs @@ -0,0 +1,64 @@ +using PMSWPF.Enums; +using SqlSugar; +using SqlSugar.DbConvert; + +namespace PMSWPF.Data.Entities +{ + public class PLC + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增 + public int id { get; set; } + /// + /// PLC名称 + /// + public string Name { get; set; } + /// + /// PLC品牌 + /// + /// //新版本:存储字符串 SqlSugar 5.1.4.66-preview02 + [SugarColumn(ColumnDataType = "varchar(30)", SqlParameterDbType = typeof(EnumToStringConvert))] + public PlcBrand PlcBrand { get; set; } + /// + /// PLC类型 + /// + public int CpuType { get; set; } + /// + /// PLC节点ID + /// + public string NodeID { get; set; } + /// + /// PLC IP地址 + /// + public string IP { get; set; } + /// + /// PLC状态 + /// + public string Status { get; set; } + /// + /// PLC连接类型 + /// + public string ConnType { get; set; } + /// + /// PLC连接时间 + /// + public DateTime ConnTime { get; set; } + /// + /// 是否启用 + /// + public bool IsEnable { get; set; } + + public PLC() + { + + } + public PLC(string name = "", string nodeID = "", string ip = "", string status = "", string connType = "") + { + this.Name = name; + this.NodeID = nodeID; + this.IP = ip; + this.Status = status; + this.ConnType = connType; + this.ConnTime = DateTime.Now; + } + } +} diff --git a/Data/Repositories/PlcRepositories.cs b/Data/Repositories/PlcRepositories.cs new file mode 100644 index 0000000..be755a9 --- /dev/null +++ b/Data/Repositories/PlcRepositories.cs @@ -0,0 +1,21 @@ +using PMSWPF.Data.Entities; +using SqlSugar; + +namespace PMSWPF.Data.Repositories +{ + internal class PlcRepositories + { + private SqlSugarClient _db; + + public PlcRepositories() + { + + _db = DbContext.GetInstance(); + var tabExist = _db.DbMaintenance.IsAnyTable(nameof(PLC), false); + if (tabExist) + { + _db.CodeFirst.InitTables(); + } + } + } +} diff --git a/Enums/Brand.cs b/Enums/Brand.cs new file mode 100644 index 0000000..6d12e2f --- /dev/null +++ b/Enums/Brand.cs @@ -0,0 +1,18 @@ +namespace PMSWPF.Enums +{ + /// + /// PLC品牌 + /// + public enum PlcBrand + { + /// + /// 西门子 + /// + Siemens = 0, + /// + /// 三菱 + /// + Melsec = 1, + + } +} diff --git a/Helper/SqlSugarHelper.cs b/Helper/SqlSugarHelper.cs new file mode 100644 index 0000000..c2f3c86 --- /dev/null +++ b/Helper/SqlSugarHelper.cs @@ -0,0 +1,26 @@ +using PMSWPF.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PMSWPF.Helper +{ + public class SqlSugarHelper + { + private DbContext _db; + + public SqlSugarHelper() { + _db=new DbContext(); + + } + + public void InitTables() + { + + } + + + } +} diff --git a/PMSWPF.csproj b/PMSWPF.csproj index 568a05b..8e041bf 100644 --- a/PMSWPF.csproj +++ b/PMSWPF.csproj @@ -22,8 +22,6 @@ - - diff --git a/ViewModels/MainViewModel.cs b/ViewModels/MainViewModel.cs index 2b41421..87419fd 100644 --- a/ViewModels/MainViewModel.cs +++ b/ViewModels/MainViewModel.cs @@ -1,13 +1,16 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; +using PMSWPF.Data.Entities; using PMSWPF.Message; +using System.Collections.ObjectModel; namespace PMSWPF.ViewModels { partial class MainViewModel : ObservableRecipient, IRecipient { + public MainViewModel() - { + { IsActive = true; } diff --git a/ViewModels/PlcListViewModel.cs b/ViewModels/PlcListViewModel.cs new file mode 100644 index 0000000..f4766b5 --- /dev/null +++ b/ViewModels/PlcListViewModel.cs @@ -0,0 +1,17 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using PMSWPF.Data.Entities; +using System.Collections.ObjectModel; + +namespace PMSWPF.ViewModels +{ + public partial class PlcListViewModel : ObservableRecipient + { + [ObservableProperty] + private ObservableCollection plcList; + public PlcListViewModel() + { + plcList = new ObservableCollection(); + + } + } +} diff --git a/Views/MainView.xaml b/Views/MainView.xaml index 8ccc508..c55a8fa 100644 --- a/Views/MainView.xaml +++ b/Views/MainView.xaml @@ -3,6 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:local="clr-namespace:PMSWPF.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" diff --git a/Views/PlcListView.xaml b/Views/PlcListView.xaml new file mode 100644 index 0000000..e0dc78a --- /dev/null +++ b/Views/PlcListView.xaml @@ -0,0 +1,29 @@ + + + + + + + + + + + + diff --git a/Views/PlcListView.xaml.cs b/Views/PlcListView.xaml.cs new file mode 100644 index 0000000..8efd747 --- /dev/null +++ b/Views/PlcListView.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace PMSWPF.Views +{ + /// + /// PlcListView.xaml 的交互逻辑 + /// + public partial class PlcListView : Window + { + public PlcListView() + { + InitializeComponent(); + } + } +}