创建了PLC相关的文件
This commit is contained in:
12
App.xaml
12
App.xaml
@@ -2,6 +2,14 @@
|
|||||||
x:Class="PMSWPF.App"
|
x:Class="PMSWPF.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="clr-namespace:PMSWPF">
|
xmlns:local="clr-namespace:PMSWPF"
|
||||||
<Application.Resources />
|
StartupUri="Views/PlcListView.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml" />
|
||||||
|
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml" />
|
||||||
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace PMSWPF.Data
|
namespace PMSWPF.Data
|
||||||
{
|
{
|
||||||
internal class DbContext
|
public class DbContext
|
||||||
{
|
{
|
||||||
private static SqlSugarClient _db;
|
private static SqlSugarClient _db;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ namespace PMSWPF.Data
|
|||||||
{
|
{
|
||||||
if (_db == null)
|
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()
|
_db = new SqlSugarClient(new ConnectionConfig()
|
||||||
{
|
{
|
||||||
ConnectionString = connectionString,
|
ConnectionString = connectionString,
|
||||||
|
|||||||
64
Data/Entities/PLC.cs
Normal file
64
Data/Entities/PLC.cs
Normal file
@@ -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; }
|
||||||
|
/// <summary>
|
||||||
|
/// PLC名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// PLC品牌
|
||||||
|
/// </summary>
|
||||||
|
/// //新版本:存储字符串 SqlSugar 5.1.4.66-preview02
|
||||||
|
[SugarColumn(ColumnDataType = "varchar(30)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||||
|
public PlcBrand PlcBrand { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// PLC类型
|
||||||
|
/// </summary>
|
||||||
|
public int CpuType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// PLC节点ID
|
||||||
|
/// </summary>
|
||||||
|
public string NodeID { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// PLC IP地址
|
||||||
|
/// </summary>
|
||||||
|
public string IP { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// PLC状态
|
||||||
|
/// </summary>
|
||||||
|
public string Status { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// PLC连接类型
|
||||||
|
/// </summary>
|
||||||
|
public string ConnType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// PLC连接时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime ConnTime { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 是否启用
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
Data/Repositories/PlcRepositories.cs
Normal file
21
Data/Repositories/PlcRepositories.cs
Normal file
@@ -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<PLC>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Enums/Brand.cs
Normal file
18
Enums/Brand.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace PMSWPF.Enums
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// PLC品牌
|
||||||
|
/// </summary>
|
||||||
|
public enum PlcBrand
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 西门子
|
||||||
|
/// </summary>
|
||||||
|
Siemens = 0,
|
||||||
|
/// <summary>
|
||||||
|
/// 三菱
|
||||||
|
/// </summary>
|
||||||
|
Melsec = 1,
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
26
Helper/SqlSugarHelper.cs
Normal file
26
Helper/SqlSugarHelper.cs
Normal file
@@ -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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,8 +22,6 @@
|
|||||||
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.193" />
|
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.193" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Data\Entities\" />
|
|
||||||
<Folder Include="Data\Repositories\" />
|
|
||||||
<Folder Include="Models\" />
|
<Folder Include="Models\" />
|
||||||
<Folder Include="Resources\" />
|
<Folder Include="Resources\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Messaging;
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
|
using PMSWPF.Data.Entities;
|
||||||
using PMSWPF.Message;
|
using PMSWPF.Message;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
namespace PMSWPF.ViewModels
|
namespace PMSWPF.ViewModels
|
||||||
{
|
{
|
||||||
partial class MainViewModel : ObservableRecipient, IRecipient<MyMessage>
|
partial class MainViewModel : ObservableRecipient, IRecipient<MyMessage>
|
||||||
{
|
{
|
||||||
|
|
||||||
public MainViewModel()
|
public MainViewModel()
|
||||||
{
|
{
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
|
|||||||
17
ViewModels/PlcListViewModel.cs
Normal file
17
ViewModels/PlcListViewModel.cs
Normal file
@@ -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<PLC> plcList;
|
||||||
|
public PlcListViewModel()
|
||||||
|
{
|
||||||
|
plcList = new ObservableCollection<PLC>();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
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:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
xmlns:local="clr-namespace:PMSWPF.Views"
|
xmlns:local="clr-namespace:PMSWPF.Views"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
|||||||
29
Views/PlcListView.xaml
Normal file
29
Views/PlcListView.xaml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<Window
|
||||||
|
x:Class="PMSWPF.Views.PlcListView"
|
||||||
|
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:local="clr-namespace:PMSWPF.Views"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
||||||
|
Title="PlcListView"
|
||||||
|
Width="800"
|
||||||
|
Height="450"
|
||||||
|
d:DataContext="{d:DesignInstance vm:PlcListViewModel}"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
<StackPanel>
|
||||||
|
<StackPanel Height="auto" />
|
||||||
|
<DataGrid
|
||||||
|
AutoGenerateColumns="False"
|
||||||
|
CanUserAddRows="True"
|
||||||
|
CanUserDeleteRows="True"
|
||||||
|
ItemsSource="{Binding PlcList}">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Binding="{Binding Path=Name}" Header="名称" />
|
||||||
|
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
</Window>
|
||||||
27
Views/PlcListView.xaml.cs
Normal file
27
Views/PlcListView.xaml.cs
Normal file
@@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// PlcListView.xaml 的交互逻辑
|
||||||
|
/// </summary>
|
||||||
|
public partial class PlcListView : Window
|
||||||
|
{
|
||||||
|
public PlcListView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user